Skip to content

Commit 884cc27

Browse files
committed
eof: Add semantic test setting consistency check.
tests: Use enum setting for `compileViaYul`
1 parent 053807e commit 884cc27

File tree

5 files changed

+71
-22
lines changed

5 files changed

+71
-22
lines changed

test/TestCase.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,17 @@ void EVMVersionRestrictedTestCase::processBytecodeFormatSetting()
149149
// EOF only available since Osaka
150150
solAssert(!eofVersion.has_value() || solidity::test::CommonOptions::get().evmVersion().supportsEOF());
151151

152-
std::string bytecodeFormatString = m_reader.stringSetting("bytecodeFormat", "legacy,>=EOFv1");
153-
if (bytecodeFormatString == "legacy,>=EOFv1" || bytecodeFormatString == ">=EOFv1,legacy")
152+
m_bytecodeFormat = m_reader.stringSetting("bytecodeFormat", "legacy,>=EOFv1");
153+
if (bytecodeFormat() == "legacy,>=EOFv1" || bytecodeFormat() == ">=EOFv1,legacy")
154154
return;
155155

156156
// TODO: This is naive implementation because for now we support only one EOF version.
157-
if (bytecodeFormatString == "legacy" && eofVersion.has_value())
157+
if (bytecodeFormat() == "legacy" && eofVersion.has_value())
158158
m_shouldRun = false;
159-
else if (bytecodeFormatString == ">=EOFv1" && !eofVersion.has_value())
159+
else if (bytecodeFormat() == ">=EOFv1" && !eofVersion.has_value())
160160
m_shouldRun = false;
161-
else if (bytecodeFormatString != "legacy" && bytecodeFormatString != ">=EOFv1" )
162-
BOOST_THROW_EXCEPTION(std::runtime_error{"Invalid bytecodeFormat flag: \"" + bytecodeFormatString + "\""});
161+
else if (bytecodeFormat() != "legacy" && bytecodeFormat() != ">=EOFv1" )
162+
BOOST_THROW_EXCEPTION(std::runtime_error{"Invalid bytecodeFormat flag: \"" + bytecodeFormat() + "\""});
163163
}
164164

165165
EVMVersionRestrictedTestCase::EVMVersionRestrictedTestCase(std::string const& _filename):
@@ -168,3 +168,16 @@ EVMVersionRestrictedTestCase::EVMVersionRestrictedTestCase(std::string const& _f
168168
processEVMVersionSetting();
169169
processBytecodeFormatSetting();
170170
}
171+
172+
std::ostream& solidity::frontend::test::operator<<(std::ostream& _output, CompileViaYul _compileViaYul)
173+
{
174+
switch (_compileViaYul)
175+
{
176+
case CompileViaYul::False: _output << "false"; break;
177+
case CompileViaYul::True: _output << "true"; break;
178+
case CompileViaYul::Also: _output << "also"; break;
179+
case CompileViaYul::onlyOnEOF: _output << "onlyOnEOF"; break;
180+
}
181+
return _output;
182+
}
183+

test/TestCase.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,25 @@ class TestCase
113113
class EVMVersionRestrictedTestCase: public TestCase
114114
{
115115
private:
116+
std::string m_bytecodeFormat;
117+
116118
void processEVMVersionSetting();
117119
void processBytecodeFormatSetting();
118120

119121
protected:
122+
const std::string& bytecodeFormat() const { return m_bytecodeFormat; }
123+
120124
EVMVersionRestrictedTestCase(std::string const& _filename);
121125
};
122126

127+
enum class CompileViaYul
128+
{
129+
False,
130+
True,
131+
Also,
132+
onlyOnEOF,
133+
};
134+
135+
std::ostream& operator<<(std::ostream& _output, CompileViaYul _compileViaYul);
136+
123137
}

