Skip to content

Commit 9be6619

Browse files
authored
Merge pull request #16565 from argotorg/make-ethdebug-consistent-with-existing-conventions
Make ethdebug inputs/outputs consistent
2 parents ac9c70d + 32a5a84 commit 9be6619

71 files changed

Lines changed: 1636 additions & 408 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ Language Features:
66
Compiler Features:
77
* Commandline Interface: Disallow selecting the deprecated assembly input mode that was only accessible via `--assemble` instead of treating it as equivalent to `--strict-assembly`.
88
* Commandline Interface: Introduce `--experimental` flag required for enabling the experimental mode.
9+
* Commandline Interface: Replace ``--ethdebug`` and ``--ethdebug-runtime`` with more granular ``--ethdebug-resources``, ``--ethdebug-compilation``, ``--ethdebug-program`` and ``--ethdebug-program-runtime`` flags. Per-contract program outputs no longer force full binary compilation.
910
* EVM: Introduce experimental EVM version `@future`.
1011
* General: Introduce the SSA CFG codegen (experimental).
1112
* General: Improve performance of sanity checks throughout the compiler implementation.
1213
* General: Restrict the existing experimental features (`generic-solidity`, `lsp`, `ethdebug`, `eof`, `evm`, `ast-import`, `evmasm-import`, `ir-ast`, `ssa-cfg`) to experimental mode.
1314
* Metadata: Store the state of the experimental mode in JSON and CBOR metadata. In CBOR this broadens the meaning of the existing `experimental` field, which used to indicate only the presence of certain experimental pragmas in the source.
1415
* Standard JSON Interface: Introduce `settings.experimental` setting required for enabling the experimental mode.
16+
* Standard JSON Interface: Replace the top-level ``ethdebug`` output with ``ethdebug.resources`` and ``ethdebug.compilation``. Decouple ethdebug outputs from binary compilation so that global ethdebug outputs can be produced without generating bytecode.
1517
* Yul Optimizer: Improve performance of control flow side effects collector and function references resolver.
1618

1719
Bugfixes:

docs/using-the-compiler.rst

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ Input Description
393393
// The snippet is quoted and follows the corresponding `@src` annotation.
394394
// - `ast-id`: Annotations of the form `@ast-id <id>` over elements that can be mapped back to a definition in the original Solidity file.
395395
// `<id>` is a node ID in the Solidity AST ('ast' output).
396-
// - `ethdebug`: Ethdebug annotations (experimental).
396+
// - `ethdebug`: Ethdebug annotations (experimental). Automatically enabled when any ethdebug output is requested.
397397
// - `*`: Wildcard value that can be used to request all non-experimental components.
398398
"debugInfo": ["location", "snippet", "ast-id", "ethdebug"]
399399
},
@@ -453,8 +453,8 @@ Input Description
453453
// transientStorageLayout - Slots, offsets and types of the contract's state variables in transient storage
454454
// evm.assembly - New assembly format
455455
// evm.legacyAssembly - Old-style assembly format in JSON
456-
// evm.bytecode.ethdebug - Debug information in ethdebug format (ethdebug/format/program schema). Can only be requested when compiling via IR. (experimental)
457-
// evm.deployedBytecode.ethdebug - Like evm.bytecode.ethdebug, but for the runtime part of the contract (experimental)
456+
// evm.bytecode.ethdebug - Debug information in ethdebug format (ethdebug/format/program schema for creation bytecode). Can only be requested when compiling via IR. (experimental)
457+
// evm.deployedBytecode.ethdebug - Debug information in ethdebug format (ethdebug/format/program schema for deployed bytecode). Can only be requested when compiling via IR. (experimental)
458458
// evm.bytecode.functionDebugData - Debugging information at function level
459459
// evm.bytecode.object - Bytecode object
460460
// evm.bytecode.opcodes - Opcodes list
@@ -467,6 +467,10 @@ Input Description
467467
// evm.gasEstimates - Function gas estimates
468468
// yulCFGJson - Control Flow Graph (CFG) of the Single Static Assignment (SSA) form of the contract (experimental)
469469
//
470+
// Global level (needs "*" as file name and "*" as contract name):
471+
// ethdebug.resources - Global ethdebug output (ethdebug/format/info/resources schema) containing source list and compiler info (experimental)
472+
// ethdebug.compilation - Global ethdebug compilation output (the 'compilation' key from ethdebug/format/info/resources schema) (experimental)
473+
//
470474
// Note that using `evm`, `evm.bytecode`, etc. will select every
471475
// target part of that output. Additionally, `*` can be used as a wildcard to request everything.
472476
//
@@ -696,7 +700,12 @@ Output Description
696700
}
697701
},
698702
// Global Ethdebug output (experimental)
699-
"ethdebug": {/* ... */ }
703+
"ethdebug": {
704+
// Requested via ethdebug.resources output selection
705+
"resources": {/* ... */},
706+
// Requested via ethdebug.compilation output selection
707+
"compilation": {/* ... */}
708+
}
700709
}
701710
702711
@@ -751,26 +760,26 @@ Note that the use of this mode is recorded in the metadata:
751760

