Skip to content

Commit 82d683a

Browse files
committed
WIP remove type immediates
1 parent b1d65ce commit 82d683a

13 files changed

+125
-124
lines changed

src/ir/child-typer.h

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,11 +1050,17 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
10501050
note(&curr->end, Type::i32);
10511051
}
10521052

1053-
void visitContNew(ContNew* curr) { note(&curr->func, curr->type); }
1053+
void visitContNew(ContNew* curr) {
1054+
note(&curr->func,
1055+
Type(curr->type.getHeapType().getContinuation().type, Nullable));
1056+
}
10541057

10551058
void visitContBind(ContBind* curr) {
1056-
auto sourceParams =
1057-
curr->sourceType.getContinuation().type.getSignature().params;
1059+
note(&curr->cont, curr->cont->type);
1060+
auto sourceParams = curr->cont->type.getHeapType()
1061+
.getContinuation()
1062+
.type.getSignature()
1063+
.params;
10581064
auto targetParams =
10591065
curr->type.getHeapType().getContinuation().type.getSignature().params;
10601066
assert(sourceParams.size() >= targetParams.size());
@@ -1063,7 +1069,6 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
10631069
for (size_t i = 0; i < n; ++i) {
10641070
note(&curr->operands[i], sourceParams[i]);
10651071
}
1066-
note(&curr->cont, Type(curr->sourceType, Nullable));
10671072
}
10681073

10691074
void visitSuspend(Suspend* curr) {
@@ -1075,31 +1080,37 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
10751080
}
10761081

10771082
void visitResume(Resume* curr) {
1078-
auto params = curr->contType.getContinuation().type.getSignature().params;
1083+
note(&curr->cont, curr->cont->type);
1084+
auto params = curr->cont->type.getHeapType()
1085+
.getContinuation()
1086+
.type.getSignature()
1087+
.params;
10791088
assert(params.size() == curr->operands.size());
10801089
for (size_t i = 0; i < params.size(); ++i) {
10811090
note(&curr->operands[i], params[i]);
10821091
}
1083-
note(&curr->cont, Type(curr->contType, Nullable));
10841092
}
10851093

10861094
void visitResumeThrow(ResumeThrow* curr) {
1095+
note(&curr->cont, curr->cont->type);
10871096
auto params = wasm.getTag(curr->tag)->sig.params;
10881097
assert(params.size() == curr->operands.size());
10891098
for (size_t i = 0; i < params.size(); ++i) {
10901099
note(&curr->operands[i], params[i]);
10911100
}
1092-
note(&curr->cont, Type(curr->contType, Nullable));
10931101
}
10941102

10951103
void visitStackSwitch(StackSwitch* curr) {
1096-
auto params = curr->contType.getContinuation().type.getSignature().params;
1104+
note(&curr->cont, curr->cont->type);
1105+
auto params = curr->cont->type.getHeapType()
1106+
.getContinuation()
1107+
.type.getSignature()
1108+
.params;
10971109
assert(params.size() >= 1 &&
10981110
((params.size() - 1) == curr->operands.size()));
10991111
for (size_t i = 0; i < params.size() - 1; ++i) {
11001112
note(&curr->operands[i], params[i]);
11011113
}
1102-
note(&curr->cont, Type(curr->contType, Nullable));
11031114
}
11041115
};
11051116

src/ir/module-utils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,18 +460,18 @@ struct CodeScanner
460460
} else if (auto* set = curr->dynCast<ArraySet>()) {
461461
info.note(set->ref->type);
462462
} else if (auto* contBind = curr->dynCast<ContBind>()) {
463-
info.note(contBind->sourceType);
463+
info.note(contBind->cont->type);
464464
info.note(contBind->type);
465465
} else if (auto* contNew = curr->dynCast<ContNew>()) {
466466
info.note(contNew->type);
467467
} else if (auto* resume = curr->dynCast<Resume>()) {
468-
info.note(resume->contType);
468+
info.note(resume->cont->type);
469469
info.note(resume->type);
470470
} else if (auto* resumeThrow = curr->dynCast<ResumeThrow>()) {
471-
info.note(resumeThrow->contType);
471+
info.note(resumeThrow->cont->type);
472472
info.note(resumeThrow->type);
473473
} else if (auto* switch_ = curr->dynCast<StackSwitch>()) {
474-
info.note(switch_->contType);
474+
info.note(switch_->cont->type);
475475
info.note(switch_->type);
476476
} else if (Properties::isControlFlowStructure(curr)) {
477477
info.noteControlFlow(Signature(Type::none, curr->type));

src/passes/Print.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -386,29 +386,25 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
386386
}
387387
}
388388
void visitContBind(ContBind* curr) {
389-
if (!maybePrintUnreachableOrNullReplacement(
390-
curr, Type(curr->sourceType, Nullable)) &&
389+
if (!maybePrintUnreachableOrNullReplacement(curr, curr->cont->type) &&
391390
!maybePrintUnreachableOrNullReplacement(curr, curr->type)) {
392391
visitExpression(curr);
393392
}
394393
}
395394
void visitResume(Resume* curr) {
396-
if (!maybePrintUnreachableOrNullReplacement(
397-
curr, Type(curr->contType, Nullable)) &&
395+
if (!maybePrintUnreachableOrNullReplacement(curr, curr->cont->type) &&
398396
!maybePrintUnreachableOrNullReplacement(curr, curr->type)) {
399397
visitExpression(curr);
400398
}
401399
}
402400
void visitResumeThrow(ResumeThrow* curr) {
403-
if (!maybePrintUnreachableOrNullReplacement(
404-
curr, Type(curr->contType, Nullable)) &&
401+
if (!maybePrintUnreachableOrNullReplacement(curr, curr->cont->type) &&
405402
!maybePrintUnreachableOrNullReplacement(curr, curr->type)) {
406403
visitExpression(curr);
407404
}
408405
}
409406
void visitStackSwitch(StackSwitch* curr) {
410-
if (!maybePrintUnreachableOrNullReplacement(
411-
curr, Type(curr->contType, Nullable)) &&
407+
if (!maybePrintUnreachableOrNullReplacement(curr, curr->cont->type) &&
412408
!maybePrintUnreachableOrNullReplacement(curr, curr->type)) {
413409
visitExpression(curr);
414410
}
@@ -2466,7 +2462,7 @@ struct PrintExpressionContents
24662462
}
24672463
void visitContBind(ContBind* curr) {
24682464
printMedium(o, "cont.bind ");
2469-
printHeapType(curr->sourceType);
2465+
printHeapType(curr->cont->type.getHeapType());
24702466
o << ' ';
24712467
printHeapType(curr->type.getHeapType());
24722468
}
@@ -2495,15 +2491,15 @@ struct PrintExpressionContents
24952491
printMedium(o, "resume");
24962492

24972493
o << ' ';
2498-
printHeapType(curr->contType);
2494+
printHeapType(curr->cont->type.getHeapType());
24992495

25002496
handleResumeTable(o, curr);
25012497
}
25022498
void visitResumeThrow(ResumeThrow* curr) {
25032499
printMedium(o, "resume_throw");
25042500

25052501
o << ' ';
2506-
printHeapType(curr->contType);
2502+
printHeapType(curr->cont->type.getHeapType());
25072503
o << ' ';
25082504
curr->tag.print(o);
25092505

@@ -2513,7 +2509,7 @@ struct PrintExpressionContents
25132509
printMedium(o, "switch");
25142510

25152511
o << ' ';
2516-
printHeapType(curr->contType);
2512+
printHeapType(curr->cont->type.getHeapType());
25172513
o << ' ';
25182514
curr->tag.print(o);
25192515
}

src/wasm-builder.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,76 +1168,76 @@ class Builder {
11681168
ret->finalize();
11691169
return ret;
11701170
}
1171-
ContNew* makeContNew(HeapType type, Expression* func) {
1171+
ContNew* makeContNew(Type type, Expression* func) {
11721172
auto* ret = wasm.allocator.alloc<ContNew>();
1173-
ret->type = Type(type, NonNullable);
1173+
ret->type = type;
11741174
ret->func = func;
11751175
ret->finalize();
11761176
return ret;
11771177
}
1178-
ContBind* makeContBind(HeapType sourceType,
1179-
HeapType targetType,
1178+
ContBind* makeContBind(Type type,
11801179
const std::vector<Expression*>& operands,
11811180
Expression* cont) {
11821181
auto* ret = wasm.allocator.alloc<ContBind>();
1183-
ret->sourceType = sourceType;
1184-
ret->type = Type(targetType, NonNullable);
1182+
ret->type = type;
11851183
ret->operands.set(operands);
11861184
ret->cont = cont;
11871185
ret->finalize();
11881186
return ret;
11891187
}
1190-
Suspend* makeSuspend(Name tag, const std::vector<Expression*>& args) {
1188+
Suspend*
1189+
makeSuspend(Type type, Name tag, const std::vector<Expression*>& args) {
11911190
auto* ret = wasm.allocator.alloc<Suspend>();
1191+
ret->type = type;
11921192
ret->tag = tag;
11931193
ret->operands.set(args);
11941194
ret->finalize(&wasm);
11951195
return ret;
11961196
}
1197-
Resume* makeResume(HeapType contType,
1197+
Resume* makeResume(Type type,
11981198
const std::vector<Name>& handlerTags,
11991199
const std::vector<Name>& handlerBlocks,
12001200
const std::vector<Type>& sentTypes,
12011201
const std::vector<Expression*>& operands,
12021202
Expression* cont) {
12031203
auto* ret = wasm.allocator.alloc<Resume>();
1204-
ret->contType = contType;
1204+
ret->type = type;
12051205
ret->handlerTags.set(handlerTags);
12061206
ret->handlerBlocks.set(handlerBlocks);
12071207
ret->sentTypes.set(sentTypes);
12081208
ret->operands.set(operands);
12091209
ret->cont = cont;
1210-
ret->finalize(&wasm);
1210+
ret->finalize();
12111211
return ret;
12121212
}
1213-
ResumeThrow* makeResumeThrow(HeapType contType,
1213+
ResumeThrow* makeResumeThrow(Type type,
12141214
Name tag,
12151215
const std::vector<Name>& handlerTags,
12161216
const std::vector<Name>& handlerBlocks,
12171217
const std::vector<Type>& sentTypes,
12181218
const std::vector<Expression*>& operands,
12191219
Expression* cont) {
12201220
auto* ret = wasm.allocator.alloc<ResumeThrow>();
1221-
ret->contType = contType;
1221+
ret->type = type;
12221222
ret->tag = tag;
12231223
ret->handlerTags.set(handlerTags);
12241224
ret->handlerBlocks.set(handlerBlocks);
12251225
ret->sentTypes.set(sentTypes);
12261226
ret->operands.set(operands);
12271227
ret->cont = cont;
1228-
ret->finalize(&wasm);
1228+
ret->finalize();
12291229
return ret;
12301230
}
1231-
StackSwitch* makeStackSwitch(HeapType contType,
1231+
StackSwitch* makeStackSwitch(Type type,
12321232
Name tag,
12331233
const std::vector<Expression*>& operands,
12341234
Expression* cont) {
12351235
auto* ret = wasm.allocator.alloc<StackSwitch>();
1236-
ret->contType = contType;
1236+
ret->type = type;
12371237
ret->tag = tag;
12381238
ret->operands.set(operands);
12391239
ret->cont = cont;
1240-
ret->finalize(&wasm);
1240+
ret->finalize();
12411241
return ret;
12421242
}
12431243

src/wasm-delegations-fields.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,6 @@ DELEGATE_FIELD_CASE_END(ContNew)
772772
DELEGATE_FIELD_CASE_START(ContBind)
773773
DELEGATE_FIELD_CHILD(ContBind, cont)
774774
DELEGATE_FIELD_CHILD_VECTOR(ContBind, operands)
775-
DELEGATE_FIELD_HEAPTYPE(ContBind, sourceType)
776775
DELEGATE_FIELD_CASE_END(ContBind)
777776

778777
DELEGATE_FIELD_CASE_START(Suspend)
@@ -786,7 +785,6 @@ DELEGATE_FIELD_CHILD(Resume, cont)
786785
DELEGATE_FIELD_CHILD_VECTOR(Resume, operands)
787786
DELEGATE_FIELD_SCOPE_NAME_USE_VECTOR(Resume, handlerBlocks)
788787
DELEGATE_FIELD_NAME_KIND_VECTOR(Resume, handlerTags, ModuleItemKind::Tag)
789-
DELEGATE_FIELD_HEAPTYPE(Resume, contType)
790788
DELEGATE_FIELD_CASE_END(Resume)
791789

792790
DELEGATE_FIELD_CASE_START(ResumeThrow)
@@ -795,14 +793,12 @@ DELEGATE_FIELD_CHILD(ResumeThrow, cont)
795793
DELEGATE_FIELD_CHILD_VECTOR(ResumeThrow, operands)
796794
DELEGATE_FIELD_SCOPE_NAME_USE_VECTOR(ResumeThrow, handlerBlocks)
797795
DELEGATE_FIELD_NAME_KIND_VECTOR(ResumeThrow, handlerTags, ModuleItemKind::Tag)
798-
DELEGATE_FIELD_HEAPTYPE(ResumeThrow, contType)
799796
DELEGATE_FIELD_NAME_KIND(ResumeThrow, tag, ModuleItemKind::Tag)
800797
DELEGATE_FIELD_CASE_END(ResumeThrow)
801798

802799
DELEGATE_FIELD_CASE_START(StackSwitch)
803800
DELEGATE_FIELD_CHILD(StackSwitch, cont)
804801
DELEGATE_FIELD_CHILD_VECTOR(StackSwitch, operands)
805-
DELEGATE_FIELD_HEAPTYPE(StackSwitch, contType)
806802
DELEGATE_FIELD_NAME_KIND(StackSwitch, tag, ModuleItemKind::Tag)
807803
DELEGATE_FIELD_CASE_END(StackSwitch)
808804

src/wasm-ir-builder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,17 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {
213213
Result<> makeStringWTF16Get();
214214
Result<> makeStringIterNext();
215215
Result<> makeStringSliceWTF();
216-
Result<> makeContNew(HeapType ct);
216+
Result<> makeContNew(HeapType type);
217217
Result<> makeContBind(HeapType sourceType, HeapType targetType);
218218
Result<> makeSuspend(Name tag);
219-
Result<> makeResume(HeapType ct,
219+
Result<> makeResume(HeapType type,
220220
const std::vector<Name>& tags,
221221
const std::vector<std::optional<Index>>& labels);
222-
Result<> makeResumeThrow(HeapType ct,
222+
Result<> makeResumeThrow(HeapType type,
223223
Name tag,
224224
const std::vector<Name>& tags,
225225
const std::vector<std::optional<Index>>& labels);
226-
Result<> makeStackSwitch(HeapType ct, Name tag);
226+
Result<> makeStackSwitch(HeapType type, Name tag);
227227

228228
// Private functions that must be public for technical reasons.
229229
Result<> visitExpression(Expression*);

src/wasm.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,6 @@ class ContBind : public SpecificExpression<Expression::ContBindId> {
19421942

19431943
// Syntax: cont.bind $src $dst
19441944
// We store $src here, and $dst in the inherited `type` member.
1945-
HeapType sourceType;
19461945
ExpressionList operands;
19471946
Expression* cont;
19481947

@@ -1968,7 +1967,6 @@ class Resume : public SpecificExpression<Expression::ResumeId> {
19681967
: handlerTags(allocator), handlerBlocks(allocator), operands(allocator),
19691968
sentTypes(allocator) {}
19701969

1971-
HeapType contType;
19721970
// The following two vectors are to be understood together
19731971
// pointwise. That is, the ith component of each vector together
19741972
// classifies an on-clause `(on $tag $label)` or `(on $tag
@@ -1986,7 +1984,7 @@ class Resume : public SpecificExpression<Expression::ResumeId> {
19861984
// When 'Module*' parameter is given, we populate the 'sentTypes' array, so
19871985
// that the types can be accessed in other analyses without accessing the
19881986
// module.
1989-
void finalize(Module* wasm = nullptr);
1987+
void finalize();
19901988

19911989
// sentTypes[i] contains the type of the values that will be sent to the block
19921990
// handlerBlocks[i] if suspending with tag handlerTags[i]. Not part of the
@@ -2002,7 +2000,6 @@ class ResumeThrow : public SpecificExpression<Expression::ResumeThrowId> {
20022000
: handlerTags(allocator), handlerBlocks(allocator), operands(allocator),
20032001
sentTypes(allocator) {}
20042002

2005-
HeapType contType;
20062003
Name tag;
20072004
// See the comment on `Resume` above.
20082005
ArenaVector<Name> handlerTags;
@@ -2014,7 +2011,7 @@ class ResumeThrow : public SpecificExpression<Expression::ResumeThrowId> {
20142011
// When 'Module*' parameter is given, we populate the 'sentTypes' array, so
20152012
// that the types can be accessed in other analyses without accessing the
20162013
// module.
2017-
void finalize(Module* wasm = nullptr);
2014+
void finalize();
20182015

20192016
// sentTypes[i] contains the type of the values that will be sent to the block
20202017
// handlerBlocks[i] if suspending with tag handlerTags[i]. Not part of the
@@ -2028,14 +2025,13 @@ class StackSwitch : public SpecificExpression<Expression::StackSwitchId> {
20282025
public:
20292026
StackSwitch(MixedArena& allocator) : operands(allocator) {}
20302027

2031-
HeapType contType;
20322028
Name tag;
20332029

20342030
ExpressionList operands;
20352031
Expression* cont;
20362032

20372033
// We need access to the module to obtain the signature of the tag.
2038-
void finalize(Module* wasm = nullptr);
2034+
void finalize();
20392035
};
20402036

20412037
// Globals

0 commit comments

Comments
 (0)