refactor(compiler): keep direct params as values#50
Merged
Conversation
Keep direct-call scalar params in SSA form inside the callee by default and only materialize slots when semantics require addressable storage. Preserve aliased range accumulator behavior by tracking only aliased direct params in function-lowering state instead of eagerly spilling all direct params. Tighten conditional pre-promotion to indirect call arguments only and add focused compiler/math coverage for direct param SSA handling, nested direct calls, and empty-range alias semantics.
Clear aliased direct-param state once promotion materializes a slot, simplify direct named call-arg lowering to avoid redundant dereference work, and add an explicit invariant panic when a validated named direct arg is unexpectedly missing from scope. Also document why code-scope bindings bypass param-alias resolution. Re-ran go test ./compiler and python3 test.py tests/math.
Replace the one-field function-lowering wrapper with a direct param alias stack on Compiler while keeping FuncNameMangled on the existing local save/restore path in compileFunc. This preserves the same alias lifetime semantics with less structure and indirection. Validation: PATH=/opt/homebrew/bin:/Users/tejas/.codex/tmp/arg0/codex-arg0Opgoyz:/Users/tejas/.bun/bin:/Users/tejas/.bun/bin:/Users/tejas/.antigravity/antigravity/bin:/opt/homebrew/opt/lld/bin:/opt/homebrew/opt/llvm/bin:/opt/homebrew/opt/tcl-tk/bin:/Users/tejas/.juliaup/bin:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/pkg/env/active/bin:/opt/pmk/env/global/bin:/Library/Apple/usr/bin:/Library/TeX/texbin:/Applications/Codex.app/Contents/Resources /opt/homebrew/bin/go test ./compiler; PATH=/opt/homebrew/bin:/opt/homebrew/opt/llvm/bin:/Users/tejas/.codex/tmp/arg0/codex-arg0Opgoyz:/Users/tejas/.bun/bin:/Users/tejas/.bun/bin:/Users/tejas/.antigravity/antigravity/bin:/opt/homebrew/opt/lld/bin:/opt/homebrew/opt/llvm/bin:/opt/homebrew/opt/tcl-tk/bin:/Users/tejas/.juliaup/bin:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/pkg/env/active/bin:/opt/pmk/env/global/bin:/Library/Apple/usr/bin:/Library/TeX/texbin:/Applications/Codex.app/Contents/Resources python3 test.py tests/math
Keep straight-line direct scalar outputs in SSA form inside callees, while retaining slot-backed loop-carried direct outputs until output-phi convergence exists. Resolve aliased direct params against live output bindings by name, tighten scalar cleanup, and add focused compiler and math coverage for the new behavior.
Remove redundant nil and empty-stack checks from the param-alias helpers while preserving the existing lowering invariants and validation coverage.
Factor the common local-scope and code-scope identifier lookup into one helper under getRawSymbol and namedValueSymbol, while preserving alias-aware value resolution for local bindings.
Rename scopedValueSymbol to localValSymbol so the helper reads as local-scope value lookup rather than a general scoped lookup, while keeping the alias-aware semantics unchanged.
Return a source enum from lookupNamedSymbol and extract the aliased branch of promoteToMemory into promoteAlias so identifier lookup and param-to-slot promotion stay readable without changing lowering semantics.
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.
Summary
Validation
PATH=/opt/homebrew/bin:$PATH /opt/homebrew/bin/go test ./compilerPATH=/opt/homebrew/bin:/opt/homebrew/opt/llvm/bin:$PATH python3 test.py tests/math