Skip to content

Commit f844de0

Browse files
authored
Rename ref.cast_desc to ref.cast_desc_eq (#8250)
And similarly for br_on_cast_desc and br_on_cast_desc_fail. This corresponds with an upcoming rename in the proposal repo. Continue parsing the old instruction names for now and add a test to confirm that this still works.
1 parent be62412 commit f844de0

39 files changed

+785
-684
lines changed

scripts/gen-s-parser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,17 @@
618618
("i31.get_u", "makeI31Get(false)"),
619619
("ref.test", "makeRefTest()"),
620620
("ref.cast", "makeRefCast(false)"),
621-
("ref.cast_desc", "makeRefCast(true)"),
621+
("ref.cast_desc", "makeRefCast(true)"), # Deprecated
622+
("ref.cast_desc_eq", "makeRefCast(true)"),
622623
("ref.get_desc", "makeRefGetDesc()"),
623624
("br_on_null", "makeBrOnNull()"),
624625
("br_on_non_null", "makeBrOnNull(true)"),
625626
("br_on_cast", "makeBrOnCast(BrOnCast)"),
626627
("br_on_cast_fail", "makeBrOnCast(BrOnCastFail)"),
627-
("br_on_cast_desc", "makeBrOnCast(BrOnCastDesc)"),
628-
("br_on_cast_desc_fail", "makeBrOnCast(BrOnCastDescFail)"),
628+
("br_on_cast_desc", "makeBrOnCast(BrOnCastDescEq)"), # Deprecated
629+
("br_on_cast_desc_fail", "makeBrOnCast(BrOnCastDescEqFail)"), # Deprecated
630+
("br_on_cast_desc_eq", "makeBrOnCast(BrOnCastDescEq)"),
631+
("br_on_cast_desc_eq_fail", "makeBrOnCast(BrOnCastDescEqFail)"),
629632
("struct.new", "makeStructNew(false, false)"),
630633
("struct.new_default", "makeStructNew(true, false)"),
631634
("struct.new_desc", "makeStructNew(false, true)"),

src/gen-s-parser.inc

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,38 @@ switch (buf[0]) {
276276
switch (buf[15]) {
277277
case '\0':
278278
if (op == "br_on_cast_desc"sv) {
279-
CHECK_ERR(makeBrOnCast(ctx, pos, annotations, BrOnCastDesc));
279+
CHECK_ERR(makeBrOnCast(ctx, pos, annotations, BrOnCastDescEq));
280280
return Ok{};
281281
}
282282
goto parse_error;
283-
case '_':
284-
if (op == "br_on_cast_desc_fail"sv) {
285-
CHECK_ERR(makeBrOnCast(ctx, pos, annotations, BrOnCastDescFail));
286-
return Ok{};
283+
case '_': {
284+
switch (buf[16]) {
285+
case 'e': {
286+
switch (buf[18]) {
287+
case '\0':
288+
if (op == "br_on_cast_desc_eq"sv) {
289+
CHECK_ERR(makeBrOnCast(ctx, pos, annotations, BrOnCastDescEq));
290+
return Ok{};
291+
}
292+
goto parse_error;
293+
case '_':
294+
if (op == "br_on_cast_desc_eq_fail"sv) {
295+
CHECK_ERR(makeBrOnCast(ctx, pos, annotations, BrOnCastDescEqFail));
296+
return Ok{};
297+
}
298+
goto parse_error;
299+
default: goto parse_error;
300+
}
301+
}
302+
case 'f':
303+
if (op == "br_on_cast_desc_fail"sv) {
304+
CHECK_ERR(makeBrOnCast(ctx, pos, annotations, BrOnCastDescEqFail));
305+
return Ok{};
306+
}
307+
goto parse_error;
308+
default: goto parse_error;
287309
}
288-
goto parse_error;
310+
}
289311
default: goto parse_error;
290312
}
291313
}
@@ -4894,12 +4916,23 @@ switch (buf[0]) {
48944916
return Ok{};
48954917
}
48964918
goto parse_error;
4897-
case '_':
4898-
if (op == "ref.cast_desc"sv) {
4899-
CHECK_ERR(makeRefCast(ctx, pos, annotations, true));
4900-
return Ok{};
4919+
case '_': {
4920+
switch (buf[13]) {
4921+
case '\0':
4922+
if (op == "ref.cast_desc"sv) {
4923+
CHECK_ERR(makeRefCast(ctx, pos, annotations, true));
4924+
return Ok{};
4925+
}
4926+
goto parse_error;
4927+
case '_':
4928+
if (op == "ref.cast_desc_eq"sv) {
4929+
CHECK_ERR(makeRefCast(ctx, pos, annotations, true));
4930+
return Ok{};
4931+
}
4932+
goto parse_error;
4933+
default: goto parse_error;
49014934
}
4902-
goto parse_error;
4935+
}
49034936
default: goto parse_error;
49044937
}
49054938
}

src/ir/child-typer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -911,15 +911,15 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
911911
return;
912912
case BrOnCast:
913913
case BrOnCastFail:
914-
case BrOnCastDesc:
915-
case BrOnCastDescFail: {
914+
case BrOnCastDescEq:
915+
case BrOnCastDescEqFail: {
916916
if (!target) {
917917
assert(curr->castType.isRef());
918918
target = curr->castType;
919919
}
920920
auto top = target->getHeapType().getTop();
921921
note(&curr->ref, Type(top, Nullable));
922-
if (curr->op == BrOnCastDesc || curr->op == BrOnCastDescFail) {
922+
if (curr->op == BrOnCastDescEq || curr->op == BrOnCastDescEqFail) {
923923
auto desc = target->getHeapType().getDescriptorType();
924924
assert(desc);
925925
note(&curr->desc, Type(*desc, Nullable));

src/ir/cost.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,8 @@ struct CostAnalyzer : public OverriddenVisitor<CostAnalyzer, CostType> {
692692
case BrOnCast:
693693
case BrOnCastFail:
694694
return CastCost + visit(curr->ref);
695-
case BrOnCastDesc:
696-
case BrOnCastDescFail:
695+
case BrOnCastDescEq:
696+
case BrOnCastDescEqFail:
697697
// These are not as expensive as full casts, since they just do a
698698
// identity check on the descriptor.
699699
return 2 + visit(curr->ref) + visit(curr->desc);

src/ir/struct-utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ struct StructScanner
300300

301301
void visitBrOn(BrOn* curr) {
302302
if (curr->desc &&
303-
(curr->op == BrOnCastDesc || curr->op == BrOnCastDescFail)) {
303+
(curr->op == BrOnCastDescEq || curr->op == BrOnCastDescEqFail)) {
304304
handleDescRead(curr->getCastType());
305305
}
306306
}

src/ir/subtype-exprs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ struct SubtypingDiscoverer : public OverriddenVisitor<SubType> {
329329
break;
330330
case BrOnCast:
331331
case BrOnCastFail:
332-
case BrOnCastDesc:
333-
case BrOnCastDescFail:
332+
case BrOnCastDescEq:
333+
case BrOnCastDescEqFail:
334334
self()->noteCast(curr->ref, curr->castType);
335335
break;
336336
}

src/passes/AbstractTypeRefining.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ struct AbstractTypeRefining : public Pass {
345345

346346
// We may have casts like this:
347347
//
348-
// (ref.cast_desc (ref null $optimized-to-bottom)
348+
// (ref.cast_desc_eq (ref null $optimized-to-bottom)
349349
// (some struct...)
350350
// (some desc...)
351351
// )
@@ -435,7 +435,7 @@ struct AbstractTypeRefining : public Pass {
435435
}
436436
// Optimize the same way we optimize ref.cast*.
437437
Builder builder(*getModule());
438-
bool isFail = curr->op == BrOnCastDescFail;
438+
bool isFail = curr->op == BrOnCastDescEqFail;
439439
if (curr->castType.isExact() || (curr->desc && optimized->isBottom())) {
440440
if (curr->desc) {
441441
if (curr->desc->type.isNullable() &&

src/passes/GlobalStructInference.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ struct GlobalStructInference : public Pass {
9292
// type-based inference, and this remains empty.
9393
std::unordered_map<HeapType, std::vector<Name>> typeGlobals;
9494

95-
// Whether to optimize ref.cast to ref.cast_desc. This increases code size, so
96-
// it may not always be beneficial (perhaps running it late in the pipeline,
97-
// and before type-merging, could make sense).
95+
// Whether to optimize ref.cast to ref.cast_desc_eq. This increases code size,
96+
// so it may not always be beneficial (perhaps running it late in the
97+
// pipeline, and before type-merging, could make sense).
9898
bool optimizeToDescCasts;
9999

100100
std::unique_ptr<SubTypes> subTypes;
@@ -515,10 +515,11 @@ struct GlobalStructInference : public Pass {
515515

516516
void visitRefCast(RefCast* curr) {
517517
// When we see (ref.cast $T), and the type has a descriptor, and that
518-
// descriptor only has a single global, then we can do (ref.cast_desc)
519-
// using the descriptor. Descriptor casts are usually more efficient
520-
// than normal ones (and even more so if we get lucky and are in a loop,
521-
// where the global.get of the descriptor can be hoisted).
518+
// descriptor only has a single global, then we can do
519+
// (ref.cast_desc_eq) using the descriptor. Descriptor casts are usually
520+
// more efficient than normal ones (and even more so if we get lucky and
521+
// are in a loop, where the global.get of the descriptor can be
522+
// hoisted).
522523
// TODO: only do this when shrinkLevel == 0?
523524
if (!parent.optimizeToDescCasts) {
524525
return;
@@ -535,8 +536,8 @@ struct GlobalStructInference : public Pass {
535536
return;
536537
}
537538

538-
// Check if the type has no (relevant) subtypes, as a ref.cast_desc will
539-
// find precisely that type and nothing else.
539+
// Check if the type has no (relevant) subtypes, as a ref.cast_desc_eq
540+
// will find precisely that type and nothing else.
540541
if (!type.isExact() &&
541542
!parent.subTypes->getStrictSubTypes(heapType).empty()) {
542543
return;

src/passes/Heap2Local.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,10 @@ struct EscapeAnalyzer {
402402
}
403403
} else {
404404
// Either the child is the descriptor, in which case we consume it, or
405-
// we have already optimized this ref.cast_desc for an allocation that
406-
// flowed through as its `ref`. In the latter case the current child
407-
// must have originally been the descriptor, so we can still say it's
408-
// fully consumed, but we cannot assert that curr->desc == child.
405+
// we have already optimized this ref.cast_desc_eq for an allocation
406+
// that flowed through as its `ref`. In the latter case the current
407+
// child must have originally been the descriptor, so we can still say
408+
// it's fully consumed, but we cannot assert that curr->desc == child.
409409
fullyConsumes = true;
410410
}
411411
}
@@ -869,23 +869,23 @@ struct Struct2Local : PostWalker<Struct2Local> {
869869
builder.makeUnreachable()));
870870
};
871871

872-
// If we are doing a ref.cast_desc of the optimized allocation, but the
872+
// If we are doing a ref.cast_desc_eq of the optimized allocation, but the
873873
// allocation does not have a descriptor, then we know the cast must fail.
874874
// We also know the cast must fail (except for nulls it might let through)
875875
// if the optimized allocation flows in as the descriptor, since it cannot
876876
// possibly have been used in the allocation of the cast value without
877877
// having been considered to escape.
878878
bool allocIsCastRef =
879879
analyzer.getInteraction(curr->ref) == ParentChildInteraction::Flows;
880-
bool allocIsCastDesc =
880+
bool allocIsCastDescEq =
881881
analyzer.getInteraction(curr->desc) == ParentChildInteraction::Flows;
882-
if (!allocation->desc || allocIsCastDesc) {
882+
if (!allocation->desc || allocIsCastDescEq) {
883883
// It would seem convenient to use ChildLocalizer here, but we cannot.
884884
// ChildLocalizer would create a local.set for a desc operand with
885885
// side effects, but that local.set would not be reflected in the parent
886886
// map, so it would not be updated if the allocation flowing through
887887
// that desc operand were later optimized.
888-
if (allocIsCastDesc && !allocIsCastRef && curr->type.isNullable()) {
888+
if (allocIsCastDescEq && !allocIsCastRef && curr->type.isNullable()) {
889889
// There might be a null value to let through. Reuse curr as a cast to
890890
// null. Use a scratch local to move the reference value past the desc
891891
// value.

src/passes/Print.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,7 +2225,7 @@ struct PrintExpressionContents
22252225
}
22262226
void visitRefCast(RefCast* curr) {
22272227
if (curr->desc) {
2228-
printMedium(o, "ref.cast_desc ");
2228+
printMedium(o, "ref.cast_desc_eq ");
22292229
} else {
22302230
printMedium(o, "ref.cast ");
22312231
}
@@ -2259,21 +2259,21 @@ struct PrintExpressionContents
22592259
curr->name.print(o);
22602260
return;
22612261
case BrOnCast:
2262-
case BrOnCastDesc:
2262+
case BrOnCastDescEq:
22632263
case BrOnCastFail:
2264-
case BrOnCastDescFail:
2264+
case BrOnCastDescEqFail:
22652265
switch (curr->op) {
22662266
case BrOnCast:
22672267
printMedium(o, "br_on_cast");
22682268
break;
22692269
case BrOnCastFail:
22702270
printMedium(o, "br_on_cast_fail");
22712271
break;
2272-
case BrOnCastDesc:
2273-
printMedium(o, "br_on_cast_desc");
2272+
case BrOnCastDescEq:
2273+
printMedium(o, "br_on_cast_desc_eq");
22742274
break;
2275-
case BrOnCastDescFail:
2276-
printMedium(o, "br_on_cast_desc_fail");
2275+
case BrOnCastDescEqFail:
2276+
printMedium(o, "br_on_cast_desc_eq_fail");
22772277
break;
22782278
default:
22792279
WASM_UNREACHABLE("unexpected op");
@@ -2294,7 +2294,7 @@ struct PrintExpressionContents
22942294
return;
22952295
printMedium(o,
22962296
curr->op == BrOnCastFail ? "br_on_cast_fail "
2297-
: "br_on_cast_desc_fail ");
2297+
: "br_on_cast_desc_eq_fail ");
22982298
curr->name.print(o);
22992299
o << ' ';
23002300
if (curr->ref->type == Type::unreachable) {

0 commit comments

Comments
 (0)