Repository navigation
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.
kripken
left a comment
There was a problem hiding this comment.
Nice!
lgtm aside from the one question.
| data, | ||
| }; | ||
| static constexpr BasicHeapType _last_basic_type = data; | ||
| static constexpr uintptr_t _invalid_type = -1; |
There was a problem hiding this comment.
why not 0? (is -1 guaranteed to segfault on use like 0 is?)
There was a problem hiding this comment.
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.
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.