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

Object types should use adjustments, include mutability #5762

Closed
nikomatsakis opened this issue Apr 6, 2013 · 8 comments
Closed

Object types should use adjustments, include mutability #5762

nikomatsakis opened this issue Apr 6, 2013 · 8 comments
Labels
A-codegen Area: Code generation

Comments

@nikomatsakis
Copy link
Contributor

Object types are currently quite hacky in method lookup and in the compiler. They don't include mutability information, for example, and they are not transformed like other pointer types during method lookup etc. This should be rectified so that they are basically treated like ty_evec. There are various FIXMEs for this (or there will be in the code that lands to fix #5656).

cc #5527

@nikomatsakis
Copy link
Contributor Author

As part of this work, we should be using adjustments to deal with borrowing objects and so forth. From a recent IRC conversation with @Sodel-the-Vociferous:

[17:26:42] <nmatsakis> anyway, so yeah, the idea would be to (1) add a new kind of adjustment for objects
[17:26:54] <nmatsakis> (2) modify code-generation (what we call `trans`) to deal with that
[17:27:10] <nmatsakis> (3) modify the method code to borrow in search_for_autosliced_method()
[17:27:24] <nmatsakis> and (4) modify the method code to handle the @self etc coercions
[17:27:34] <nmatsakis> if that all works out, then the end result is that whenever we call a method that expects &self

A simple test case (which works today, but not via the intended paths) would be:

trait MyTrait {
    fn get_by_ref(&self) -> uint;
}

struct MyStruct {
    f: uint
}

impl MyTrait for MyStruct {
    fn get_by_ref(&self) -> uint {
        self.f
    }
}

fn main() {
    let s: @MyTrait = (@MyStruct {f: 22}) as @MyTrait;
    assert!(s.get_by_ref() == 22);
}

@nikomatsakis
Copy link
Contributor Author

Modified title to be more pithy.

@Sodel-the-Vociferous
Copy link
Contributor

Is @pcwalton's old pull request #5597 relevant to coercing ~/@traits to &Traits? From the look of those commits, this could be more involved than I had hoped.

Would it be worthwhile to get that patch set working with the latest incoming, and building atop that? Though, as I'm still getting acquainted with the compiler's innards, that task seems a bit daunting.

Also, note that my above commits have borked something in compile-time checking of objects' methods. I'll try to set aside some time to debug that sometime in the next few days.

@nikomatsakis
Copy link
Contributor Author

@Sodel-the-Vociferous that PR is not all that relevant, actually, it addresses a different issue.

@nikomatsakis
Copy link
Contributor Author

@Sodel-the-Vociferous I'll try to find some time to checkout your patch and build it...

@Sodel-the-Vociferous
Copy link
Contributor

@nikomatsakis Ah, good. On I go debugging, then!

@graydon
Copy link
Contributor

graydon commented Jul 18, 2013

FIXMEs in question are still alive, this looks legit still.

@nikomatsakis
Copy link
Contributor Author

Status update: I got a version of this building, bsaed on Sodel-the-V's branch, but encountered a problem with how method lookup is defined. I embarked to rewrite method lookup to fix this problem but haven't finished that work. The problem is a quesiton of how we prioritize methods: I believe we have to prioritize inherent methods over trait methods. Bonus is that I would expect this to improve compilation time.

@bors bors closed this as completed in b285f1e Aug 12, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 11, 2020
…anishearth

Stable sort primitive

changelog: Implements rust-lang#5762
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants