summaryrefslogtreecommitdiff
path: root/src/passes
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes')
-rw-r--r--src/passes/OptimizeInstructions.cpp28
-rw-r--r--src/passes/Print.cpp26
2 files changed, 20 insertions, 34 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 884afcdd4..e8c6dc1fe 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -2118,35 +2118,13 @@ struct OptimizeInstructions
if (curr->op == ExternExternalize || curr->op == ExternInternalize) {
// We can't optimize these. Even removing a non-null cast is not valid as
- // they allow nulls to filter through, unlike other RefAs*
+ // they allow nulls to filter through, unlike other RefAs*.
return;
}
+ assert(curr->op == RefAsNonNull);
skipNonNullCast(curr->value);
-
- // Check if the type is the kind we are checking for.
- auto result = GCTypeUtils::evaluateKindCheck(curr);
-
- if (result == GCTypeUtils::Success) {
- // We know the kind is correct, so all that is left is a check for
- // non-nullability, which we do lower down.
- curr->op = RefAsNonNull;
- } else if (result == GCTypeUtils::Failure) {
- // This is the wrong kind, so it will trap. The binaryen optimizer does
- // not differentiate traps, so we can perform a replacement here. We
- // replace 2 bytes of ref.as_* with one byte of unreachable and one of a
- // drop, which is no worse, and the value and the drop can be optimized
- // out later if the value has no side effects.
- Builder builder(*getModule());
- // Make sure to emit a block with the same type as us; leave updating
- // types for other passes.
- replaceCurrent(builder.makeBlock(
- {builder.makeDrop(curr->value), builder.makeUnreachable()},
- curr->type));
- return;
- }
-
- if (curr->op == RefAsNonNull && !curr->value->type.isNullable()) {
+ if (!curr->value->type.isNullable()) {
replaceCurrent(curr->value);
return;
}
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 12c185e69..e0d9a46a3 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -2122,6 +2122,23 @@ struct PrintExpressionContents
if (curr->safety == RefCast::Unsafe) {
printMedium(o, "ref.cast_nop ");
} else {
+ // TODO: These instructions are deprecated. Remove them.
+ if (auto type = curr->type.getHeapType();
+ type.isBasic() && curr->type.isNonNullable()) {
+ switch (type.getBasic()) {
+ case HeapType::func:
+ printMedium(o, "ref.as_func");
+ return;
+ case HeapType::data:
+ printMedium(o, "ref.as_data");
+ return;
+ case HeapType::i31:
+ printMedium(o, "ref.as_i31");
+ return;
+ default:
+ break;
+ }
+ }
if (curr->type.isNullable()) {
printMedium(o, "ref.cast null ");
} else {
@@ -2329,15 +2346,6 @@ struct PrintExpressionContents
case RefAsNonNull:
printMedium(o, "ref.as_non_null");
break;
- case RefAsFunc:
- printMedium(o, "ref.as_func");
- break;
- case RefAsData:
- printMedium(o, "ref.as_data");
- break;
- case RefAsI31:
- printMedium(o, "ref.as_i31");
- break;
case ExternInternalize:
printMedium(o, "extern.internalize");
break;