-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
fix universe map in ifcx.instantiate_canonical_* #99814
Conversation
Previously, `infcx.instantiate_canonical_*` maps the root universe in `canonical` into `ty::UniverseIndex::Root`, I think because it assumes it works with a fresh `infcx` but this is not true for the use cases in mir typeck. Now the root universe is mapped into `infcx.universe()`. I catched this accidentally while reviewing the code. I'm not sure if this is the right fix or if it is really a bug!
(rust-highfive has picked a reviewer for you, use r? to override) |
r? @rust-lang/types |
Any chance there's some test we can add? |
@@ -63,8 +63,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { | |||
// in them, so this code has no effect, but it is looking | |||
// forward to the day when we *do* want to carry universes | |||
// through into queries. | |||
let universes: IndexVec<ty::UniverseIndex, _> = std::iter::once(ty::UniverseIndex::ROOT) |
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.
Currently reading about Universes/Placeholders and am curious, why can we do that? Why can't we encounter canonicalized variables with UniverseIndex::Root
inside instantiate_canonical_vars
?
I think this looks fine, but I'd like @nikomatsakis's eyes on this |
I'm not sure what a test would look like for this, but I see the logic in the proposed behavior. |
@aliemjay any idea if you can come up with a test for this? |
@jackh726 I don't think a test is possible because the only place this method is used on a non-fresh InferCtxt is when instantiating UserTypeAnnotation in MIR typeck, but type annotations are currently only used in root universe AFAIK. For example if we're type-checking closures in a different way (using universes), the test would be like: fn test() { // U0
for<'a> |s: &'a str| { //U1
let _: &'_ str = s; // `'_` lives in a higher universe
};
} |
Could this be done with rust-lang/rfcs#3216? |
hello, checking progress. What's the current status? Based on the previous comment, I'd switch to waiting for a feedback from @aliemjay (hope I am reading the status correctly). Feel free to request a review with @rustbot author |
Going to go ahead and approve this. The new code looks more right and writing a test for this is hard. @bors r+ rollup=never (no rollup so it's easier to bisect if it is indeed wrong somehow) |
☀️ Test successful - checks-actions |
Finished benchmarking commit (90711a8): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. |
Previously,
infcx.instantiate_canonical_*
maps the root universe incanonical
intoty::UniverseIndex::Root
, I think because it assumes it works with a freshinfcx
but this is not true for the use cases in mir typeck. Now the root universe is mapped intoinfcx.universe()
.I catched this accidentally while reviewing the code. I'm not sure if this is the right fix or if it is really a bug!