Only list used source names.

This commit is contained in:
chriseth 2021-08-31 12:57:13 +02:00
parent 4615e62514
commit f14b7598c7
28 changed files with 87 additions and 83 deletions

View File

@ -127,9 +127,10 @@ string IRNames::zeroValue(Type const& _type, string const& _variableName)
return "zero_" + _type.identifier() + _variableName;
}
string sourceLocationComment(langutil::SourceLocation const& _location, IRGenerationContext const& _context)
string sourceLocationComment(langutil::SourceLocation const& _location, IRGenerationContext& _context)
{
solAssert(_location.sourceName, "");
_context.markSourceUsed(*_location.sourceName);
return "/// @src "
+ to_string(_context.sourceIndices().at(*_location.sourceName))
+ ":"
@ -138,7 +139,7 @@ string sourceLocationComment(langutil::SourceLocation const& _location, IRGenera
+ to_string(_location.end);
}
string sourceLocationComment(ASTNode const& _node, IRGenerationContext const& _context)
string sourceLocationComment(ASTNode const& _node, IRGenerationContext& _context)
{
return sourceLocationComment(_node.location(), _context);
}

View File

@ -73,8 +73,8 @@ struct IRNames
* @returns a source location comment in the form of
* `/// @src <sourceIndex>:<locationStart>:<locationEnd>`.
*/
std::string sourceLocationComment(langutil::SourceLocation const& _location, IRGenerationContext const& _context);
std::string sourceLocationComment(ASTNode const& _node, IRGenerationContext const& _context);
std::string sourceLocationComment(langutil::SourceLocation const& _location, IRGenerationContext& _context);
std::string sourceLocationComment(ASTNode const& _node, IRGenerationContext& _context);
}

View File

@ -166,6 +166,8 @@ public:
void copyFunctionIDsFrom(IRGenerationContext const& _other);
std::map<std::string, unsigned> const& sourceIndices() const { return m_sourceIndices; }
void markSourceUsed(std::string const& _name) { m_usedSourceNames.insert(_name); }
std::set<std::string> const& usedSourceNames() const { return m_usedSourceNames; }
bool immutableRegistered(VariableDeclaration const& _varDecl) const { return m_immutableVariables.count(&_varDecl); }
@ -175,6 +177,7 @@ private:
RevertStrings m_revertStrings;
OptimiserSettings m_optimiserSettings;
std::map<std::string, unsigned> m_sourceIndices;
std::set<std::string> m_usedSourceNames;
ContractDefinition const* m_mostDerivedContract = nullptr;
std::map<VariableDeclaration const*, IRVariable> m_localVariables;
/// Memory offsets reserved for the values of immutable variables during contract creation.

View File

