-
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
RFC for "fat objects" for DSTs #9
Conversation
This is similar to what I was suggesting to @pcwalton, though I was thinking of explicit vtable fields. |
I had liked eddyb's suggestion r.e. explicit vtable fields alot, I liked the idea that it would be a versatile building block - for example vtables could be embedded in 'class objects' holding one vtable and many instances, or they could be changed dynamically for state-machines. (This is something i'd always wanted to do in C++ but was always discouraged in a team environment by the hacky nature of poking the first word (every compiler i've seen has the vtable there but its not specifically defined to be I think..)) Something like an intrinsic type: eg, It wasn't so unpleasant to write this with transmute as it is now, I think you could make convinient library code and have it work safely and still be minimal features above whats there now |
I've amended this to add a translation of jdm's servo example. While it can be translated, there are some annoying aspects of it that suggest some needed revisions to this RFC if it were to move forward. |
@dobkeratops wouldn't the ability to switch vtables at run time be limited to cases where the subclasses did not add any of their own fields? Under that limitation, what you have is basically an enum (that similarity was the observation that led to #11, which is quite interesting.) |
I do not think being able to change vtables at runtime is a good idea. We On Sun, Apr 6, 2014 at 5:16 PM, Micah Chalmer [email protected]:
|
I think he meant switching subclasses in-place by replacing a pointer to one constant vtable with a pointer to another, rather than changing the vtables themselves. Having said that, I don't quite see the usefulness of that. |
The use is state machines; a vtable can hold responses to certain events for example. As I understand enums and vtables are orthogobal (closed set of types, open methods,, vs open set ot types, closed methods). The 'subclasses' would indeed have the same data layout, but represent different states of the same object. People have one picture of OOP from C++.. its interesting to compare with more dynamic behavior (objective-C, even CLOS) well, it will be interesting to see what happens with enums.. we used to do all sorts of tricks with function pointer tables in C, then C++ came along providing sugar for one specific case.. thats why I found the possibility of something more versatile interesting. I realise of course we can still use function pointer tables, and macros could probably streamline custom cases. I suppose if you do just go the route of mimicking some of what C++ does (i can see single inheritance + traits would be a nice combination) it would be easier to interoperate with C++, and translate some subset of their classes across.
is this an attribute of the pointer or the vtable itself? i'm thinking of merely swapping the pointer with other vtables - they would still be in constant memory, having still been 'rolled' by the compiler. Other times you'd still have the mutable/immutable information for optimizing I hope |
Sorry for taking so long. This is a very interesting, elegant, and high quality proposal, an alternative 'virtual struct' design (#5). Since it builds on DST, and is probably a post 1.0 feature we can afford to take our time deciding on it. We will consider this seriously in designing single inheritance though. Thanks. |
I really like how orthogonal this proposal is. (I'd be happy if we could find another word than |
@MicahChalmer or @pnkfelix could you show how https://gist.github.com/jdm/9900569 would be encoded under this proposal please? |
6357402
to
e0acdf4
Compare
@nick29581 @MicahChalmer already added it I think, back on apr 6th: https://github.com/MicahChalmer/rust-rfcs/blob/fat-objects/active/0000-fat-objects.md#jdms-servo-example |
// Methods defined here have access to the fields and methods of NodeFields via `self` [5] | ||
fn frobify_children(&self) { | ||
// .children is a static offset field access--no extra pointer indirection [1] | ||
for node in children.iter() { |
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.
typo: should be self.children.iter()
here
I did some corrections to the errors @pnkfelix noted. I think the RFC as a whole could be improved by choosing a different version of single inheritance. But I don't know that it's necessary--I think the main idea has reached where it needs to reach. |
The team did a recent review of all of the RFC PR's around inheritance: During that meeting we determined that this RFC has a promising idea, so promising that it was then duplicated into other RFC's that are under consideration. Since the good idea have propagated elsewhere, and this RFC on its own does not resolve all of the issues that we need to address (in particular, note the issue with upcasting from a trait to a super-trait via the same thin pointer, noted on a different discuss thread), we are going to close this RFC PR. Note again that this is not because we think the core idea itself is bad, but rather because we think this PR has served its purpose well. You can see some critiques of the details of this RFC here, but that is relatively unimportant. |
fixed 2 typos in documention for Task
Update from recent discussions
This is intended as an alternative to #5.