Skip to content

Capture variables referenced only inside assembly - #625

Open
micahscopes wants to merge 2 commits into
mainfrom
fix/asm-only-closure-captures
Open

micahscopes wants to merge 2 commits into
mainfrom
fix/asm-only-closure-captures

Conversation

@micahscopes

Copy link
Copy Markdown

A closure that reads an enclosing variable only inside assembly currently omits it from its captured environment. The existing inc-closure.sol fixture compiles to Hull that yule rejects with Undefined variable: x:

let f = lam () {
  let res: word;
  assembly { res := add(x, 1) }
  return res;
};

Include assembly variable reads and assignment targets in closure capture analysis. Respect assembly-local bindings, nested scopes, function parameters and loop initializers; call names do not become captures.

Adds eight focused tests, including checks that generated Hull typechecks, and a fixture exercising shadowing and loop-local bindings.

Validation:

  • All 1,471 tests pass.
  • The existing closure fixture and new scope fixture compile through yule and solc, deploy, and return 1 and 42 respectively.
  • Independent Astra review found no introduced defects; twelve additional execution checks passed.

Collect Yul variable reads and assignment targets with lexical scope handling, excluding call names and assembly-local bindings. Include these word-typed references in closure conversion. Add capture-analysis checks and generated-Hull typechecking for the existing inc-closure example and a nested-block/loop fixture.

@rodrigogribeiro rodrigogribeiro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rodrigogribeiro
rodrigogribeiro self-requested a review October 23, 2026 10:08
@micahscopes
micahscopes marked this pull request as ready for review October 24, 2026 04:38

This branch has not been deployed

No deployments
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.

2 participants