@ -131,12 +131,21 @@ string IRGenerator::generate(
subObjectsSources += _otherYulSources.at(subObject);
return subObjectsSources;
};
auto formatUseSrcMap = [](IRGenerationContext const& _context) -> string
{
return joinHumanReadable(
ranges::views::transform(_context.usedSourceNames(), [_context](string const& _sourceName) {
return to_string(_context.sourceIndices().at(_sourceName)) + ":" + escapeAndQuoteString(_sourceName);
}),
", "
);
};
Whiskers t(R"(
/// @use-src <useSrcMapCreation>
object "<CreationObject>" {
code {
<sourceLocationComment>
<sourceLocationCommentCreation>
<memoryInitCreation>
<callValueCheck>
<?library>
@ -150,7 +159,7 @@ string IRGenerator::generate(
/// @use-src <useSrcMapDeployed>
object "<DeployedObject>" {
code {
<sourceLocationComment>
<sourceLocationCommentDeployed>
<memoryInitDeployed>
<?library>
let called_via_delegatecall := iszero(eq(loadimmutable("<library_address>"), address()))
@ -169,19 +178,8 @@ string IRGenerator::generate(
for (VariableDeclaration const* var: ContractType(_contract).immutableVariables())
m_context.registerImmutableVariable(*var);
auto invertedSourceIndicies = invertMap(m_context.sourceIndices());
string useSrcMap = joinHumanReadable(
ranges::views::transform(invertedSourceIndicies, [](auto&& _pair) {
return to_string(_pair.first) + ":" + escapeAndQuoteString(_pair.second);
}),
", "
);
t("useSrcMapCreation", useSrcMap);
t("sourceLocationComment", sourceLocationComment(_contract));
t("CreationObject", IRNames::creationObject(_contract));
t("sourceLocationCommentCreation", sourceLocationComment(_contract));
t("library", _contract.isLibrary());
FunctionDefinition const* constructor = _contract.constructor();
@ -211,6 +209,7 @@ string IRGenerator::generate(
// This has to be called only after all other code generation for the creation object is complete.
bool creationInvolvesAssembly = m_context.inlineAssemblySeen();
t("memoryInitCreation", memoryInit(!creationInvolvesAssembly));
t("useSrcMapCreation", formatUseSrcMap(m_context));
resetContext(_contract, ExecutionContext::Deployed);
@ -220,8 +219,8 @@ string IRGenerator::generate(
m_context.initializeInternalDispatch(move(internalDispatchMap));
// Do not register immutables to avoid assignment.
t("useSrcMapDeployed", useSrcMap);
t("DeployedObject", IRNames::deployedObject(_contract));
t("sourceLocationCommentDeployed", sourceLocationComment(_contract));
t("library_address", IRNames::libraryAddressImmutable());
t("dispatch", dispatchRoutine(_contract));
set<FunctionDefinition const*> deployedFunctionList = generateQueuedFunctions();
@ -231,6 +230,7 @@ string IRGenerator::generate(
t("metadataName", yul::Object::metadataName());
t("cborMetadata", toHex(_cborMetadata));
t("useSrcMapDeployed", formatUseSrcMap(m_context));
// This has to be called only after all other code generation for the deployed object is complete.
bool deployedInvolvesAssembly = m_context.inlineAssemblySeen();
@ -1073,7 +1073,7 @@ void IRGenerator::resetContext(ContractDefinition const& _contract, ExecutionCon
m_context.addStateVariable(*get<0>(var), get<1>(var), get<2>(var));
}
string IRGenerator::sourceLocationComment(ASTNode const& _node) const
string IRGenerator::sourceLocationComment(ASTNode const& _node)
{
return ::sourceLocationComment(_node, m_context);
}

View File

@ -119,7 +119,7 @@ private:
void resetContext(ContractDefinition const& _contract, ExecutionContext _context);
std::string sourceLocationComment(ASTNode const& _node) const;
std::string sourceLocationComment(ASTNode const& _node);
langutil::EVMVersion const m_evmVersion;
OptimiserSettings const m_optimiserSettings;

View File

@ -6,7 +6,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"constant_optimizer_yul/input.sol", 1:"#utility.yul"
/// @use-src 0:"constant_optimizer_yul/input.sol"
object "C_12" {
code {
{
@ -21,7 +21,7 @@ object "C_12" {
return(128, _1)
}
}
/// @use-src 0:"constant_optimizer_yul/input.sol", 1:"#utility.yul"
/// @use-src 0:"constant_optimizer_yul/input.sol"
object "C_12_deployed" {
code {
{

View File

@ -7,7 +7,7 @@ IR:
*=====================================================*/
/// @use-src 0:"exp_base_literal/input.sol", 1:"#utility.yul"
/// @use-src 0:"exp_base_literal/input.sol"
object "C_81" {
code {
/// @src 0:82:370
@ -38,7 +38,7 @@ object "C_81" {
}
}
/// @use-src 0:"exp_base_literal/input.sol", 1:"#utility.yul"
/// @use-src 0:"exp_base_literal/input.sol"
object "C_81_deployed" {
code {
/// @src 0:82:370

View File

@ -6,7 +6,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"ir_compiler_inheritance_nosubobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_compiler_inheritance_nosubobjects/input.sol"
object "C_7" {
code {
{
@ -18,7 +18,7 @@ object "C_7" {
return(128, _1)
}
}
/// @use-src 0:"ir_compiler_inheritance_nosubobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_compiler_inheritance_nosubobjects/input.sol"
object "C_7_deployed" {
code {
{
@ -39,7 +39,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"ir_compiler_inheritance_nosubobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_compiler_inheritance_nosubobjects/input.sol"
object "D_10" {
code {
{
@ -51,7 +51,7 @@ object "D_10" {
return(128, _1)
}
}
/// @use-src 0:"ir_compiler_inheritance_nosubobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_compiler_inheritance_nosubobjects/input.sol"
object "D_10_deployed" {
code {
{

View File

@ -6,7 +6,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"ir_compiler_subobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_compiler_subobjects/input.sol"
object "C_3" {
code {
{
@ -18,7 +18,7 @@ object "C_3" {
return(128, _1)
}
}
/// @use-src 0:"ir_compiler_subobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_compiler_subobjects/input.sol"
object "C_3_deployed" {
code {
{
@ -39,7 +39,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"ir_compiler_subobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_compiler_subobjects/input.sol"
object "D_16" {
code {
{
@ -51,7 +51,7 @@ object "D_16" {
return(128, _1)
}
}
/// @use-src 0:"ir_compiler_subobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_compiler_subobjects/input.sol"
object "D_16_deployed" {
code {
{
@ -90,7 +90,7 @@ object "D_16" {
revert(0, 0)
}
}
/// @use-src 0:"ir_compiler_subobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_compiler_subobjects/input.sol"
object "C_3" {
code {
{
@ -102,7 +102,7 @@ object "D_16" {
return(128, _1)
}
}
/// @use-src 0:"ir_compiler_subobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_compiler_subobjects/input.sol"
object "C_3_deployed" {
code {
{

View File

@ -6,7 +6,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"ir_with_assembly_no_memoryguard_creation/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_with_assembly_no_memoryguard_creation/input.sol"
object "D_12" {
code {
{
@ -18,7 +18,7 @@ object "D_12" {
return(128, _1)
}
}
/// @use-src 0:"ir_with_assembly_no_memoryguard_creation/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_with_assembly_no_memoryguard_creation/input.sol"
object "D_12_deployed" {
code {
{

View File

@ -6,7 +6,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"ir_with_assembly_no_memoryguard_runtime/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_with_assembly_no_memoryguard_runtime/input.sol"
object "D_8" {
code {
{
@ -18,7 +18,7 @@ object "D_8" {
return(128, _1)
}
}
/// @use-src 0:"ir_with_assembly_no_memoryguard_runtime/input.sol", 1:"#utility.yul"
/// @use-src 0:"ir_with_assembly_no_memoryguard_runtime/input.sol"
object "D_8_deployed" {
code {
{

View File

@ -6,7 +6,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"keccak_optimization_deploy_code/input.sol", 1:"#utility.yul"
/// @use-src 0:"keccak_optimization_deploy_code/input.sol"
object "C_12" {
code {
{
@ -22,7 +22,7 @@ object "C_12" {
return(128, _1)
}
}
/// @use-src 0:"keccak_optimization_deploy_code/input.sol", 1:"#utility.yul"
/// @use-src 0:"keccak_optimization_deploy_code/input.sol"
object "C_12_deployed" {
code {
{

View File

@ -6,7 +6,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"keccak_optimization_low_runs/input.sol", 1:"#utility.yul"
/// @use-src 0:"keccak_optimization_low_runs/input.sol"
object "C_7" {
code {
{
@ -18,7 +18,7 @@ object "C_7" {
return(128, _1)
}
}
/// @use-src 0:"keccak_optimization_low_runs/input.sol", 1:"#utility.yul"
/// @use-src 0:"keccak_optimization_low_runs/input.sol"
object "C_7_deployed" {
code {
{

View File

@ -6,7 +6,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"name_simplifier/input.sol", 1:"#utility.yul"
/// @use-src 0:"name_simplifier/input.sol"
object "C_59" {
code {
{
@ -18,7 +18,7 @@ object "C_59" {
return(128, _1)
}
}
/// @use-src 0:"name_simplifier/input.sol", 1:"#utility.yul"
/// @use-src 0:"name_simplifier/input.sol"
object "C_59_deployed" {
code {
{

View File

@ -6,7 +6,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"optimizer_array_sload/input.sol", 1:"#utility.yul"
/// @use-src 0:"optimizer_array_sload/input.sol"
object "Arraysum_34" {
code {
{
@ -18,7 +18,7 @@ object "Arraysum_34" {
return(128, _1)
}
}
/// @use-src 0:"optimizer_array_sload/input.sol", 1:"#utility.yul"
/// @use-src 0:"optimizer_array_sload/input.sol"
object "Arraysum_34_deployed" {
code {
{

View File

@ -7,7 +7,7 @@ IR:
*=====================================================*/
/// @use-src 0:"revert_strings/input.sol", 1:"#utility.yul"
/// @use-src 0:"revert_strings/input.sol"
object "C_15" {
code {
/// @src 0:59:147
@ -53,7 +53,7 @@ object "C_15" {
}
}
/// @use-src 0:"revert_strings/input.sol", 1:"#utility.yul"
/// @use-src 0:"revert_strings/input.sol"
object "C_15_deployed" {
code {
/// @src 0:59:147

View File

@ -5,7 +5,7 @@
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_7\" {
code {
/// @src 0:79:121
@ -25,7 +25,7 @@ object \"C_7\" {
function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb()
{ revert(0, 0) }
}
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_7_deployed\" {
code {
/// @src 0:79:121

View File

@ -6,7 +6,7 @@
*=====================================================*/
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_7\" {
code {
/// @src 0:79:121
@ -37,7 +37,7 @@ object \"C_7\" {
}
}
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_7_deployed\" {
code {
/// @src 0:79:121

View File

@ -6,7 +6,7 @@
*=====================================================*/
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_3\" {
code {
/// @src 0:79:92
@ -37,7 +37,7 @@ object \"C_3\" {
}
}
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_3_deployed\" {
code {
/// @src 0:79:92
@ -83,7 +83,7 @@ object \"C_3\" {
*=====================================================*/
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"D_16\" {
code {
/// @src 0:93:146
@ -114,7 +114,7 @@ object \"D_16\" {
}
}
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"D_16_deployed\" {
code {
/// @src 0:93:146
@ -215,7 +215,7 @@ object \"D_16\" {
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_3\" {
code {
/// @src 0:79:92
@ -246,7 +246,7 @@ object \"D_16\" {
}
}
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_3_deployed\" {
code {
/// @src 0:79:92

View File

@ -7,7 +7,7 @@ IR:
*=====================================================*/
/// @use-src 0:"viair_abicoder_v1/input.sol", 1:"#utility.yul"
/// @use-src 0:"viair_abicoder_v1/input.sol"
object "test_11" {
code {
/// @src 0:79:169
@ -38,7 +38,7 @@ object "test_11" {
}
}
/// @use-src 0:"viair_abicoder_v1/input.sol", 1:"#utility.yul"
/// @use-src 0:"viair_abicoder_v1/input.sol"
object "test_11_deployed" {
code {
/// @src 0:79:169

View File

@ -12,7 +12,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"viair_subobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"viair_subobjects/input.sol"
object "C_3" {
code {
{
@ -24,7 +24,7 @@ object "C_3" {
return(128, _1)
}
}
/// @use-src 0:"viair_subobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"viair_subobjects/input.sol"
object "C_3_deployed" {
code {
{
@ -51,7 +51,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"viair_subobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"viair_subobjects/input.sol"
object "D_16" {
code {
{
@ -63,7 +63,7 @@ object "D_16" {
return(128, _1)
}
}
/// @use-src 0:"viair_subobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"viair_subobjects/input.sol"
object "D_16_deployed" {
code {
{
@ -102,7 +102,7 @@ object "D_16" {
revert(0, 0)
}
}
/// @use-src 0:"viair_subobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"viair_subobjects/input.sol"
object "C_3" {
code {
{
@ -114,7 +114,7 @@ object "D_16" {
return(128, _1)
}
}
/// @use-src 0:"viair_subobjects/input.sol", 1:"#utility.yul"
/// @use-src 0:"viair_subobjects/input.sol"
object "C_3_deployed" {
code {
{

View File

@ -6,7 +6,7 @@ Optimized IR:
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"yul_optimizer_steps/input.sol", 1:"#utility.yul"
/// @use-src 0:"yul_optimizer_steps/input.sol"
object "C_7" {
code {
{
@ -25,7 +25,7 @@ object "C_7" {
function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb()
{ revert(0, 0) }
}
/// @use-src 0:"yul_optimizer_steps/input.sol", 1:"#utility.yul"
/// @use-src 0:"yul_optimizer_steps/input.sol"
object "C_7_deployed" {
code {
{

View File

@ -6,7 +6,7 @@
*=====================================================*/
/// @use-src 0:\"C\", 1:\"D\", 2:\"#utility.yul\"
/// @use-src 0:\"C\"
object \"C_54\" {
code {
/// @src 0:79:428
@ -156,7 +156,7 @@ object \"C_54\" {
}
}
/// @use-src 0:\"C\", 1:\"D\", 2:\"#utility.yul\"
/// @use-src 0:\"C\"
object \"C_54_deployed\" {
code {
/// @src 0:79:428
@ -564,7 +564,7 @@ object \"C_54\" {
*=====================================================*/
/// @use-src 0:\"C\", 1:\"D\", 2:\"#utility.yul\"
/// @use-src 0:\"C\", 1:\"D\"
object \"D_72\" {
code {
/// @src 1:91:166
@ -781,7 +781,7 @@ object \"D_72\" {
}
}
/// @use-src 0:\"C\", 1:\"D\", 2:\"#utility.yul\"
/// @use-src 0:\"C\", 1:\"D\"
object \"D_72_deployed\" {
code {
/// @src 1:91:166

View File

@ -6,7 +6,7 @@
*=====================================================*/
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_11\" {
code {
/// @src 0:78:164
@ -37,7 +37,7 @@ object \"C_11\" {
}
}
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_11_deployed\" {
code {
/// @src 0:78:164

View File

@ -6,7 +6,7 @@
*=====================================================*/
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_11\" {
code {
/// @src 0:78:158
@ -37,7 +37,7 @@ object \"C_11\" {
}
}
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_11_deployed\" {
code {
/// @src 0:78:158

View File

@ -6,7 +6,7 @@
*=====================================================*/
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_11\" {
code {
/// @src 0:78:159
@ -37,7 +37,7 @@ object \"C_11\" {
}
}
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_11_deployed\" {
code {
/// @src 0:78:159

View File

@ -6,7 +6,7 @@
*=====================================================*/
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_11\" {
code {
/// @src 0:78:243
@ -37,7 +37,7 @@ object \"C_11\" {
}
}
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_11_deployed\" {
code {
/// @src 0:78:243

View File

@ -6,7 +6,7 @@
*=====================================================*/
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_11\" {
code {
/// @src 0:78:159
@ -37,7 +37,7 @@ object \"C_11\" {
}
}
/// @use-src 0:\"A\", 1:\"#utility.yul\"
/// @use-src 0:\"A\"
object \"C_11_deployed\" {
code {
/// @src 0:78:159