Repository navigation
refactor(ir): calc lowering moves to lower.ToCalc, the runtime holds a program.Calc - #2146
Open
devin-ai-integration[bot] wants to merge 5 commits into
Open
devin-ai-integration[bot] wants to merge 5 commits into
devin-ai-integration[bot] wants to merge 5 commits into
Conversation
…a program.Calc calcShape becomes program.Calc built by lower.ToCalc; its body, bindings and expressions stay on the lower side as CalcTrees indexed by ExprID until expressions are lowered. The runtime wraps the record in loadedCalc with what it builds per calc (write targets, tool, compiled tier) and memoizes by symbol as before; compileBatch.callees is keyed by *program.Calc. Co-Authored-By: jason.han <hanhuijun@gmail.com>
…nd loadedCalc The spec-compliance sources name the functions that implement each rule; the calc interface now lowers in lower/calc.go and is held by the runtime's loadedCalc. Co-Authored-By: jason.han <hanhuijun@gmail.com>
The compliance maps name file:function pairs that a hygiene test checks against the tree; the calc chain, parameters, result binding and predicate classification now live in lower/calc.go and program/calc.go, and the runtime's record is loadedCalc. Drops Context.calcMemberDeclOf, left unused by the move. Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Step 5 of the execution-owned IR migration (
docs/internals/execution-ir-design.md, "Migration as a stack of pull requests", row 5), stacked on #2137 (feat/ir-program-ids). Merge order: #2137 first; this PR is then retargeted todevelop.Calc lowering leaves the runtime.
runtime.calcShape— the flattened invocation interface the runtime built fromsymbol.Declininvoke_calc.go— becomesprogram.Calc, built bylower.ToCalc. The runtime wraps the record inloadedCalc(the state only the runtime has: the compiled tier and its eligibility, the tool binding, member-declaration metadata, per-run statement orders) and keeps memoizing by symbol inModel.calcShapes/Model.predicateShapes.compileBatch.calleesis keyed by*program.Calc; the batch keeps a*program.Calc → *loadedCalcmap (held) for the runtime state it settles.What
program.Calcholds and what it defersPer the design's "Expressions" section,
programimports nothing frominternal/syntax/ast(the layering test pins it) and expressions are not lowered until steps 6a/6b. So:internal/ir/program/calc.go): the calc symbol, itsOrigin, qualifiedName,KindandLabel; the specializationChain; the positionalParams(name, owner, declaring symbol, theCalcMemberdeclarations along the chain, subject/actor/calc flags);ParamNamesand the redefinitionAliases; theOutputs(name, owner, declarations, result/in-out/initial flags);BodyOwnerandBodyOutputs;Returns,StepsReturn,StepCount.program.ExprID: every expression — a parameter'sDefault, an output'sValue, theResultexpression — is an opaque id (dense from 1, 0 = none) into a per-calc table.lowerside (lower.CalcTrees): the body statements and theirStatementOrder, the steps, the bodyNodesandBindings, and theExprID → ast.Nodetable (CalcTrees.Expr). The runtime reads an expression throughloadedCalc.Expr(id)exactly where it read theast.Nodefield before, so evaluation, error timing and error text are unchanged.Public surface added
internal/ir/program:Calc,CalcParam,CalcOutput,CalcMember,ResultOutputName,Canonical,AliasRedefined; methodsCalc.ResultOutputIndex/ResultOutput/HasInitialOutput/IsCase/Performs/BodyScope/Parameter/HasParameter/SubjectParameter/PositionalIndexes/PositionalArity/OutputNames/UsageSpelling.internal/ir/lower:CalcEnv,CalcTrees(+Expr),ToCalc,ToPredicate,ToCalcSignature,CalcChain,CalcKind,CalcStatesComputation,UnboundResultHint,DefaultValueOf,IsCalcDecl,IsPredicateDecl,PredicateKind,IsCalcUsageSymbol,UnwrappedDeclMembers,EachUnwrappedDeclMember,SubjectDecl,SubjectDeclaration.Nothing from #2137's API changed.
Where the design met the code
invoke_predicate.go) sharedcalcShape; they lower throughlower.ToPredicate, so the runtime keeps one record type and no second AST-reading constructor.resolveLibraryPerformance) built a bodilesscalcShape; that islower.ToCalcSignature.tests/perfcalc benchmarks", but no benchmark intests/perfmatches-bench Calc; the calc-invoking benchmarks areBenchmarkREPLEvalExpr,BenchmarkGRPCEvaluateandBenchmarkConnectEvaluateHTTP(each evaluatesPerf::Calc1(2.0, 3.0)), reported below.lower/calc.go,program/calc.goandloadedCalc.Baselines
None moved: no conformance
.expected.json, golden trace,testdata/compiledfile, corpus ratchet or pilot-differential record changed.How it was verified
Full gate on the head (base
feat/ir-program-idsmerged in with--no-ff):go build ./...,go vet ./...,gofmt -l .(empty),make lint,go test ./...,go test -count=1 ./tests/corpus -run 'TestTrainingExamples|TestPilotCorpora'with both corpora fetched,go test -count=1 ./tests/hygiene,go test -C tools ./..., and the two-line-comment check over the diff (prints nothing). New unit tests ininternal/ir/lower/calc_test.gopin the chain/interface lowering, the chained-assignment rule and the dense, deterministic expression ids.Benchmarks (
go test ./tests/perf -run '^$' -bench 'REPLEvalExpr|GRPCEvaluate|ConnectEvaluateHTTP' -benchmem,benchstat, basefeat/ir-program-idsvs this head):Three interleaved comparisons on the same box (n=6, n=8, n=4); benchstat finds no difference the noise does not explain, and the allocation profile is byte- and count-identical:
The wall-clock spread (±25–44%) is the shared runner, not the change: the earlier n=6 comparison put this head at −13% geomean, this one at +6%, both inside the interval.
Pilot execution differential (
go run -C tools ./cmd/pilot-exec-diff, evaluator provisioned): agree 229 · kind-only 1 · order-only 0 · disagree 38 · differs-by-design 5 · pilot-unevaluated 167 · pilot-silent 24 · pilot-error 7 · ours-error 10 · ours-undetermined 17 · both-error 16 · nondeterministic 0 (514 cases) — identical to the committed record indocs/project/pilot-execution-referee.md.Checklist
make testandmake lintpass locallychanges/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.md— internal refactor, no user-visible changemake docs-countsrun if a gate count moved (compliance rows need nothing: the census is counted at docs build) — nothing movedF4,K5) in the body, docs, or changelogLink to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/d00fc0ddec284f26b9cb865143821490
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/d00fc0ddec284f26b9cb865143821490?variant=devin
Requested by: @HuiJun
🟢 Devin Review found nothing to fix · View findings