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

fix universe map in ifcx.instantiate_canonical_* #99814

Merged
merged 2 commits into from
Nov 30, 2022

Conversation

aliemjay
Copy link
Member

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!

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
Copy link
Collaborator

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 27, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 27, 2022
@aliemjay
Copy link
Member Author

r? @rust-lang/types

@aliemjay aliemjay marked this pull request as ready for review July 27, 2022 15:58
@jackh726
Copy link
Member

jackh726 commented Aug 3, 2022

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

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?

@jackh726
Copy link
Member

jackh726 commented Aug 7, 2022

I think this looks fine, but I'd like @nikomatsakis's eyes on this

@nikomatsakis
Copy link
Contributor

I'm not sure what a test would look like for this, but I see the logic in the proposed behavior.

@jackh726
Copy link
Member

@aliemjay any idea if you can come up with a test for this?

@aliemjay
Copy link
Member Author

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

@jackh726
Copy link
Member

Could this be done with rust-lang/rfcs#3216?

@apiraino
Copy link
Contributor

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 ready, thanks!

@rustbot author

@rustbot rustbot 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 Nov 29, 2022
@jackh726
Copy link
Member

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)

@bors
Copy link
Contributor

bors commented Nov 30, 2022

📌 Commit 70200ac has been approved by jackh726

It is now in the queue for this repository.

@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 Nov 30, 2022
@bors
Copy link
Contributor

bors commented Nov 30, 2022

⌛ Testing commit 70200ac with merge 90711a8...

@bors
Copy link
Contributor

bors commented Nov 30, 2022

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing 90711a8 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 30, 2022
@bors bors merged commit 90711a8 into rust-lang:master Nov 30, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 30, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (90711a8): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This 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.

Cycles

This benchmark run did not return any relevant results for this metric.

@aliemjay aliemjay deleted the patch-2 branch December 1, 2022 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants