mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #4100 from ethereum/julia-exceptions
Avoid using solAssert in libjulia
This commit is contained in:
commit
c80c422bfe
35
libjulia/Exceptions.h
Normal file
35
libjulia/Exceptions.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
This file is part of solidity.
|
||||
|
||||
solidity is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
solidity is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* Exceptions in Julia.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libdevcore/Exceptions.h>
|
||||
#include <libdevcore/Assertions.h>
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace julia
|
||||
{
|
||||
|
||||
struct IuliaException: virtual Exception {};
|
||||
struct OptimizerException: virtual IuliaException {};
|
||||
|
||||
}
|
||||
}
|
@ -20,9 +20,9 @@
|
||||
|
||||
#include <libjulia/optimiser/ASTCopier.h>
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
#include <libjulia/Exceptions.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
|
||||
#include <libdevcore/Common.h>
|
||||
|
||||
@ -30,10 +30,9 @@ using namespace std;
|
||||
using namespace dev;
|
||||
using namespace dev::julia;
|
||||
|
||||
|
||||
Statement ASTCopier::operator()(Instruction const&)
|
||||
{
|
||||
solAssert(false, "Invalid operation.");
|
||||
assertThrow(false, OptimizerException, "Invalid operation.");
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -62,13 +61,13 @@ Statement ASTCopier::operator()(Assignment const& _assignment)
|
||||
|
||||
Statement ASTCopier::operator()(StackAssignment const&)
|
||||
{
|
||||
solAssert(false, "Invalid operation.");
|
||||
assertThrow(false, OptimizerException, "Invalid operation.");
|
||||
return {};
|
||||
}
|
||||
|
||||
Statement ASTCopier::operator()(Label const&)
|
||||
{
|
||||
solAssert(false, "Invalid operation.");
|
||||
assertThrow(false, OptimizerException, "Invalid operation.");
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,6 @@
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
|
||||
#include <boost/range/adaptor/reversed.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include <libjulia/ASTDataForward.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <libjulia/Exceptions.h>
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
@ -44,13 +44,13 @@ class ASTWalker: public boost::static_visitor<>
|
||||
public:
|
||||
virtual ~ASTWalker() = default;
|
||||
virtual void operator()(Literal const&) {}
|
||||
virtual void operator()(Instruction const&) { solAssert(false, ""); }
|
||||
virtual void operator()(Instruction const&) { assertThrow(false, OptimizerException, ""); }
|
||||
virtual void operator()(Identifier const&) {}
|
||||
virtual void operator()(FunctionalInstruction const& _instr);
|
||||
virtual void operator()(FunctionCall const& _funCall);
|
||||
virtual void operator()(ExpressionStatement const& _statement);
|
||||
virtual void operator()(Label const&) { solAssert(false, ""); }
|
||||
virtual void operator()(StackAssignment const&) { solAssert(false, ""); }
|
||||
virtual void operator()(Label const&) { assertThrow(false, OptimizerException, ""); }
|
||||
virtual void operator()(StackAssignment const&) { assertThrow(false, OptimizerException, ""); }
|
||||
virtual void operator()(Assignment const& _assignment);
|
||||
virtual void operator()(VariableDeclaration const& _varDecl);
|
||||
virtual void operator()(If const& _if);
|
||||
@ -85,13 +85,13 @@ class ASTModifier: public boost::static_visitor<>
|
||||
public:
|
||||
virtual ~ASTModifier() = default;
|
||||
virtual void operator()(Literal&) {}
|
||||
virtual void operator()(Instruction&) { solAssert(false, ""); }
|
||||
virtual void operator()(Instruction&) { assertThrow(false, OptimizerException, ""); }
|
||||
virtual void operator()(Identifier&) {}
|
||||
virtual void operator()(FunctionalInstruction& _instr);
|
||||
virtual void operator()(FunctionCall& _funCall);
|
||||
virtual void operator()(ExpressionStatement& _statement);
|
||||
virtual void operator()(Label&) { solAssert(false, ""); }
|
||||
virtual void operator()(StackAssignment&) { solAssert(false, ""); }
|
||||
virtual void operator()(Label&) { assertThrow(false, OptimizerException, ""); }
|
||||
virtual void operator()(StackAssignment&) { assertThrow(false, OptimizerException, ""); }
|
||||
virtual void operator()(Assignment& _assignment);
|
||||
virtual void operator()(VariableDeclaration& _varDecl);
|
||||
virtual void operator()(If& _if);
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include <libjulia/optimiser/Metrics.h>
|
||||
#include <libjulia/optimiser/SyntacticalEquality.h>
|
||||
#include <libjulia/Exceptions.h>
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
|
||||
@ -37,7 +38,7 @@ void CommonSubexpressionEliminator::visit(Expression& _e)
|
||||
// TODO this search rather inefficient.
|
||||
for (auto const& var: m_value)
|
||||
{
|
||||
solAssert(var.second, "");
|
||||
assertThrow(var.second, OptimizerException, "");
|
||||
if (SyntacticalEqualityChecker::equal(_e, *var.second))
|
||||
{
|
||||
_e = Identifier{locationOf(_e), var.first};
|
||||
|
@ -23,11 +23,11 @@
|
||||
#include <libjulia/optimiser/DataFlowAnalyzer.h>
|
||||
|
||||
#include <libjulia/optimiser/NameCollector.h>
|
||||
#include <libjulia/optimiser/Semantics.h>
|
||||
#include <libjulia/Exceptions.h>
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
|
||||
#include <libjulia/optimiser/Semantics.h>
|
||||
|
||||
#include <libdevcore/CommonData.h>
|
||||
|
||||
#include <boost/range/adaptor/reversed.hpp>
|
||||
@ -41,7 +41,7 @@ void DataFlowAnalyzer::operator()(Assignment& _assignment)
|
||||
set<string> names;
|
||||
for (auto const& var: _assignment.variableNames)
|
||||
names.insert(var.name);
|
||||
solAssert(_assignment.value, "");
|
||||
assertThrow(_assignment.value, OptimizerException, "");
|
||||
visit(*_assignment.value);
|
||||
handleAssignment(names, _assignment.value.get());
|
||||
}
|
||||
@ -120,7 +120,7 @@ void DataFlowAnalyzer::operator()(Block& _block)
|
||||
m_variableScopes.emplace_back(false);
|
||||
ASTModifier::operator()(_block);
|
||||
m_variableScopes.pop_back();
|
||||
solAssert(numScopes == m_variableScopes.size(), "");
|
||||
assertThrow(numScopes == m_variableScopes.size(), OptimizerException, "");
|
||||
}
|
||||
|
||||
void DataFlowAnalyzer::handleAssignment(set<string> const& _variables, Expression* _value)
|
||||
|
@ -20,11 +20,11 @@
|
||||
|
||||
#include <libjulia/optimiser/Disambiguator.h>
|
||||
|
||||
#include <libjulia/Exceptions.h>
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
#include <libsolidity/inlineasm/AsmScope.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace dev::julia;
|
||||
@ -34,9 +34,9 @@ using Scope = dev::solidity::assembly::Scope;
|
||||
|
||||
string Disambiguator::translateIdentifier(string const& _originalName)
|
||||
{
|
||||
solAssert(!m_scopes.empty() && m_scopes.back(), "");
|
||||
assertThrow(!m_scopes.empty() && m_scopes.back(), OptimizerException, "");
|
||||
Scope::Identifier const* id = m_scopes.back()->lookup(_originalName);
|
||||
solAssert(id, "");
|
||||
assertThrow(id, OptimizerException, "");
|
||||
if (!m_translations.count(id))
|
||||
m_translations[id] = m_nameDispenser.newName(_originalName);
|
||||
return m_translations.at(id);
|
||||
@ -69,7 +69,7 @@ void Disambiguator::enterScopeInternal(Scope& _scope)
|
||||
|
||||
void Disambiguator::leaveScopeInternal(Scope& _scope)
|
||||
{
|
||||
solAssert(!m_scopes.empty(), "");
|
||||
solAssert(m_scopes.back() == &_scope, "");
|
||||
assertThrow(!m_scopes.empty(), OptimizerException, "");
|
||||
assertThrow(m_scopes.back() == &_scope, OptimizerException, "");
|
||||
m_scopes.pop_back();
|
||||
}
|
||||
|
@ -23,8 +23,6 @@
|
||||
|
||||
#include <libjulia/ASTDataForward.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
|
||||
#include <libdevcore/CommonData.h>
|
||||
|
||||
using namespace std;
|
||||
|
@ -24,11 +24,10 @@
|
||||
#include <libjulia/optimiser/ASTWalker.h>
|
||||
#include <libjulia/optimiser/NameCollector.h>
|
||||
#include <libjulia/optimiser/Semantics.h>
|
||||
#include <libjulia/Exceptions.h>
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
|
||||
#include <libdevcore/CommonData.h>
|
||||
|
||||
#include <boost/range/adaptor/reversed.hpp>
|
||||
@ -38,18 +37,16 @@ using namespace dev;
|
||||
using namespace dev::julia;
|
||||
using namespace dev::solidity;
|
||||
|
||||
|
||||
|
||||
FullInliner::FullInliner(Block& _ast):
|
||||
m_ast(_ast)
|
||||
{
|
||||
solAssert(m_ast.statements.size() >= 1, "");
|
||||
solAssert(m_ast.statements.front().type() == typeid(Block), "");
|
||||
assertThrow(m_ast.statements.size() >= 1, OptimizerException, "");
|
||||
assertThrow(m_ast.statements.front().type() == typeid(Block), OptimizerException, "");
|
||||
m_nameDispenser.m_usedNames = NameCollector(m_ast).names();
|
||||
|
||||
for (size_t i = 1; i < m_ast.statements.size(); ++i)
|
||||
{
|
||||
solAssert(m_ast.statements.at(i).type() == typeid(FunctionDefinition), "");
|
||||
assertThrow(m_ast.statements.at(i).type() == typeid(FunctionDefinition), OptimizerException, "");
|
||||
FunctionDefinition& fun = boost::get<FunctionDefinition>(m_ast.statements.at(i));
|
||||
m_functions[fun.name] = &fun;
|
||||
m_functionsToVisit.insert(&fun);
|
||||
@ -58,7 +55,7 @@ FullInliner::FullInliner(Block& _ast):
|
||||
|
||||
void FullInliner::run()
|
||||
{
|
||||
solAssert(m_ast.statements[0].type() == typeid(Block), "");
|
||||
assertThrow(m_ast.statements[0].type() == typeid(Block), OptimizerException, "");
|
||||
InlineModifier(*this, m_nameDispenser, "").visit(m_ast.statements[0]);
|
||||
while (!m_functionsToVisit.empty())
|
||||
handleFunction(**m_functionsToVisit.begin());
|
||||
@ -79,7 +76,7 @@ void InlineModifier::operator()(FunctionalInstruction& _instruction)
|
||||
|
||||
void InlineModifier::operator()(FunctionCall&)
|
||||
{
|
||||
solAssert(false, "Should be handled in visit() instead.");
|
||||
assertThrow(false, OptimizerException, "Should be handled in visit() instead.");
|
||||
}
|
||||
|
||||
void InlineModifier::operator()(ForLoop& _loop)
|
||||
@ -249,7 +246,7 @@ Statement BodyCopier::operator()(VariableDeclaration const& _varDecl)
|
||||
|
||||
Statement BodyCopier::operator()(FunctionDefinition const& _funDef)
|
||||
{
|
||||
solAssert(false, "Function hoisting has to be done before function inlining.");
|
||||
assertThrow(false, OptimizerException, "Function hoisting has to be done before function inlining.");
|
||||
return _funDef;
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,9 @@
|
||||
#include <libjulia/optimiser/ASTCopier.h>
|
||||
#include <libjulia/optimiser/ASTWalker.h>
|
||||
#include <libjulia/optimiser/NameDispenser.h>
|
||||
#include <libjulia/Exceptions.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
@ -100,7 +101,7 @@ public:
|
||||
{ }
|
||||
~InlineModifier()
|
||||
{
|
||||
solAssert(m_statementsToPrefix.empty(), "");
|
||||
assertThrow(m_statementsToPrefix.empty(), OptimizerException, "");
|
||||
}
|
||||
|
||||
virtual void operator()(FunctionalInstruction&) override;
|
||||
|
@ -23,8 +23,6 @@
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
|
||||
#include <boost/range/algorithm_ext/erase.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
|
||||
#include <libdevcore/CommonData.h>
|
||||
|
||||
using namespace std;
|
||||
|
@ -20,9 +20,9 @@
|
||||
|
||||
#include <libjulia/optimiser/InlinableExpressionFunctionFinder.h>
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
#include <libjulia/optimiser/Utilities.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
@ -56,7 +56,7 @@ void InlinableExpressionFunctionFinder::operator()(FunctionDefinition const& _fu
|
||||
// We cannot overwrite previous settings, because this function definition
|
||||
// would not be valid here if we were searching inside a functionally inlinable
|
||||
// function body.
|
||||
solAssert(m_disallowedIdentifiers.empty() && !m_foundDisallowedIdentifier, "");
|
||||
assertThrow(m_disallowedIdentifiers.empty() && !m_foundDisallowedIdentifier, OptimizerException, "");
|
||||
m_disallowedIdentifiers = set<string>{retVariable, _function.name};
|
||||
boost::apply_visitor(*this, *assignment.value);
|
||||
if (!m_foundDisallowedIdentifier)
|
||||
|
@ -23,8 +23,6 @@
|
||||
#include <libjulia/ASTDataForward.h>
|
||||
#include <libjulia/optimiser/ASTWalker.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace dev
|
||||
|
@ -22,11 +22,10 @@
|
||||
#include <libjulia/optimiser/MainFunction.h>
|
||||
|
||||
#include <libjulia/optimiser/NameCollector.h>
|
||||
#include <libjulia/Exceptions.h>
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
|
||||
#include <libdevcore/CommonData.h>
|
||||
|
||||
using namespace std;
|
||||
@ -36,12 +35,12 @@ using namespace dev::solidity;
|
||||
|
||||
void MainFunction::operator()(Block& _block)
|
||||
{
|
||||
solAssert(_block.statements.size() >= 1, "");
|
||||
solAssert(_block.statements[0].type() == typeid(Block), "");
|
||||
assertThrow(_block.statements.size() >= 1, OptimizerException, "");
|
||||
assertThrow(_block.statements[0].type() == typeid(Block), OptimizerException, "");
|
||||
for (size_t i = 1; i < _block.statements.size(); ++i)
|
||||
solAssert(_block.statements.at(i).type() == typeid(FunctionDefinition), "");
|
||||
assertThrow(_block.statements.at(i).type() == typeid(FunctionDefinition), OptimizerException, "");
|
||||
/// @todo this should handle scopes properly and instead of an assertion it should rename the conflicting function
|
||||
solAssert(NameCollector(_block).names().count("main") == 0, "");
|
||||
assertThrow(NameCollector(_block).names().count("main") == 0, OptimizerException, "");
|
||||
|
||||
Block& block = boost::get<Block>(_block.statements[0]);
|
||||
FunctionDefinition main{
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include <libjulia/optimiser/Metrics.h>
|
||||
#include <libjulia/optimiser/ASTCopier.h>
|
||||
#include <libjulia/Exceptions.h>
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
|
||||
@ -44,7 +45,7 @@ void Rematerialiser::visit(Expression& _e)
|
||||
expressionValid = false;
|
||||
break;
|
||||
}
|
||||
solAssert(m_value.at(name), "");
|
||||
assertThrow(m_value.at(name), OptimizerException, "");
|
||||
auto const& value = *m_value.at(name);
|
||||
if (expressionValid && CodeSize::codeSize(value) <= 7)
|
||||
_e = (ASTCopier{}).translate(value);
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include <libjulia/optimiser/Semantics.h>
|
||||
|
||||
#include <libjulia/Exceptions.h>
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
|
||||
#include <libevmasm/SemanticInformation.h>
|
||||
@ -56,5 +58,5 @@ void MovableChecker::operator()(FunctionCall const&)
|
||||
|
||||
void MovableChecker::visit(Statement const&)
|
||||
{
|
||||
solAssert(false, "Movability for statement requested.");
|
||||
assertThrow(false, OptimizerException, "Movability for statement requested.");
|
||||
}
|
||||
|
@ -20,8 +20,9 @@
|
||||
|
||||
#include <libjulia/optimiser/SyntacticalEquality.h>
|
||||
|
||||
#include <libjulia/Exceptions.h>
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
|
||||
#include <libdevcore/CommonData.h>
|
||||
|
||||
@ -62,7 +63,7 @@ bool SyntacticalEqualityChecker::equal(Expression const& _e1, Expression const&
|
||||
}
|
||||
else
|
||||
{
|
||||
solAssert(false, "Invlid expression");
|
||||
assertThrow(false, OptimizerException, "Invalid expression");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <libjulia/optimiser/NameCollector.h>
|
||||
#include <libjulia/optimiser/Semantics.h>
|
||||
#include <libjulia/optimiser/Utilities.h>
|
||||
#include <libjulia/Exceptions.h>
|
||||
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
|
||||
@ -108,8 +109,8 @@ void UnusedPruner::subtractReferences(map<string, size_t> const& _subtrahend)
|
||||
{
|
||||
for (auto const& ref: _subtrahend)
|
||||
{
|
||||
solAssert(m_references.count(ref.first), "");
|
||||
solAssert(m_references.at(ref.first) >= ref.second, "");
|
||||
assertThrow(m_references.count(ref.first), OptimizerException, "");
|
||||
assertThrow(m_references.at(ref.first) >= ref.second, OptimizerException, "");
|
||||
m_references[ref.first] -= ref.second;
|
||||
m_shouldRunAgain = true;
|
||||
}
|
||||
|
@ -22,16 +22,11 @@
|
||||
|
||||
#include <libjulia/ASTDataForward.h>
|
||||
|
||||
#include <libdevcore/Exceptions.h>
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace julia
|
||||
{
|
||||
|
||||
struct IuliaException: virtual Exception {};
|
||||
struct OptimizerException: virtual IuliaException {};
|
||||
|
||||
/// Removes statements that are just empty blocks (non-recursive).
|
||||
void removeEmptyBlocks(Block& _block);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user