Experimental feature switch for ABI encoder.

This commit is contained in:
chriseth 2017-08-10 17:56:04 +02:00 committed by Alex Beregszaszi
parent ee6f56d641
commit d1ad62fccc
4 changed files with 16 additions and 4 deletions

View File

@ -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 },
};

View File

@ -56,6 +56,8 @@ public:
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);
@ -264,6 +266,8 @@ private:
} 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

View File

@ -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();

View File

@ -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();