752761
The table below details all currently available experimental features.
753762

754-
+-----------------------+--------------------------+------------------+-------------------------------------------------------------------+
755-
| Feature | ID | Affects bytecode | Flag/pragma |
756-
+=======================+==========================+==================+===================================================================+
757-
| AST import | ``ast-import`` | yes | ``--import-ast`` |
758-
+-----------------------+--------------------------+------------------+-------------------------------------------------------------------+
759-
| LSP | ``lsp`` | no | ``--lsp`` |
760-
+-----------------------+--------------------------+------------------+-------------------------------------------------------------------+
761-
| EVM Assembly import | ``evmasm-import`` | yes | ``--import-asm-json`` |
762-
+-----------------------+--------------------------+------------------+-------------------------------------------------------------------+
763-
| Generic Solidity | ``generic-solidity`` | yes | ``pragma experimental solidity`` |
764-
+-----------------------+--------------------------+------------------+-------------------------------------------------------------------+
765-
| IR AST | ``ir-ast`` | no | ``--ir-ast-json``, ``--ir-optimized-ast-json`` |
766-
+-----------------------+--------------------------+------------------+-------------------------------------------------------------------+
767-
| EOF | ``eof`` | yes | ``--experimental-eof-version`` |
768-
+-----------------------+--------------------------+------------------+-------------------------------------------------------------------+
769-
| Non-mainnet EVMs | ``evm`` | yes | ``--evm-version <version name>`` |
770-
+-----------------------+--------------------------+------------------+-------------------------------------------------------------------+
771-
| Ethdebug | ``ethdebug`` | no | ``--ethdebug``, ``--ethdebug-runtime``, ``--debug-info ethdebug`` |
772-
+-----------------------+--------------------------+------------------+-------------------------------------------------------------------+
773-
| | | no | ``--yul-cfg-json`` |
774-
| SSA CFG + ``ssa-cfg`` +------------------+-------------------------------------------------------------------+
775-
| | | yes | ``--via-ssa-cfg`` |
776-
+-----------------------+--------------------------+------------------+-------------------------------------------------------------------+
763+
+-----------------------+--------------------------+------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
764+
| Feature | ID | Affects bytecode | Flag/pragma |
765+
+=======================+==========================+==================+=========================================================================================================================================+
766+
| AST import | ``ast-import`` | yes | ``--import-ast`` |
767+
+-----------------------+--------------------------+------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
768+
| LSP | ``lsp`` | no | ``--lsp`` |
769+
+-----------------------+--------------------------+------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
770+
| EVM Assembly import | ``evmasm-import`` | yes | ``--import-asm-json`` |
771+
+-----------------------+--------------------------+------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
772+
| Generic Solidity | ``generic-solidity`` | yes | ``pragma experimental solidity`` |
773+
+-----------------------+--------------------------+------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
774+
| IR AST | ``ir-ast`` | no | ``--ir-ast-json``, ``--ir-optimized-ast-json`` |
775+
+-----------------------+--------------------------+------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
776+
| EOF | ``eof`` | yes | ``--experimental-eof-version`` |
777+
+-----------------------+--------------------------+------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
778+
| Non-mainnet EVMs | ``evm`` | yes | ``--evm-version <version name>`` |
779+
+-----------------------+--------------------------+------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
780+
| Ethdebug | ``ethdebug`` | no | ``--ethdebug-resources``, ``--ethdebug-compilation``, ``--ethdebug-program``, ``--ethdebug-program-runtime``, ``--debug-info ethdebug`` |
781+
+-----------------------+--------------------------+------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
782+
| | | no | ``--yul-cfg-json`` |
783+
| SSA CFG + ``ssa-cfg`` +------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
784+
| | | yes | ``--via-ssa-cfg`` |
785+
+-----------------------+--------------------------+------------------+-----------------------------------------------------------------------------------------------------------------------------------------+

libevmasm/AbstractAssemblyStack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class AbstractAssemblyStack
4343
virtual Json ethdebug(std::string const& _contractName) const = 0;
4444
virtual Json ethdebugRuntime(std::string const& _contractName) const = 0;
4545
virtual Json ethdebug() const = 0;
46+
virtual Json ethdebugCompilation() const = 0;
4647

4748
virtual Json assemblyJSON(std::string const& _contractName) const = 0;
4849
virtual std::string assemblyString(std::string const& _contractName, StringMap const& _sourceCodes) const = 0;

libevmasm/EVMAssemblyStack.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ Json EVMAssemblyStack::ethdebug() const
123123
return {};
124124
}
125125

