Compile runtime backtracing to ASM and compile-time to ABI JSON #7387
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
This PR implements the compilation of the ABI backtracking, as described in the ABI Backtracking RFC.
The PR closes two remaining implementation steps listed in the #7276:
Changes in the ABI JSON and IR Compilation
panickingCalls
section in the ABI JSONEach panicking call is identified by a unique number and provided in the new
panickingCalls
section in the ABI JSON.E.g., for this panicking call in a module
some_module
of a packagesome_package
:the following ABI JSON entry is created:
Encoding error code and backtrace in a
panic
revert codeThe generation of the
panic
revert code is changed. Apanic
revert code now encodes:panic
expression,errorCodes
section of the ABI JSON,panickingCalls
section of the ABI JSON.The encoding of the
u64
revert code works as following:1_pppppppp_CCCCCCCCCCC_CCCCCCCCCCC_CCCCCCCCCCC_CCCCCCCCCCC_CCCCCCCCCCC
1
denotes a revert code generated by apanic
expression. Arbitrary user-defined revert codes will must have the starting bit set to0
or in other words be less then or equal to9223372036854775807₁₀ = 7FFFFFFFFFFFFFFF₁₆
.pppppppp
denotes the error code in theerrorCodes
section of the ABI JSON, that identifies the actualpanic
location.CCCCCCCCCCC
section denotes a panicking call code in thepanickingCalls
section of the ABI JSON. The calls represent the callstack, where the right-most code is the code of the immediate function call in which thepanic
occurs. If allC
s a zero it means no-call. This will happen if the actual call-depth is less then five calls.Calculating backtrace
Ever non-entry function that can panic gets an additional function argument:
__backtrace: u64
. The__backtrace
to pass to a panicking call is calculated at runtime by left-shift the existing__backtrace
provided by the caller function and append/bitwise OR the unique panicking call ID of the exact panicking call. The ID of that exact panicking call is a compile-time, compiler-generated constant as explained above.The detailed mechanism with examples is provided in the "Runtime execution and bytecode and gas overhead" chapter of the ABI Backtracking RFC.
Additional Changes
The
panickingCalls
section of the ABI JSON can differ betweendebug
andrelease
builds which required adding support for different ABI JSON oracle files in test thatvalidate_abi
. The requirement to display a fully qualified function name in the panicking call and the backtrace resulted in adding flexibility to displaying functions and types in general. Adjusting affected tests was used as opportunity to remove unnecessary dependencies to thestd
and reducedstd
libraries in a large number of tests. Also, a cleanup is done in some parts of the code, like, e.g., removing code duplications.The PR implements these additional changes:
TyFunctionDisplay
andTypeInfoDisplay
for configurable displaying of functions and types. Replacing current various custom implementations of displaying with these two types, mostly in error messages, will be done in separate PRs, with low priority. Also, display might be improved in some edge cases. There are TODOs left in code for such, and improvements will be done in separate PRs, with lower priority.impl DisplayWithEngines for TypeInfo
. This is done so that we can easily spot errors and warnings that should use specificTyFunctionDisplay
andTypeInfoDisplay
(tests will break) and adapt those in the follow up PR that will address Add settings toTypeInfoDisplay
for optimal displaying of types in different contexts #7389.CompileError::MethodNotFound
and utilizeTyFunctionDisplay
for displaying all matching candidates.Value::new_u64_constant
and removing duplicated code for a common scenario of creating an IR Constant of typeu64
.clone()
s andString
allocations.typeid
to follow more general naming convention forTypeId
fields and parameters.std
or reducedstd
libraries in tests.json_abi_oracle
files fordebug
andrelease
build profiles. ThepanickingCalls
part of the ABI JSON can vary depending on the build profile. A test that verifies ABI JSON now must provide expected oracles for both build profiles, unless a profile is unsupported viaunsupported_profiles
test option. An alternative was considered, to allow just a single oracle file if bothdebug
andrelease
oracles are the same. The reasoning for having two as mandatory even in that case was to gain more explicit test setup. We can change this upon feedback if needed. The oracles have a suffix of either.debug.json
or.release.json
and the name part is, as before, one of the following:json_abi_oracle
for obsolete old encoding,json_abi_oracle.<experimental feature>
for experimental features,json_abi_oracle_new_encoding
for new encoding without other experimental features.panic
s in functions of same name and content #7386.Checklist
Breaking*
orNew Feature
labels where relevant.