Merge pull request #11908 from ethereum/preventOptimizerRunningMultipleTimes

Run the optimizer only once.
This commit is contained in:
chriseth 2021-09-07 17:37:54 +02:00 committed by GitHub
commit c9360ef80d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View File

@ -15,6 +15,7 @@ Compiler Features:
Bugfixes:
* Opcode Optimizer: Prevent the optimizer from running multiple times to avoid potential bytecode differences for referenced code.
* Name Resolver: Fix that when importing an aliased symbol using ``import {AliasedName} from "a.sol"`` it would use the original name of the symbol and not the aliased one.
* SMTChecker: Fix false negative caused by ``push`` on storage array references returned by internal functions.
* SMTChecker: Fix false positive in external calls from constructors.

View File

@ -409,18 +409,21 @@ Assembly& Assembly::optimise(OptimiserSettings const& _settings)
return *this;
}
map<u256, u256> Assembly::optimiseInternal(
map<u256, u256> const& Assembly::optimiseInternal(
OptimiserSettings const& _settings,
std::set<size_t> _tagsReferencedFromOutside
)
{
if (m_tagReplacements)
return *m_tagReplacements;
// Run optimisation for sub-assemblies.
for (size_t subId = 0; subId < m_subs.size(); ++subId)
{
OptimiserSettings settings = _settings;
// Disable creation mode for sub-assemblies.
settings.isCreation = false;
map<u256, u256> subTagReplacements = m_subs[subId]->optimiseInternal(
map<u256, u256> const& subTagReplacements = m_subs[subId]->optimiseInternal(
settings,
JumpdestRemover::referencedTags(m_items, subId)
);
@ -546,7 +549,8 @@ map<u256, u256> Assembly::optimiseInternal(
*this
);
return tagReplacements;
m_tagReplacements = move(tagReplacements);
return *m_tagReplacements;
}
LinkerObject const& Assembly::assemble() const

View File

@ -165,7 +165,7 @@ protected:
/// Does the same operations as @a optimise, but should only be applied to a sub and
/// returns the replaced tags. Also takes an argument containing the tags of this assembly
/// that are referenced in a super-assembly.
std::map<u256, u256> optimiseInternal(OptimiserSettings const& _settings, std::set<size_t> _tagsReferencedFromOutside);
std::map<u256, u256> const& optimiseInternal(OptimiserSettings const& _settings, std::set<size_t> _tagsReferencedFromOutside);
unsigned bytesRequired(unsigned subTagSize) const;
@ -210,6 +210,10 @@ protected:
/// This map is used only for sub-assemblies which are not direct sub-assemblies (where path is having more than one value).
std::map<std::vector<size_t>, size_t> m_subPaths;
/// Contains the tag replacements relevant for super-assemblies.
/// If set, it means the optimizer has run and we will not run it again.
std::optional<std::map<u256, u256>> m_tagReplacements;
mutable LinkerObject m_assembledObject;
mutable std::vector<size_t> m_tagPositionsInBytecode;