Don't run resolve_vars_if_possible in normalize_erasing_regions#77616
Don't run resolve_vars_if_possible in normalize_erasing_regions#77616bors merged 1 commit intorust-lang:masterfrom
resolve_vars_if_possible in normalize_erasing_regions#77616Conversation
|
I know what it's for ( |
|
@lcnr said:
So possibly there are other call sites that also don't need to do this? |
nikomatsakis
left a comment
There was a problem hiding this comment.
Is the motivation here purely performance?
|
The performance doesn't hurt, but mostly I'm trying to understand why this is necessary in the first place. eddyb suggested that I add |
|
I believe that So I do think it is valuable to remove that afaict unnecessary step here. |
|
I think I put it in there mostly as a precaution, in case inference variables wound up in the output. I'm not sure if that can happen or not to be honest. |
|
In particular I don't think of it is as an invariant that normalization will yield a result free of inference variables-- do you think it is an invariant, @lcnr ? |
|
I don't expect the result to be free to inference variables, I expect the result to be free of My personal expectation is that this should be an invariant and believe that this is already the case, even if not documented rn. I have only recently familiarized myself with this code so I might be incorrect here though |
|
@lcnr "known" inference variables are indeed what I meant. I guess I don't generally expect that as an invariant from any particular function I imagine that sometimes we wind up substituting or returning things that may reference inference variables that not been fully "resolved" to their known types. I can believe that it's true that in this case that we maintain the invariant, but if so I don't feel like it was intentional (but maybe if I re-read the code I'll realize it has to be that way). |
|
☔ The latest upstream changes (presumably #78313) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels: |
|
@nikomatsakis would you mind adding a debug assert here for now so that if we do ever create known inference variables, we have a test case? |
|
@lcnr in other words, landing this PR but with a debug assert? I would be ok with that. |
NOTE: `needs_infer()` needs to come after ignoring generic parameters
Ok, I updated this to use a debug assert in both cases. |
| // It's unclear when `resolve_vars` would have an effect in a | ||
| // fresh `InferCtxt`. If this assert does trigger, it will give | ||
| // us a test case. | ||
| debug_assert_eq!(normalized_value, resolved_value); |
There was a problem hiding this comment.
I'm ok with this, but I'm not sure if this is what @lcnr meant -- I suspect they meant to move the resolve_vars_if_possible into the debug assert as well. I guess that I mildly prefer this in that I don't think it's generally meant to be an invariant that functions will return "fully resolved" types that don't contain inference variables.
There was a problem hiding this comment.
I think the approach by @jyn514 is good as it doesn't even change the behavior, so it most definity can't break anything
I would keep it as is, even if it isn't what i originally intended
- Only run for `QPath::Resolved` with `Some` self parameter (`<X as Y>::T`) - Fall back to the previous behavior if the path can't be resolved - Show what the behavior is if the type can't be normalized - Run `resolve_vars_if_possible` It's not clear whether or not this is necessary. See rust-lang#77616 for more context. - Add a test for cross-crate re-exports - Use the same code for both `hir::Ty` and `Ty`
|
This is ready for review. |
|
looks simple enough to me @bors r+ rollup |
|
📌 Commit 6354e85 has been approved by |
|
☀️ Test successful - checks-actions |
Neither @eddyb nor I could figure out what this was for. I changed it to
assert_eq!(normalized_value, infcx.resolve_vars_if_possible(&normalized_value));and it passed the UI test suite.Outdated, I figured out the issue -
needs_infer()needs to come after erasing the lifetimesStrangely, if I change it to
assert!(!normalized_value.needs_infer())it panics almost immediately:I'm not entirely sure what's going on - maybe the two disagree?
For context, this came up while reviewing #77467 (cc @lcnr).
Possibly this needs a crater run?
r? @nikomatsakis
cc @matthewjasper