-
Notifications
You must be signed in to change notification settings - Fork 13k
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
make interface types more like closures #1567
Comments
Also, calls are cheaper (one less deref to get vtable) |
The idea with just storing the function pointer for single-method interfaces won't work. The 'dict' stored in the value does not just contain the vtable. If you have for example this impl:
It must also store the tydesc for T and the dict for the to_str implementation of T that was in scope at the point that created the boxed iface. So you'll always, even for ifaces that themselves do not have parameters, have to allow for these extra fields. As for the &/~/@ stuff... I'm always grossed out by more sigils being added to say simple things, but I guess this does add expressiveness, and people are already familiar with a similar system for fns, so I could live with it. |
So, the bit about optimizing single-entry vtables is not important, I just threw it in for fun. I'm not surprised it's more complex than I first envisioned. I am more interested in the bounds so that we can make instances sendable and more analogous to closures. Similarly, I don't have a strong opinion about whether instances should be one or two words, but I think two words would allow us to avoid an allocation in some cases (basically impls over pointer types). I am sure there is a wrinkle there I haven't thought all the way through as well. =) |
It seems people regularly get confused by the iface type name being used both for param bounds and as a boxed iface type. Having a sigil at the end of the boxed type would probably help. I'm liking this proposal more and more. |
I'd be willing to tackle it. |
They are now a (dictptr, box) pair, where box is a regular boxed representation of the inner type. This cuts down on some special case code. Also removes some code from trans::base that was moved to shape but then somehow restored in trans::base through a bad merge. Starts on issue #1567
I'm ok with this (though I imagine the trailing sigils will come to have slightly different meaning if and when explicit-region work occurs). |
dup of #3157 |
Interface types are really very similar conceptually and in practice to closures. I think we should make them resemble closures more closely both in the language and implementation as follows:
(vtable, data)
(analogous to a closure's (fptr, data))Therefore, for an iface
X
, the type:X
indicates any interface instance Such a closure cannot be copied, just asfn
cannot be copiedX&
indicates an interface instance whose data is located on the stack.X@
indicates an interface instance whose data is boxedX~
indicates an interface instance whose data is sendable and stored via unique ptrAdvantages:
X~
instances can be sentX&
instances are particularly cheap to constructThe text was updated successfully, but these errors were encountered: