Skip to content

refactor(compiler): keep direct params as values#50

Merged
thiremani merged 11 commits intomasterfrom
codex/direct-param-values
Apr 13, 2026
Merged

refactor(compiler): keep direct params as values#50
thiremani merged 11 commits intomasterfrom
codex/direct-param-values

Conversation

@thiremani
Copy link
Copy Markdown
Owner

Summary

  • keep direct scalar params as SSA values in the callee by default instead of eagerly spilling them
  • materialize slots lazily only when semantics require addressable storage, while preserving aliased range accumulator behavior through function-scoped param alias tracking
  • tighten conditional call-arg pre-promotion and add focused compiler plus math coverage for nested direct calls and empty-range alias semantics

Validation

  • PATH=/opt/homebrew/bin:$PATH /opt/homebrew/bin/go test ./compiler
  • PATH=/opt/homebrew/bin:/opt/homebrew/opt/llvm/bin:$PATH python3 test.py tests/math

thiremani added 11 commits April 8, 2026 22:16
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.
@thiremani thiremani merged commit 99cd193 into master Apr 13, 2026
2 checks passed
@thiremani thiremani deleted the codex/direct-param-values branch April 13, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant