yul: Compile objects that carry deploy code only - #597
Open
dimartiro wants to merge 3 commits into
Open
Conversation
xermicus
approved these changes
Sep 8, 2026
| "An object carrying deploy code only, without a `_deployed` sub-object", | ||
| ); | ||
|
|
||
| // `solc` accepts this too, which is the whole point: the two front-ends should agree. |
Member
There was a problem hiding this comment.
Suggested change
| // `solc` accepts this too, which is the whole point: the two front-ends should agree. |
This is the default behavior so no comment needed.
Comment on lines
+555
to
+556
| // An explicit `stop`, so that `__runtime` is emitted with a terminator. | ||
| assert_eq!(inner.code.block.statements.len(), 1); |
Member
There was a problem hiding this comment.
Suggested change
| // An explicit `stop`, so that `__runtime` is emitted with a terminator. | |
| assert_eq!(inner.code.block.statements.len(), 1); | |
| assert_eq!(inner.code.block.statements.len(), 1, "expected one statement"); |
xermicus
reviewed
Sep 8, 2026
Comment on lines
+181
to
+195
| /// Builds the runtime code object for a deploy-only object, that is one the source omitted | ||
| /// the `_deployed` sub-object for. | ||
| /// | ||
| /// Such an object carries deploy code only, so the deployed contract has no runtime code to | ||
| /// run. `solc` accepts this, and the EVM behaviour of "no runtime code" is a successful | ||
| /// return with empty data, which is exactly what an empty Yul code block lowers to (see | ||
| /// `Code::into_llvm`, which terminates every code block with an implicit `stop`). | ||
| /// | ||
| /// Materializing the sub-object here instead of special casing its absence in code | ||
| /// generation keeps every consumer of the AST -- both IR pipelines, the visitors and the | ||
| /// analyses -- on the one path they already handle. | ||
| /// | ||
| /// The body is an explicit `stop` rather than an empty block. The two are equivalent, but an | ||
| /// empty runtime block currently trips an assertion in `polkavm-linker` when lowered through | ||
| /// the `--newyork` pipeline. |
Member
There was a problem hiding this comment.
Suggested change
| /// Builds the runtime code object for a deploy-only object, that is one the source omitted | |
| /// the `_deployed` sub-object for. | |
| /// | |
| /// Such an object carries deploy code only, so the deployed contract has no runtime code to | |
| /// run. `solc` accepts this, and the EVM behaviour of "no runtime code" is a successful | |
| /// return with empty data, which is exactly what an empty Yul code block lowers to (see | |
| /// `Code::into_llvm`, which terminates every code block with an implicit `stop`). | |
| /// | |
| /// Materializing the sub-object here instead of special casing its absence in code | |
| /// generation keeps every consumer of the AST -- both IR pipelines, the visitors and the | |
| /// analyses -- on the one path they already handle. | |
| /// | |
| /// The body is an explicit `stop` rather than an empty block. The two are equivalent, but an | |
| /// empty runtime block currently trips an assertion in `polkavm-linker` when lowered through | |
| /// the `--newyork` pipeline. | |
| /// A short-hand constructor returning an object with a call to `stop`. |
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.
Description
Closes #490
resolc --yulrejected any Yul object that carries deploy code only, that is one without a_deployedruntime sub-object, whilesolccompiles it:Cause
Object::declaredeclaresPolkaVMRuntimeCodeFunctionunconditionally, so__runtimealways exists with an emptyentryblock.Object::into_llvmonly ever defines it from the_deployedbranch, which is reached throughif let Some(object) = self.inner_object. With no sub-object the function stays declared and undefined, and the module fails verification.Not declaring it is not an option:
Entry::leave_entrylooks__runtimeup and bails withContract runtime code not found, since__entrydispatches to either__deployor__runtimeon the call flag.Fix
Object::parsenow materializes the runtime sub-object when the source omits it, so the AST that reaches code generation always has one.Doing it in the parser rather than special casing the absence in code generation keeps every consumer on the path it already handles. That matters here because both IR pipelines read this field:
newyork'sYulTranslator::translate_objecthas the sameif let Some(inner_object)shape, and--newyorkreproduces the identical error. One parser-level change fixes both.The synthesized body is an explicit
stop().Code::into_llvmterminates every code block with an implicitstopanyway ("The EVM lets the code return implicitly"), so this is exactly what an empty runtime block lowers to, and it matches the EVM behaviour of calling an account with no code: success with empty return data.I did not use an empty block, for two reasons. It would leave
__runtimeasentry: br %return/return: unreachable, and thatunreachableis now reachable rather than a dead tail, which is UB the optimizer is free to exploit —__runtimeisPrivateand called only from__entry, so folding it away could turn a call into a constructor run. And separately, an empty runtime block currently trips an assertion inpolkavm-linkerunder--newyork(see below), which thestop()avoids.Tests added:
revive-yul: the deploy-only object gets the implicit runtime object with astop()body, and an explicit_deployedobject is not clobbered by it.resolc:compiles_object_without_a_runtime_sub_objectcompiles the newdeploy_only_object.yulfixture end to end and cross-checks thatsolcagrees on the exit code, which is the premise of the issue.