-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
rustc: simpler ParameterEnvironment and free regions. #41914
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
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.
OK, this looks pretty nice. I left two small nits.
src/librustc/middle/region.rs
Outdated
body | ||
}) | ||
.unwrap_or_else(|| { | ||
let root = tcx.hir.as_local_node_id(fr.scope).unwrap(); |
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 can't really follow what's going on here; maybe add a comment or two for what kinds of rust code falls into which case here?
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 explained on root_parent
but do note this is not the final version of that function.
Let me know on the final functions where it seems unclear.
@@ -213,6 +215,7 @@ pub struct RegionVarBindings<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { | |||
// record the fact that `'a <= 'b` is implied by the fn signature, | |||
// and then ignore the constraint when solving equations. This is | |||
// a bit of a hack but seems to work. | |||
early_bound_givens: RefCell<FxHashSet<(ty::EarlyBoundRegion, ty::RegionVid)>>, |
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.
maybe combine these by changing the type to RefCell<FxHashSet<(ty::Region<'tcx>, ty::RegionVid)>>
, where the region is either an early-bound or free?
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 was wondering if that would be more expensive but I doubt it now. Will do.
I see that the |
|
src/librustc/middle/region.rs
Outdated
} | ||
_ => fr.scope | ||
}; | ||
assert_eq!(param_owner, fr.scope); |
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.
Why can't you use fr.scope
directly?
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 wanted to have no regressions from lifetime parameters not defined on the scope leaking into e.g. the signature of a closure.
I changed that to a pointer because there were various contexts that needed to be able to access the data without having enough context to get a region-maps (note that there is now more than one region-maps). But passing by value is probably even better. (Also, in the meantime, we've started to intern Regions, so I don't think that the size matters so much anymore anyway.) |
|
||
let param_owner_id = tcx.hir.as_local_node_id(param_owner).unwrap(); | ||
let body_id = tcx.hir.maybe_body_owned_by(param_owner_id).unwrap_or_else(|| { | ||
// The lifetime was defined on node that doesn't own a body, |
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.
👍 nice comment
@bors r+ |
📌 Commit 788e70e has been approved by |
☔ The latest upstream changes (presumably #41965) made this pull request unmergeable. Please resolve the merge conflicts. |
@bors r=nikomatsakis |
📌 Commit 6da4123 has been approved by |
@bors p=1000 (separate for perf. I wish we had a guaranteed to keep PRs out of rollups) |
rustc: simpler ParameterEnvironment and free regions. The commits describe the slow transformation but the highlights are: * `ReEarlyBound` is considered free, with a scope based on the item that defined the lifetime parameter, and the root body of the `RegionMaps` in use, removing the need for `free_substs` * `liberate_late_bound_regions` and `implicit_region_bound` moved to typeck * `CodeExtent` not interned at all now - ideally it would be 2 `u32` but it's small anyway Future work building up on this could include: * `ParameterEnvironment` becoming just the result of `predicates_of` * interning makes my "parent chain" scheme unnecessary * `implicit_region_bound` could be retrieved from `RegionMaps` * renaming `CodeExtent` to `Scope` * generalizing "call site" to "use site" or something better to include constants * renaming `RegionMaps` to `ScopeTree` and its API to talk about "parents" explicitly
☀️ Test successful - status-appveyor, status-travis |
The commits describe the slow transformation but the highlights are:
ReEarlyBound
is considered free, with a scope based on the item that defined the lifetime parameter, and the root body of theRegionMaps
in use, removing the need forfree_substs
liberate_late_bound_regions
andimplicit_region_bound
moved to typeckCodeExtent
not interned at all now - ideally it would be 2u32
but it's small anywayFuture work building up on this could include:
ParameterEnvironment
becoming just the result ofpredicates_of
implicit_region_bound
could be retrieved fromRegionMaps
CodeExtent
toScope
RegionMaps
toScopeTree
and its API to talk about "parents" explicitly