-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
virtual structs #5
Conversation
Will there be some way for an override method to call the parent type's override implementation? |
I would also really like to see casting elaborated upon, with examples, etc. |
I've been thinking more about this. I think that we ought to "close" subtyping so that you can only subtype a virtual struct within the same module (or some submodule). My reasoning:
Basically, virtual structs become an alternative to enums. To some extent this is the expression problem -- enums are there to provide one half, virtual structs with virtual fns to provide the other half, and traits to solve extensibility. (There is some sort of precedent, as an aside, with scala's sealed keyword) |
Closed subtyping seems an extremely interesting idea, because then one could see this not as competition for traits, but rather a generalization of enums. The current "enum" syntax could be recast as syntax sugar for virtual structs. This would give "datasort refinements" and "GADTs"/"type parametrization for variants" for free to the enum side, and would give the ability to represent the type tag in ways different than the a vtable pointer (byte-sized tag, null pointer optimization, etc.) to the virtual class side. I still wonder whether the methods would be better put in named traits, with support for declaring a "vtable trait" on the structs/enums/enums variants. Maybe there could be some syntax sugar there too, by having a "virtual impl" declarations that would be equivalent to declaring and implementing a trait, and declaring it as a vtable trait, just like the current "impl" behaves like syntax sugar for declaring and implementing a trait. BTW, I'd suggest then to make the structs either abstract or final, so that it works like the current enum vs enum variant, and doesn't have the issue of having a single identifier that names both a concrete virtual struct, and the set of virtual structs inheriting it. |
Incorporated comments from this issue. (Do comments on earlier commits just disappear? I guess I probably shouldn't have force pushed) |
If you still have the commit hashes (I guess you do, via |
On Mon, Mar 17, 2014 at 11:32:29PM -0700, Nick Cameron wrote:
Usually github keeps and lists commented, citing "an outdated version |
(filed as #14) |
@nikomatsakis The behavior you described only occurs when people comment of the diff tab and not on the commit itself. |
Another alternative to RFC rust-lang#5 and an extension/variant of RFC rust-lang#11. Unify enums and structs by allowing enums to have fields, and structs to have variants. Allow nested enums/structs. Virtual dispatch of methods on struct/enum pointers. Remove struct variants. Treat enum variants as first class. Possibly remove nullary structs and tuple structs.
Another alternative to RFC rust-lang#5 and an extension/variant of RFC rust-lang#11. Unify enums and structs by allowing enums to have fields, and structs to have variants. Allow nested enums/structs. Virtual dispatch of methods on struct/enum pointers. Remove struct variants. Treat enum variants as first class. Possibly remove nullary structs and tuple structs.
Please do not use the word "virtual", nor as a keyword, nor as a name for a feature. Even though i am used primarily to C++, i can not get used to this word. For me it means something that i can see, but is not actually there. Like in "virtual reality" or "virtual memory". The meaning of this word has nothing in common with what you plan to use it for. In source code i think it is the comment which is virtual - it looks to be there, but is actually not real source. Please choose some other words. Perhaps "dynamically dispatchable", ... . You know it better. Just not "virtual" please. |
@almale |
6357402
to
e0acdf4
Compare
Closing in favour of other RFCs which address the same problem (see http://discuss.rust-lang.org/t/summary-of-efficient-inheritance-rfcs/494). |
Clarify taking addresses of globals in globals
Updates from implementation and feedback:
Revising crt-link
…e-name Add section pointing out how associated item ambiguity is handled.
Fix RFC 2302 to support unit structs, fn pointers, and use value namespace instead for exprs
Add link to rustdoc roadmap
Document feature flags drawbacks
Fixed broken markdown in Russian translation
No description provided.