-
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
Is there a way to make i31 shared? #57
Comments
This is not quite true, since the bottom heap types all have multiple supertypes. This would be similar. I had been thinking, inspired by #80, that we could type |
So this would result in rules like [Paragraph removed as it was based on me misreading the previous comment's proposed subtype relationship.] There had been discussions around I don't think any of that is simple or intuitive and it sounds to me that the only reason for these inconsistencies would be "We can re-use the existing The overview of this proposal lists 37 instructions and we'd reduce that number by 1. Having to implement decoding and typing for these two "create an i31" instructions will probably be significantly less work in any engine compared to the difficulties and issues that arise from having this one type that can "pierce through sharedness boundaries" like no other type can. Building type-based optimizations that handle these i31 corner cases correctly doesn't sound easy and logic bugs in these optimizations are often an exploitable vulnerability. |
@Liedtke, you may well be right that it isn't worth it. But note that it's not just for the sake of saving an instruction. It would also be in order to have the ability to pass on an i31 to where a shared ref is required, and vice versa, without having to untag and retag it redundantly. Though we could probably add specific type coercion instructions to cover that. |
Do we have an idea why that could be needed? Similarly, I see two options:
Is there a guarantee by the wasm standard that a |
I don't have any concrete example, but I'd expect something like this could arise in a scenario where there is a distinction between global and thread-local state, while scalars are moved between the two. But admittedly, that is rather vague.
The intent of i31 is to represent unboxed scalars, but of course, the spec has no way of enforcing that, since it can ultimately only specify observable behaviour. But yes, if such a coercion would run the risk of requiring allocation under some common implementation schemes, then it should not be provided. |
As @rossberg pointed out in #55 (comment), it would be nice if we could allow i31ref in shared contexts. The trouble is that it would then have to be a subtype of both
eqref
and(shared eqref)
(at least AFAICT), and we have never allowed a type to have multiple supertypes before, making this a risky new frontier. We should experiment with this and see whether we run into problems in practice.The text was updated successfully, but these errors were encountered: