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

Work around ICE in diagnostics for local super-universes missing UniverseInfos #115384

Merged
merged 5 commits into from Aug 31, 2023

Conversation

lqd
Copy link
Member

@lqd lqd commented Aug 30, 2023

In issue #114907, canonicalization of liveness dropck-outlives results (IIUC) encounters universes absent from the original query. Some local universes are created for the mapping, but importantly, they won't have associated causes.

These missing UniverseInfos can be needed during diagnostics, causing the IndexMap: key not found ICE seen in the issue.

This PR works around this by returning the suboptimal catch-all cause, to avoid the ICE. It does results in suboptimal diagnostics right now, but it's better than an ICE.

r? @matthewjasper.

Let me know if there's a good easy-ish way to fix this, but I believe that for some of these erroneous cases and diagnostics, that inference/canonicalization/higher-ranked subtyping/etc may not behave exactly the same with the new trait solver? If that's the case then it'd probably be best to wait a bit more to do the correct fix.

Fixes #114907.

cc @aliemjay

Query canonicalization can create local super-universes without causes,
creating ICEs when accessed during diagnostics.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 30, 2023
Copy link
Contributor

@matthewjasper matthewjasper left a comment

Choose a reason for hiding this comment

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

So, there's a choice between doing this and instead making sure that universe_causes has all universes that get created. I think this approach makes more sense because it's pretty hard to track down every code path that might add universes.

// #114907 where this happens via liveness and dropck outlives results.
// Therefore, we return a default value in case that happens, which should at worst emit a
// suboptimal error, instead of the ICE.
self.universe_causes.get(&universe).cloned().unwrap_or_else(|| UniverseInfo::other())
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're going to do this here we should remove the places where we add UniverseInfo::other to universe causes.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've pushed a few commits to remove these. I think that's all of them.

@lqd
Copy link
Member Author

lqd commented Aug 31, 2023

I think this approach makes more sense because it's pretty hard to track down every code path that might add universes.

My thoughts exactly. Ensuring all these code paths have access to the correct universe cause map (possibly throughout queries), and that we couldn't regress diagnostics by mistake, should also mean having new APIs always requiring a cause when a universe is created. That seems like quite a complicated refactor for such rare ICEs, especially if we can independently improve these higher-ranked subtyping diagnostics in general, and if/when the new solver changes things in these situations.

…ical_with_fresh_inference_vars`

This was backfilling causes for the new universes that can be created by
the InferCtxt. We don't need to do that anymore: `other()` is the default when
there is no registered universe cause.
This was pre-filling causes for universes that could already exist in
the InferCtxt. We don't need to do that anymore: `other()` is the default when
there is no registered universe cause.
This was backfilling causes for new universes that may have been created
by an op, when there was no error info to use for improved
diagnostics. We don't need to do that anymore: `other()` is the default when
there is no registered universe cause.
@matthewjasper
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 31, 2023

📌 Commit 10ef8d9 has been approved by matthewjasper

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-review Status: Awaiting review from the assignee but also interested parties. labels Aug 31, 2023
@bors
Copy link
Contributor

bors commented Aug 31, 2023

⌛ Testing commit 10ef8d9 with merge 4b71f03...

@bors
Copy link
Contributor

bors commented Aug 31, 2023

☀️ Test successful - checks-actions
Approved by: matthewjasper
Pushing 4b71f03 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 31, 2023
@bors bors merged commit 4b71f03 into rust-lang:master Aug 31, 2023
12 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Aug 31, 2023
@lqd lqd deleted the default-universe-info branch August 31, 2023 18:22
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4b71f03): 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)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.1% [1.1%, 1.1%] 1
Regressions ❌
(secondary)
1.2% [1.1%, 1.3%] 4
Improvements ✅
(primary)
-1.6% [-2.7%, -0.8%] 4
Improvements ✅
(secondary)
-1.2% [-1.4%, -1.0%] 2
All ❌✅ (primary) -1.1% [-2.7%, 1.1%] 5

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.7% [-0.7%, -0.7%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.7% [-0.7%, -0.7%] 1

Binary size

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

Bootstrap: 631.748s -> 629.802s (-0.31%)
Artifact size: 316.58 MiB -> 316.41 MiB (-0.05%)

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.

ICE in rustc_borrowck/src/region_infer
5 participants