126+
Json EVMAssemblyStack::ethdebugCompilation() const
127+
{
128+
return {};
129+
}
130+
126131
Json EVMAssemblyStack::assemblyJSON() const
127132
{
128133
solAssert(m_evmAssembly);

libevmasm/EVMAssemblyStack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class EVMAssemblyStack: public AbstractAssemblyStack
7474
Json ethdebug(std::string const& _contractName) const override;
7575
Json ethdebugRuntime(std::string const& _contractName) const override;
7676
Json ethdebug() const override;
77+
Json ethdebugCompilation() const override;
7778

7879
Json assemblyJSON() const;
7980
Json assemblyJSON(std::string const& _contractName) const override;

libevmasm/Ethdebug.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,16 @@ Json ethdebug::resources(std::vector<std::string> const& _sources, std::string c
160160
sources.push_back(source);
161161
}
162162
Json result = Json::object();
163-
result["compilation"] = Json::object();
164-
result["compilation"]["compiler"] = Json::object();
165-
result["compilation"]["compiler"]["name"] = "solc";
166-
result["compilation"]["compiler"]["version"] = _version;
163+
result["compilation"] = compilation(_version);
167164
result["compilation"]["sources"] = sources;
168165
return result;
169166
}
167+
168+
Json ethdebug::compilation(std::string_view _version)
169+
{
170+
Json result = Json::object();
171+
result["compiler"] = Json::object();
172+
result["compiler"]["name"] = "solc";
173+
result["compiler"]["version"] = _version;
174+
return result;
175+
}

libevmasm/Ethdebug.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ Json program(std::string_view _name, unsigned _sourceID, Assembly const& _assemb
3232
// returns ethdebug/format/info/resources
3333
Json resources(std::vector<std::string> const& _sources, std::string const& _version);
3434

35+
// returns the 'compilation' object from ethdebug/format/info/resources
36+
Json compilation(std::string_view _version);
37+
3538
} // namespace solidity::evmasm::ethdebug

libsolidity/interface/CompilerStack.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ bool CompilerStack::compile(State _stopAfter)
792792

793793
// Only compile contracts individually which have been requested.
794794
std::map<ContractDefinition const*, std::shared_ptr<Compiler const>> otherCompilers;
795+
bool requiresFullCompilation = false;
795796

796797
for (Source const* source: m_sourceOrder)
797798
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
@@ -802,6 +803,11 @@ bool CompilerStack::compile(State _stopAfter)
802803

803804
try
804805
{
806+
// Skip if full compilation is not needed (i.e. no IR/bytecode requested)
807+
if (!pipelineConfig.needsFullCompilation())
808+
continue;
809+
requiresFullCompilation = true;
810+
805811
if (pipelineConfig.needIR(m_viaIR))
806812
generateIR(*contract, pipelineConfig.needIRCodegenOnly(m_viaIR));
807813
if (pipelineConfig.needBytecode())
@@ -831,7 +837,8 @@ bool CompilerStack::compile(State _stopAfter)
831837

832838
solAssert(!m_errorReporter.hasErrors());
833839
m_stackState = CompilationSuccessful;
834-
this->link();
840+
if (requiresFullCompilation)
841+
this->link();
835842
return true;
836843
}
837844

@@ -1227,10 +1234,14 @@ Json CompilerStack::interfaceSymbols(std::string const& _contractName) const
12271234
Json CompilerStack::ethdebug() const
12281235
{
12291236
solAssert(m_stackState >= AnalysisSuccessful, "Analysis was not successful.");
1230-
solAssert(!m_contracts.empty());
12311237
return evmasm::ethdebug::resources(sourceNames(), VersionString);
12321238
}
12331239

1240+
Json CompilerStack::ethdebugCompilation() const
1241+
{
1242+
return evmasm::ethdebug::compilation(VersionString);
1243+
}
1244+
12341245
Json CompilerStack::ethdebug(std::string const& _contractName) const
12351246
{
12361247
return ethdebug(contract(_contractName), /* runtime */ false);

libsolidity/interface/CompilerStack.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ class CompilerStack: public langutil::CharStreamProvider, public evmasm::Abstrac
160160
return bytecode;
161161
}
162162

163+
bool needsFullCompilation() const
164+
{
165+
return irCodegen || irOptimization || bytecode;
166+
}
167+
163168
PipelineConfig operator|(PipelineConfig const& _other) const
164169
{
165170
return {
@@ -410,6 +415,9 @@ class CompilerStack: public langutil::CharStreamProvider, public evmasm::Abstrac
410415
/// Prerequisite: Successful call to parse or compile.
411416
Json ethdebug() const override;
412417

418+
/// @returns a JSON representing the ethdebug compilation data (compiler name and version).
419+
Json ethdebugCompilation() const override;
420+
413421
/// @returns the Contract Metadata matching the pipeline selected using the viaIR setting.
414422
std::string const& metadata(std::string const& _contractName) const { return metadata(contract(_contractName)); }
415423

0 commit comments

Comments
 (0)