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

procedural field values #7

Open
nikomatsakis opened this issue May 25, 2017 · 0 comments
Open

procedural field values #7

nikomatsakis opened this issue May 25, 2017 · 0 comments

Comments

@nikomatsakis
Copy link
Owner

Building on #4, if we permit field mappings to be more flexible than an offset, we could also permit custom code to execute. It's not exactly clear what form this should take.

One possibility -- the most flexible, but also most primitive -- would be something that returns a raw pointer to the field that the compiler can use. This would be unsafe code, because the user would have to guarantee the disjointedness requirements.

However, one could also imagine safe code -- we could use the same sort of borrowck rules to check for disjointedness. That would though be rather tricky in that we would want (I imagine) one set of rules that works for either & or &mut borrows.

A use case: In the GNOME mapping, we might want to be able to execute code for locating the "private" fields. Interestingly, this could be made to work in the case of GNOME without any unsafe code, but only if we support shared-only fields (#5). This is because all GNOME private fields would be shared-only. I imagine something like this:

trait GnomeClass {
    let f: u32; // private field
    let g: u32; // another private field
}

impl GnomeClass for GnomeType {
    let f: u32 = self.private().f;
    let g: u32 = self.private().g;
}

We would type-check this by checking, for each pair of fields, that if you do (effectively):

    let x: &GnomeType;
    let tmp0 = &x.private().f;
    let tmp1 = &x.private().g;
    use(tmp0, tmp1);

you don't get any borrowck errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant