-
Notifications
You must be signed in to change notification settings - Fork 793
[WasmGC] Heap2Local: Optimize RefCast failures #6727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This reverts commit d36281b.
;; CHECK-NEXT: (local.get $3) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (local.set $2 | ||
;; CHECK-NEXT: (local.get $4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are what I meant in the second paragraph - $B
has an extra field now, which is also handled here (with value 1
). This does not affect what the test is testing.
// succeeds or fails. | ||
if (Type::isSubType(allocation->type, curr->type)) { | ||
// The cast succeeds, so it is a no-op, and we can skip it. | ||
replaceCurrent(curr->ref); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if the cast is known to succeed, we might still need it to make the static types work out, right? This replacement is only valid if curr->ref->type
is a subtype of curr->type
, not necessarily if allocation->type
is a subtype.
This isn't a new issue, so I must be missing something that makes this safe.
Aha, it's because we're going to remove the allocation entirely. This is worth a comment!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I added a comment.
Followup to #6727 which added support for failing casts in Struct2Local, but it turns out that it required Array2Struct changes as well. Specifically, when we turn an array into a struct then casts can look like they behave differently (what used to be an array input, becomes a struct), so like with RefTest that we already handled, check if the cast succeeds in the original form and handle that.
Previously we just did not optimize cases where our escape analysis showed an
allocation flowed into a cast that failed. However, after inlining there can be
real-world cases where that happens, even in traps-never-happen mode (if the
cast is behind a conditional branch), so it seems worth optimizing.
Note that a field was added to the struct
$B
in the test, which is needed for some ofthe new checks. That extra field causes minor changes to existing tests (the extra
value is dropped).