Skip to content

Commit e5c9ab4

Browse files
Address PR comments
1 parent 0cb3bf5 commit e5c9ab4

File tree

7 files changed

+25
-24
lines changed

7 files changed

+25
-24
lines changed

scripts/test/shared.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ def get_tests(test_dir, extensions=[], recursive=False):
443443
'imports.wast', # Missing validation of missing function on instantiation
444444
'proposals/threads/imports.wast', # Missing memory type validation on instantiation
445445
'linking.wast', # Missing function type validation on instantiation
446-
# 'memory.wast', # Requires wast `module definition` support
447446
'proposals/threads/memory.wast', # Missing memory type validation on instantiation
448447
'memory64-imports.wast', # Missing validation on instantiation
449448
'annotations.wast', # String annotations IDs should be allowed

scripts/test/support.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,12 @@ def to_end(j):
151151
break
152152
i = to_end(start + 1)
153153
chunk = wast[start:i]
154-
if QUOTED.match(chunk):
154+
if QUOTED.match(chunk) or MODULE_DEFINITION_OR_INSTANCE.match(chunk):
155155
# There may be assertions after this quoted module, but we aren't
156156
# returning the module, so we need to skip the assertions as well.
157157
ignoring_quoted = True
158158
continue
159159
if chunk.startswith('(module'):
160-
if MODULE_DEFINITION_OR_INSTANCE.match(chunk):
161-
continue
162160
ignoring_quoted = False
163161
ret += [(chunk, [])]
164162
elif chunk.startswith('(assert_invalid'):

src/parser/wast-parser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Result<Action> action(Lexer& in) {
9191
// (module id binary string*)
9292
// (module id quote string*)
9393
// (module definition id? ...)
94+
// (module definition id? binary ...)
9495
Result<WASTModule> wastModule(Lexer& in, bool maybeInvalid = false) {
9596
Lexer reset = in;
9697
if (!in.takeSExprStart("module"sv)) {
@@ -122,7 +123,7 @@ Result<WASTModule> wastModule(Lexer& in, bool maybeInvalid = false) {
122123
}
123124
}
124125
std::string mod(reset.next().substr(0, in.getPos() - reset.getPos()));
125-
return QuotedModule{!isDefinition, QuotedModuleType::Text, mod};
126+
return WASTModule{isDefinition, QuotedModule{QuotedModuleType::Text, mod}};
126127
} else {
127128
// In this case the module is mostly valid WAT, unless it is a module
128129
// definition in which case it will begin with (module definition ...)
@@ -146,8 +147,7 @@ Result<WASTModule> wastModule(Lexer& in, bool maybeInvalid = false) {
146147
return in.err("expected end of module");
147148
}
148149

149-
wasm->isDefinition = isDefinition;
150-
return wasm;
150+
return WASTModule{isDefinition, wasm};
151151
}
152152

153153
// We have a quote or binary module. Collect its contents.
@@ -160,7 +160,7 @@ Result<WASTModule> wastModule(Lexer& in, bool maybeInvalid = false) {
160160
return in.err("expected end of module");
161161
}
162162

163-
return QuotedModule{isDefinition, type, ss.str()};
163+
return WASTModule{isDefinition, QuotedModule{type, ss.str()}};
164164
}
165165

166166
Result<NaNKind> nan(Lexer& in) {
@@ -558,7 +558,7 @@ Result<WASTScript> wast(Lexer& in) {
558558
// No, that wasn't the problem. Return the original error.
559559
return Err{err->msg};
560560
}
561-
cmds.push_back({WASTModule{std::move(wasm)}, line});
561+
cmds.push_back({WASTModule{/*isDefinition=*/false, std::move(wasm)}, line});
562562
return cmds;
563563
}
564564
CHECK_ERR(cmd);

