[yul-phaser] Pass unique_ptr rather than a mutable reference to Program::applyOptimisationSteps()

- Giving the function ownership of an object and then receiving back another object is better than letting it implicitly modify data passed in an argument.
This commit is contained in:
cameel 2020-01-31 11:32:44 +01:00 committed by Kamil Śliwak
parent dd7a5c3386
commit a189c8b6e2
2 changed files with 8 additions and 6 deletions

View File

@ -79,7 +79,7 @@ Program Program::load(CharStream& _sourceCode)
void Program::optimise(vector<string> const& _optimisationSteps)
{
applyOptimisationSteps(m_dialect, m_nameDispenser, *m_ast, _optimisationSteps);
m_ast = applyOptimisationSteps(m_dialect, m_nameDispenser, move(m_ast), _optimisationSteps);
}
ostream& phaser::operator<<(ostream& _stream, Program const& _program)
@ -133,10 +133,10 @@ unique_ptr<Block> Program::disambiguateAST(
return make_unique<Block>(get<Block>(disambiguator(_ast)));
}
void Program::applyOptimisationSteps(
unique_ptr<Block> Program::applyOptimisationSteps(
Dialect const& _dialect,
NameDispenser& _nameDispenser,
Block& _ast,
unique_ptr<Block> _ast,
vector<string> const& _optimisationSteps
)
{
@ -146,7 +146,9 @@ void Program::applyOptimisationSteps(
OptimiserStepContext context{_dialect, _nameDispenser, externallyUsedIdentifiers};
for (string const& step: _optimisationSteps)
OptimiserSuite::allSteps().at(step)->run(context, _ast);
OptimiserSuite::allSteps().at(step)->run(context, *_ast);
return _ast;
}
size_t Program::computeCodeSize(Block const& _ast)

View File

@ -97,10 +97,10 @@ private:
yul::Block const& _ast,
yul::AsmAnalysisInfo const& _analysisInfo
);
static void applyOptimisationSteps(
static std::unique_ptr<yul::Block> applyOptimisationSteps(
yul::Dialect const& _dialect,
yul::NameDispenser& _nameDispenser,
yul::Block& _ast,
std::unique_ptr<yul::Block> _ast,
std::vector<std::string> const& _optimisationSteps
);
static size_t computeCodeSize(yul::Block const& _ast);