yul: Compile objects that carry deploy code only - #597
Open
dimartiro wants to merge 2 commits into
Open
Conversation
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.