-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
[nll] teach SCC about 'static
#53327
Conversation
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
None | ||
}; | ||
|
||
let normal_successors = self.graph.outgoing_regions(node).collect::<Vec<_>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to .collect()
here to work around a lifetime issue.
|
||
impl<'s, 'graph> graph::GraphSuccessors<'graph> for AugmentedRegionGraph<'s> { | ||
type Item = RegionVid; | ||
type Iter = Box<dyn Iterator<Item = Self::Item>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't figure out how to name this type so I just boxed it. Should I hand roll a custom Iterator
instead?
cc #53178 |
@bors try |
⌛ Trying commit 6e918df9c2afcdd4f71c364c27a0e7d5e3710279 with merge ed285b7a46c0949465c4c1af1d968de39cc1dbbc... |
☀️ Test successful - status-travis |
@rust-timer build ed285b7a46c0949465c4c1af1d968de39cc1dbbc |
Success: Queued ed285b7a46c0949465c4c1af1d968de39cc1dbbc with parent 5050349, comparison URL. |
(FYI perf is ready) |
It seems like the big win here is max-rss:
though instructions win too
|
f8be3e8
to
c2ca559
Compare
OK, I pushed some commits fixing the nits that @wesleywiser was hitting |
@wesleywiser take a look at the changes I pushed; it seems like the only thing holding this up from landing is possible changes to the error messages? Can you run |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
let static_successors: Range<RegionVid> = if node == self.static_region { | ||
// `'static: 'a` for all regions `'a` -- so add an edge | ||
// from `'static` to every other region. | ||
0.into() .. self.graph.constraint_graph.first_constraints.len().into() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.into()
could just be self.static_region
LL | f(x) | ||
| ^^^^ `x` escapes the function body here | ||
LL | let f: fn(_) -> _ = foo; | ||
| ^^^ cast requires that `'a` must outlive `'static` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, these errors do look less good, but they are also not wrong; I certainly see how they arise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a tricky case, but I think if we provide the suggested output in the other comment it would be slightly more understandable. Something closer to the ideal output in my mind would be:
error: unsatisfied lifetime constraints
--> $DIR/mir_check_cast_reify.rs:46:25
|
LL | fn foo<'a>(x: &'a u32) -> &'a u32
| --------------------------------- `foo` is not `'static` due to this definition
...
LL | fn bar<'a>(x: &'a u32) -> &'static u32 {
| -- --- -------- `foo` needs to be `'static` due to this return type
| | |
| | `x` is `'a` due to this
| lifetime `'a` defined here
...
LL | let f: fn(_) -> _ = foo;
| ^^^ this is `'a` but it must outlive `'static`
| -- lifetime `'a` defined here | ||
LL | //~^ ERROR unsatisfied lifetime constraints | ||
LL | x | ||
| ^ cast requires that `'a` must outlive `'static` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this case I sort of prefer the error =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I suppose it's mostly the crazy span; I think we are labeling the wrong point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"cast requires..." is not a great label, but the spans are correct in my mind, although I would try and detect this kind of case and point at the return type:
error: unsatisfied lifetime constraints
--> $DIR/mir_check_cast_unsize.rs:19:5
|
LL | fn bar<'a>(x: &'a u32) -> &'static dyn Debug {
| -- --- -------- `x` must be `'static` due to this return type
| | |
| | `x` is `'a` due to this type definition
| lifetime `'a` defined here
LL | x
| ^ this is `'a` but it must outlive `'static`
cc @matthewjasper @davidtwco @estebank — expanding the definition of SCC here is messing with our error messages a bit. But then again these have always been heuristics. I am sort of inclined to land this PR "as is" and try to address in follow-up changes to the heuristics -- but I'm curious what y'all think. I'm not really sure (in any case) what those changes ought to be. The problem here remains that it's hard to separate out the outlives edges that users want to be shown; using the SCC rules seemed to do a decent job of screening out a lot of "junk" at the bottom of the graph, but it's imperfect, and there ought to be a better basis somehow. |
All of the cases where we've changed messages are for conflicting files, I'm not sure if there will be any changes after a rebase. |
I'll rebase tonight and we can see if that fixes the issues or not. |
@nikomatsakis I agree, lets merge and file tickets. From what I'm seeing there are two cases, and one is a special case of the other, which means that improving the more general case would make both better, and we can take our time to fix the latter. |
Actually, that's wrong. |
It is the
|
Ok, I was totally off =) the region is not early-bound here but rather late-bound, and this is the code path that is returning invalid data: rust/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs Lines 108 to 112 in 35a5541
|
PS @varkor I'm sorry I cited you, your impeccable refactorings are definitely not the problem =) |
OK, so, I'm not sure the best fix, but the problem has to do with this code: rust/src/librustc_mir/borrow_check/nll/universal_regions.rs Lines 701 to 721 in 35a5541
Here we are walking over the hir-id for each late-bound region on the function. We are particularly interested in late-bound regions that are declared but not used -- in fact, we only care here about late-bound regions that have been give names (this code is needed because people may refer to those names elsewhere, and we used to get ICEs if those names were not used somewhere in the function). The problem is that the late-bound region here is anonymous; somehow the node-id we get for it winds up mapping to |
Thanks for your help @nikomatsakis! I'll rebase tonight and fix the merge conflicts with the tests. |
@bors p=1 RC milestone |
1e55c80
to
b1211e8
Compare
Rebased |
This is ready for review. |
@bors r+ It would be nice to improve the heuristics, though. |
📌 Commit b1211e8 has been approved by |
[nll] teach SCC about `'static` r? @nikomatsakis I think this is right? I am seeing better performance on the `html5ever` benchmark but I'd like a perf run to quantify the exact speedup. There's a few ui tests failing due to changes in the error messages. The main issue seems to be that returns aren't being detected correctly? `mir_check_cast_unsize.rs` before: ``` error: unsatisfied lifetime constraints --> mir_check_cast_unsize.rs:17:46 | 17 | fn bar<'a>(x: &'a u32) -> &'static dyn Debug { | ________--____________________________________^ | | | | | lifetime `'a` defined here 18 | | //~^ ERROR unsatisfied lifetime constraints 19 | | x 20 | | //~^ WARNING not reporting region error due to nll 21 | | } | |_^ return requires that `'a` must outlive `'static` ``` `mir_check_cast_unsize.rs` after: ``` error: unsatisfied lifetime constraints --> mir_check_cast_unsize.rs:19:5 | 17 | fn bar<'a>(x: &'a u32) -> &'static dyn Debug { | -- lifetime `'a` defined here 18 | //~^ ERROR unsatisfied lifetime constraints 19 | x | ^ cast requires that `'a` must outlive `'static` ```
☀️ Test successful - status-appveyor, status-travis |
r? @nikomatsakis
I think this is right? I am seeing better performance on the
html5ever
benchmark but I'd like a perf run to quantify the exact speedup. There's a few ui tests failing due to changes in the error messages. The main issue seems to be that returns aren't being detected correctly?mir_check_cast_unsize.rs
before:mir_check_cast_unsize.rs
after: