Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

MicahChalmer
Copy link

This is intended as an alternative to #5.

@emberian
Copy link
Member

cc @pcwalton @nikomatsakis

@eddyb
Copy link
Member

eddyb commented Mar 16, 2014

This is similar to what I was suggesting to @pcwalton, though I was thinking of explicit vtable fields.
+1 nonetheless, saved me from writing my own RFC.

@dobkeratops
Copy link

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: VTable<Type, Trait> .. an intrinsic to construct the 'fatpointer' for a vcall, which could be put in a deref operator.

eg, as_trait_object<Type,Trait>(data:&Type, vtable:&VTable<Type,Trait>)->&Trait /* safe because it knows where the table & data are compatible */

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

@MicahChalmer
Copy link
Author

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.

@MicahChalmer
Copy link
Author

@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.)

@emberian
Copy link
Member

emberian commented Apr 6, 2014

I do not think being able to change vtables at runtime is a good idea. We
can get nice optimizations when the vtable ptr is pointsToConstantMemory.

On Sun, Apr 6, 2014 at 5:16 PM, Micah Chalmer notifications@github.comwrote:

@dobkeratops https://github.com/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#11,
which is quite interesting.)


Reply to this email directly or view it on GitHubhttps://github.com//pull/9#issuecomment-39681165
.

http://octayn.net/

@MicahChalmer
Copy link
Author

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.

@dobkeratops
Copy link

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.

We can get nice optimizations when the vtable ptr is pointsToConstantMemory.

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

@brson
Copy link
Contributor

brson commented May 7, 2014

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.

@ben0x539
Copy link

I really like how orthogonal this proposal is. (I'd be happy if we could find another word than fat for the user interface for this, though)

@gereeter gereeter mentioned this pull request Sep 1, 2014
@nrc nrc self-assigned this Sep 4, 2014
@brson brson assigned pnkfelix and unassigned nrc Sep 9, 2014
@nrc
Copy link
Member

nrc commented Sep 11, 2014

@MicahChalmer or @pnkfelix could you show how https://gist.github.com/jdm/9900569 would be encoded under this proposal please?

@pnkfelix
Copy link
Member

// 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() {
Copy link
Member

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

@MicahChalmer
Copy link
Author

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.

@rpjohnst rpjohnst mentioned this pull request Sep 22, 2014
@pnkfelix
Copy link
Member

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.

@pnkfelix pnkfelix closed this Sep 25, 2014
withoutboats pushed a commit to withoutboats/rfcs that referenced this pull request Jan 15, 2017
fixed 2 typos in documention for Task
dhardy pushed a commit to dhardy/rfcs that referenced this pull request Jul 5, 2017
oli-obk pushed a commit that referenced this pull request Mar 11, 2024
Update from recent discussions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants