-
Notifications
You must be signed in to change notification settings - Fork 758
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
Support type use before definition in binaries #3588
Conversation
Update parsing of binary type sections to use TypeBuilder to support uses before definitions. Now that both the binary and text parsers support out-of-order type uses, this PR also relaxes the logic for emitting types to allow uses to be emitted before definitions.
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.
Nice!
lgtm aside from the one question.
src/wasm-type.h
Outdated
@@ -308,6 +308,9 @@ class HeapType { | |||
data, | |||
}; | |||
static constexpr BasicHeapType _last_basic_type = data; | |||
static constexpr uintptr_t _invalid_type = -1; |
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.
why not 0? (is -1
guaranteed to segfault on use like 0 is?)
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.
Actually, is this needed? It would be better to avoid allowing an invalid HeapType at all. It seems like getBasicHeapType
returns a boolean already, so we know if a value was found or not. Given that, the HeapType could be initialized to a valid value (say, anyref
, doesn't matter) before the call? (There is a risk to doing that as well, but with a good comment there I think it's less risky than a general change to allow invalid HeapTypes to be declared as easily as HeapType bad;
).
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.
Sure, I can have the default constructor just choose an arbitrary BasicHeapType. FWIW, address -1 should segfault on all reasonable platforms (as long as you're not in kernel mode or in WebAssembly or something 😉).
Side note, @jakobkummerow and I happened to look at a wasm file with recursive types now (testcase for the names section), and I noticed that it crashes with this PR,
(Infinite recursion?) That wasm has something like this: // type 0: struct $StrA (field ($byte i8) ($word i16) ($pointer (ref $StrB)))
// type 1: struct $StrB (field ($next (ref null $StrA))) |
Yeah there are going to be lots of infinite recursions for recursive types right now, but I'm surprised that this didn't trigger an assertion in the TypeBuilder first. |
Update parsing of binary type sections to use TypeBuilder to support uses before
definitions. Now that both the binary and text parsers support out-of-order type
uses, this PR also relaxes the logic for emitting types to allow uses to be
emitted before definitions.