Skip to content

feat(slang): emit external getters for public state variables#463

Draft
hedgar2017 wants to merge 1 commit into
mainfrom
feat-slang-state-var-getters
Draft

feat(slang): emit external getters for public state variables#463
hedgar2017 wants to merge 1 commit into
mainfrom
feat-slang-state-var-getters

Conversation

@hedgar2017
Copy link
Copy Markdown
Contributor

Solidity auto-generates an external view getter for every public state variable. The Slang frontend was registering only user-defined functions, so any test that read a public state var through its getter selector failed at the test harness's selector-lookup step (selector of the method 'X' not found).

For each ContractMember::StateVariableDefinition, when compute_abi_entry() returns a Function entry with no inputs (scalar getter) the emitter now lays down a sol.func named after the slang canonical signature, carrying the slang-computed selector and View mutability, with a body that loads the corresponding storage slot and returns the value. Indexed getters for T[], mappings, and structs still need sol.gep / sol.map plumbing and are deliberately skipped so the rest of the contract still compiles. AstEmitter::emit also includes state-variable selectors in the method-identifier table the caller hands to the test harness.

tests/solidity/simple -O M3B3 moves from 1896 passed / 3 failed / 307 invalid to 1952 passed / 13 failed / 298 invalid — net +56 passing tests (+10 failed, -9 invalid). The new failures are tests where the getter resolves but some other behavior in the same test mismatches; the bulk of the formerly-invalid selector not found cluster (num, count, text, MY_ADDRESS, oneWei, etc.) now runs and most pass.

Solidity auto-generates an external `view` getter for every `public`
state variable. The Slang frontend was registering only user-defined
functions, so any test that read a public state var through its getter
selector failed at the test harness's selector-lookup step
(`selector of the method 'X' not found`).

For each `ContractMember::StateVariableDefinition`, when
`compute_abi_entry()` returns a `Function` entry with no inputs (scalar
getter) the emitter now lays down a `sol.func` named after the slang
canonical signature, carrying the slang-computed selector and `View`
mutability, with a body that loads the corresponding storage slot and
returns the value. Indexed getters for `T[]`, mappings, and structs
still need `sol.gep` / `sol.map` plumbing and are deliberately skipped
so the rest of the contract still compiles. `AstEmitter::emit` also
includes state-variable selectors in the method-identifier table the
caller hands to the test harness.

`tests/solidity/simple -O M3B3`: 1896/3/307 baseline → 1952/13/298, net
+56 passing tests (+10 failed, -9 invalid).
@hedgar2017 hedgar2017 added the ci:slang Trigger slang unit tests on PR label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:slang Trigger slang unit tests on PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant