-
Notifications
You must be signed in to change notification settings - Fork 107
switch to a single handle type (for now) #203
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
Conversation
ricochet
left a comment
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.
The only other name that I can come up with is something that embraces a subtyping future like refhandle for "reference counted handle", but I like rc just as well.
|
Thanks for writing this up! Reading over this now though one idea that has stuck out to me is: what if instead of removing own/borrow and adding rc instead we "simply" removed borrow? This would slim down the set of handle types to exclusively
Would something like that end up working out? I'm not familiar with the underlying motivations for |
|
Starting with only The first issue is that, with only The second issue is how to handle cases like
Thinking about this more, one way to mitigate the verbosity of option 1 is to add WDYT? |
|
Ah that's a good point about methods, and the "natural" solution to that is to bring back For use cases which motivate I suppose another way to phrase this is that I'm thinking about this from a Rust-like perspective. Rust only has ownership at the language level which is akin sort of to the component model only having ownership. At the runtime level of Rust, however, there is a |
|
I got a bit excited about option (1) above, but thinking more about it, I remembered some other problems with the "caching getter" approach which had stopped me earlier (in particular, caching assumes the underlying value doesn't change), so that whole option probably isn't the right one. Option (3) does increasingly seem like a good idea. Initially, I had assumed that the deduping behavior of Incidentally, I think the post-Preview-2 solution for wasi-http is not an So then, iiuc, if we go with Option (3) and keep |
|
Ok so, in summary, I think this boils down to "is DOM-like wrapper object identity important". To summarize both I talked with @tschneidereit this morning and it sounds like y'all previously concluded that wrapper object identity is important. It sounds at least @guybedford may be leaning the other way now. To be clear though I don't personally mean to provide an opinion on this specific point since I don't fully understand it. I understand how it works and what it means for JS in a literal sense, but I don't have enough of a grasp on the downstream implications for developers and what pitfalls might be encountered and such to be able to weigh the importance of this point. That all being said, there's two more things I've been thinking recently about this:
This sort of points me to I realize my own thinking is sort of going back and forth on this, so sorry about that! I'm also happy to talk over video over this for more high-bandwidth discussion. |
|
Heh, yeah, totally understand the flip-flopping on this; it's a nuanced topic. Also happy to jump into a higher-bandwidth chat any time. I think Guy and I are probably thinking of the same concern. To explain it a bit more, the issue is: if I create an object wrapper of an If we don't end up ever adding identity, it's possible we'll never want But also, it's a good point that |
|
Ok had a good talk with Luke this morning and our conclusion was that we'll probably want to stick with |
|
Sounds good to me! Thanks for all the discussion and consideration on this, it definitely helped refine my understanding of the short- and long-term goal state here. I'll close now, but if anyone wants to continue discussing this approach, feel free to comment and reopen. |
The current explainer has two handle types (
ownandborrow). Unfortunately, to describe realistic interfaces (such as WASI HTTP), additional handle types are needed (forownto actually mean (transitive) exclusive ownership). I was working on this in the child-handles branch before realizing the need for more varieties and thus a potentially better, more-general, more-orthogonal design (currently sketched in the generalize-handles) branch. In the meantime, we need to make progress on Preview 2, so for now (and perhaps until after Preview 2), I think it'd be a good idea to have a single handle type that represents non-exclusive, reference-counted ownership, since this is able to express any interface honestly (albeit sometimes imprecisely and suboptimally). In the future, when we add back more-precise handle types (capturing ownership, exclusivity and scope in the call contract), this non-exclusive, reference-counted handle would continue to exist as one of the options, so Wit and components written using it would continue to be valid.There is the question of what to call this reference-counted handle type (in Wat and Wit).
sharedorrefwould make sense, but these names are already in use by core wasm and so it's probably a good idea to avoid creating confusion. The best I could think of (that isn't super long) isrc(standing for "reference counted"), so that's what in the PR, but happy to hear better options. E.g., in Wit, this would look likerc<file>(wherefileis a resource type). This reserves use of the resource-type's name (without qualifier) for the unique/linear handle case, which seems like the right default option to suggest to interface authors.A new issue that needs to be addressed for
rc(and non-exclusive handles in general) is how to handle identity (e.g., when tworchandles to the same resource are given to a component). Guest programs may need to ask whether two handles point to the same resource and/or use a resource as a key in a hash-table. This can be solved in an ad hoc way on a per-interface basis (e.g., adding expliciteqandhash-code/idmethods to resources), but (1) this is opaque to bindings generation, (2)hash-code/idraise various virtualization hazards, (3) it requires the interface author to anticipate usage patterns. Instead, this PR proposes that the Canonical ABI lowering automatically de-duplicates multiplerchandles pointing to the same resource, ultimately giving them the samei32handle index, thus allowing thei32index to serve as the (component-local) identity of the resource for use in bindings generators.