Registry Mirror
Skip to content

Conversation

@nikomatsakis

Copy link
Copy Markdown
Contributor

Fixes #32278.

r? @eddyb

@nikomatsakis

Copy link
Copy Markdown
Contributor Author

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

@nikomatsakis

Copy link
Copy Markdown
Contributor Author

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

@nikomatsakis

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Gah, fails to build.

@nikomatsakis

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

Comment thread src/librustc_typeck/check/coercion.rs Outdated

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor Author

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

Comment thread src/librustc_typeck/check/coercion.rs Outdated

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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.


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
Copy Markdown
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
Copy Markdown
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

eddyb commented Mar 18, 2016

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Mar 18, 2016

Copy link
Copy Markdown
Contributor

📌 Commit 43aed96 has been approved by eddyb

@bors

bors commented Mar 19, 2016

Copy link
Copy Markdown
Contributor

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

@bors

bors commented Mar 19, 2016

Copy link
Copy Markdown
Contributor

💔 Test failed - auto-mac-32-opt

@alexcrichton

Copy link
Copy Markdown
Member

@bors: retry

On Sat, Mar 19, 2016 at 9:39 AM, bors notifications@github.com 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
Copy Markdown
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
Copy Markdown
Member

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

@bors

bors commented Mar 20, 2016

Copy link
Copy Markdown
Contributor

⌛ 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