-
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
Refactor DebruijnIndex to be 0-based #50475
Conversation
r? @estebank (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
@@ -1866,22 +1866,22 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { | |||
trait_ref: &hir::PolyTraitRef, | |||
modifier: hir::TraitBoundModifier, | |||
) { | |||
self.binder_depth += 1; | |||
self.outer_index.shifted_in(1); |
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.
Probably this should be shift_in
} | ||
|
||
fn visit_lifetime(&mut self, lifetime_ref: &hir::Lifetime) { | ||
if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.id) { | ||
match lifetime { | ||
Region::LateBound(debruijn, _, _) | Region::LateBoundAnon(debruijn, _) | ||
if debruijn.index < self.binder_depth => | ||
if debruijn.index < self.outer_index.index => |
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.
Can we make this debruijn < self.outer_index
?
Another request: Add the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #50200) made this pull request unmergeable. Please resolve the merge conflicts. |
5e560d5
to
ee5db9f
Compare
src/test/ui/issue-26638.stderr
Outdated
| | ||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments | ||
= help: consider giving it an explicit bounded or 'static lifetime | ||
|
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.
@nikomatsakis what's going wrong here? error checking is skipped for this function.
This comment has been minimized.
This comment has been minimized.
{ | ||
self.have_bound_regions = true; | ||
} | ||
_ => { | ||
self.lifetimes | ||
.insert(lifetime.from_depth(self.binder_depth)); |
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, I suspect this is where the bug is coming from. The binder_depth
in the "before code" is equal to index
, but (if you look at the definition of from_depth
) you will see that used to be computing adjusting by depth - 1
, basically.
I think the way I would want to compute the "depth" by giving two debruijn indices. In particular, we might do something like self.outer_index.depth_from(INNERMOST)
, where we have:
impl DebruijnIndex {
/// Assuming that these two debruijn indices are both in scope,
/// returns the number of binding levels *between* them.
/// This is often used if `outer` represents some starting binding
/// and `self` represents the current innermost binding; it would then
/// compute the number of bindings passed over so far.
///
/// As the name suggests, `outer` is assumed to be the
/// outermost depth of the two.
fn depth_from(self, outer: DebruijnIndex) -> usize {
assert!(self.index >= other.index); // or return the absolute value
self.index - other.index
}
}
☔ The latest upstream changes (presumably #48523) made this pull request unmergeable. Please resolve the merge conflicts. |
src/librustc/ty/sty.rs
Outdated
@@ -990,7 +990,7 @@ impl<'a, 'gcx, 'tcx> ParamTy { | |||
pub struct DebruijnIndex { | |||
/// We maintain the invariant that this is never 0. So 1 indicates | |||
/// the innermost binder. To ensure this, create with `DebruijnIndex::new`. |
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 comment is wrong now, right? Also, why make the field private, especially now that there's no invariant?
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.
Comments repairing is listed in my TODO, it'll be fixed once the key change works.
the field is private: new impl DebruijnIndex
provide enough pub-methods to manipulate it.
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. Maybe the external interface should use usize
? Not sure if super relevant.
47e4120
to
8dbe74b
Compare
This comment has been minimized.
This comment has been minimized.
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
@bors r+ |
📌 Commit 783fe4f has been approved by |
@bors r- |
@bors r+ |
📌 Commit 783fe4f has been approved by |
Refactor DebruijnIndex to be 0-based Fixes #49813
☀️ Test successful - status-appveyor, status-travis |
Fixes #49813