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

Restrict recursive opaque type check #113636

Merged
merged 2 commits into from
Jul 18, 2023

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jul 13, 2023

We have a recursive opaque check in writeback to avoid inferring the hidden of an opaque type to be itself:

struct RecursionChecker {
def_id: LocalDefId,
}
impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for RecursionChecker {
type BreakTy = ();
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *t.kind() {
if def_id == self.def_id.to_def_id() {
return ControlFlow::Break(());
}
}
t.super_visit_with(self)
}
}
if hidden_type
.visit_with(&mut RecursionChecker { def_id: opaque_type_key.def_id })
.is_break()
{
continue;
}

Issue #113619 treats make_option2 as not defining the TAIT TestImpl since it is inferred to have the definition TestImpl := B<TestImpl>, which fails this check. This regressed in #102700 (5d15beb), I think due to the refactoring that made us record the hidden types of TAITs during writeback.

However, nothing actually seems to go bad if we relax this recursion checker to only check for directly recursive definitions. This PR fixes #113619 by changing this recursive check from being a visitor to just checking that the hidden type is exactly the same as the opaque being inferred.

Alternatively, we may be able to fix #113619 by restricting this recursion check only to RPITs/async fns. It seems to only be possible to use misuse the recursion check to cause ICEs for TAITs (though I didn't try too hard to create a bad RPIT example... may be possible, actually.)

r? @oli-obk

--

Fixes #113314

@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 Jul 13, 2023
@compiler-errors
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Jul 13, 2023

⌛ Trying commit 0871d66e463572a466d36634f9993526c7dd80dc with merge 168adca86021b4acdae9e717a4c09015b0f1062f...

@compiler-errors compiler-errors force-pushed the opaque-recursive-check-bad branch from 0871d66 to 5e179f7 Compare July 13, 2023 00:49
@compiler-errors
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Jul 13, 2023

⌛ Trying commit 5e179f7364488f069858d7bda7259aba7f42a526 with merge 1066537ce94b83c04b9e840838af0b66b0ef1500...

@bors
Copy link
Contributor

bors commented Jul 13, 2023

☀️ Try build successful - checks-actions
Build commit: 1066537ce94b83c04b9e840838af0b66b0ef1500 (1066537ce94b83c04b9e840838af0b66b0ef1500)

@compiler-errors
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-113636 created and queued.
🤖 Automatically detected try build 1066537ce94b83c04b9e840838af0b66b0ef1500
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 13, 2023
@craterbot
Copy link
Collaborator

🚧 Experiment pr-113636 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@compiler-errors compiler-errors force-pushed the opaque-recursive-check-bad branch from 41e77ae to d4fcef7 Compare July 13, 2023 19:13
@craterbot
Copy link
Collaborator

🎉 Experiment pr-113636 is completed!
📊 6 regressed and 3 fixed (321870 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Jul 14, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Jul 14, 2023

All regressions are spurious disk failures

@bors r+

@bors
Copy link
Contributor

bors commented Jul 14, 2023

📌 Commit d4fcef7df7b25f0d24b57531dc2289f4cfa2c23e has been approved by oli-obk

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 Jul 14, 2023
@bors
Copy link
Contributor

bors commented Jul 14, 2023

☔ The latest upstream changes (presumably #113328) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 14, 2023
@rust-cloud-vms rust-cloud-vms bot force-pushed the opaque-recursive-check-bad branch from d4fcef7 to ef0a872 Compare July 14, 2023 15:20
@rust-log-analyzer

This comment has been minimized.

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 16, 2023
@rust-log-analyzer

This comment has been minimized.

.is_break()
if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.kind()
&& alias_ty.def_id == opaque_type_key.def_id.to_def_id()
&& alias_ty.substs == opaque_type_key.substs
Copy link
Contributor

Choose a reason for hiding this comment

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

The previous check was only checking the def_id.
This would accept TAIT<T, U> being inferred to Tait<u32, u32>.
Do we want to accept that?

Copy link
Contributor

Choose a reason for hiding this comment

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

that is rejected later. I guess we could do some of these checks here, too, but I don't see any way we could miss doing the checks (as we get the hidden type from borrowck, not from typeck)

@rust-cloud-vms rust-cloud-vms bot force-pushed the opaque-recursive-check-bad branch from d1930d1 to 6875589 Compare July 18, 2023 15:56
@oli-obk
Copy link
Contributor

oli-obk commented Jul 18, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Jul 18, 2023

📌 Commit 6875589 has been approved by oli-obk

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 Jul 18, 2023
@bors
Copy link
Contributor

bors commented Jul 18, 2023

⌛ Testing commit 6875589 with merge f19439247f57f0c68e397536e9fb07b018599a72...

@bors
Copy link
Contributor

bors commented Jul 18, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 18, 2023
@rust-log-analyzer
Copy link
Collaborator

The job dist-aarch64-linux failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@oli-obk
Copy link
Contributor

oli-obk commented Jul 18, 2023

@bors retry empty log

@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 Jul 18, 2023
@bors
Copy link
Contributor

bors commented Jul 18, 2023

⌛ Testing commit 6875589 with merge d351515...

@bors
Copy link
Contributor

bors commented Jul 18, 2023

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing d351515 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 18, 2023
@bors bors merged commit d351515 into rust-lang:master Jul 18, 2023
@rustbot rustbot added this to the 1.73.0 milestone Jul 18, 2023
@compiler-errors compiler-errors deleted the opaque-recursive-check-bad branch July 18, 2023 22:53
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d351515): 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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.8% [-1.0%, -0.7%] 2
Improvements ✅
(secondary)
-3.2% [-3.2%, -3.2%] 1
All ❌✅ (primary) -0.8% [-1.0%, -0.7%] 2

Cycles

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

Binary size

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

Bootstrap: 660.475s -> 658.716s (-0.27%)

@clubby789 clubby789 mentioned this pull request Oct 16, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 25, 2023
…piler-errors

Add test for 113326

Closes rust-lang#113326
Bisecting points to rust-lang#113636 as the fix
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 25, 2023
Rollup merge of rust-lang#116801 - clubby789:issue-113326-test, r=compiler-errors

Add test for 113326

Closes rust-lang#113326
Bisecting points to rust-lang#113636 as the fix
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
8 participants