-
Notifications
You must be signed in to change notification settings - Fork 1
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
Unreachable code and shared
typing
#80
Comments
Good question. @rossberg, this seems to require type variables for the shareability. Do our shared-polymorphic instructions like |
@abrown does your typing algorithm explicitly represent IIUC there should be two cases:
|
Oh, looking more closely at the current typing rule for |
No instruction currently results in |
[Short reply from vacation.] Yes, interestingly, it seems like this is okay for Principal Types, but breaks closedness of Principal Forward Types, which is the property engines depend on. We'd need to either introduce "bottom sharability" or require separate instructions / annotations. |
Adding a bottom shareability for validation purposes would be an interesting solution. The typing rules for shareability-polymorphic instructions would have to propagate bottom shareability from their input to their output, so this solution is similar to the solution @conrad-watt suggested of propagating the bottom value type from the input to the output. But AFAICT bottom shareability propagation maintains the current decomposition property that says any valid sequence of instructions can be decomposed into two valid sequences of instructions at any point, whereas full-blown bottom type propagation would break that property. (We didn't notice this problem in Binaryen because we do full-blown bottom type propagation anyway, contrary to the spec. It would be nice to fix this in our parsers at some point.) @abrown, do you think this bottom shareability idea would be easily implementable in wasm-tools? |
Nullability is recorded directly on the reftype but shareability comes from the heaptype, so there would be some spec messiness unless we restrict
Well, with bottom propagation the second sequence of instructions would have type |
It looks like we introduce a |
The situation is a little funky in wasm-tools because historically we've tried to avoid adding enum MaybeType {
Bot,
HeapBot,
Type(ValType),
} which enables us to encapsulate the bottom-ness within the validator itself and not part of the public API of reading a wasm module or getting its type information. In that sense adding I'll admit though I'm not following some of the discussion here 100%, so I wanted to ask a question about this. Is the idea that if there's a Or is the suggestion that there's a new |
The The type on the stack after If I were trying to implement this in wasm-tools, I would try using something like these enums: enum MaybeShare {
ShareBot,
Share(Shareability),
}
enum MaybeHeapType {
HeapBot,
MaybeShare(MaybeShare, AbsHeapType),
Type(HeapType)
}
enum MaybeType {
Bot,
MaybeReference(MaybeHeapType),
Type(ValType),
} And enforce an invariant that the |
In prototyping this I found that it was sufficient to effectively add the concept of a bottom heap type with an optionally known abstract heap type. The heap bottom type suffices to represent "maybe shared, maybe not" and the optionally known abstract heap type handles the enum MaybeType {
Bot,
HeapBot(Option<AbstractHeapType>),
Type(ValType),
} in the validator. I've only updated the instructions that @abrown has implemented for shared-everything-threads in wasm-tools though so this may not be sufficient for everything if there's more flavorful instructions to be added. |
Sounds plausible. The spec internally extends the type grammar for validation purposes, as specified here (which come with suitable subtyping rules). For sharedness, we'll need a corresponding extension with bot. An actual implementation of validation will have to do something similar. But not all expressible cases can arise with the current instruction set. IIUC, the representation you show uses HeapBot to represent (ref (botshared absheaptype)), but it cannot express (ref null (botshared absheaptype)) or (ref (botshared $t)). Currently that's probably okay, because the latter do not arise in any instruction's forward principal type, I think. Though there could be future instructions that need to distinguish some of these cases. |
To perhaps close the loop on this, an update to wasm-tools's implementation was in bytecodealliance/wasm-tools#1734 with a number of new tests that pass as a result of that PR as well. |
I'm writing a PR to update the overview to describe Do we want to have both shareability type variables and |
Before looking at the PR in detail, I'm surprised by the following statement in it:
I'd expect that shareability type variables in the rules + i.e. consider the following typing rules in a system where one of the allowed values of
(apologies if I'm getting the
(@rossberg please check my intuition above) Unrelated thought - I think there's also a connection between |
Yes, keeping both the type variables and the bottom shareability means we can still disallow mixed shareability in |
Can you expand a little on what we'd be removing with the PR's approach? IIUC the main expansion of the concept of principle types comes from allowing I don't think it's important whether the
and so long as the range of |
Yes, thanks, I was confused. We still need sharedness metavariables for principal types, so there's no reason to make a change to |
While implementing validation logic for instructions like
any.convert_extern
, I ran into a question: if we're validating unreachable code, we may not have a type available for the incoming operand. For the result type of that instruction, thenullable
bit is set tofalse
— what should theshared
bit be set to?The text was updated successfully, but these errors were encountered: