Skip to content

Commit f9dd59e

Browse files
authored
Store HeapTypes in Tags (#7220)
Tags in WebAssembly syntactically refer to function heap types, but Binaryen IR was previously storing signatures instead and reconstructing heap types as necessary when emitting binaries. Before WasmGC this was not a problem because the reconstructed types would be the same as the original types, but with WasmGC round tripping function types through Signature could lose information such as the rec group, the declared supertype, and the finality from the original type. Store the original heap type in the IR instead to stop losing this information. Fixes #7219.
1 parent c582f8d commit f9dd59e

File tree

94 files changed

+290
-294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+290
-294
lines changed

src/binaryen-c.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4770,7 +4770,7 @@ BinaryenTagRef BinaryenAddTag(BinaryenModuleRef module,
47704770
BinaryenType results) {
47714771
auto* ret = new Tag();
47724772
ret->setExplicitName(name);
4773-
ret->sig = Signature(Type(params), Type(results));
4773+
ret->type = Signature(Type(params), Type(results));
47744774
((Module*)module)->addTag(ret);
47754775
return ret;
47764776
}
@@ -4874,7 +4874,7 @@ void BinaryenAddTagImport(BinaryenModuleRef module,
48744874
tag->name = internalName;
48754875
tag->module = externalModuleName;
48764876
tag->base = externalBaseName;
4877-
tag->sig = Signature(Type(params), Type(results));
4877+
tag->type = Signature(Type(params), Type(results));
48784878
((Module*)module)->addTag(std::move(tag));
48794879
} else {
48804880
// already exists so just set module and base
@@ -5838,11 +5838,11 @@ const char* BinaryenTagGetName(BinaryenTagRef tag) {
58385838
return ((Tag*)tag)->name.str.data();
58395839
}
58405840
BinaryenType BinaryenTagGetParams(BinaryenTagRef tag) {
5841-
return ((Tag*)tag)->sig.params.getID();
5841+
return ((Tag*)tag)->params().getID();
58425842
}
58435843

58445844
BinaryenType BinaryenTagGetResults(BinaryenTagRef tag) {
5845-
return ((Tag*)tag)->sig.results.getID();
5845+
return ((Tag*)tag)->results().getID();
58465846
}
58475847

58485848
//

src/ir/child-typer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
789789
void visitTryTable(TryTable* curr) { note(&curr->body, curr->type); }
790790

791791
void visitThrow(Throw* curr) {
792-
auto type = wasm.getTag(curr->tag)->sig.params;
792+
auto type = wasm.getTag(curr->tag)->params();
793793
assert(curr->operands.size() == type.size());
794794
for (size_t i = 0; i < type.size(); ++i) {
795795
note(&curr->operands[i], type[i]);
@@ -1113,7 +1113,7 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
11131113
}
11141114

11151115
void visitSuspend(Suspend* curr) {
1116-
auto params = wasm.getTag(curr->tag)->sig.params;
1116+
auto params = wasm.getTag(curr->tag)->params();
11171117
assert(params.size() == curr->operands.size());
11181118
for (size_t i = 0; i < params.size(); ++i) {
11191119
note(&curr->operands[i], params[i]);

src/ir/eh-utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void handleBlockNestedPop(Try* try_, Function* func, Module& wasm) {
111111
for (Index i = 0; i < try_->catchTags.size(); i++) {
112112
Name tagName = try_->catchTags[i];
113113
auto* tag = wasm.getTag(tagName);
114-
if (tag->sig.params == Type::none) {
114+
if (tag->params() == Type::none) {
115115
continue;
116116
}
117117

src/ir/module-splitting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ void ModuleSplitter::shareImportableItems() {
883883

884884
for (auto& tag : primary.tags) {
885885
auto secondaryTag = std::make_unique<Tag>();
886-
secondaryTag->sig = tag->sig;
886+
secondaryTag->type = tag->type;
887887
makeImportExport(*tag, *secondaryTag, "tag", ExternalKind::Tag);
888888
secondary.addTag(std::move(secondaryTag));
889889
}

src/ir/module-utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Tag* copyTag(Tag* tag, Module& out) {
125125
auto* ret = new Tag();
126126
ret->name = tag->name;
127127
ret->hasExplicitName = tag->hasExplicitName;
128-
ret->sig = tag->sig;
128+
ret->type = tag->type;
129129
ret->module = tag->module;
130130
ret->base = tag->base;
131131
out.addTag(ret);
@@ -474,7 +474,7 @@ InsertOrderedMap<HeapType, HeapTypeInfo> collectHeapTypeInfo(
474474
info.note(curr->type);
475475
}
476476
for (auto& curr : wasm.tags) {
477-
info.note(curr->sig);
477+
info.note(curr->type);
478478
}
479479
for (auto& curr : wasm.tables) {
480480
info.note(curr->type);

src/ir/possible-contents.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ struct InfoCollector
11511151
auto tag = curr->catchTags[tagIndex];
11521152
auto* body = curr->catchBodies[tagIndex];
11531153

1154-
auto params = getModule()->getTag(tag)->sig.params;
1154+
auto params = getModule()->getTag(tag)->params();
11551155
if (params.size() == 0) {
11561156
continue;
11571157
}
@@ -1189,7 +1189,7 @@ struct InfoCollector
11891189

11901190
Index exnrefIndex = 0;
11911191
if (tag.is()) {
1192-
auto params = getModule()->getTag(tag)->sig.params;
1192+
auto params = getModule()->getTag(tag)->params();
11931193

11941194
for (Index i = 0; i < params.size(); i++) {
11951195
if (isRelevant(params[i])) {

src/ir/subtype-exprs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ struct SubtypingDiscoverer : public OverriddenVisitor<SubType> {
257257
}
258258
}
259259
void visitThrow(Throw* curr) {
260-
Type params = self()->getModule()->getTag(curr->tag)->sig.params;
260+
Type params = self()->getModule()->getTag(curr->tag)->params();
261261
assert(params.size() == curr->operands.size());
262262
for (size_t i = 0, size = curr->operands.size(); i < size; ++i) {
263263
self()->noteSubtype(curr->operands[i], params[i]);

src/ir/type-updating.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,6 @@ void GlobalTypeRewriter::mapTypes(const TypeMap& oldToNewTypes) {
225225
return type;
226226
}
227227

228-
Signature getNew(Signature sig) {
229-
return Signature(getNew(sig.params), getNew(sig.results));
230-
}
231-
232228
void visitExpression(Expression* curr) {
233229
// local.get and local.tee are special in that their type is tied to the
234230
// type of the local in the function, which is tied to the signature. That
@@ -304,7 +300,7 @@ void GlobalTypeRewriter::mapTypes(const TypeMap& oldToNewTypes) {
304300
global->type = updater.getNew(global->type);
305301
}
306302
for (auto& tag : wasm.tags) {
307-
tag->sig = updater.getNew(tag->sig);
303+
tag->type = updater.getNew(tag->type);
308304
}
309305
}
310306

src/parser/contexts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ struct ParseModuleTypesCtx : TypeParserCtx<ParseModuleTypesCtx>,
13721372
if (!use.type.isSignature()) {
13731373
return in.err(pos, "tag type must be a signature");
13741374
}
1375-
t->sig = use.type.getSignature();
1375+
t->type = use.type;
13761376
return Ok{};
13771377
}
13781378
};

src/passes/MergeBlocks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ struct ProblemFinder
144144
// make more sense in TupleOptimization though as it would need
145145
// to track uses of parts of a tuple.
146146
if (!tryy->catchTags[i] ||
147-
getModule()->getTag(tryy->catchTags[i])->sig.params.size() == 0) {
147+
getModule()->getTag(tryy->catchTags[i])->params().size() == 0) {
148148
// There must be a ref here, otherwise there is no value being sent
149149
// at all, and we should not be running ProblemFinder at all.
150150
assert(tryy->catchRefs[i]);

0 commit comments

Comments
 (0)