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

Replace CanonicalVar with DebruijnIndex #52984

Merged
merged 2 commits into from
Oct 21, 2018
Merged

Replace CanonicalVar with DebruijnIndex #52984

merged 2 commits into from
Oct 21, 2018

Conversation

fabric-and-ink
Copy link
Contributor

Close #49887

@rust-highfive
Copy link
Collaborator

r? @michaelwoerister

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 2, 2018
@michaelwoerister
Copy link
Member

Thanks for the PR, @fabric-and-ink! This looks like something that @nikomatsakis will want to review.

r? @nikomatsakis

@fabric-and-ink
Copy link
Contributor Author

fabric-and-ink commented Aug 2, 2018

The test suite will fail with a few errors that I don't understand.

Edit: Well, locally they failed... there were a few errors in the debuginfo suite... strange.

@varkor

This comment has been minimized.

@fabric-and-ink
Copy link
Contributor Author

fabric-and-ink commented Aug 2, 2018

I don't follow... CanonicalVar is being removed.

@varkor
Copy link
Member

varkor commented Aug 2, 2018

Sorry, I was thinking of CanonicalVarValues along with CanonicalVar. This looks good to me.

@fabric-and-ink
Copy link
Contributor Author

Ok. @nikomatsakis probably has a plan about CanonicalVarValues et.al.

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below for some thoughts. Trying to decide whether to merge as is or not.