test/libsolidity/SemanticTest.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ SemanticTest::SemanticTest(
7373
m_enforceGasCost(_enforceGasCost),
7474
m_enforceGasCostMinValue(std::move(_enforceGasCostMinValue))
7575
{
76-
static std::set<std::string> const compileViaYulAllowedValues{"also", "true", "false"};
77-
static std::set<std::string> const yulRunTriggers{"also", "true"};
78-
static std::set<std::string> const legacyRunTriggers{"also", "false", "default"};
76+
static std::set<CompileViaYul> const yulRunTriggers{CompileViaYul::Also, CompileViaYul::True};
77+
static std::set<CompileViaYul> const legacyRunTriggers{CompileViaYul::Also, CompileViaYul::False};
7978

8079
m_requiresYulOptimizer = m_reader.enumSetting<RequiresYulOptimizer>(
8180
"requiresYulOptimizer",
@@ -92,18 +91,31 @@ SemanticTest::SemanticTest(
9291
m_shouldRun = false;
9392

9493
auto const eofEnabled = solidity::test::CommonOptions::get().eofVersion().has_value();
95-
std::string compileViaYul = m_reader.stringSetting("compileViaYul", eofEnabled ? "true" : "also");
9694

97-
if (compileViaYul == "false" && eofEnabled)
95+
auto const compileViaYul = m_reader.enumSetting<CompileViaYul>(
96+
"compileViaYul",
97+
{
98+
{toString(CompileViaYul::False), CompileViaYul::False},
99+
{toString(CompileViaYul::True), CompileViaYul::True},
100+
{toString(CompileViaYul::Also), CompileViaYul::Also},
101+
{toString(CompileViaYul::onlyOnEOF), CompileViaYul::onlyOnEOF}
102+
},
103+
eofEnabled ? toString(CompileViaYul::True) : toString(CompileViaYul::Also)
104+
);
105+
106+
std::string bytecodeFormatString = m_reader.stringSetting("bytecodeFormat", "unset");
107+
if (bytecodeFormatString == ">=EOFv1" && compileViaYul == CompileViaYul::False)
108+
BOOST_THROW_EXCEPTION(std::runtime_error("Compilation to EOF requires using Yul IR"));
109+
110+
if (compileViaYul == CompileViaYul::False && eofEnabled)
98111
m_shouldRun = false;
99112

100-
if (m_runWithABIEncoderV1Only && compileViaYul != "false")
113+
if (m_runWithABIEncoderV1Only && compileViaYul != CompileViaYul::False)
101114
BOOST_THROW_EXCEPTION(std::runtime_error(
102115
"ABIEncoderV1Only tests cannot be run via yul, "
103116
"so they need to also specify ``compileViaYul: false``"
104117
));
105-
if (!util::contains(compileViaYulAllowedValues, compileViaYul))
106-
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid compileViaYul value: " + compileViaYul + "."));
118+
107119
m_testCaseWantsYulRun = util::contains(yulRunTriggers, compileViaYul);
108120
m_testCaseWantsLegacyRun = util::contains(legacyRunTriggers, compileViaYul);
109121

test/libsolidity/SyntaxTest.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,25 @@ SyntaxTest::SyntaxTest(
4646
CommonSyntaxTest(_filename, _evmVersion),
4747
m_minSeverity(_minSeverity)
4848
{
49-
static std::set<std::string> const compileViaYulAllowedValues{"true", "false"};
50-
5149
auto const eofEnabled = solidity::test::CommonOptions::get().eofVersion().has_value();
5250

53-
m_compileViaYul = m_reader.stringSetting("compileViaYul", eofEnabled ? "true" : "false");
54-
if (!util::contains(compileViaYulAllowedValues, m_compileViaYul))
55-
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid compileViaYul value: " + m_compileViaYul + "."));
51+
m_compileViaYul = m_reader.enumSetting<CompileViaYul>(
52+
"compileViaYul",
53+
{
54+
{toString(CompileViaYul::False), CompileViaYul::False},
55+
{toString(CompileViaYul::True), CompileViaYul::True},
56+
{toString(CompileViaYul::Also), CompileViaYul::Also},
57+
{toString(CompileViaYul::onlyOnEOF), CompileViaYul::onlyOnEOF}
58+
},
59+
toString(CompileViaYul::onlyOnEOF)
60+
);
61+
62+
solUnimplementedAssert(m_compileViaYul != CompileViaYul::Also);
63+
64+
if (bytecodeFormat() == ">=EOFv1" && m_compileViaYul == CompileViaYul::False)
65+
BOOST_THROW_EXCEPTION(std::runtime_error("Compilation to EOF requires using Yul IR"));
5666

57-
if (m_compileViaYul == "false" && eofEnabled)
67+
if (m_compileViaYul == CompileViaYul::False && eofEnabled)
5868
m_shouldRun = false;
5969

6070
m_optimiseYul = m_reader.boolSetting("optimize-yul", true);
@@ -80,7 +90,7 @@ void SyntaxTest::setupCompiler(CompilerStack& _compiler)
8090
OptimiserSettings::full() :
8191
OptimiserSettings::minimal()
8292
);
83-
_compiler.setViaIR(m_compileViaYul == "true");
93+
_compiler.setViaIR(m_compileViaYul == CompileViaYul::True);
8494
_compiler.setMetadataFormat(CompilerStack::MetadataFormat::NoMetadata);
8595
_compiler.setMetadataHash(CompilerStack::MetadataHash::None);
8696
}

test/libsolidity/SyntaxTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class SyntaxTest: public AnalysisFramework, public solidity::test::CommonSyntaxT
5353
virtual void filterObtainedErrors();
5454

5555
bool m_optimiseYul{};
56-
std::string m_compileViaYul{};
56+
CompileViaYul m_compileViaYul{};
5757
langutil::Error::Severity m_minSeverity{};
5858
PipelineStage m_stopAfter;
5959
};

0 commit comments

Comments
 (0)