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

Refactor DebruijnIndex to be 0-based #50475

Merged
merged 13 commits into from
May 29, 2018
Merged

Refactor DebruijnIndex to be 0-based #50475

merged 13 commits into from
May 29, 2018

Conversation

csmoe
Copy link
Member

@csmoe csmoe commented May 6, 2018

Fixes #49813

@rust-highfive
Copy link
Collaborator

r? @estebank

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive
Copy link
Collaborator

warning Warning warning

  • These commits modify submodules.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 6, 2018
@csmoe
Copy link
Member Author

csmoe commented May 6, 2018

r? @nikomatsakis

@rust-highfive

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);
Copy link
Contributor

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 =>
Copy link
Contributor

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?

@nikomatsakis
Copy link
Contributor

Another request: Add the #[must_use] attribute to shifted_in and shifted_out

@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@bors
Copy link
Contributor

bors commented May 10, 2018

☔ The latest upstream changes (presumably #50200) made this pull request unmergeable. Please resolve the merge conflicts.

@csmoe csmoe force-pushed the debr branch 2 times, most recently from 5e560d5 to ee5db9f Compare May 12, 2018 01:26
|
= 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

Copy link
Member Author

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.

@rust-highfive

This comment has been minimized.

{
self.have_bound_regions = true;
}
_ => {
self.lifetimes
.insert(lifetime.from_depth(self.binder_depth));
Copy link
Contributor

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
    }
}

@nikomatsakis nikomatsakis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 14, 2018
@bors
Copy link
Contributor

bors commented May 16, 2018

☔ The latest upstream changes (presumably #48523) made this pull request unmergeable. Please resolve the merge conflicts.

@@ -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`.
Copy link
Member

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?

Copy link
Member Author

@csmoe csmoe May 16, 2018

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.

Copy link
Member

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.

@csmoe csmoe force-pushed the debr branch 2 times, most recently from 47e4120 to 8dbe74b Compare May 18, 2018 04:31
@rust-highfive

This comment has been minimized.

nikomatsakis and others added 10 commits May 28, 2018 19:47
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>
@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 28, 2018

📌 Commit 783fe4f has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 28, 2018
@nikomatsakis
Copy link
Contributor

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 28, 2018
@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 29, 2018

📌 Commit 783fe4f has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 29, 2018
@bors
Copy link
Contributor

bors commented May 29, 2018

⌛ Testing commit 783fe4f with merge 5ae5361...

bors added a commit that referenced this pull request May 29, 2018
Refactor DebruijnIndex to be 0-based

Fixes #49813
@bors
Copy link
Contributor

bors commented May 29, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 5ae5361 to master...

@bors bors merged commit 783fe4f into rust-lang:master May 29, 2018
@csmoe csmoe deleted the debr branch July 13, 2018 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants