Skip to content

Commit 8b13110

Browse files
Try allowing globals to be imported in ctor eval
1 parent ae1b333 commit 8b13110

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

src/tools/wasm-ctor-eval.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,16 @@ class EvallingModuleRunner;
7171

7272
class EvallingImportResolver : public ImportResolver {
7373
public:
74-
EvallingImportResolver(
75-
std::map<Name, std::shared_ptr<EvallingModuleRunner>> linkedInstances,
76-
ModuleRunnerBase<EvallingModuleRunner>::ExternalInterface*
77-
externalInterface)
78-
: externalInterface(externalInterface) {}
74+
EvallingImportResolver() {}
7975

8076
std::optional<Literals*> getGlobal(QualifiedName name,
8177
Type type) const override {
82-
externalInterface->trap((std::stringstream()
83-
<< "EvallingImportResolver: unexpected getGlobal "
84-
<< name)
85-
.str());
86-
return std::nullopt;
78+
auto [it, _] = stubLiterals.try_emplace(name, Literals({Literal(type)}));
79+
return &it->second;
8780
}
8881

8982
private:
90-
ModuleRunnerBase<EvallingModuleRunner>::ExternalInterface* externalInterface;
83+
mutable std::map<QualifiedName, Literals> stubLiterals;
9184
};
9285

9386
class EvallingModuleRunner : public ModuleRunnerBase<EvallingModuleRunner> {
@@ -98,8 +91,7 @@ class EvallingModuleRunner : public ModuleRunnerBase<EvallingModuleRunner> {
9891
std::map<Name, std::shared_ptr<EvallingModuleRunner>> linkedInstances_ = {})
9992
: ModuleRunnerBase(wasm,
10093
externalInterface,
101-
std::make_shared<EvallingImportResolver>(
102-
linkedInstances_, externalInterface),
94+
std::make_shared<EvallingImportResolver>(),
10395
linkedInstances_) {}
10496

10597
Flow visitGlobalGet(GlobalGet* curr) {
@@ -570,6 +562,9 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
570562
wasm->updateMaps();
571563

572564
for (auto& oldGlobal : oldGlobals) {
565+
if (oldGlobal->imported()) {
566+
continue;
567+
}
573568
// Serialize the global's value. While doing so, pass in the name of this
574569
// global, as we may be able to reuse the global as the defining global
575570
// for the value. See getSerialization() for more details.

src/wasm/qualified-name.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ struct QualifiedName {
1313
friend std::ostream& operator<<(std::ostream& o, const QualifiedName& qname) {
1414
return o << qname.module << "." << qname.name;
1515
}
16+
17+
bool operator<(const QualifiedName& other) const {
18+
return std::tie(module, name) < std::tie(other.module, other.name);
19+
}
1620
};
1721

1822
} // namespace wasm
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
(module
2-
(type $0 (func))
3-
(export "test1" (func $test1))
4-
(func $test1 (type $0)
5-
(nop)
6-
)
72
)

0 commit comments

Comments
 (0)