-
Notifications
You must be signed in to change notification settings - Fork 827
[EH][GC] Send a non-nullable exnref from TryTable #7013
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. | ||
|
|
||
| ;; Test that we do not emit an invalid (ref exn) when exceptions are enabled | ||
| ;; but not GC. GC is required for us to be non-nullable. | ||
|
|
||
| ;; RUN: wasm-opt %s --enable-reference-types --enable-exception-handling --disable-gc --roundtrip -S -o - | filecheck %s | ||
|
|
||
| (module | ||
| ;; CHECK: (func $test (result exnref) | ||
| ;; CHECK-NEXT: (block $label$1 (result exnref) | ||
| ;; CHECK-NEXT: (try_table (catch_all_ref $label$1) | ||
| ;; CHECK-NEXT: (unreachable) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (func $test (result exnref) | ||
| ;; It is valid to write (ref exn) in Binaryen IR, and internally that is how | ||
| ;; we represent things, but when we emit the binary we emit a nullable type, | ||
| ;; so after the roundtrip we are less refined. | ||
| (block $label (result (ref exn)) | ||
| (try_table (catch_all_ref $label) | ||
| (unreachable) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I understand it's better to make types as refined as possible for optimization, but shouldn't we not error error out on nullable
exnrefin the validator? I think we also generate nullableexnrefs in the fuzzer. I think we should leave it as is and check for not the equality but the subtype below (in line 2696)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.
I think we should be sending a non-nullable exnref. The target might be less refined (until ReFinalize fixes that) but we should still be sending the refined type, as the spec says?
Unless I missed something in the code here and it is checking something other than the type being sent?
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.
If I'm misunderstanding you, can you give an example of code that should validate but this code will not accept?
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.
I think I might have misunderstood what this PR does. So basically, from now on we assume
exnref==(ref exn)and not(ref null exn)and treat it as such in the IR and all passes, and make it(ref null exn)only when we write it back to a binary. Right? (By the way don't we need to do the same thing when we write it back as a text?)If that's the case, if you programatically create a
TryTableobject withexnrefinsentTypefield, it will not validate. Of course, we don't usually manually set the fields in the IR classes; we usually use constructors andfinalizemethods, so I guess practically it's fine, but it was a little confusing to me. (Maybe givingTryTable::sentTypeaprivatevisibility might help a little.)I think it'd help if we have little more comments in wasm.cpp that why we are doing this. Also, can't we also validate
(ref null exn)insentTypeas valid? (I can't give you an example wast program that does not validate, because we basically readexnrefas(ref exn)when reading.)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.
exnrefshould be equivalent to(ref null exn), not(ref exn). Sincetry_tablenever produces a null exn value, the most precise type for the exn value it produces is always(ref exn). We can therefore take it as an invariant that the IR models sending a(ref exn). However, non-nullable references like that do not exist without GC enabled, so without GC, we fix it up by transforming the(ref exn)intoexnref(i.e.(ref null exn)) in the binary writer.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.
I added a comment now. I also noticed we were missing docs on this in the readme and added those.