src/parser/wat-parser.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,14 @@ struct AssertAction {
9393
enum class QuotedModuleType { Text, Binary };
9494

9595
struct QuotedModule {
96-
bool isDefinition = false;
9796
QuotedModuleType type;
9897
std::string module;
9998
};
10099

101-
using WASTModule = std::variant<QuotedModule, std::shared_ptr<Module>>;
100+
struct WASTModule {
101+
bool isDefinition = false;
102+
std::variant<QuotedModule, std::shared_ptr<Module>> module;
103+
};
102104

103105
enum class ModuleAssertionType { Trap, Malformed, Invalid, Unlinkable };
104106

src/tools/wasm-shell.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ using namespace wasm;
3939
using namespace wasm::WATParser;
4040

4141
struct Shell {
42-
// Keyed by module name
42+
// Keyed by module name.
4343
std::map<Name, std::shared_ptr<Module>> modules;
4444

45-
// Keyed by instance name
45+
// Keyed by instance name.
4646
std::map<Name, std::shared_ptr<ShellExternalInterface>> interfaces;
4747
std::map<Name, std::shared_ptr<ModuleRunner>> instances;
48-
// used for imports, keyed by instance name
48+
// Used for imports, keyed by instance name.
4949
std::map<Name, std::shared_ptr<ModuleRunner>> linkedInstances;
5050

5151
Name lastModule;
@@ -100,12 +100,11 @@ struct Shell {
100100

101101
Result<std::shared_ptr<Module>> makeModule(WASTModule& mod) {
102102
std::shared_ptr<Module> wasm;
103-
if (auto* quoted = std::get_if<QuotedModule>(&mod)) {
103+
if (auto* quoted = std::get_if<QuotedModule>(&mod.module)) {
104104
wasm = std::make_shared<Module>();
105105
switch (quoted->type) {
106106
case QuotedModuleType::Text: {
107107
CHECK_ERR(parseModule(*wasm, quoted->module));
108-
wasm->isDefinition = quoted->isDefinition;
109108
break;
110109
}
111110
case QuotedModuleType::Binary: {
@@ -119,11 +118,10 @@ struct Shell {
119118
p.dump(ss);
120119
return Err{ss.str()};
121120
}
122-
wasm->isDefinition = quoted->isDefinition;
123121
break;
124122
}
125123
}
126-
} else if (auto* ptr = std::get_if<std::shared_ptr<Module>>(&mod)) {
124+
} else if (auto* ptr = std::get_if<std::shared_ptr<Module>>(&mod.module)) {
127125
wasm = *ptr;
128126
} else {
129127
WASM_UNREACHABLE("unexpected module kind");
@@ -173,7 +171,7 @@ struct Shell {
173171

174172
lastModule = wasm->name;
175173
modules[lastModule] = wasm;
176-
if (!wasm->isDefinition) {
174+
if (!mod.isDefinition) {
177175
CHECK_ERR(instantiate(*wasm, wasm->name));
178176
}
179177

@@ -530,7 +528,7 @@ struct Shell {
530528

531529
// print_* functions are handled separately, no need to define here.
532530

533-
WASTModule mod = std::move(spectest);
531+
WASTModule mod = {/*isDefinition=*/false, spectest};
534532
auto added = addModule(mod);
535533
if (added.getErr()) {
536534
WASM_UNREACHABLE("error building spectest module");

src/tools/wasm2js.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,10 @@ void AssertionEmitter::emit() {
788788
Name testFuncName("check" + std::to_string(i));
789789
auto& cmd = script[i].cmd;
790790
if (auto* mod = std::get_if<WASTModule>(&cmd)) {
791-
if (auto* w = std::get_if<std::shared_ptr<Module>>(mod)) {
791+
if (mod->isDefinition) {
792+
Fatal() << "Module definition is not supported on line " << script[i].line;
793+
}
794+
if (auto* w = std::get_if<std::shared_ptr<Module>>(&mod->module)) {
792795
wasm = *w;
793796
// We have already done the parse, but we still do this to apply the
794797
// features from the command line.
@@ -951,7 +954,10 @@ int main(int argc, const char* argv[]) {
951954
Fatal() << "expected module";
952955
}
953956
if (auto* mod = std::get_if<WASTModule>(&(*script)[0].cmd)) {
954-
if (auto* w = std::get_if<std::shared_ptr<Module>>(mod)) {
957+
if (mod->isDefinition) {
958+
Fatal() << "module definition is not supported";
959+
}
960+
if (auto* w = std::get_if<std::shared_ptr<Module>>(&mod->module)) {
955961
wasm = *w;
956962
// This isn't actually before the parse, but we can't apply the
957963
// feature options any earlier. FIXME.

src/wasm.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,8 +2519,6 @@ class Module {
25192519

25202520
Name start;
25212521

2522-
bool isDefinition = false;
2523-
25242522
std::vector<CustomSection> customSections;
25252523

25262524
// Optional user section IR representation.

0 commit comments

Comments
 (0)