@@ -385,7 +385,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
// direct linear search of `var_values`.
if let Some(idx) = var_values.iter().position(|&k| k == kind) {
// `kind` is already present in `var_values`.
CanonicalVar::new(idx)
DebruijnIndex::new(idx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this doesn't seem right. To really do this properly, we have to track the number of binders and adjust the debruijn index accordingly.

So, for example, if we are canonicalizing something like this:

for<'a> fn(&'a _)

then there is one binder in scope (from the fn) and hence I would expect the debruijn index to be adusted.

OTOH, I suppose that — at present — these canonical variables effectively occupy a "separate universe" from late-bound regions and things, and hence it doesn't make sense to adjust for the number of binders in scope. I think that's why this code all works fine.

Hmm, so maybe the PR is right "as is", at least as a stepping stone to the final intended setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Let me know when you have made a decision. I suppose a gradual but not strictly correct approach wouldn't be too bad...

For a correct solution I would probably need a bit of mentoring, since I am not sure if I understand the problem completely.

@nikomatsakis
Copy link
Contributor

I had a brief discussion with @scalexm today and we got to thinking about how best to integrate this stuff. Our thought was that we should probably try to "go with the flow" --

  • Use debruijn indices to represent "binding levels" and not individual variables, as the compiler already does
  • Introduce some kind of TyBound(DebruijnIndex, BoundTyIndex) that represents a "bound type"
    • It would use the debrujin index to select binding level, and the usize to distinguish different types at that same level

Canonical variables would thus change from TyCanonical to TyBound -- the CanonicalVar would change to BoundTyIndex. The idea would be that canonical things are things bound at a particular binding level.

@fabric-and-ink
Copy link
Contributor Author

Ok!

@bors
Copy link
Contributor

bors commented Aug 22, 2018

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

@pietroalbini pietroalbini 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 Aug 27, 2018
@TimNN
Copy link
Contributor

TimNN commented Sep 4, 2018

Ping from triage @fabric-and-ink: What are your plans for this PR? It looks like some change have been requested and this PR needs a rebase.

@fabric-and-ink
Copy link
Contributor Author

Didn't forget about it. There have been some holidays and lots of other stuff. I will continue to work on it hopefully next weekend.

@fabric-and-ink fabric-and-ink changed the title Replace CanonicalVar with DebruijnIndex WIP: Replace CanonicalVar with DebruijnIndex Sep 8, 2018
@fabric-and-ink
Copy link
Contributor Author

fabric-and-ink commented Sep 8, 2018

@nikomatsakis You mentioned that I should rename CanonicalVar to BoundTyIndex. There are several closely related types to CanonicalVar:

  • CanonicalVarInfo and CanonicalVarInfos
  • CanonicalVarKind
  • CanonicalVarValues
  • SmallCanonicalVarValues

I would suggest to rename them to BoundTy.... What do you think?

Edit: Talked to Niko, will do that.

@bors
Copy link
Contributor

bors commented Sep 26, 2018

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

@fabric-and-ink
Copy link
Contributor Author

fabric-and-ink commented Sep 30, 2018

I replaced CanonicalTy(...) with BoundTy(BoundTy) where BoundTy { level: DebruijnIndex, var: BoundTyIndex }. Since the BoundTyIndex is calculated here (called from here) this calculation now has to produce a DebruijnIndex along with a BoundTyIndex. How would I determine its value in this function? Am I heading in the right direction?

@bors
Copy link
Contributor

bors commented Oct 1, 2018

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

@nikomatsakis
Copy link
Contributor

@fabric-and-ink I think this is probably in the right direction but I've been kind of busy with other things. I think I'm going to hand off to @scalexm

r? @scalexm

@rust-highfive rust-highfive assigned scalexm and unassigned nikomatsakis Oct 2, 2018
@scalexm
Copy link
Member

scalexm commented Oct 9, 2018

@fabric-and-ink I think we can start with the assumption that types live in a different universe than lifetimes -- as @nikomatsakis wrote in a previous comment -- and since we don't support binding over types yet, you can just use 0 for the DebruijnIndex.

@fabric-and-ink
Copy link
Contributor Author

fabric-and-ink commented Oct 14, 2018

@scalexm I changed CanonicalTy to BoundTy and adapted fn canonical_var(...) accordingly. Changes in this area seem to be very far-reaching and I am not sure where to stop. (And I need to catch up to upstream regularly.)

@fabric-and-ink fabric-and-ink changed the title WIP: Replace CanonicalVar with DebruijnIndex Replace CanonicalVar with DebruijnIndex Oct 14, 2018
@bors
Copy link
Contributor

bors commented Oct 15, 2018

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

Copy link
Member

@scalexm scalexm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabric-and-ink This seems good, I just find it weird that we use BoundTyInfo / BoundTyKind to describe something that could be a type or a region.

Last thing, could you add some assertions like debug_assert_eq!(ty::INNERMOST, b.level) everywhere a BoundTy is effectively used? So that it'll be harder to forget about changing the logic when we move to non-zero binding levels.

@fabric-and-ink
Copy link
Contributor Author

fabric-and-ink commented Oct 16, 2018

@scalexm Your right, I didn't think of that. Do you have a suggestion for a better name? Should I revert it to the old name?

@scalexm
Copy link
Member

scalexm commented Oct 16, 2018

@fabric-and-ink Yes I'd say just change the name for things that only relate to types. I don't think that leaving some things named Canonical... is a problem, especially if they are defined in the canonical module :)

@fabric-and-ink
Copy link
Contributor Author

Ok :)

@fabric-and-ink
Copy link
Contributor Author

fabric-and-ink commented Oct 20, 2018

@scalexm I updated my PR. Please have a look and let me know if something is missing. 🙂 (I left out the renaming of the bitflag. Wasn't sure about that.)

@scalexm
Copy link
Member

scalexm commented Oct 21, 2018

@fabric-and-ink Ok it seems good enough like that. We’ll eventually get rid of ReCanonical as well, so I guess we’ll rename the bitflag at that moment then.

@scalexm
Copy link
Member

scalexm commented Oct 21, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Oct 21, 2018

📌 Commit 2f41c0d has been approved by scalexm

@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 Oct 21, 2018
@bors
Copy link
Contributor

bors commented Oct 21, 2018

⌛ Testing commit 2f41c0d with merge 0e2f912...

bors added a commit that referenced this pull request Oct 21, 2018
Replace CanonicalVar with DebruijnIndex

Close #49887
@bors
Copy link
Contributor

bors commented Oct 21, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: scalexm
Pushing 0e2f912 to master...

@bors bors merged commit 2f41c0d into rust-lang:master Oct 21, 2018
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.

9 participants