feat(slang): emit every contract in a source unit#460
Draft
hedgar2017 wants to merge 1 commit into
Draft
Conversation
The Slang frontend was processing only the first contract per source unit, silently dropping the rest of the file. Tests targeting a non-first contract failed with `selector not found` because the contract was never registered, and any future cross-contract lowering would have nothing to point at on the right-hand side of `new B()` or `B(addr).method()`. `AstEmitter::emit` now takes a single `ContractDefinition` and is invoked once per concrete contract, with a fresh `solx_mlir::Context` per contract. Each contract gets its own deploy + runtime MLIR module pair through the existing `finalize_module` path and lands in `output.contracts[file_id][contract_name]` independently. Abstract contracts are skipped — their unimplemented members would crash the emitter, and derived concrete contracts continue to emit on their own.
5a6eff0 to
7fe873f
Compare
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.
The Slang frontend was processing only the first contract per source unit, silently dropping the rest of the file. Tests targeting a non-first contract failed with
selector not foundbecause the contract was never registered, and any future cross-contract lowering would have nothing to point at on the right-hand side ofnew B()orB(addr).method().AstEmitter::emitnow takes a singleContractDefinitionand is invoked once per concrete contract in the source unit, with a freshsolx_mlir::Contextper contract. Each contract gets its own deploy + runtime MLIR module pair through the existingfinalize_modulepath and lands inoutput.contracts[file_id][contract_name]independently. Abstract contracts are skipped — their unimplemented members would crash the emitter, and derived concrete contracts continue to emit on their own.Test delta on
tests/solidity/simple -O M3B3is zero (1903 passed, 4 failed, 305 invalid both with and without this change). Every multi-contract test in that suite also depends on contract creation, external calls, or inheritance — none of which are wired in the Slang pipeline yet. This change is a prerequisite for those: without it, the second contract's MLIR is never produced, so even after loweringnew B()andb.method()the call sites would have nothing to bind to.solx-soliditysemantic tests are unaffected — they exercise the solc-based frontend, not Slang.Direct verification with a synthetic two-contract source confirms both contracts now appear in
output.contracts[file_id]where previously only the first did.