Skip to content

Commit

Permalink
Experimental feature switch for ABI encoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Aug 11, 2017
1 parent 37adf15 commit 264be50
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions libsolidity/ast/ExperimentalFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ namespace solidity

enum class ExperimentalFeature
{
ABIEncoderV2, // new ABI encoder that makes use of JULIA
Test,
TestOnlyAnalysis
};

static const std::map<ExperimentalFeature, bool> ExperimentalFeatureOnlyAnalysis = {
static const std::map<ExperimentalFeature, bool> ExperimentalFeatureOnlyAnalysis =
{
{ ExperimentalFeature::TestOnlyAnalysis, true },
};

static const std::map<std::string, ExperimentalFeature> ExperimentalFeatureNames = {
static const std::map<std::string, ExperimentalFeature> ExperimentalFeatureNames =
{
{ "ABIEncoderV2", ExperimentalFeature::ABIEncoderV2 },
{ "__test", ExperimentalFeature::Test },
{ "__testOnlyAnalysis", ExperimentalFeature::TestOnlyAnalysis },
};
Expand Down
4 changes: 4 additions & 0 deletions libsolidity/codegen/CompilerContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class CompilerContext
m_runtimeSub = size_t(m_asm->newSub(m_runtimeContext->m_asm).data());
}

void setExperimentalFeatures(std::set<ExperimentalFeature> const& _features) { m_experimentalFeatures = _features; }
bool experimentalFeatureActive(ExperimentalFeature _feature) const { return m_experimentalFeatures.count(_feature); }

void addStateVariable(VariableDeclaration const& _declaration, u256 const& _storageOffset, unsigned _byteOffset);
void addVariable(VariableDeclaration const& _declaration, unsigned _offsetToCurrent = 0);
Expand Down Expand Up @@ -264,6 +266,8 @@ class CompilerContext
} m_functionCompilationQueue;

eth::AssemblyPointer m_asm;
/// Activated experimental features.
std::set<ExperimentalFeature> m_experimentalFeatures;
/// Other already compiled contracts to be used in contract creation calls.
std::map<ContractDefinition const*, eth::Assembly const*> m_compiledContracts;
/// Storage offsets of state variables
Expand Down
7 changes: 5 additions & 2 deletions libsolidity/codegen/CompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,13 @@ void CompilerUtils::encodeToMemory(
t = t->mobileType()->interfaceType(_encodeAsLibraryTypes)->encodingType();
}

bool activateNewEncoder = false;
if (_givenTypes.empty())
return;
else if (activateNewEncoder && _padToWordBoundaries && !_copyDynamicDataInPlace)
else if (
_padToWordBoundaries &&
!_copyDynamicDataInPlace &&
m_context.experimentalFeatureActive(ExperimentalFeature::ABIEncoderV2)
)
{
// Use the new JULIA-based encoding function
auto stackHeightBefore = m_context.stackHeight();
Expand Down
1 change: 1 addition & 0 deletions libsolidity/codegen/ContractCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void ContractCompiler::initializeContext(
map<ContractDefinition const*, eth::Assembly const*> const& _compiledContracts
)
{
m_context.setExperimentalFeatures(_contract.sourceUnit().annotation().experimentalFeatures);
m_context.setCompiledContracts(_compiledContracts);
m_context.setInheritanceHierarchy(_contract.annotation().linearizedBaseContracts);
CompilerUtils(m_context).initialiseFreeMemoryPointer();
Expand Down

0 comments on commit 264be50

Please sign in to comment.