-
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
Replace CanonicalVar with DebruijnIndex #52984
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Thanks for the PR, @fabric-and-ink! This looks like something that @nikomatsakis will want to review. |
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. |
This comment has been minimized.
This comment has been minimized.
I don't follow... |
Sorry, I was thinking of |
Ok. @nikomatsakis probably has a plan about |
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.
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) |
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, 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.
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. 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.
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" --
Canonical variables would thus change from |
Ok! |
☔ The latest upstream changes (presumably #53581) made this pull request unmergeable. Please resolve the merge conflicts. |
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. |
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. |
@nikomatsakis You mentioned that I should rename
I would suggest to rename them to Edit: Talked to Niko, will do that. |
☔ The latest upstream changes (presumably #54453) made this pull request unmergeable. Please resolve the merge conflicts. |
I replaced |
☔ The latest upstream changes (presumably #54711) made this pull request unmergeable. Please resolve the merge conflicts. |
@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 |
@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 |
@scalexm I changed |
☔ The latest upstream changes (presumably #54858) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
@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.
@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? |
@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 |
Ok :) |
@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.) |
@fabric-and-ink Ok it seems good enough like that. We’ll eventually get rid of |
@bors r+ |
📌 Commit 2f41c0d has been approved by |
Replace CanonicalVar with DebruijnIndex Close #49887
☀️ Test successful - status-appveyor, status-travis |
Close #49887