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

create fewer region variables in coercions #32306

Merged
merged 9 commits into from
Mar 20, 2016

Conversation

nikomatsakis
Copy link
Contributor

Fixes #32278.

r? @eddyb

@nikomatsakis
Copy link
Contributor Author

I am still running a final make check, but things were passing at one not so long ago point. :)

@nikomatsakis
Copy link
Contributor Author

Ah, I think I forgot some kind of regression test.

@nikomatsakis
Copy link
Contributor Author

Regression test: rust-lang-deprecated/rustc-benchmarks#3

Do you think it makes sense to add to run-pass? The full test takes 3 or 4 seconds to compile, and reduced ones don't seem that interesting.

@nikomatsakis
Copy link
Contributor Author

Gah, fails to build.

@nikomatsakis
Copy link
Contributor Author

Well, have to stop now, the error feels fixable. Somehow region inference isn't creating the required edges I think. The minimized test case is:

use std::rc::Rc;

#[derive(Clone)]
enum CachedMir<'mir> {
    Ref(&'mir String),
    Owned(Rc<String>),
}

impl<'mir> CachedMir<'mir> {
    fn get_ref<'a>(&'a self) -> &'a String {
        match *self {
            CachedMir::Ref(r) => r,
            CachedMir::Owned(ref rc) => &rc,
        }
    }
}

fn main() { }

which fails with an error:

/home/nmatsakis/tmp/foo.rs:13:42: 13:44 error: `rc` does not live long enough
/home/nmatsakis/tmp/foo.rs:13             CachedMir::Owned(ref rc) => &rc,
                                                                       ^~
/home/nmatsakis/tmp/foo.rs:10:44: 15:6 note: reference must be valid for the lifetime 'a as defined on the block at 10:43...
/home/nmatsakis/tmp/foo.rs:10     fn get_ref<'a>(&'a self) -> &'a String {
/home/nmatsakis/tmp/foo.rs:11         match *self {
/home/nmatsakis/tmp/foo.rs:12             CachedMir::Ref(r) => r,
/home/nmatsakis/tmp/foo.rs:13             CachedMir::Owned(ref rc) => &rc,
/home/nmatsakis/tmp/foo.rs:14         }
/home/nmatsakis/tmp/foo.rs:15     }
/home/nmatsakis/tmp/foo.rs:11:9: 14:10 note: ...but borrowed value is only valid for the match at 11:8
/home/nmatsakis/tmp/foo.rs:11         match *self {
/home/nmatsakis/tmp/foo.rs:12             CachedMir::Ref(r) => r,
/home/nmatsakis/tmp/foo.rs:13             CachedMir::Owned(ref rc) => &rc,
/home/nmatsakis/tmp/foo.rs:14         }
error: aborting due to previous error

@nikomatsakis
Copy link
Contributor Author

(Obviously the &rc isn't needed, but it ought to work.)

// want to use that target type region (`'b`) because --
// for the program to type-check -- it must be the
// smaller of the two.
let r = if self.use_lub {r_a} else {r_b}; // [2] above
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you still have to relate r_a and r_b in sub mode, e.g. &'a T coerced to &'b T in sub mode would only require that &'b T is a subtype of &'b T, but not that 'a outlives 'b.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eddyb

I believe you still have to relate r_a and r_b in sub mode, e.g. &'a T coerced to &'b T in sub mode would only require that &'b T is a subtype of &'b T, but not that 'a outlives 'b.

We discussed on IRC, but this is not the problem. TL;DR regionck adds the edge. I added more text to the comment to address exactly this point in 1f30fe0.

@nikomatsakis
Copy link
Contributor Author

OK, I think the problem is fixed now, and the compilation performance is still good.

ty, autoderefs, autoref);
Ok((ty, AdjustDerefRef(AutoDerefRef {
autoderefs: autoderefs,
autoref: autoref,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't trying to avoid noop reborrow coercions? I don't want the array of strings to have any coercions at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eddyb it's not obvious when we can avoid those -- I guess if r_borrow == r_a and autoderefs == 1, you mean? I can add a test for that, why not.

instead, extract the target region out of the autoderef loop
the goal here is to minimize creating variables
The older code would sometimes swallow errors or fail to produce a
suggestion. The newer code does not. However, just printing everything
would produce a bunch of new and kind of annoying errors, so continue
to swallow `T: 'a` errors so long as there are other things to show.
@nikomatsakis
Copy link
Contributor Author

@eddyb ok so we now should have the suggestions again and it is eliding no-op coercions. make check is still running locally but I wouldn't expect any problems.

@@ -22,7 +22,7 @@ fn bar1<'a>(x: &Bar) -> (&'a i32, &'a i32, &'a i32) {
}

fn bar2<'a, 'b, 'c>(x: &Bar<'a, 'b, 'c>) -> (&'a i32, &'a i32, &'a i32) {
//~^ HELP: consider using an explicit lifetime parameter as shown: fn bar2<'a, 'b, 'c>(x: &'a Bar<'a, 'b, 'c>) -> (&'a i32, &'a i32, &'a i32)
//~^ HELP: consider using an explicit lifetime parameter as shown: fn bar2<'a, 'c>(x: &'a Bar<'a, 'a, 'c>) -> (&'a i32, &'a i32, &'a i32)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh. I have no idea why this suggestion changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I think I get why. It's not wrong in any case.

@eddyb
Copy link
Member

eddyb commented Mar 18, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Mar 18, 2016

📌 Commit 43aed96 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Mar 19, 2016

⌛ Testing commit 43aed96 with merge 76d42f5...

@bors
Copy link
Contributor

bors commented Mar 19, 2016

💔 Test failed - auto-mac-32-opt

@alexcrichton
Copy link
Member

@bors: retry

On Sat, Mar 19, 2016 at 9:39 AM, bors [email protected] wrote:

[image: 💔] Test failed - auto-mac-32-opt
http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/8471


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#32306 (comment)

@nikomatsakis
Copy link
Contributor Author

@alexcrichton I was just going to ask if these timeouts are a thing...never seen one before? I ... highly doubt this patch made things any slower.

@alexcrichton
Copy link
Member

Yeah lldb timeouts on mac have been happening for quite some time

@bors
Copy link
Contributor

bors commented Mar 20, 2016

⌛ Testing commit 43aed96 with merge 78e8a00...

bors added a commit that referenced this pull request Mar 20, 2016
create fewer region variables in coercions

Fixes #32278.

r? @eddyb
@bors bors merged commit 43aed96 into rust-lang:master Mar 20, 2016
@nikomatsakis nikomatsakis deleted the issue-32278 branch March 30, 2016 16:15
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.

4 participants