From be849b3c4752c49d89a6eb549c4bb674c0c04aca Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Tue, 19 Nov 2019 16:42:49 +0100 Subject: [PATCH] Replace boost::variant by std::variant in libyul --- libsolidity/analysis/ViewPureChecker.cpp | 22 ++++---- .../codegen/ir/IRGeneratorForStatements.cpp | 4 +- libyul/AsmAnalysis.cpp | 24 ++++---- libyul/AsmAnalysis.h | 4 +- libyul/AsmData.h | 5 +- libyul/AsmDataForward.h | 6 +- libyul/AsmParser.cpp | 56 +++++++++---------- libyul/AsmParser.h | 4 +- libyul/AsmPrinter.cpp | 21 +++---- libyul/AsmPrinter.h | 4 +- libyul/AsmScope.cpp | 4 +- libyul/AsmScope.h | 7 +-- libyul/AsmScopeFiller.cpp | 10 ++-- libyul/AsmScopeFiller.h | 4 +- libyul/backends/evm/ConstantOptimiser.cpp | 12 ++-- libyul/backends/evm/EVMCodeTransform.cpp | 36 ++++++------ libyul/backends/evm/EVMCodeTransform.h | 4 +- libyul/backends/evm/EVMDialect.cpp | 4 +- libyul/backends/wasm/BinaryTransform.cpp | 14 ++--- libyul/backends/wasm/BinaryTransform.h | 2 +- libyul/backends/wasm/EVMToEWasmTranslator.cpp | 4 +- libyul/backends/wasm/EWasmAST.h | 4 +- libyul/backends/wasm/EWasmCodeTransform.cpp | 14 ++--- libyul/backends/wasm/EWasmCodeTransform.h | 2 +- libyul/backends/wasm/EWasmToText.cpp | 2 +- libyul/backends/wasm/EWasmToText.h | 2 +- libyul/backends/wasm/WordSizeTransform.cpp | 47 ++++++++-------- libyul/optimiser/ASTCopier.cpp | 4 +- libyul/optimiser/ASTCopier.h | 6 +- libyul/optimiser/ASTWalker.cpp | 8 +-- libyul/optimiser/ASTWalker.h | 6 +- libyul/optimiser/BlockFlattener.cpp | 4 +- .../CommonSubexpressionEliminator.cpp | 12 ++-- libyul/optimiser/ConditionalSimplifier.cpp | 12 ++-- libyul/optimiser/ConditionalUnsimplifier.cpp | 28 +++++----- libyul/optimiser/ControlFlowSimplifier.cpp | 6 +- libyul/optimiser/DataFlowAnalyzer.cpp | 13 +++-- libyul/optimiser/DeadCodeEliminator.cpp | 2 +- libyul/optimiser/Disambiguator.h | 2 - libyul/optimiser/ExpressionInliner.cpp | 6 +- libyul/optimiser/ExpressionInliner.h | 2 - libyul/optimiser/ExpressionJoiner.cpp | 12 ++-- libyul/optimiser/ExpressionSplitter.cpp | 2 +- libyul/optimiser/ForLoopConditionIntoBody.cpp | 4 +- .../optimiser/ForLoopConditionOutOfBody.cpp | 16 +++--- libyul/optimiser/ForLoopInitRewriter.cpp | 4 +- libyul/optimiser/FullInliner.cpp | 24 ++++---- libyul/optimiser/FullInliner.h | 2 - libyul/optimiser/FunctionGrouper.cpp | 8 +-- libyul/optimiser/FunctionHoister.cpp | 4 +- .../InlinableExpressionFunctionFinder.cpp | 6 +- libyul/optimiser/KnowledgeBase.cpp | 23 ++++---- libyul/optimiser/LoadResolver.cpp | 12 ++-- libyul/optimiser/MainFunction.cpp | 6 +- libyul/optimiser/Metrics.cpp | 24 ++++---- libyul/optimiser/NameDisplacer.cpp | 4 +- libyul/optimiser/OptimizerUtilities.cpp | 2 +- .../optimiser/RedundantAssignEliminator.cpp | 2 +- libyul/optimiser/Rematerialiser.cpp | 10 ++-- libyul/optimiser/SSAReverser.cpp | 12 ++-- libyul/optimiser/SSATransform.cpp | 32 +++++------ libyul/optimiser/Semantics.cpp | 16 +++--- libyul/optimiser/SimplificationRules.cpp | 20 +++---- libyul/optimiser/StackCompressor.cpp | 10 ++-- libyul/optimiser/StructuralSimplifier.cpp | 6 +- libyul/optimiser/Substitution.cpp | 4 +- libyul/optimiser/Suite.cpp | 8 +-- libyul/optimiser/SyntacticalEquality.cpp | 4 +- libyul/optimiser/UnusedPruner.cpp | 12 ++-- libyul/optimiser/VarDeclInitializer.cpp | 2 +- libyul/optimiser/VarNameCleaner.cpp | 4 +- test/libyul/Common.cpp | 4 +- test/libyul/YulOptimizerTest.cpp | 3 +- test/tools/yulInterpreter/Interpreter.cpp | 5 +- test/tools/yulopti.cpp | 3 +- 75 files changed, 371 insertions(+), 372 deletions(-) diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index 58baec906..b18261113 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -21,7 +21,9 @@ #include #include #include + #include +#include using namespace std; using namespace dev; @@ -31,7 +33,7 @@ using namespace dev::solidity; namespace { -class AssemblyViewPureChecker: public boost::static_visitor +class AssemblyViewPureChecker { public: explicit AssemblyViewPureChecker( @@ -52,21 +54,21 @@ public: { checkInstruction(_instr.location, _instr.instruction); for (auto const& arg: _instr.arguments) - boost::apply_visitor(*this, arg); + std::visit(*this, arg); } void operator()(yul::ExpressionStatement const& _expr) { - boost::apply_visitor(*this, _expr.expression); + std::visit(*this, _expr.expression); } void operator()(yul::StackAssignment const&) {} void operator()(yul::Assignment const& _assignment) { - boost::apply_visitor(*this, *_assignment.value); + std::visit(*this, *_assignment.value); } void operator()(yul::VariableDeclaration const& _varDecl) { if (_varDecl.value) - boost::apply_visitor(*this, *_varDecl.value); + std::visit(*this, *_varDecl.value); } void operator()(yul::FunctionDefinition const& _funDef) { @@ -80,16 +82,16 @@ public: checkInstruction(_funCall.location, *fun->instruction); for (auto const& arg: _funCall.arguments) - boost::apply_visitor(*this, arg); + std::visit(*this, arg); } void operator()(yul::If const& _if) { - boost::apply_visitor(*this, *_if.condition); + std::visit(*this, *_if.condition); (*this)(_if.body); } void operator()(yul::Switch const& _switch) { - boost::apply_visitor(*this, *_switch.expression); + std::visit(*this, *_switch.expression); for (auto const& _case: _switch.cases) { if (_case.value) @@ -100,7 +102,7 @@ public: void operator()(yul::ForLoop const& _for) { (*this)(_for.pre); - boost::apply_visitor(*this, *_for.condition); + std::visit(*this, *_for.condition); (*this)(_for.body); (*this)(_for.post); } @@ -113,7 +115,7 @@ public: void operator()(yul::Block const& _block) { for (auto const& s: _block.statements) - boost::apply_visitor(*this, s); + std::visit(*this, s); } private: diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index 5dcb811cc..b2d47292f 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -833,9 +833,9 @@ bool IRGeneratorForStatements::visit(InlineAssembly const& _inlineAsm) yul::Statement modified = bodyCopier(_inlineAsm.operations()); - solAssert(modified.type() == typeid(yul::Block), ""); + solAssert(holds_alternative(modified), ""); - m_code << yul::AsmPrinter()(boost::get(std::move(modified))) << "\n"; + m_code << yul::AsmPrinter()(std::get(std::move(modified))) << "\n"; return false; } diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index 9c62737d8..35e933cd1 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -214,7 +214,7 @@ bool AsmAnalyzer::operator()(FunctionalInstruction const& _instr) bool AsmAnalyzer::operator()(ExpressionStatement const& _statement) { int initialStackHeight = m_stackHeight; - bool success = boost::apply_visitor(*this, _statement.expression); + bool success = std::visit(*this, _statement.expression); if (m_stackHeight != initialStackHeight && (m_dialect.flavour != AsmFlavour::Loose || m_errorTypeForLoose)) { Error::Type errorType = m_dialect.flavour == AsmFlavour::Loose ? *m_errorTypeForLoose : Error::Type::TypeError; @@ -249,7 +249,7 @@ bool AsmAnalyzer::operator()(Assignment const& _assignment) int const expectedItems = _assignment.variableNames.size(); solAssert(expectedItems >= 1, ""); int const stackHeight = m_stackHeight; - bool success = boost::apply_visitor(*this, *_assignment.value); + bool success = std::visit(*this, *_assignment.value); if ((m_stackHeight - stackHeight) != expectedItems) { m_errorReporter.declarationError( @@ -276,7 +276,7 @@ bool AsmAnalyzer::operator()(VariableDeclaration const& _varDecl) if (_varDecl.value) { int const stackHeight = m_stackHeight; - success = boost::apply_visitor(*this, *_varDecl.value); + success = std::visit(*this, *_varDecl.value); int numValues = m_stackHeight - stackHeight; if (numValues != numVariables) { @@ -298,7 +298,7 @@ bool AsmAnalyzer::operator()(VariableDeclaration const& _varDecl) for (auto const& variable: _varDecl.variables) { expectValidType(variable.type.str(), variable.location); - m_activeVariables.insert(&boost::get(m_currentScope->identifiers.at(variable.name))); + m_activeVariables.insert(&std::get(m_currentScope->identifiers.at(variable.name))); } m_info.stackHeightInfo[&_varDecl] = m_stackHeight; return success; @@ -313,7 +313,7 @@ bool AsmAnalyzer::operator()(FunctionDefinition const& _funDef) for (auto const& var: _funDef.parameters + _funDef.returnVariables) { expectValidType(var.type.str(), var.location); - m_activeVariables.insert(&boost::get(varScope.identifiers.at(var.name))); + m_activeVariables.insert(&std::get(varScope.identifiers.at(var.name))); } int const stackHeight = m_stackHeight; @@ -388,15 +388,15 @@ bool AsmAnalyzer::operator()(FunctionCall const& _funCall) success = false; else if (needsLiteralArguments) { - if (arg.type() != typeid(Literal)) + if (!holds_alternative(arg)) m_errorReporter.typeError( _funCall.functionName.location, "Function expects direct literals as arguments." ); - else if (!m_dataNames.count(boost::get(arg).value)) + else if (!m_dataNames.count(std::get(arg).value)) m_errorReporter.typeError( _funCall.functionName.location, - "Unknown data object \"" + boost::get(arg).value.str() + "\"." + "Unknown data object \"" + std::get(arg).value.str() + "\"." ); } } @@ -556,7 +556,7 @@ bool AsmAnalyzer::operator()(Block const& _block) int const initialStackHeight = m_stackHeight; for (auto const& s: _block.statements) - if (!boost::apply_visitor(*this, s)) + if (!std::visit(*this, s)) success = false; m_stackHeight -= scope(&_block).numberOfVariables(); @@ -585,7 +585,7 @@ bool AsmAnalyzer::expectExpression(Expression const& _expr) { bool success = true; int const initialHeight = m_stackHeight; - if (!boost::apply_visitor(*this, _expr)) + if (!std::visit(*this, _expr)) success = false; if (!expectDeposit(1, initialHeight, locationOf(_expr))) success = false; @@ -616,12 +616,12 @@ bool AsmAnalyzer::checkAssignment(Identifier const& _variable, size_t _valueSize if (Scope::Identifier const* var = m_currentScope->lookup(_variable.name)) { // Check that it is a variable - if (var->type() != typeid(Scope::Variable)) + if (!holds_alternative(*var)) { m_errorReporter.typeError(_variable.location, "Assignment requires variable."); success = false; } - else if (!m_activeVariables.count(&boost::get(*var))) + else if (!m_activeVariables.count(&std::get(*var))) { m_errorReporter.declarationError( _variable.location, diff --git a/libyul/AsmAnalysis.h b/libyul/AsmAnalysis.h index 14337d323..40d9a1d51 100644 --- a/libyul/AsmAnalysis.h +++ b/libyul/AsmAnalysis.h @@ -30,8 +30,6 @@ #include #include -#include - #include #include #include @@ -53,7 +51,7 @@ struct AsmAnalysisInfo; * references and performs other checks. * If all these checks pass, code generation should not throw errors. */ -class AsmAnalyzer: public boost::static_visitor +class AsmAnalyzer { public: explicit AsmAnalyzer( diff --git a/libyul/AsmData.h b/libyul/AsmData.h index cedff1106..33bf48090 100644 --- a/libyul/AsmData.h +++ b/libyul/AsmData.h @@ -28,7 +28,6 @@ #include #include -#include #include #include @@ -83,7 +82,7 @@ struct Break { langutil::SourceLocation location; }; /// Continue statement (valid within for loop) struct Continue { langutil::SourceLocation location; }; -struct LocationExtractor: boost::static_visitor +struct LocationExtractor { template langutil::SourceLocation operator()(T const& _node) const { @@ -94,7 +93,7 @@ struct LocationExtractor: boost::static_visitor /// Extracts the source location from an inline assembly node. template inline langutil::SourceLocation locationOf(T const& _node) { - return boost::apply_visitor(LocationExtractor(), _node); + return std::visit(LocationExtractor(), _node); } } diff --git a/libyul/AsmDataForward.h b/libyul/AsmDataForward.h index d01b1dffa..29c9db3f3 100644 --- a/libyul/AsmDataForward.h +++ b/libyul/AsmDataForward.h @@ -22,7 +22,7 @@ #pragma once -#include +#include namespace yul { @@ -48,7 +48,7 @@ struct Block; struct TypedName; -using Expression = boost::variant; -using Statement = boost::variant; +using Expression = std::variant; +using Statement = std::variant; } diff --git a/libyul/AsmParser.cpp b/libyul/AsmParser.cpp index ae3056f21..75e488290 100644 --- a/libyul/AsmParser.cpp +++ b/libyul/AsmParser.cpp @@ -184,7 +184,7 @@ Statement Parser::parseStatement() while (true) { - if (elementary.type() != typeid(Identifier)) + if (!holds_alternative(elementary)) { auto const token = currentToken() == Token::Comma ? "," : ":="; @@ -196,7 +196,7 @@ Statement Parser::parseStatement() ); } - auto const& identifier = boost::get(elementary); + auto const& identifier = std::get(elementary); if (m_dialect.builtin(identifier.name)) fatalParserError("Cannot assign to builtin function \"" + identifier.name.str() + "\"."); @@ -212,7 +212,7 @@ Statement Parser::parseStatement() } Assignment assignment = - createWithLocation(boost::get(elementary).location); + createWithLocation(std::get(elementary).location); assignment.variableNames = std::move(variableNames); expectToken(Token::AssemblyAssign); @@ -224,10 +224,10 @@ Statement Parser::parseStatement() } case Token::Colon: { - if (elementary.type() != typeid(Identifier)) + if (!holds_alternative(elementary)) fatalParserError("Label name must precede \":\"."); - Identifier const& identifier = boost::get(elementary); + Identifier const& identifier = std::get(elementary); advance(); @@ -245,20 +245,20 @@ Statement Parser::parseStatement() break; } - if (elementary.type() == typeid(Identifier)) + if (holds_alternative(elementary)) { - Identifier& identifier = boost::get(elementary); + Identifier& identifier = std::get(elementary); return ExpressionStatement{identifier.location, { move(identifier) }}; } - else if (elementary.type() == typeid(Literal)) + else if (holds_alternative(elementary)) { - Expression expr = boost::get(elementary); + Expression expr = std::get(elementary); return ExpressionStatement{locationOf(expr), expr}; } else { - solAssert(elementary.type() == typeid(Instruction), "Invalid elementary operation."); - return boost::get(elementary); + solAssert(holds_alternative(elementary), "Invalid elementary operation."); + return std::get(elementary); } } @@ -272,9 +272,9 @@ Case Parser::parseCase() { advance(); ElementaryOperation literal = parseElementaryOperation(); - if (literal.type() != typeid(Literal)) + if (!holds_alternative(literal)) fatalParserError("Literal expected."); - _case.value = make_unique(boost::get(std::move(literal))); + _case.value = make_unique(std::get(std::move(literal))); } else solAssert(false, "Case or default case expected."); @@ -311,12 +311,12 @@ Expression Parser::parseExpression() RecursionGuard recursionGuard(*this); ElementaryOperation operation = parseElementaryOperation(); - if (operation.type() == typeid(FunctionCall)) + if (holds_alternative(operation)) return parseCall(std::move(operation)); - else if (operation.type() == typeid(Instruction)) + else if (holds_alternative(operation)) { solAssert(m_dialect.flavour == AsmFlavour::Loose, ""); - Instruction const& instr = boost::get(operation); + Instruction const& instr = std::get(operation); // Disallow instructions returning multiple values (and DUP/SWAP) as expression. if ( instructionInfo(instr.instruction).ret != 1 || @@ -345,19 +345,19 @@ Expression Parser::parseExpression() } if (currentToken() == Token::LParen) return parseCall(std::move(operation)); - else if (operation.type() == typeid(Instruction)) + else if (holds_alternative(operation)) { // Instructions not taking arguments are allowed as expressions. solAssert(m_dialect.flavour == AsmFlavour::Loose, ""); - Instruction& instr = boost::get(operation); + Instruction& instr = std::get(operation); return FunctionalInstruction{std::move(instr.location), instr.instruction, {}}; } - else if (operation.type() == typeid(Identifier)) - return boost::get(operation); + else if (holds_alternative(operation)) + return std::get(operation); else { - solAssert(operation.type() == typeid(Literal), ""); - return boost::get(operation); + solAssert(holds_alternative(operation), ""); + return std::get(operation); } } @@ -537,10 +537,10 @@ FunctionDefinition Parser::parseFunctionDefinition() Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp) { RecursionGuard recursionGuard(*this); - if (_initialOp.type() == typeid(Instruction)) + if (holds_alternative(_initialOp)) { solAssert(m_dialect.flavour != AsmFlavour::Yul, "Instructions are invalid in Yul"); - Instruction& instruction = boost::get(_initialOp); + Instruction& instruction = std::get(_initialOp); FunctionalInstruction ret; ret.instruction = instruction.instruction; ret.location = std::move(instruction.location); @@ -591,16 +591,16 @@ Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp) expectToken(Token::RParen); return ret; } - else if (_initialOp.type() == typeid(Identifier) || _initialOp.type() == typeid(FunctionCall)) + else if (holds_alternative(_initialOp) || holds_alternative(_initialOp)) { FunctionCall ret; - if (_initialOp.type() == typeid(Identifier)) + if (holds_alternative(_initialOp)) { - ret.functionName = std::move(boost::get(_initialOp)); + ret.functionName = std::move(std::get(_initialOp)); ret.location = ret.functionName.location; } else - ret = std::move(boost::get(_initialOp)); + ret = std::move(std::get(_initialOp)); expectToken(Token::LParen); if (currentToken() != Token::RParen) { diff --git a/libyul/AsmParser.h b/libyul/AsmParser.h index 6f88a211e..80b8edc26 100644 --- a/libyul/AsmParser.h +++ b/libyul/AsmParser.h @@ -30,9 +30,9 @@ #include #include +#include #include - namespace yul { @@ -56,7 +56,7 @@ public: static std::map const& instructions(); protected: - using ElementaryOperation = boost::variant; + using ElementaryOperation = std::variant; /// Creates an inline assembly node with the given source location. template T createWithLocation(langutil::SourceLocation const& _loc = {}) const diff --git a/libyul/AsmPrinter.cpp b/libyul/AsmPrinter.cpp index 71151a0cf..7814100aa 100644 --- a/libyul/AsmPrinter.cpp +++ b/libyul/AsmPrinter.cpp @@ -103,14 +103,15 @@ string AsmPrinter::operator()(FunctionalInstruction const& _functionalInstructio boost::to_lower_copy(instructionInfo(_functionalInstruction.instruction).name) + "(" + boost::algorithm::join( - _functionalInstruction.arguments | boost::adaptors::transformed(boost::apply_visitor(*this)), - ", ") + + _functionalInstruction.arguments | boost::adaptors::transformed([&](auto&& _node) { return std::visit(*this, _node); }), + ", " + ) + ")"; } string AsmPrinter::operator()(ExpressionStatement const& _statement) const { - return boost::apply_visitor(*this, _statement.expression); + return std::visit(*this, _statement.expression); } string AsmPrinter::operator()(Label const& _label) const @@ -133,7 +134,7 @@ string AsmPrinter::operator()(Assignment const& _assignment) const string variables = (*this)(_assignment.variableNames.front()); for (size_t i = 1; i < _assignment.variableNames.size(); ++i) variables += ", " + (*this)(_assignment.variableNames[i]); - return variables + " := " + boost::apply_visitor(*this, *_assignment.value); + return variables + " := " + std::visit(*this, *_assignment.value); } string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration) const @@ -148,7 +149,7 @@ string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration) c if (_variableDeclaration.value) { out += " := "; - out += boost::apply_visitor(*this, *_variableDeclaration.value); + out += std::visit(*this, *_variableDeclaration.value); } return out; } @@ -183,7 +184,7 @@ string AsmPrinter::operator()(FunctionCall const& _functionCall) const return (*this)(_functionCall.functionName) + "(" + boost::algorithm::join( - _functionCall.arguments | boost::adaptors::transformed(boost::apply_visitor(*this)), + _functionCall.arguments | boost::adaptors::transformed([&](auto&& _node) { return std::visit(*this, _node); }), ", " ) + ")"; } @@ -195,13 +196,13 @@ string AsmPrinter::operator()(If const& _if) const char delim = '\n'; if (body.find('\n') == string::npos) delim = ' '; - return "if " + boost::apply_visitor(*this, *_if.condition) + delim + (*this)(_if.body); + return "if " + std::visit(*this, *_if.condition) + delim + (*this)(_if.body); } string AsmPrinter::operator()(Switch const& _switch) const { solAssert(_switch.expression, "Invalid expression pointer."); - string out = "switch " + boost::apply_visitor(*this, *_switch.expression); + string out = "switch " + std::visit(*this, *_switch.expression); for (auto const& _case: _switch.cases) { if (!_case.value) @@ -217,7 +218,7 @@ string AsmPrinter::operator()(ForLoop const& _forLoop) const { solAssert(_forLoop.condition, "Invalid for loop condition."); string pre = (*this)(_forLoop.pre); - string condition = boost::apply_visitor(*this, *_forLoop.condition); + string condition = std::visit(*this, *_forLoop.condition); string post = (*this)(_forLoop.post); char delim = '\n'; if ( @@ -246,7 +247,7 @@ string AsmPrinter::operator()(Block const& _block) const if (_block.statements.empty()) return "{ }"; string body = boost::algorithm::join( - _block.statements | boost::adaptors::transformed(boost::apply_visitor(*this)), + _block.statements | boost::adaptors::transformed([&](auto&& _node) { return std::visit(*this, _node); }), "\n" ); if (body.size() < 30 && body.find('\n') == string::npos) diff --git a/libyul/AsmPrinter.h b/libyul/AsmPrinter.h index 82fed24f2..cf4fcecb2 100644 --- a/libyul/AsmPrinter.h +++ b/libyul/AsmPrinter.h @@ -26,12 +26,10 @@ #include -#include - namespace yul { -class AsmPrinter: public boost::static_visitor +class AsmPrinter { public: explicit AsmPrinter(bool _yul = false): m_yul(_yul) {} diff --git a/libyul/AsmScope.cpp b/libyul/AsmScope.cpp index 252361d27..b10130e57 100644 --- a/libyul/AsmScope.cpp +++ b/libyul/AsmScope.cpp @@ -58,7 +58,7 @@ Scope::Identifier* Scope::lookup(YulString _name) auto id = s->identifiers.find(_name); if (id != s->identifiers.end()) { - if (crossedFunctionBoundary && id->second.type() == typeid(Scope::Variable)) + if (crossedFunctionBoundary && holds_alternative(id->second)) return nullptr; else return &id->second; @@ -84,7 +84,7 @@ size_t Scope::numberOfVariables() const { size_t count = 0; for (auto const& identifier: identifiers) - if (identifier.second.type() == typeid(Scope::Variable)) + if (holds_alternative(identifier.second)) count++; return count; } diff --git a/libyul/AsmScope.h b/libyul/AsmScope.h index 2c7af4ef1..e8cd6ef64 100644 --- a/libyul/AsmScope.h +++ b/libyul/AsmScope.h @@ -26,11 +26,10 @@ #include -#include - #include #include #include +#include namespace yul { @@ -48,7 +47,7 @@ struct Scope std::vector returns; }; - using Identifier = boost::variant; + using Identifier = std::variant; using Visitor = dev::GenericVisitor; using NonconstVisitor = dev::GenericVisitor; @@ -74,7 +73,7 @@ struct Scope { if (Identifier* id = lookup(_name)) { - boost::apply_visitor(_visitor, *id); + std::visit(_visitor, *id); return true; } else diff --git a/libyul/AsmScopeFiller.cpp b/libyul/AsmScopeFiller.cpp index 1706b147d..3c940c92f 100644 --- a/libyul/AsmScopeFiller.cpp +++ b/libyul/AsmScopeFiller.cpp @@ -47,7 +47,7 @@ ScopeFiller::ScopeFiller(AsmAnalysisInfo& _info, ErrorReporter& _errorReporter): bool ScopeFiller::operator()(ExpressionStatement const& _expr) { - return boost::apply_visitor(*this, _expr.expression); + return std::visit(*this, _expr.expression); } bool ScopeFiller::operator()(Label const& _item) @@ -116,7 +116,7 @@ bool ScopeFiller::operator()(ForLoop const& _forLoop) if (!(*this)(_forLoop.pre)) success = false; m_currentScope = &scope(&_forLoop.pre); - if (!boost::apply_visitor(*this, *_forLoop.condition)) + if (!std::visit(*this, *_forLoop.condition)) success = false; if (!(*this)(_forLoop.body)) success = false; @@ -137,11 +137,11 @@ bool ScopeFiller::operator()(Block const& _block) // First visit all functions to make them create // an entry in the scope according to their visibility. for (auto const& s: _block.statements) - if (s.type() == typeid(FunctionDefinition)) - if (!registerFunction(boost::get(s))) + if (holds_alternative(s)) + if (!registerFunction(std::get(s))) success = false; for (auto const& s: _block.statements) - if (!boost::apply_visitor(*this, s)) + if (!std::visit(*this, s)) success = false; m_currentScope = m_currentScope->superScope; diff --git a/libyul/AsmScopeFiller.h b/libyul/AsmScopeFiller.h index 220538bb2..f019889c5 100644 --- a/libyul/AsmScopeFiller.h +++ b/libyul/AsmScopeFiller.h @@ -22,8 +22,6 @@ #include -#include - #include #include @@ -44,7 +42,7 @@ struct AsmAnalysisInfo; * Fills scopes with identifiers and checks for name clashes. * Does not resolve references. */ -class ScopeFiller: public boost::static_visitor +class ScopeFiller { public: ScopeFiller(AsmAnalysisInfo& _info, langutil::ErrorReporter& _errorReporter); diff --git a/libyul/backends/evm/ConstantOptimiser.cpp b/libyul/backends/evm/ConstantOptimiser.cpp index f8b4854d8..74fe7667e 100644 --- a/libyul/backends/evm/ConstantOptimiser.cpp +++ b/libyul/backends/evm/ConstantOptimiser.cpp @@ -27,6 +27,8 @@ #include +#include + using namespace std; using namespace dev; using namespace yul; @@ -35,13 +37,13 @@ using Representation = ConstantOptimiser::Representation; namespace { -struct MiniEVMInterpreter: boost::static_visitor +struct MiniEVMInterpreter { explicit MiniEVMInterpreter(EVMDialect const& _dialect): m_dialect(_dialect) {} u256 eval(Expression const& _expr) { - return boost::apply_visitor(*this, _expr); + return std::visit(*this, _expr); } u256 eval(dev::eth::Instruction _instr, vector const& _arguments) @@ -92,9 +94,9 @@ struct MiniEVMInterpreter: boost::static_visitor void ConstantOptimiser::visit(Expression& _e) { - if (_e.type() == typeid(Literal)) + if (holds_alternative(_e)) { - Literal const& literal = boost::get(_e); + Literal const& literal = std::get(_e); if (literal.kind != LiteralKind::Number) return; @@ -115,7 +117,7 @@ Expression const* RepresentationFinder::tryFindRepresentation(dev::u256 const& _ return nullptr; Representation const& repr = findRepresentation(_value); - if (repr.expression->type() == typeid(Literal)) + if (holds_alternative(*repr.expression)) return nullptr; else return repr.expression.get(); diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp index d3493b573..ee564ed6b 100644 --- a/libyul/backends/evm/EVMCodeTransform.cpp +++ b/libyul/backends/evm/EVMCodeTransform.cpp @@ -29,6 +29,8 @@ #include +#include + using namespace std; using namespace dev; using namespace yul; @@ -146,9 +148,9 @@ void CodeTransform::freeUnusedVariables() return; for (auto const& identifier: m_scope->identifiers) - if (identifier.second.type() == typeid(Scope::Variable)) + if (holds_alternative(identifier.second)) { - Scope::Variable const& var = boost::get(identifier.second); + Scope::Variable const& var = std::get(identifier.second); if (m_variablesScheduledForDeletion.count(&var)) deleteVariable(var); } @@ -179,7 +181,7 @@ void CodeTransform::operator()(VariableDeclaration const& _varDecl) int height = m_assembly.stackHeight(); if (_varDecl.value) { - boost::apply_visitor(*this, *_varDecl.value); + std::visit(*this, *_varDecl.value); expectDeposit(numVariables, height); } else @@ -193,7 +195,7 @@ void CodeTransform::operator()(VariableDeclaration const& _varDecl) for (int varIndex = numVariables - 1; varIndex >= 0; --varIndex) { YulString varName = _varDecl.variables[varIndex].name; - auto& var = boost::get(m_scope->identifiers.at(varName)); + auto& var = std::get(m_scope->identifiers.at(varName)); m_context->variableStackHeights[&var] = height + varIndex; if (!m_allowStackOpt) continue; @@ -242,7 +244,7 @@ void CodeTransform::stackError(StackTooDeepError _error, int _targetStackHeight) void CodeTransform::operator()(Assignment const& _assignment) { int height = m_assembly.stackHeight(); - boost::apply_visitor(*this, *_assignment.value); + std::visit(*this, *_assignment.value); expectDeposit(_assignment.variableNames.size(), height); m_assembly.setSourceLocation(_assignment.location); @@ -261,7 +263,7 @@ void CodeTransform::operator()(StackAssignment const& _assignment) void CodeTransform::operator()(ExpressionStatement const& _statement) { m_assembly.setSourceLocation(_statement.location); - boost::apply_visitor(*this, _statement.expression); + std::visit(*this, _statement.expression); checkStackHeight(&_statement); } @@ -271,7 +273,7 @@ void CodeTransform::operator()(Label const& _label) m_assembly.setSourceLocation(_label.location); solAssert(m_scope, ""); solAssert(m_scope->identifiers.count(_label.name), ""); - Scope::Label& label = boost::get(m_scope->identifiers.at(_label.name)); + Scope::Label& label = std::get(m_scope->identifiers.at(_label.name)); m_assembly.appendLabel(labelID(label)); checkStackHeight(&_label); } @@ -340,7 +342,7 @@ void CodeTransform::operator()(FunctionalInstruction const& _instruction) solAssert(_instruction.arguments.size() == 1, ""); } m_assembly.setSourceLocation(_instruction.location); - auto label = labelFromIdentifier(boost::get(_instruction.arguments.at(0))); + auto label = labelFromIdentifier(std::get(_instruction.arguments.at(0))); if (isJumpI) m_assembly.appendJumpToIf(label); else @@ -476,7 +478,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) { solAssert(m_scope, ""); solAssert(m_scope->identifiers.count(_function.name), ""); - Scope::Function& function = boost::get(m_scope->identifiers.at(_function.name)); + Scope::Function& function = std::get(m_scope->identifiers.at(_function.name)); int const localStackAdjustment = m_evm15 ? 0 : 1; int height = localStackAdjustment; @@ -485,7 +487,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) solAssert(varScope, ""); for (auto const& v: _function.parameters | boost::adaptors::reversed) { - auto& var = boost::get(varScope->identifiers.at(v.name)); + auto& var = std::get(varScope->identifiers.at(v.name)); m_context->variableStackHeights[&var] = height++; } @@ -503,7 +505,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) for (auto const& v: _function.returnVariables) { - auto& var = boost::get(varScope->identifiers.at(v.name)); + auto& var = std::get(varScope->identifiers.at(v.name)); m_context->variableStackHeights[&var] = height++; // Preset stack slots for return variables to zero. m_assembly.appendConstant(u256(0)); @@ -717,7 +719,7 @@ AbstractAssembly::LabelID CodeTransform::functionEntryID(YulString _name, Scope: void CodeTransform::visitExpression(Expression const& _expression) { int height = m_assembly.stackHeight(); - boost::apply_visitor(*this, _expression); + std::visit(*this, _expression); expectDeposit(1, height); } @@ -728,7 +730,7 @@ void CodeTransform::visitStatements(vector const& _statements) for (auto const& statement: _statements) { freeUnusedVariables(); - auto const* functionDefinition = boost::get(&statement); + auto const* functionDefinition = std::get_if(&statement); if (functionDefinition && !jumpTarget) { m_assembly.setSourceLocation(locationOf(statement)); @@ -741,7 +743,7 @@ void CodeTransform::visitStatements(vector const& _statements) jumpTarget = std::nullopt; } - boost::apply_visitor(*this, statement); + std::visit(*this, statement); } // we may have a leftover jumpTarget if (jumpTarget) @@ -759,9 +761,9 @@ void CodeTransform::finalizeBlock(Block const& _block, int blockStartStackHeight // pop variables solAssert(m_info.scopes.at(&_block).get() == m_scope, ""); for (auto const& id: m_scope->identifiers) - if (id.second.type() == typeid(Scope::Variable)) + if (holds_alternative(id.second)) { - Scope::Variable const& var = boost::get(id.second); + Scope::Variable const& var = std::get(id.second); if (m_allowStackOpt) { solAssert(!m_context->variableStackHeights.count(&var), ""); @@ -789,7 +791,7 @@ void CodeTransform::generateAssignment(Identifier const& _variableName) solAssert(m_scope, ""); if (auto var = m_scope->lookup(_variableName.name)) { - Scope::Variable const& _var = boost::get(*var); + Scope::Variable const& _var = std::get(*var); if (int heightDiff = variableHeightDiff(_var, _variableName.name, true)) m_assembly.appendInstruction(dev::eth::swapInstruction(heightDiff - 1)); m_assembly.appendInstruction(dev::eth::Instruction::POP); diff --git a/libyul/backends/evm/EVMCodeTransform.h b/libyul/backends/evm/EVMCodeTransform.h index e44953807..fde041686 100644 --- a/libyul/backends/evm/EVMCodeTransform.h +++ b/libyul/backends/evm/EVMCodeTransform.h @@ -27,8 +27,6 @@ #include #include -#include - #include #include @@ -107,7 +105,7 @@ private: Scope* m_scope = nullptr; }; -class CodeTransform: public boost::static_visitor<> +class CodeTransform { public: /// Create the code transformer. diff --git a/libyul/backends/evm/EVMDialect.cpp b/libyul/backends/evm/EVMDialect.cpp index a9cbd2cbc..0da3e8d68 100644 --- a/libyul/backends/evm/EVMDialect.cpp +++ b/libyul/backends/evm/EVMDialect.cpp @@ -113,7 +113,7 @@ map createBuiltins(langutil::EVMVersion _evmVe yulAssert(_context.currentObject, "No object available."); yulAssert(_call.arguments.size() == 1, ""); Expression const& arg = _call.arguments.front(); - YulString dataName = boost::get(arg).value; + YulString dataName = std::get(arg).value; if (_context.currentObject->name == dataName) _assembly.appendAssemblySize(); else @@ -134,7 +134,7 @@ map createBuiltins(langutil::EVMVersion _evmVe yulAssert(_context.currentObject, "No object available."); yulAssert(_call.arguments.size() == 1, ""); Expression const& arg = _call.arguments.front(); - YulString dataName = boost::get(arg).value; + YulString dataName = std::get(arg).value; if (_context.currentObject->name == dataName) _assembly.appendConstant(0); else diff --git a/libyul/backends/wasm/BinaryTransform.cpp b/libyul/backends/wasm/BinaryTransform.cpp index 18f02ec02..563d4d569 100644 --- a/libyul/backends/wasm/BinaryTransform.cpp +++ b/libyul/backends/wasm/BinaryTransform.cpp @@ -298,12 +298,12 @@ bytes BinaryTransform::operator()(BuiltinCall const& _call) // they are references to object names that should not end up in the code. if (_call.functionName == "dataoffset") { - string name = boost::get(_call.arguments.at(0)).value; + string name = std::get(_call.arguments.at(0)).value; return toBytes(Opcode::I64Const) + lebEncodeSigned(m_subModulePosAndSize.at(name).first); } else if (_call.functionName == "datasize") { - string name = boost::get(_call.arguments.at(0)).value; + string name = std::get(_call.arguments.at(0)).value; return toBytes(Opcode::I64Const) + lebEncodeSigned(m_subModulePosAndSize.at(name).second); } @@ -333,7 +333,7 @@ bytes BinaryTransform::operator()(FunctionCall const& _call) bytes BinaryTransform::operator()(LocalAssignment const& _assignment) { return - boost::apply_visitor(*this, *_assignment.value) + + std::visit(*this, *_assignment.value) + toBytes(Opcode::LocalSet) + lebEncode(m_locals.at(_assignment.variableName)); } @@ -341,7 +341,7 @@ bytes BinaryTransform::operator()(LocalAssignment const& _assignment) bytes BinaryTransform::operator()(GlobalAssignment const& _assignment) { return - boost::apply_visitor(*this, *_assignment.value) + + std::visit(*this, *_assignment.value) + toBytes(Opcode::GlobalSet) + lebEncode(m_globals.at(_assignment.variableName)); } @@ -349,7 +349,7 @@ bytes BinaryTransform::operator()(GlobalAssignment const& _assignment) bytes BinaryTransform::operator()(If const& _if) { bytes result = - boost::apply_visitor(*this, *_if.condition) + + std::visit(*this, *_if.condition) + toBytes(Opcode::If) + toBytes(ValueType::Void); @@ -559,7 +559,7 @@ bytes BinaryTransform::visit(vector const& _expressions) { bytes result; for (auto const& expr: _expressions) - result += boost::apply_visitor(*this, expr); + result += std::visit(*this, expr); return result; } @@ -567,7 +567,7 @@ bytes BinaryTransform::visitReversed(vector const& _expressions) { bytes result; for (auto const& expr: _expressions | boost::adaptors::reversed) - result += boost::apply_visitor(*this, expr); + result += std::visit(*this, expr); return result; } diff --git a/libyul/backends/wasm/BinaryTransform.h b/libyul/backends/wasm/BinaryTransform.h index 35c611b21..fb1057489 100644 --- a/libyul/backends/wasm/BinaryTransform.h +++ b/libyul/backends/wasm/BinaryTransform.h @@ -35,7 +35,7 @@ namespace wasm /** * Web assembly to binary transform. */ -class BinaryTransform: public boost::static_visitor +class BinaryTransform { public: static dev::bytes run(Module const& _module); diff --git a/libyul/backends/wasm/EVMToEWasmTranslator.cpp b/libyul/backends/wasm/EVMToEWasmTranslator.cpp index f4de4bc84..6dd6375de 100644 --- a/libyul/backends/wasm/EVMToEWasmTranslator.cpp +++ b/libyul/backends/wasm/EVMToEWasmTranslator.cpp @@ -694,7 +694,7 @@ Object EVMToEWasmTranslator::run(Object const& _object) if (!m_polyfill) parsePolyfill(); - Block ast = boost::get(Disambiguator(m_dialect, *_object.analysisInfo)(*_object.code)); + Block ast = std::get(Disambiguator(m_dialect, *_object.analysisInfo)(*_object.code)); set reservedIdentifiers; NameDispenser nameDispenser{m_dialect, ast, reservedIdentifiers}; OptimiserStepContext context{m_dialect, nameDispenser, reservedIdentifiers}; @@ -752,6 +752,6 @@ void EVMToEWasmTranslator::parsePolyfill() m_polyfillFunctions.clear(); for (auto const& statement: m_polyfill->statements) - m_polyfillFunctions.insert(boost::get(statement).name); + m_polyfillFunctions.insert(std::get(statement).name); } diff --git a/libyul/backends/wasm/EWasmAST.h b/libyul/backends/wasm/EWasmAST.h index 677668ade..8e5bc9ea4 100644 --- a/libyul/backends/wasm/EWasmAST.h +++ b/libyul/backends/wasm/EWasmAST.h @@ -20,7 +20,7 @@ #pragma once -#include +#include #include #include #include @@ -44,7 +44,7 @@ struct If; struct Loop; struct Break; struct BreakIf; -using Expression = boost::variant< +using Expression = std::variant< Literal, StringLiteral, LocalVariable, GlobalVariable, FunctionCall, BuiltinCall, LocalAssignment, GlobalAssignment, Block, If, Loop, Break, BreakIf diff --git a/libyul/backends/wasm/EWasmCodeTransform.cpp b/libyul/backends/wasm/EWasmCodeTransform.cpp index 277df0df2..3503feef2 100644 --- a/libyul/backends/wasm/EWasmCodeTransform.cpp +++ b/libyul/backends/wasm/EWasmCodeTransform.cpp @@ -45,11 +45,11 @@ wasm::Module EWasmCodeTransform::run(Dialect const& _dialect, yul::Block const& for (auto const& statement: _ast.statements) { yulAssert( - statement.type() == typeid(yul::FunctionDefinition), + holds_alternative(statement), "Expected only function definitions at the highest level." ); - if (statement.type() == typeid(yul::FunctionDefinition)) - module.functions.emplace_back(transform.translateFunction(boost::get(statement))); + if (holds_alternative(statement)) + module.functions.emplace_back(transform.translateFunction(std::get(statement))); } for (auto& imp: transform.m_functionsToImport) @@ -157,7 +157,7 @@ wasm::Expression EWasmCodeTransform::operator()(FunctionCall const& _call) { vector literals; for (auto const& arg: _call.arguments) - literals.emplace_back(wasm::StringLiteral{boost::get(arg).value.str()}); + literals.emplace_back(wasm::StringLiteral{std::get(arg).value.str()}); return wasm::BuiltinCall{_call.functionName.name.str(), std::move(literals)}; } else @@ -303,12 +303,12 @@ wasm::Expression EWasmCodeTransform::operator()(Block const& _block) unique_ptr EWasmCodeTransform::visit(yul::Expression const& _expression) { - return make_unique(boost::apply_visitor(*this, _expression)); + return make_unique(std::visit(*this, _expression)); } wasm::Expression EWasmCodeTransform::visitReturnByValue(yul::Expression const& _expression) { - return boost::apply_visitor(*this, _expression); + return std::visit(*this, _expression); } vector EWasmCodeTransform::visit(vector const& _expressions) @@ -321,7 +321,7 @@ vector EWasmCodeTransform::visit(vector const wasm::Expression EWasmCodeTransform::visit(yul::Statement const& _statement) { - return boost::apply_visitor(*this, _statement); + return std::visit(*this, _statement); } vector EWasmCodeTransform::visit(vector const& _statements) diff --git a/libyul/backends/wasm/EWasmCodeTransform.h b/libyul/backends/wasm/EWasmCodeTransform.h index cb9927d20..7b4a248c9 100644 --- a/libyul/backends/wasm/EWasmCodeTransform.h +++ b/libyul/backends/wasm/EWasmCodeTransform.h @@ -32,7 +32,7 @@ namespace yul { struct AsmAnalysisInfo; -class EWasmCodeTransform: public boost::static_visitor +class EWasmCodeTransform { public: static wasm::Module run(Dialect const& _dialect, yul::Block const& _ast); diff --git a/libyul/backends/wasm/EWasmToText.cpp b/libyul/backends/wasm/EWasmToText.cpp index 3971be1f6..cc8e4711d 100644 --- a/libyul/backends/wasm/EWasmToText.cpp +++ b/libyul/backends/wasm/EWasmToText.cpp @@ -171,7 +171,7 @@ string EWasmToText::transform(wasm::FunctionDefinition const& _function) string EWasmToText::visit(wasm::Expression const& _expression) { - return boost::apply_visitor(*this, _expression); + return std::visit(*this, _expression); } string EWasmToText::joinTransformed(vector const& _expressions, char _separator) diff --git a/libyul/backends/wasm/EWasmToText.h b/libyul/backends/wasm/EWasmToText.h index 6163fd80b..51b27c9c9 100644 --- a/libyul/backends/wasm/EWasmToText.h +++ b/libyul/backends/wasm/EWasmToText.h @@ -28,7 +28,7 @@ namespace yul { struct AsmAnalysisInfo; -class EWasmToText: public boost::static_visitor +class EWasmToText { public: std::string run(wasm::Module const& _module); diff --git a/libyul/backends/wasm/WordSizeTransform.cpp b/libyul/backends/wasm/WordSizeTransform.cpp index 81c80da99..0394252b5 100644 --- a/libyul/backends/wasm/WordSizeTransform.cpp +++ b/libyul/backends/wasm/WordSizeTransform.cpp @@ -25,6 +25,7 @@ #include #include +#include using namespace std; using namespace dev; @@ -84,13 +85,13 @@ void WordSizeTransform::operator()(Block& _block) _block.statements, [&](Statement& _s) -> std::optional> { - if (_s.type() == typeid(VariableDeclaration)) + if (holds_alternative(_s)) { - VariableDeclaration& varDecl = boost::get(_s); + VariableDeclaration& varDecl = std::get(_s); // Special handling for datasize and dataoffset - they will only need one variable. - if (varDecl.value && varDecl.value->type() == typeid(FunctionCall)) - if (BuiltinFunction const* f = m_inputDialect.builtin(boost::get(*varDecl.value).functionName.name)) + if (varDecl.value && holds_alternative(*varDecl.value)) + if (BuiltinFunction const* f = m_inputDialect.builtin(std::get(*varDecl.value).functionName.name)) if (f->literalArguments) { yulAssert(f->name == "datasize"_yulstring || f->name == "dataoffset"_yulstring, ""); @@ -113,8 +114,8 @@ void WordSizeTransform::operator()(Block& _block) if ( !varDecl.value || - varDecl.value->type() == typeid(FunctionalInstruction) || - varDecl.value->type() == typeid(FunctionCall) + holds_alternative(*varDecl.value) || + holds_alternative(*varDecl.value) ) { if (varDecl.value) visit(*varDecl.value); @@ -122,8 +123,8 @@ void WordSizeTransform::operator()(Block& _block) return std::nullopt; } else if ( - varDecl.value->type() == typeid(Identifier) || - varDecl.value->type() == typeid(Literal) + holds_alternative(*varDecl.value) || + holds_alternative(*varDecl.value) ) { yulAssert(varDecl.variables.size() == 1, ""); @@ -143,14 +144,14 @@ void WordSizeTransform::operator()(Block& _block) else yulAssert(false, ""); } - else if (_s.type() == typeid(Assignment)) + else if (holds_alternative(_s)) { - Assignment& assignment = boost::get(_s); + Assignment& assignment = std::get(_s); yulAssert(assignment.value, ""); // Special handling for datasize and dataoffset - they will only need one variable. - if (assignment.value->type() == typeid(FunctionCall)) - if (BuiltinFunction const* f = m_inputDialect.builtin(boost::get(*assignment.value).functionName.name)) + if (holds_alternative(*assignment.value)) + if (BuiltinFunction const* f = m_inputDialect.builtin(std::get(*assignment.value).functionName.name)) if (f->literalArguments) { yulAssert(f->name == "datasize"_yulstring || f->name == "dataoffset"_yulstring, ""); @@ -172,8 +173,8 @@ void WordSizeTransform::operator()(Block& _block) } if ( - assignment.value->type() == typeid(FunctionalInstruction) || - assignment.value->type() == typeid(FunctionCall) + holds_alternative(*assignment.value) || + holds_alternative(*assignment.value) ) { if (assignment.value) visit(*assignment.value); @@ -181,8 +182,8 @@ void WordSizeTransform::operator()(Block& _block) return std::nullopt; } else if ( - assignment.value->type() == typeid(Identifier) || - assignment.value->type() == typeid(Literal) + holds_alternative(*assignment.value) || + holds_alternative(*assignment.value) ) { yulAssert(assignment.variableNames.size() == 1, ""); @@ -202,8 +203,8 @@ void WordSizeTransform::operator()(Block& _block) else yulAssert(false, ""); } - else if (_s.type() == typeid(Switch)) - return handleSwitch(boost::get(_s)); + else if (holds_alternative(_s)) + return handleSwitch(std::get(_s)); else visit(_s); return std::nullopt; @@ -342,7 +343,7 @@ std::vector WordSizeTransform::handleSwitch(Switch& _switch) } vector splitExpressions; for (auto const& expr: expandValue(*_switch.expression)) - splitExpressions.emplace_back(boost::get(*expr).name); + splitExpressions.emplace_back(std::get(*expr).name); ret += handleSwitchInternal( _switch.location, @@ -372,15 +373,15 @@ array WordSizeTransform::generateU64IdentifierNames(YulString cons array, 4> WordSizeTransform::expandValue(Expression const& _e) { array, 4> ret; - if (_e.type() == typeid(Identifier)) + if (holds_alternative(_e)) { - Identifier const& id = boost::get(_e); + Identifier const& id = std::get(_e); for (int i = 0; i < 4; i++) ret[i] = make_unique(Identifier{id.location, m_variableMapping.at(id.name)[i]}); } - else if (_e.type() == typeid(Literal)) + else if (holds_alternative(_e)) { - Literal const& lit = boost::get(_e); + Literal const& lit = std::get(_e); u256 val = valueOfLiteral(lit); for (int i = 3; i >= 0; i--) { diff --git a/libyul/optimiser/ASTCopier.cpp b/libyul/optimiser/ASTCopier.cpp index efe3ff854..53c14ad67 100644 --- a/libyul/optimiser/ASTCopier.cpp +++ b/libyul/optimiser/ASTCopier.cpp @@ -155,12 +155,12 @@ Statement ASTCopier::operator ()(Block const& _block) Expression ASTCopier::translate(Expression const& _expression) { - return _expression.apply_visitor(static_cast(*this)); + return std::visit(static_cast(*this), _expression); } Statement ASTCopier::translate(Statement const& _statement) { - return _statement.apply_visitor(static_cast(*this)); + return std::visit(static_cast(*this), _statement); } Block ASTCopier::translate(Block const& _block) diff --git a/libyul/optimiser/ASTCopier.h b/libyul/optimiser/ASTCopier.h index dab3e296a..a2840b7ff 100644 --- a/libyul/optimiser/ASTCopier.h +++ b/libyul/optimiser/ASTCopier.h @@ -24,8 +24,6 @@ #include -#include - #include #include #include @@ -34,7 +32,7 @@ namespace yul { -class ExpressionCopier: public boost::static_visitor +class ExpressionCopier { public: virtual ~ExpressionCopier() = default; @@ -44,7 +42,7 @@ public: virtual Expression operator()(FunctionCall const&) = 0; }; -class StatementCopier: public boost::static_visitor +class StatementCopier { public: virtual ~StatementCopier() = default; diff --git a/libyul/optimiser/ASTWalker.cpp b/libyul/optimiser/ASTWalker.cpp index 523cc8a92..88d5a02b7 100644 --- a/libyul/optimiser/ASTWalker.cpp +++ b/libyul/optimiser/ASTWalker.cpp @@ -94,12 +94,12 @@ void ASTWalker::operator()(Block const& _block) void ASTWalker::visit(Statement const& _st) { - boost::apply_visitor(*this, _st); + std::visit(*this, _st); } void ASTWalker::visit(Expression const& _e) { - boost::apply_visitor(*this, _e); + std::visit(*this, _e); } void ASTModifier::operator()(FunctionalInstruction& _instr) @@ -176,10 +176,10 @@ void ASTModifier::operator()(Block& _block) void ASTModifier::visit(Statement& _st) { - boost::apply_visitor(*this, _st); + std::visit(*this, _st); } void ASTModifier::visit(Expression& _e) { - boost::apply_visitor(*this, _e); + std::visit(*this, _e); } diff --git a/libyul/optimiser/ASTWalker.h b/libyul/optimiser/ASTWalker.h index 995f5fe21..47aab43f7 100644 --- a/libyul/optimiser/ASTWalker.h +++ b/libyul/optimiser/ASTWalker.h @@ -25,8 +25,6 @@ #include #include -#include - #include #include #include @@ -38,7 +36,7 @@ namespace yul /** * Generic AST walker. */ -class ASTWalker: public boost::static_visitor<> +class ASTWalker { public: virtual ~ASTWalker() = default; @@ -75,7 +73,7 @@ protected: /** * Generic AST modifier (i.e. non-const version of ASTWalker). */ -class ASTModifier: public boost::static_visitor<> +class ASTModifier { public: virtual ~ASTModifier() = default; diff --git a/libyul/optimiser/BlockFlattener.cpp b/libyul/optimiser/BlockFlattener.cpp index 48816c695..f93d6e082 100644 --- a/libyul/optimiser/BlockFlattener.cpp +++ b/libyul/optimiser/BlockFlattener.cpp @@ -32,8 +32,8 @@ void BlockFlattener::operator()(Block& _block) _block.statements, [](Statement& _s) -> std::optional> { - if (_s.type() == typeid(Block)) - return std::move(boost::get(_s).statements); + if (holds_alternative(_s)) + return std::move(std::get(_s).statements); else return {}; } diff --git a/libyul/optimiser/CommonSubexpressionEliminator.cpp b/libyul/optimiser/CommonSubexpressionEliminator.cpp index 65e0bae02..5baea5eb2 100644 --- a/libyul/optimiser/CommonSubexpressionEliminator.cpp +++ b/libyul/optimiser/CommonSubexpressionEliminator.cpp @@ -56,8 +56,8 @@ void CommonSubexpressionEliminator::visit(Expression& _e) bool descend = true; // If this is a function call to a function that requires literal arguments, // do not try to simplify there. - if (_e.type() == typeid(FunctionCall)) - if (BuiltinFunction const* builtin = m_dialect.builtin(boost::get(_e).functionName.name)) + if (holds_alternative(_e)) + if (BuiltinFunction const* builtin = m_dialect.builtin(std::get(_e).functionName.name)) if (builtin->literalArguments) // We should not modify function arguments that have to be literals // Note that replacing the function call entirely is fine, @@ -72,16 +72,16 @@ void CommonSubexpressionEliminator::visit(Expression& _e) if (descend) DataFlowAnalyzer::visit(_e); - if (_e.type() == typeid(Identifier)) + if (holds_alternative(_e)) { - Identifier& identifier = boost::get(_e); + Identifier& identifier = std::get(_e); YulString name = identifier.name; if (m_value.count(name)) { assertThrow(m_value.at(name), OptimizerException, ""); - if (m_value.at(name)->type() == typeid(Identifier)) + if (holds_alternative(*m_value.at(name))) { - YulString value = boost::get(*m_value.at(name)).name; + YulString value = std::get(*m_value.at(name)).name; assertThrow(inScope(value), OptimizerException, ""); _e = Identifier{locationOf(_e), value}; } diff --git a/libyul/optimiser/ConditionalSimplifier.cpp b/libyul/optimiser/ConditionalSimplifier.cpp index d720ae88d..8d811233e 100644 --- a/libyul/optimiser/ConditionalSimplifier.cpp +++ b/libyul/optimiser/ConditionalSimplifier.cpp @@ -29,12 +29,12 @@ using namespace yul; void ConditionalSimplifier::operator()(Switch& _switch) { visit(*_switch.expression); - if (_switch.expression->type() != typeid(Identifier)) + if (!holds_alternative(*_switch.expression)) { ASTModifier::operator()(_switch); return; } - YulString expr = boost::get(*_switch.expression).name; + YulString expr = std::get(*_switch.expression).name; for (auto& _case: _switch.cases) { if (_case.value) @@ -59,17 +59,17 @@ void ConditionalSimplifier::operator()(Block& _block) [&](Statement& _s) -> std::optional> { visit(_s); - if (_s.type() == typeid(If)) + if (holds_alternative(_s)) { - If& _if = boost::get(_s); + If& _if = std::get(_s); if ( - _if.condition->type() == typeid(Identifier) && + holds_alternative(*_if.condition) && !_if.body.statements.empty() && TerminationFinder(m_dialect).controlFlowKind(_if.body.statements.back()) != TerminationFinder::ControlFlow::FlowOut ) { - YulString condition = boost::get(*_if.condition).name; + YulString condition = std::get(*_if.condition).name; langutil::SourceLocation location = _if.location; return make_vector( std::move(_s), diff --git a/libyul/optimiser/ConditionalUnsimplifier.cpp b/libyul/optimiser/ConditionalUnsimplifier.cpp index 224634017..a405205a3 100644 --- a/libyul/optimiser/ConditionalUnsimplifier.cpp +++ b/libyul/optimiser/ConditionalUnsimplifier.cpp @@ -29,12 +29,12 @@ using namespace yul; void ConditionalUnsimplifier::operator()(Switch& _switch) { visit(*_switch.expression); - if (_switch.expression->type() != typeid(Identifier)) + if (!holds_alternative(*_switch.expression)) { ASTModifier::operator()(_switch); return; } - YulString expr = boost::get(*_switch.expression).name; + YulString expr = std::get(*_switch.expression).name; for (auto& _case: _switch.cases) { if (_case.value) @@ -42,15 +42,15 @@ void ConditionalUnsimplifier::operator()(Switch& _switch) (*this)(*_case.value); if ( !_case.body.statements.empty() && - _case.body.statements.front().type() == typeid(Assignment) + holds_alternative(_case.body.statements.front()) ) { - Assignment const& assignment = boost::get(_case.body.statements.front()); + Assignment const& assignment = std::get(_case.body.statements.front()); if ( assignment.variableNames.size() == 1 && assignment.variableNames.front().name == expr && - assignment.value->type() == typeid(Literal) && - valueOfLiteral(boost::get(*assignment.value)) == valueOfLiteral(*_case.value) + holds_alternative(*assignment.value) && + valueOfLiteral(std::get(*assignment.value)) == valueOfLiteral(*_case.value) ) _case.body.statements.erase(_case.body.statements.begin()); } @@ -66,27 +66,27 @@ void ConditionalUnsimplifier::operator()(Block& _block) _block.statements, [&](Statement& _stmt1, Statement& _stmt2) -> std::optional> { - if (_stmt1.type() == typeid(If)) + if (holds_alternative(_stmt1)) { - If& _if = boost::get(_stmt1); + If& _if = std::get(_stmt1); if ( - _if.condition->type() == typeid(Identifier) && + holds_alternative(*_if.condition) && !_if.body.statements.empty() ) { - YulString condition = boost::get(*_if.condition).name; + YulString condition = std::get(*_if.condition).name; if ( - _stmt2.type() == typeid(Assignment) && + holds_alternative(_stmt2) && TerminationFinder(m_dialect).controlFlowKind(_if.body.statements.back()) != TerminationFinder::ControlFlow::FlowOut ) { - Assignment const& assignment = boost::get(_stmt2); + Assignment const& assignment = std::get(_stmt2); if ( assignment.variableNames.size() == 1 && assignment.variableNames.front().name == condition && - assignment.value->type() == typeid(Literal) && - valueOfLiteral(boost::get(*assignment.value)) == 0 + holds_alternative(*assignment.value) && + valueOfLiteral(std::get(*assignment.value)) == 0 ) return {make_vector(std::move(_stmt1))}; } diff --git a/libyul/optimiser/ControlFlowSimplifier.cpp b/libyul/optimiser/ControlFlowSimplifier.cpp index 99fa4b137..65da3e8fb 100644 --- a/libyul/optimiser/ControlFlowSimplifier.cpp +++ b/libyul/optimiser/ControlFlowSimplifier.cpp @@ -138,9 +138,9 @@ void ControlFlowSimplifier::operator()(Block& _block) void ControlFlowSimplifier::visit(Statement& _st) { - if (_st.type() == typeid(ForLoop)) + if (holds_alternative(_st)) { - ForLoop& forLoop = boost::get(_st); + ForLoop& forLoop = std::get(_st); yulAssert(forLoop.pre.statements.empty(), ""); size_t outerBreak = m_numBreakStatements; @@ -211,7 +211,7 @@ void ControlFlowSimplifier::simplify(std::vector& _statements) _statements, [&](Statement& _stmt) -> OptionalStatements { - OptionalStatements result = boost::apply_visitor(visitor, _stmt); + OptionalStatements result = std::visit(visitor, _stmt); if (result) simplify(*result); else diff --git a/libyul/optimiser/DataFlowAnalyzer.cpp b/libyul/optimiser/DataFlowAnalyzer.cpp index 6cf65ff25..9696e5e3f 100644 --- a/libyul/optimiser/DataFlowAnalyzer.cpp +++ b/libyul/optimiser/DataFlowAnalyzer.cpp @@ -32,6 +32,7 @@ #include #include +#include using namespace std; using namespace dev; @@ -364,19 +365,19 @@ std::optional> DataFlowAnalyzer::isSimpleStore( _store == dev::eth::Instruction::SSTORE, "" ); - if (_statement.expression.type() == typeid(FunctionCall)) + if (holds_alternative(_statement.expression)) { - FunctionCall const& funCall = boost::get(_statement.expression); + FunctionCall const& funCall = std::get(_statement.expression); if (EVMDialect const* dialect = dynamic_cast(&m_dialect)) if (auto const* builtin = dialect->builtin(funCall.functionName.name)) if (builtin->instruction == _store) if ( - funCall.arguments.at(0).type() == typeid(Identifier) && - funCall.arguments.at(1).type() == typeid(Identifier) + holds_alternative(funCall.arguments.at(0)) && + holds_alternative(funCall.arguments.at(1)) ) { - YulString key = boost::get(funCall.arguments.at(0)).name; - YulString value = boost::get(funCall.arguments.at(1)).name; + YulString key = std::get(funCall.arguments.at(0)).name; + YulString value = std::get(funCall.arguments.at(1)).name; return make_pair(key, value); } } diff --git a/libyul/optimiser/DeadCodeEliminator.cpp b/libyul/optimiser/DeadCodeEliminator.cpp index 95e1cf284..a2daf9452 100644 --- a/libyul/optimiser/DeadCodeEliminator.cpp +++ b/libyul/optimiser/DeadCodeEliminator.cpp @@ -56,7 +56,7 @@ void DeadCodeEliminator::operator()(Block& _block) remove_if( _block.statements.begin() + index + 1, _block.statements.end(), - [] (Statement const& _s) { return _s.type() != typeid(yul::FunctionDefinition); } + [] (Statement const& _s) { return !holds_alternative(_s); } ), _block.statements.end() ); diff --git a/libyul/optimiser/Disambiguator.h b/libyul/optimiser/Disambiguator.h index cd3ff49a2..14b7b7cc3 100644 --- a/libyul/optimiser/Disambiguator.h +++ b/libyul/optimiser/Disambiguator.h @@ -25,8 +25,6 @@ #include #include -#include - #include #include diff --git a/libyul/optimiser/ExpressionInliner.cpp b/libyul/optimiser/ExpressionInliner.cpp index 5b1064cc8..0288b92f2 100644 --- a/libyul/optimiser/ExpressionInliner.cpp +++ b/libyul/optimiser/ExpressionInliner.cpp @@ -49,9 +49,9 @@ void ExpressionInliner::operator()(FunctionDefinition& _fun) void ExpressionInliner::visit(Expression& _expression) { ASTModifier::visit(_expression); - if (_expression.type() == typeid(FunctionCall)) + if (holds_alternative(_expression)) { - FunctionCall& funCall = boost::get(_expression); + FunctionCall& funCall = std::get(_expression); if (!m_inlinableFunctions.count(funCall.functionName.name)) return; FunctionDefinition const& fun = *m_inlinableFunctions.at(funCall.functionName.name); @@ -74,6 +74,6 @@ void ExpressionInliner::visit(Expression& _expression) substitutions[paraName] = &arg; } - _expression = Substitution(substitutions).translate(*boost::get(fun.body.statements.front()).value); + _expression = Substitution(substitutions).translate(*std::get(fun.body.statements.front()).value); } } diff --git a/libyul/optimiser/ExpressionInliner.h b/libyul/optimiser/ExpressionInliner.h index 9404f3e73..b08df86c0 100644 --- a/libyul/optimiser/ExpressionInliner.h +++ b/libyul/optimiser/ExpressionInliner.h @@ -22,9 +22,7 @@ #include #include -#include #include - #include namespace yul diff --git a/libyul/optimiser/ExpressionJoiner.cpp b/libyul/optimiser/ExpressionJoiner.cpp index 911d44de0..c991b5b4a 100644 --- a/libyul/optimiser/ExpressionJoiner.cpp +++ b/libyul/optimiser/ExpressionJoiner.cpp @@ -66,12 +66,12 @@ void ExpressionJoiner::operator()(Block& _block) void ExpressionJoiner::visit(Expression& _e) { - if (_e.type() == typeid(Identifier)) + if (holds_alternative(_e)) { - Identifier const& identifier = boost::get(_e); + Identifier const& identifier = std::get(_e); if (isLatestStatementVarDeclJoinable(identifier)) { - VariableDeclaration& varDecl = boost::get(*latestStatement()); + VariableDeclaration& varDecl = std::get(*latestStatement()); _e = std::move(*varDecl.value); // Delete the variable declaration (also get the moved-from structure back into a sane state) @@ -101,7 +101,7 @@ void ExpressionJoiner::handleArguments(vector& _arguments) for (Expression const& arg: _arguments | boost::adaptors::reversed) { --i; - if (arg.type() != typeid(Identifier) && arg.type() != typeid(Literal)) + if (!holds_alternative(arg) && !holds_alternative(arg)) break; } // i points to the last element that is neither an identifier nor a literal, @@ -138,9 +138,9 @@ Statement* ExpressionJoiner::latestStatement() bool ExpressionJoiner::isLatestStatementVarDeclJoinable(Identifier const& _identifier) { Statement const* statement = latestStatement(); - if (!statement || statement->type() != typeid(VariableDeclaration)) + if (!statement || !holds_alternative(*statement)) return false; - VariableDeclaration const& varDecl = boost::get(*statement); + VariableDeclaration const& varDecl = std::get(*statement); if (varDecl.variables.size() != 1 || !varDecl.value) return false; assertThrow(varDecl.variables.size() == 1, OptimizerException, ""); diff --git a/libyul/optimiser/ExpressionSplitter.cpp b/libyul/optimiser/ExpressionSplitter.cpp index 86fb6206f..c0759126e 100644 --- a/libyul/optimiser/ExpressionSplitter.cpp +++ b/libyul/optimiser/ExpressionSplitter.cpp @@ -101,7 +101,7 @@ void ExpressionSplitter::operator()(Block& _block) void ExpressionSplitter::outlineExpression(Expression& _expr) { - if (_expr.type() == typeid(Identifier)) + if (holds_alternative(_expr)) return; visit(_expr); diff --git a/libyul/optimiser/ForLoopConditionIntoBody.cpp b/libyul/optimiser/ForLoopConditionIntoBody.cpp index a3c213a05..d232ecbe9 100644 --- a/libyul/optimiser/ForLoopConditionIntoBody.cpp +++ b/libyul/optimiser/ForLoopConditionIntoBody.cpp @@ -33,8 +33,8 @@ void ForLoopConditionIntoBody::operator()(ForLoop& _forLoop) { if ( m_dialect.booleanNegationFunction() && - _forLoop.condition->type() != typeid(Literal) && - _forLoop.condition->type() != typeid(Identifier) + !holds_alternative(*_forLoop.condition) && + !holds_alternative(*_forLoop.condition) ) { langutil::SourceLocation loc = locationOf(*_forLoop.condition); diff --git a/libyul/optimiser/ForLoopConditionOutOfBody.cpp b/libyul/optimiser/ForLoopConditionOutOfBody.cpp index e3d0f13ff..e7f93b8b6 100644 --- a/libyul/optimiser/ForLoopConditionOutOfBody.cpp +++ b/libyul/optimiser/ForLoopConditionOutOfBody.cpp @@ -36,17 +36,17 @@ void ForLoopConditionOutOfBody::operator()(ForLoop& _forLoop) if ( !m_dialect.booleanNegationFunction() || - _forLoop.condition->type() != typeid(Literal) || - valueOfLiteral(boost::get(*_forLoop.condition)) == u256(0) || + !holds_alternative(*_forLoop.condition) || + valueOfLiteral(std::get(*_forLoop.condition)) == u256(0) || _forLoop.body.statements.empty() || - _forLoop.body.statements.front().type() != typeid(If) + !holds_alternative(_forLoop.body.statements.front()) ) return; - If& firstStatement = boost::get(_forLoop.body.statements.front()); + If& firstStatement = std::get(_forLoop.body.statements.front()); if ( firstStatement.body.statements.empty() || - firstStatement.body.statements.front().type() != typeid(Break) + !holds_alternative(firstStatement.body.statements.front()) ) return; if (!SideEffectsCollector(m_dialect, *firstStatement.condition).movable()) @@ -56,10 +56,10 @@ void ForLoopConditionOutOfBody::operator()(ForLoop& _forLoop) langutil::SourceLocation location = locationOf(*firstStatement.condition); if ( - firstStatement.condition->type() == typeid(FunctionCall) && - boost::get(*firstStatement.condition).functionName.name == iszero + holds_alternative(*firstStatement.condition) && + std::get(*firstStatement.condition).functionName.name == iszero ) - _forLoop.condition = make_unique(std::move(boost::get(*firstStatement.condition).arguments.front())); + _forLoop.condition = make_unique(std::move(std::get(*firstStatement.condition).arguments.front())); else _forLoop.condition = make_unique(FunctionCall{ location, diff --git a/libyul/optimiser/ForLoopInitRewriter.cpp b/libyul/optimiser/ForLoopInitRewriter.cpp index a11215e50..ff2786d6d 100644 --- a/libyul/optimiser/ForLoopInitRewriter.cpp +++ b/libyul/optimiser/ForLoopInitRewriter.cpp @@ -29,9 +29,9 @@ void ForLoopInitRewriter::operator()(Block& _block) _block.statements, [&](Statement& _stmt) -> std::optional> { - if (_stmt.type() == typeid(ForLoop)) + if (holds_alternative(_stmt)) { - auto& forLoop = boost::get(_stmt); + auto& forLoop = std::get(_stmt); (*this)(forLoop.pre); (*this)(forLoop.body); (*this)(forLoop.post); diff --git a/libyul/optimiser/FullInliner.cpp b/libyul/optimiser/FullInliner.cpp index 8b0af2691..54c8555d2 100644 --- a/libyul/optimiser/FullInliner.cpp +++ b/libyul/optimiser/FullInliner.cpp @@ -50,7 +50,7 @@ FullInliner::FullInliner(Block& _ast, NameDispenser& _dispenser): SSAValueTracker tracker; tracker(m_ast); for (auto const& ssaValue: tracker.values()) - if (ssaValue.second && ssaValue.second->type() == typeid(Literal)) + if (ssaValue.second && holds_alternative(*ssaValue.second)) m_constants.emplace(ssaValue.first); // Store size of global statements. @@ -58,9 +58,9 @@ FullInliner::FullInliner(Block& _ast, NameDispenser& _dispenser): map references = ReferencesCounter::countReferences(m_ast); for (auto& statement: m_ast.statements) { - if (statement.type() != typeid(FunctionDefinition)) + if (!holds_alternative(statement)) continue; - FunctionDefinition& fun = boost::get(statement); + FunctionDefinition& fun = std::get(statement); m_functions[fun.name] = &fun; // Always inline functions that are only called once. if (references[fun.name] == 1) @@ -72,8 +72,8 @@ FullInliner::FullInliner(Block& _ast, NameDispenser& _dispenser): void FullInliner::run() { for (auto& statement: m_ast.statements) - if (statement.type() == typeid(Block)) - handleBlock({}, boost::get(statement)); + if (holds_alternative(statement)) + handleBlock({}, std::get(statement)); // TODO it might be good to determine a visiting order: // first handle functions that are called from many places. @@ -112,9 +112,9 @@ bool FullInliner::shallInline(FunctionCall const& _funCall, YulString _callSite) // Constant arguments might provide a means for further optimization, so they cause a bonus. bool constantArg = false; for (auto const& argument: _funCall.arguments) - if (argument.type() == typeid(Literal) || ( - argument.type() == typeid(Identifier) && - m_constants.count(boost::get(argument).name) + if (holds_alternative(argument) || ( + holds_alternative(argument) && + m_constants.count(std::get(argument).name) )) { constantArg = true; @@ -157,7 +157,7 @@ void InlineModifier::operator()(Block& _block) std::optional> InlineModifier::tryInlineStatement(Statement& _statement) { // Only inline for expression statements, assignments and variable declarations. - Expression* e = boost::apply_visitor(GenericFallbackReturnsVisitor( + Expression* e = std::visit(GenericFallbackReturnsVisitor( [](ExpressionStatement& _s) { return &_s.expression; }, [](Assignment& _s) { return _s.value.get(); }, [](VariableDeclaration& _s) { return _s.value.get(); } @@ -165,7 +165,7 @@ std::optional> InlineModifier::tryInlineStatement(Statement& _ if (e) { // Only inline direct function calls. - FunctionCall* funCall = boost::apply_visitor(GenericFallbackReturnsVisitor( + FunctionCall* funCall = std::visit(GenericFallbackReturnsVisitor( [](FunctionCall& _e) { return &_e; } ), *e); if (funCall && m_driver.shallInline(*funCall, m_currentFunction)) @@ -203,9 +203,9 @@ vector InlineModifier::performInline(Statement& _statement, FunctionC newVariable(var, nullptr); Statement newBody = BodyCopier(m_nameDispenser, variableReplacements)(function->body); - newStatements += std::move(boost::get(newBody).statements); + newStatements += std::move(std::get(newBody).statements); - boost::apply_visitor(GenericFallbackVisitor{ + std::visit(GenericFallbackVisitor{ [&](Assignment& _assignment) { for (size_t i = 0; i < _assignment.variableNames.size(); ++i) diff --git a/libyul/optimiser/FullInliner.h b/libyul/optimiser/FullInliner.h index 746cc46db..21fdb3552 100644 --- a/libyul/optimiser/FullInliner.h +++ b/libyul/optimiser/FullInliner.h @@ -29,8 +29,6 @@ #include -#include - #include #include diff --git a/libyul/optimiser/FunctionGrouper.cpp b/libyul/optimiser/FunctionGrouper.cpp index a8d7982b4..b6a79265a 100644 --- a/libyul/optimiser/FunctionGrouper.cpp +++ b/libyul/optimiser/FunctionGrouper.cpp @@ -40,10 +40,10 @@ void FunctionGrouper::operator()(Block& _block) for (auto&& statement: _block.statements) { - if (statement.type() == typeid(FunctionDefinition)) + if (holds_alternative(statement)) reordered.emplace_back(std::move(statement)); else - boost::get(reordered.front()).statements.emplace_back(std::move(statement)); + std::get(reordered.front()).statements.emplace_back(std::move(statement)); } _block.statements = std::move(reordered); } @@ -52,10 +52,10 @@ bool FunctionGrouper::alreadyGrouped(Block const& _block) { if (_block.statements.empty()) return false; - if (_block.statements.front().type() != typeid(Block)) + if (!holds_alternative(_block.statements.front())) return false; for (size_t i = 1; i < _block.statements.size(); ++i) - if (_block.statements.at(i).type() != typeid(FunctionDefinition)) + if (!holds_alternative(_block.statements.at(i))) return false; return true; } diff --git a/libyul/optimiser/FunctionHoister.cpp b/libyul/optimiser/FunctionHoister.cpp index 6ed930fcc..d2981691d 100644 --- a/libyul/optimiser/FunctionHoister.cpp +++ b/libyul/optimiser/FunctionHoister.cpp @@ -36,8 +36,8 @@ void FunctionHoister::operator()(Block& _block) m_isTopLevel = false; for (auto&& statement: _block.statements) { - boost::apply_visitor(*this, statement); - if (statement.type() == typeid(FunctionDefinition)) + std::visit(*this, statement); + if (holds_alternative(statement)) { m_functions.emplace_back(std::move(statement)); statement = Block{_block.location, {}}; diff --git a/libyul/optimiser/InlinableExpressionFunctionFinder.cpp b/libyul/optimiser/InlinableExpressionFunctionFinder.cpp index f72e5357c..33309009e 100644 --- a/libyul/optimiser/InlinableExpressionFunctionFinder.cpp +++ b/libyul/optimiser/InlinableExpressionFunctionFinder.cpp @@ -45,9 +45,9 @@ void InlinableExpressionFunctionFinder::operator()(FunctionDefinition const& _fu { YulString retVariable = _function.returnVariables.front().name; Statement const& bodyStatement = _function.body.statements.front(); - if (bodyStatement.type() == typeid(Assignment)) + if (holds_alternative(bodyStatement)) { - Assignment const& assignment = boost::get(bodyStatement); + Assignment const& assignment = std::get(bodyStatement); if (assignment.variableNames.size() == 1 && assignment.variableNames.front().name == retVariable) { // TODO: use code size metric here @@ -57,7 +57,7 @@ void InlinableExpressionFunctionFinder::operator()(FunctionDefinition const& _fu // function body. assertThrow(m_disallowedIdentifiers.empty() && !m_foundDisallowedIdentifier, OptimizerException, ""); m_disallowedIdentifiers = set{retVariable, _function.name}; - boost::apply_visitor(*this, *assignment.value); + std::visit(*this, *assignment.value); if (!m_foundDisallowedIdentifier) m_inlinableFunctions[_function.name] = &_function; m_disallowedIdentifiers.clear(); diff --git a/libyul/optimiser/KnowledgeBase.cpp b/libyul/optimiser/KnowledgeBase.cpp index 2c13ac05b..8d488688e 100644 --- a/libyul/optimiser/KnowledgeBase.cpp +++ b/libyul/optimiser/KnowledgeBase.cpp @@ -27,6 +27,9 @@ #include +#include + +using namespace std; using namespace yul; using namespace dev; @@ -37,12 +40,12 @@ bool KnowledgeBase::knownToBeDifferent(YulString _a, YulString _b) // If that fails, try `eq(_a, _b)`. Expression expr1 = simplify(FunctionCall{{}, {{}, "sub"_yulstring}, make_vector(Identifier{{}, _a}, Identifier{{}, _b})}); - if (expr1.type() == typeid(Literal)) - return valueOfLiteral(boost::get(expr1)) != 0; + if (holds_alternative(expr1)) + return valueOfLiteral(std::get(expr1)) != 0; Expression expr2 = simplify(FunctionCall{{}, {{}, "eq"_yulstring}, make_vector(Identifier{{}, _a}, Identifier{{}, _b})}); - if (expr2.type() == typeid(Literal)) - return valueOfLiteral(boost::get(expr2)) == 0; + if (holds_alternative(expr2)) + return valueOfLiteral(std::get(expr2)) == 0; return false; } @@ -53,9 +56,9 @@ bool KnowledgeBase::knownToBeDifferentByAtLeast32(YulString _a, YulString _b) // current values to turn `sub(_a, _b)` into a constant whose absolute value is at least 32. Expression expr1 = simplify(FunctionCall{{}, {{}, "sub"_yulstring}, make_vector(Identifier{{}, _a}, Identifier{{}, _b})}); - if (expr1.type() == typeid(Literal)) + if (holds_alternative(expr1)) { - u256 val = valueOfLiteral(boost::get(expr1)); + u256 val = valueOfLiteral(std::get(expr1)); return val >= 32 && val <= u256(0) - 32; } @@ -74,11 +77,11 @@ Expression KnowledgeBase::simplify(Expression _expression) else --m_recursionCounter; - if (_expression.type() == typeid(FunctionCall)) - for (Expression& arg: boost::get(_expression).arguments) + if (holds_alternative(_expression)) + for (Expression& arg: std::get(_expression).arguments) arg = simplify(arg); - else if (_expression.type() == typeid(FunctionalInstruction)) - for (Expression& arg: boost::get(_expression).arguments) + else if (holds_alternative(_expression)) + for (Expression& arg: std::get(_expression).arguments) arg = simplify(arg); if (auto match = SimplificationRules::findFirstMatch(_expression, m_dialect, m_variableValues)) diff --git a/libyul/optimiser/LoadResolver.cpp b/libyul/optimiser/LoadResolver.cpp index 184214254..df625b513 100644 --- a/libyul/optimiser/LoadResolver.cpp +++ b/libyul/optimiser/LoadResolver.cpp @@ -48,16 +48,16 @@ void LoadResolver::visit(Expression& _e) if (!dynamic_cast(&m_dialect)) return; - if (_e.type() == typeid(FunctionCall)) + if (holds_alternative(_e)) { - FunctionCall const& funCall = boost::get(_e); + FunctionCall const& funCall = std::get(_e); if (auto const* builtin = dynamic_cast(m_dialect).builtin(funCall.functionName.name)) if (builtin->instruction) tryResolve(_e, *builtin->instruction, funCall.arguments); } - else if (_e.type() == typeid(FunctionalInstruction)) + else if (holds_alternative(_e)) { - FunctionalInstruction const& instruction = boost::get(_e); + FunctionalInstruction const& instruction = std::get(_e); tryResolve(_e, instruction.instruction, instruction.arguments); } } @@ -68,10 +68,10 @@ void LoadResolver::tryResolve( vector const& _arguments ) { - if (_arguments.empty() || _arguments.at(0).type() != typeid(Identifier)) + if (_arguments.empty() || !holds_alternative(_arguments.at(0))) return; - YulString key = boost::get(_arguments.at(0)).name; + YulString key = std::get(_arguments.at(0)).name; if ( _instruction == dev::eth::Instruction::SLOAD && m_storage.values.count(key) diff --git a/libyul/optimiser/MainFunction.cpp b/libyul/optimiser/MainFunction.cpp index 7ece2c330..770e59259 100644 --- a/libyul/optimiser/MainFunction.cpp +++ b/libyul/optimiser/MainFunction.cpp @@ -35,13 +35,13 @@ using namespace yul; void MainFunction::operator()(Block& _block) { assertThrow(_block.statements.size() >= 1, OptimizerException, ""); - assertThrow(_block.statements[0].type() == typeid(Block), OptimizerException, ""); + assertThrow(holds_alternative(_block.statements[0]), OptimizerException, ""); for (size_t i = 1; i < _block.statements.size(); ++i) - assertThrow(_block.statements.at(i).type() == typeid(FunctionDefinition), OptimizerException, ""); + assertThrow(holds_alternative(_block.statements.at(i)), OptimizerException, ""); /// @todo this should handle scopes properly and instead of an assertion it should rename the conflicting function assertThrow(NameCollector(_block).names().count("main"_yulstring) == 0, OptimizerException, ""); - Block& block = boost::get(_block.statements[0]); + Block& block = std::get(_block.statements[0]); FunctionDefinition main{ block.location, "main"_yulstring, diff --git a/libyul/optimiser/Metrics.cpp b/libyul/optimiser/Metrics.cpp index dfc8d98b5..bbd578ab0 100644 --- a/libyul/optimiser/Metrics.cpp +++ b/libyul/optimiser/Metrics.cpp @@ -65,23 +65,23 @@ size_t CodeSize::codeSizeIncludingFunctions(Block const& _block) void CodeSize::visit(Statement const& _statement) { - if (_statement.type() == typeid(FunctionDefinition) && m_ignoreFunctions) + if (holds_alternative(_statement) && m_ignoreFunctions) return; else if ( - _statement.type() == typeid(If) || - _statement.type() == typeid(Break) || - _statement.type() == typeid(Continue) + holds_alternative(_statement) || + holds_alternative(_statement) || + holds_alternative(_statement) ) m_size += 2; - else if (_statement.type() == typeid(ForLoop)) + else if (holds_alternative(_statement)) m_size += 3; - else if (_statement.type() == typeid(Switch)) - m_size += 1 + 2 * boost::get(_statement).cases.size(); + else if (holds_alternative(_statement)) + m_size += 1 + 2 * std::get(_statement).cases.size(); else if (!( - _statement.type() == typeid(Block) || - _statement.type() == typeid(ExpressionStatement) || - _statement.type() == typeid(Assignment) || - _statement.type() == typeid(VariableDeclaration) + holds_alternative(_statement) || + holds_alternative(_statement) || + holds_alternative(_statement) || + holds_alternative(_statement) )) ++m_size; @@ -90,7 +90,7 @@ void CodeSize::visit(Statement const& _statement) void CodeSize::visit(Expression const& _expression) { - if (_expression.type() != typeid(Identifier)) + if (!holds_alternative(_expression)) ++m_size; ASTWalker::visit(_expression); } diff --git a/libyul/optimiser/NameDisplacer.cpp b/libyul/optimiser/NameDisplacer.cpp index cc6273fb2..2c8db2b12 100644 --- a/libyul/optimiser/NameDisplacer.cpp +++ b/libyul/optimiser/NameDisplacer.cpp @@ -64,8 +64,8 @@ void NameDisplacer::operator()(Block& _block) // First replace all the names of function definitions // because of scoping. for (auto& st: _block.statements) - if (st.type() == typeid(FunctionDefinition)) - checkAndReplaceNew(boost::get(st).name); + if (holds_alternative(st)) + checkAndReplaceNew(std::get(st).name); ASTModifier::operator()(_block); } diff --git a/libyul/optimiser/OptimizerUtilities.cpp b/libyul/optimiser/OptimizerUtilities.cpp index f9571a4c2..47c43a285 100644 --- a/libyul/optimiser/OptimizerUtilities.cpp +++ b/libyul/optimiser/OptimizerUtilities.cpp @@ -33,7 +33,7 @@ using namespace yul; void yul::removeEmptyBlocks(Block& _block) { auto isEmptyBlock = [](Statement const& _st) -> bool { - return _st.type() == typeid(Block) && boost::get(_st).statements.empty(); + return holds_alternative(_st) && std::get(_st).statements.empty(); }; boost::range::remove_erase_if(_block.statements, isEmptyBlock); } diff --git a/libyul/optimiser/RedundantAssignEliminator.cpp b/libyul/optimiser/RedundantAssignEliminator.cpp index 16383d307..477814e22 100644 --- a/libyul/optimiser/RedundantAssignEliminator.cpp +++ b/libyul/optimiser/RedundantAssignEliminator.cpp @@ -296,7 +296,7 @@ void RedundantAssignEliminator::finalize( void AssignmentRemover::operator()(Block& _block) { boost::range::remove_erase_if(_block.statements, [=](Statement const& _statement) -> bool { - return _statement.type() == typeid(Assignment) && m_toRemove.count(&boost::get(_statement)); + return holds_alternative(_statement) && m_toRemove.count(&std::get(_statement)); }); ASTModifier::operator()(_block); diff --git a/libyul/optimiser/Rematerialiser.cpp b/libyul/optimiser/Rematerialiser.cpp index c9088a431..1df07c52f 100644 --- a/libyul/optimiser/Rematerialiser.cpp +++ b/libyul/optimiser/Rematerialiser.cpp @@ -68,9 +68,9 @@ Rematerialiser::Rematerialiser( void Rematerialiser::visit(Expression& _e) { - if (_e.type() == typeid(Identifier)) + if (holds_alternative(_e)) { - Identifier& identifier = boost::get(_e); + Identifier& identifier = std::get(_e); YulString name = identifier.name; if (m_value.count(name)) { @@ -96,15 +96,15 @@ void Rematerialiser::visit(Expression& _e) void LiteralRematerialiser::visit(Expression& _e) { - if (_e.type() == typeid(Identifier)) + if (holds_alternative(_e)) { - Identifier& identifier = boost::get(_e); + Identifier& identifier = std::get(_e); YulString name = identifier.name; if (m_value.count(name)) { Expression const* value = m_value.at(name); assertThrow(value, OptimizerException, ""); - if (value->type() == typeid(Literal)) + if (holds_alternative(*value)) _e = *value; } } diff --git a/libyul/optimiser/SSAReverser.cpp b/libyul/optimiser/SSAReverser.cpp index 2a421f9d9..bca44097b 100644 --- a/libyul/optimiser/SSAReverser.cpp +++ b/libyul/optimiser/SSAReverser.cpp @@ -19,6 +19,8 @@ #include #include +#include + using namespace std; using namespace dev; using namespace yul; @@ -37,7 +39,7 @@ void SSAReverser::operator()(Block& _block) _block.statements, [&](Statement& _stmt1, Statement& _stmt2) -> std::optional> { - auto* varDecl = boost::get(&_stmt1); + auto* varDecl = std::get_if(&_stmt1); if (!varDecl || varDecl->variables.size() != 1 || !varDecl->value) return {}; @@ -48,9 +50,9 @@ void SSAReverser::operator()(Block& _block) // with // a := E // let a_1 := a - if (auto* assignment = boost::get(&_stmt2)) + if (auto* assignment = std::get_if(&_stmt2)) { - auto* identifier = boost::get(assignment->value.get()); + auto* identifier = std::get_if(assignment->value.get()); if ( assignment->variableNames.size() == 1 && identifier && @@ -81,9 +83,9 @@ void SSAReverser::operator()(Block& _block) // with // let a := E // let a_1 := a - else if (auto* varDecl2 = boost::get(&_stmt2)) + else if (auto* varDecl2 = std::get_if(&_stmt2)) { - auto* identifier = boost::get(varDecl2->value.get()); + auto* identifier = std::get_if(varDecl2->value.get()); if ( varDecl2->variables.size() == 1 && identifier && diff --git a/libyul/optimiser/SSATransform.cpp b/libyul/optimiser/SSATransform.cpp index 1f5d47e20..0b464f043 100644 --- a/libyul/optimiser/SSATransform.cpp +++ b/libyul/optimiser/SSATransform.cpp @@ -60,9 +60,9 @@ void IntroduceSSA::operator()(Block& _block) _block.statements, [&](Statement& _s) -> std::optional> { - if (_s.type() == typeid(VariableDeclaration)) + if (holds_alternative(_s)) { - VariableDeclaration& varDecl = boost::get(_s); + VariableDeclaration& varDecl = std::get(_s); if (varDecl.value) visit(*varDecl.value); @@ -90,12 +90,12 @@ void IntroduceSSA::operator()(Block& _block) make_unique(Identifier{loc, newName}) }); } - boost::get(statements.front()).variables = std::move(newVariables); + std::get(statements.front()).variables = std::move(newVariables); return { std::move(statements) }; } - else if (_s.type() == typeid(Assignment)) + else if (holds_alternative(_s)) { - Assignment& assignment = boost::get(_s); + Assignment& assignment = std::get(_s); visit(*assignment.value); for (auto const& var: assignment.variableNames) assertThrow(m_variablesToReplace.count(var.name), OptimizerException, ""); @@ -117,7 +117,7 @@ void IntroduceSSA::operator()(Block& _block) make_unique(Identifier{loc, newName}) }); } - boost::get(statements.front()).variables = std::move(newVariables); + std::get(statements.front()).variables = std::move(newVariables); return { std::move(statements) }; } else @@ -228,9 +228,9 @@ void IntroduceControlFlowSSA::operator()(Block& _block) } m_variablesToReassign.clear(); - if (_s.type() == typeid(VariableDeclaration)) + if (holds_alternative(_s)) { - VariableDeclaration& varDecl = boost::get(_s); + VariableDeclaration& varDecl = std::get(_s); for (auto const& var: varDecl.variables) if (m_variablesToReplace.count(var.name)) { @@ -238,9 +238,9 @@ void IntroduceControlFlowSSA::operator()(Block& _block) m_variablesInScope.insert(var.name); } } - else if (_s.type() == typeid(Assignment)) + else if (holds_alternative(_s)) { - Assignment& assignment = boost::get(_s); + Assignment& assignment = std::get(_s); for (auto const& var: assignment.variableNames) if (m_variablesToReplace.count(var.name)) assignedVariables.insert(var.name); @@ -304,14 +304,14 @@ void PropagateValues::operator()(VariableDeclaration& _varDecl) if (m_variablesToReplace.count(variable)) { // `let a := a_1` - regular declaration of non-SSA variable - yulAssert(_varDecl.value->type() == typeid(Identifier), ""); - m_currentVariableValues[variable] = boost::get(*_varDecl.value).name; + yulAssert(holds_alternative(*_varDecl.value), ""); + m_currentVariableValues[variable] = std::get(*_varDecl.value).name; m_clearAtEndOfBlock.insert(variable); } - else if (_varDecl.value && _varDecl.value->type() == typeid(Identifier)) + else if (_varDecl.value && holds_alternative(*_varDecl.value)) { // `let a_1 := a` - assignment to SSA variable after a branch. - YulString value = boost::get(*_varDecl.value).name; + YulString value = std::get(*_varDecl.value).name; if (m_variablesToReplace.count(value)) { // This is safe because `a_1` is not a "variable to replace" and thus @@ -333,8 +333,8 @@ void PropagateValues::operator()(Assignment& _assignment) if (!m_variablesToReplace.count(name)) return; - yulAssert(_assignment.value && _assignment.value->type() == typeid(Identifier), ""); - m_currentVariableValues[name] = boost::get(*_assignment.value).name; + yulAssert(_assignment.value && holds_alternative(*_assignment.value), ""); + m_currentVariableValues[name] = std::get(*_assignment.value).name; m_clearAtEndOfBlock.insert(name); } diff --git a/libyul/optimiser/Semantics.cpp b/libyul/optimiser/Semantics.cpp index 001193533..62aaa0e0f 100644 --- a/libyul/optimiser/Semantics.cpp +++ b/libyul/optimiser/Semantics.cpp @@ -165,13 +165,13 @@ pair TerminationFinder::firstUncondition TerminationFinder::ControlFlow TerminationFinder::controlFlowKind(Statement const& _statement) { if ( - _statement.type() == typeid(ExpressionStatement) && - isTerminatingBuiltin(boost::get(_statement)) + holds_alternative(_statement) && + isTerminatingBuiltin(std::get(_statement)) ) return ControlFlow::Terminate; - else if (_statement.type() == typeid(Break)) + else if (holds_alternative(_statement)) return ControlFlow::Break; - else if (_statement.type() == typeid(Continue)) + else if (holds_alternative(_statement)) return ControlFlow::Continue; else return ControlFlow::FlowOut; @@ -179,13 +179,13 @@ TerminationFinder::ControlFlow TerminationFinder::controlFlowKind(Statement cons bool TerminationFinder::isTerminatingBuiltin(ExpressionStatement const& _exprStmnt) { - if (_exprStmnt.expression.type() == typeid(FunctionalInstruction)) + if (holds_alternative(_exprStmnt.expression)) return eth::SemanticInformation::terminatesControlFlow( - boost::get(_exprStmnt.expression).instruction + std::get(_exprStmnt.expression).instruction ); - else if (_exprStmnt.expression.type() == typeid(FunctionCall)) + else if (holds_alternative(_exprStmnt.expression)) if (auto const* dialect = dynamic_cast(&m_dialect)) - if (auto const* builtin = dialect->builtin(boost::get(_exprStmnt.expression).functionName.name)) + if (auto const* builtin = dialect->builtin(std::get(_exprStmnt.expression).functionName.name)) if (builtin->instruction) return eth::SemanticInformation::terminatesControlFlow(*builtin->instruction); return false; diff --git a/libyul/optimiser/SimplificationRules.cpp b/libyul/optimiser/SimplificationRules.cpp index 0575ac578..683534d26 100644 --- a/libyul/optimiser/SimplificationRules.cpp +++ b/libyul/optimiser/SimplificationRules.cpp @@ -67,13 +67,13 @@ bool SimplificationRules::isInitialized() const std::optional const*>> SimplificationRules::instructionAndArguments(Dialect const& _dialect, Expression const& _expr) { - if (_expr.type() == typeid(FunctionalInstruction)) - return make_pair(boost::get(_expr).instruction, &boost::get(_expr).arguments); - else if (_expr.type() == typeid(FunctionCall)) + if (holds_alternative(_expr)) + return make_pair(std::get(_expr).instruction, &std::get(_expr).arguments); + else if (holds_alternative(_expr)) if (auto const* dialect = dynamic_cast(&_dialect)) - if (auto const* builtin = dialect->builtin(boost::get(_expr).functionName.name)) + if (auto const* builtin = dialect->builtin(std::get(_expr).functionName.name)) if (builtin->instruction) - return make_pair(*builtin->instruction, &boost::get(_expr).arguments); + return make_pair(*builtin->instruction, &std::get(_expr).arguments); return {}; } @@ -136,9 +136,9 @@ bool Pattern::matches( // Resolve the variable if possible. // Do not do it for "Any" because we can check identity better for variables. - if (m_kind != PatternKind::Any && _expr.type() == typeid(Identifier)) + if (m_kind != PatternKind::Any && holds_alternative(_expr)) { - YulString varName = boost::get(_expr).name; + YulString varName = std::get(_expr).name; if (_ssaValues.count(varName)) if (Expression const* new_expr = _ssaValues.at(varName)) expr = new_expr; @@ -147,9 +147,9 @@ bool Pattern::matches( if (m_kind == PatternKind::Constant) { - if (expr->type() != typeid(Literal)) + if (!holds_alternative(*expr)) return false; - Literal const& literal = boost::get(*expr); + Literal const& literal = std::get(*expr); if (literal.kind != LiteralKind::Number) return false; if (m_data && *m_data != u256(literal.value.str())) @@ -233,7 +233,7 @@ Expression Pattern::toExpression(SourceLocation const& _location) const u256 Pattern::d() const { - return valueOfNumberLiteral(boost::get(matchGroupValue())); + return valueOfNumberLiteral(std::get(matchGroupValue())); } Expression const& Pattern::matchGroupValue() const diff --git a/libyul/optimiser/StackCompressor.cpp b/libyul/optimiser/StackCompressor.cpp index 72f63b76d..611883b2e 100644 --- a/libyul/optimiser/StackCompressor.cpp +++ b/libyul/optimiser/StackCompressor.cpp @@ -85,9 +85,9 @@ public: // get called on left-hand-sides of assignments. void visit(Expression& _e) override { - if (_e.type() == typeid(Identifier)) + if (holds_alternative(_e)) { - YulString name = boost::get(_e).name; + YulString name = std::get(_e).name; if (m_expressionCodeCost.count(name)) { if (!m_value.count(name)) @@ -162,7 +162,7 @@ bool StackCompressor::run( { yulAssert( _object.code && - _object.code->statements.size() > 0 && _object.code->statements.at(0).type() == typeid(Block), + _object.code->statements.size() > 0 && holds_alternative(_object.code->statements.at(0)), "Need to run the function grouper before the stack compressor." ); bool allowMSizeOptimzation = !MSizeFinder::containsMSize(_dialect, *_object.code); @@ -177,7 +177,7 @@ bool StackCompressor::run( yulAssert(stackSurplus.at({}) > 0, "Invalid surplus value."); eliminateVariables( _dialect, - boost::get(_object.code->statements.at(0)), + std::get(_object.code->statements.at(0)), stackSurplus.at({}), allowMSizeOptimzation ); @@ -185,7 +185,7 @@ bool StackCompressor::run( for (size_t i = 1; i < _object.code->statements.size(); ++i) { - FunctionDefinition& fun = boost::get(_object.code->statements[i]); + FunctionDefinition& fun = std::get(_object.code->statements[i]); if (!stackSurplus.count(fun.name)) continue; diff --git a/libyul/optimiser/StructuralSimplifier.cpp b/libyul/optimiser/StructuralSimplifier.cpp index 706176456..424caf575 100644 --- a/libyul/optimiser/StructuralSimplifier.cpp +++ b/libyul/optimiser/StructuralSimplifier.cpp @@ -95,7 +95,7 @@ void StructuralSimplifier::simplify(std::vector& _statements) _statements, [&](Statement& _stmt) -> OptionalStatements { - OptionalStatements result = boost::apply_visitor(visitor, _stmt); + OptionalStatements result = std::visit(visitor, _stmt); if (result) simplify(*result); else @@ -123,8 +123,8 @@ bool StructuralSimplifier::expressionAlwaysFalse(Expression const& _expression) std::optional StructuralSimplifier::hasLiteralValue(Expression const& _expression) const { - if (_expression.type() == typeid(Literal)) - return valueOfLiteral(boost::get(_expression)); + if (holds_alternative(_expression)) + return valueOfLiteral(std::get(_expression)); else return std::optional(); } diff --git a/libyul/optimiser/Substitution.cpp b/libyul/optimiser/Substitution.cpp index bc9efe962..98d71d410 100644 --- a/libyul/optimiser/Substitution.cpp +++ b/libyul/optimiser/Substitution.cpp @@ -28,9 +28,9 @@ using namespace yul; Expression Substitution::translate(Expression const& _expression) { - if (_expression.type() == typeid(Identifier)) + if (holds_alternative(_expression)) { - YulString name = boost::get(_expression).name; + YulString name = std::get(_expression).name; if (m_substitutions.count(name)) // No recursive substitution return ASTCopier().translate(*m_substitutions.at(name)); diff --git a/libyul/optimiser/Suite.cpp b/libyul/optimiser/Suite.cpp index 50bfc6603..e35146e93 100644 --- a/libyul/optimiser/Suite.cpp +++ b/libyul/optimiser/Suite.cpp @@ -80,7 +80,7 @@ void OptimiserSuite::run( set reservedIdentifiers = _externallyUsedIdentifiers; reservedIdentifiers += _dialect.fixedFunctionNames(); - *_object.code = boost::get(Disambiguator( + *_object.code = std::get(Disambiguator( _dialect, *_object.analysisInfo, reservedIdentifiers @@ -291,7 +291,7 @@ void OptimiserSuite::run( { // If the first statement is an empty block, remove it. // We should only have function definitions after that. - if (ast.statements.size() > 1 && boost::get(ast.statements.front()).statements.empty()) + if (ast.statements.size() > 1 && std::get(ast.statements.front()).statements.empty()) ast.statements.erase(ast.statements.begin()); } suite.runSequence({ @@ -361,7 +361,7 @@ void OptimiserSuite::runSequence(std::vector const& _steps, Block& _ast) { unique_ptr copy; if (m_debug == Debug::PrintChanges) - copy = make_unique(boost::get(ASTCopier{}(_ast))); + copy = make_unique(std::get(ASTCopier{}(_ast))); for (string const& step: _steps) { if (m_debug == Debug::PrintStep) @@ -376,7 +376,7 @@ void OptimiserSuite::runSequence(std::vector const& _steps, Block& _ast) { cout << "== Running " << step << " changed the AST." << endl; cout << AsmPrinter{}(_ast) << endl; - copy = make_unique(boost::get(ASTCopier{}(_ast))); + copy = make_unique(std::get(ASTCopier{}(_ast))); } } } diff --git a/libyul/optimiser/SyntacticalEquality.cpp b/libyul/optimiser/SyntacticalEquality.cpp index 9e425b17e..85a0dfb6d 100644 --- a/libyul/optimiser/SyntacticalEquality.cpp +++ b/libyul/optimiser/SyntacticalEquality.cpp @@ -32,7 +32,7 @@ using namespace yul; bool SyntacticallyEqual::operator()(Expression const& _lhs, Expression const& _rhs) { - return boost::apply_visitor([this](auto&& _lhsExpr, auto&& _rhsExpr) -> bool { + return std::visit([this](auto&& _lhsExpr, auto&& _rhsExpr) -> bool { // ``this->`` is redundant, but required to work around a bug present in gcc 6.x. return this->expressionEqual(_lhsExpr, _rhsExpr); }, _lhs, _rhs); @@ -40,7 +40,7 @@ bool SyntacticallyEqual::operator()(Expression const& _lhs, Expression const& _r bool SyntacticallyEqual::operator()(Statement const& _lhs, Statement const& _rhs) { - return boost::apply_visitor([this](auto&& _lhsStmt, auto&& _rhsStmt) -> bool { + return std::visit([this](auto&& _lhsStmt, auto&& _rhsStmt) -> bool { // ``this->`` is redundant, but required to work around a bug present in gcc 6.x. return this->statementEqual(_lhsStmt, _rhsStmt); }, _lhs, _rhs); diff --git a/libyul/optimiser/UnusedPruner.cpp b/libyul/optimiser/UnusedPruner.cpp index f77c1f95c..e0d5a3dbe 100644 --- a/libyul/optimiser/UnusedPruner.cpp +++ b/libyul/optimiser/UnusedPruner.cpp @@ -68,18 +68,18 @@ UnusedPruner::UnusedPruner( void UnusedPruner::operator()(Block& _block) { for (auto&& statement: _block.statements) - if (statement.type() == typeid(FunctionDefinition)) + if (holds_alternative(statement)) { - FunctionDefinition& funDef = boost::get(statement); + FunctionDefinition& funDef = std::get(statement); if (!used(funDef.name)) { subtractReferences(ReferencesCounter::countReferences(funDef.body)); statement = Block{std::move(funDef.location), {}}; } } - else if (statement.type() == typeid(VariableDeclaration)) + else if (holds_alternative(statement)) { - VariableDeclaration& varDecl = boost::get(statement); + VariableDeclaration& varDecl = std::get(statement); // Multi-variable declarations are special. We can only remove it // if all variables are unused and the right-hand-side is either // movable or it returns a single value. In the latter case, we @@ -108,9 +108,9 @@ void UnusedPruner::operator()(Block& _block) }}; } } - else if (statement.type() == typeid(ExpressionStatement)) + else if (holds_alternative(statement)) { - ExpressionStatement& exprStmt = boost::get(statement); + ExpressionStatement& exprStmt = std::get(statement); if ( SideEffectsCollector(m_dialect, exprStmt.expression, m_functionSideEffects). sideEffectFree(m_allowMSizeOptimization) diff --git a/libyul/optimiser/VarDeclInitializer.cpp b/libyul/optimiser/VarDeclInitializer.cpp index 45b53ee61..d6f07bc1e 100644 --- a/libyul/optimiser/VarDeclInitializer.cpp +++ b/libyul/optimiser/VarDeclInitializer.cpp @@ -51,5 +51,5 @@ void VarDeclInitializer::operator()(Block& _block) } } }; - iterateReplacing(_block.statements, boost::apply_visitor(visitor)); + iterateReplacing(_block.statements, [&](auto&& _statement) { return std::visit(visitor, _statement); }); } diff --git a/libyul/optimiser/VarNameCleaner.cpp b/libyul/optimiser/VarNameCleaner.cpp index 4c3946295..edb60a82b 100644 --- a/libyul/optimiser/VarNameCleaner.cpp +++ b/libyul/optimiser/VarNameCleaner.cpp @@ -40,8 +40,8 @@ VarNameCleaner::VarNameCleaner( m_translatedNames{} { for (auto const& statement: _ast.statements) - if (statement.type() == typeid(FunctionDefinition)) - m_blacklist.insert(boost::get(statement).name); + if (holds_alternative(statement)) + m_blacklist.insert(std::get(statement).name); m_usedNames = m_blacklist; } diff --git a/test/libyul/Common.cpp b/test/libyul/Common.cpp index c8948e6c3..aa3492cb0 100644 --- a/test/libyul/Common.cpp +++ b/test/libyul/Common.cpp @@ -37,6 +37,8 @@ #include +#include + using namespace std; using namespace langutil; using namespace yul; @@ -75,7 +77,7 @@ pair, shared_ptr> yul::test::parse(strin yul::Block yul::test::disambiguate(string const& _source, bool _yul) { auto result = parse(_source, _yul); - return boost::get(Disambiguator(defaultDialect(_yul), *result.second, {})(*result.first)); + return std::get(Disambiguator(defaultDialect(_yul), *result.second, {})(*result.first)); } string yul::test::format(string const& _source, bool _yul) diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index fb120ea03..07dc8a5c3 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -74,6 +74,7 @@ #include #include +#include using namespace dev; using namespace langutil; @@ -415,7 +416,7 @@ bool YulOptimizerTest::parse(ostream& _stream, string const& _linePrefix, bool c void YulOptimizerTest::disambiguate() { - *m_ast = boost::get(Disambiguator(*m_dialect, *m_analysisInfo)(*m_ast)); + *m_ast = std::get(Disambiguator(*m_dialect, *m_analysisInfo)(*m_ast)); m_analysisInfo.reset(); updateContext(); } diff --git a/test/tools/yulInterpreter/Interpreter.cpp b/test/tools/yulInterpreter/Interpreter.cpp index 390c5bf05..d1b361c4e 100644 --- a/test/tools/yulInterpreter/Interpreter.cpp +++ b/test/tools/yulInterpreter/Interpreter.cpp @@ -35,6 +35,7 @@ #include #include +#include using namespace std; using namespace dev; @@ -161,9 +162,9 @@ void Interpreter::operator()(Block const& _block) openScope(); // Register functions. for (auto const& statement: _block.statements) - if (statement.type() == typeid(FunctionDefinition)) + if (holds_alternative(statement)) { - FunctionDefinition const& funDef = boost::get(statement); + FunctionDefinition const& funDef = std::get(statement); solAssert(!m_scopes.back().count(funDef.name), ""); m_scopes.back().emplace(funDef.name, &funDef); } diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index aaaeab511..ce3f70762 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -72,6 +72,7 @@ #include #include #include +#include using namespace std; using namespace dev; @@ -131,7 +132,7 @@ public: set reservedIdentifiers; if (!disambiguated) { - *m_ast = boost::get(Disambiguator(m_dialect, *m_analysisInfo)(*m_ast)); + *m_ast = std::get(Disambiguator(m_dialect, *m_analysisInfo)(*m_ast)); m_analysisInfo.reset(); m_nameDispenser = make_shared(m_dialect, *m_ast, reservedIdentifiers); disambiguated = true;