Skip to content

Commit 084a2f8

Browse files
Try allowing globals to be imported in ctor eval
1 parent e1e16b8 commit 084a2f8

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

src/tools/wasm-ctor-eval.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,15 @@ class EvallingModuleRunner;
7272
class EvallingImportResolver : public ImportResolver {
7373
public:
7474
EvallingImportResolver(
75-
std::map<Name, std::shared_ptr<EvallingModuleRunner>> linkedInstances,
76-
ModuleRunnerBase<EvallingModuleRunner>::ExternalInterface*
77-
externalInterface)
78-
: externalInterface(externalInterface) {}
75+
std::map<Name, std::shared_ptr<EvallingModuleRunner>> linkedInstances) {}
7976

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

8882
private:
89-
ModuleRunnerBase<EvallingModuleRunner>::ExternalInterface* externalInterface;
83+
std::map<QualifiedName, Literals> stubLiterals;
9084
};
9185

9286
class EvallingModuleRunner : public ModuleRunnerBase<EvallingModuleRunner> {
@@ -569,6 +563,8 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
569563
wasm->updateMaps();
570564

571565
for (auto& oldGlobal : oldGlobals) {
566+
if (oldGlobal->imported())
567+
continue;
572568
// Serialize the global's value. While doing so, pass in the name of this
573569
// global, as we may be able to reuse the global as the defining global
574570
// 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)