Skip to content

Don't try to prove opaque type bounds twice on the same types #114094

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

Closed
wants to merge 3 commits into from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jul 26, 2023

fixes #109268

The other alternative I came up with was to filter obligations out by trying to prove them on their own first. Basically <Foo<'_> as Fn() -> Foo<'_>>::Output = Foo<'_> should always hold without needing to reveal the opaque type or without trying to register a hidden type for it.

r? @compiler-errors cc @lcnr

@rustbot
Copy link
Collaborator

rustbot commented Jul 26, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @compiler-errors (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@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 26, 2023
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Jul 26, 2023

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@@ -0,0 +1,10 @@
#![feature(type_alias_impl_trait)]
Copy link
Member

Choose a reason for hiding this comment

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

how does this behave on the new trait solver? I think the new trait solver does re-prove bounds even if it's unifying with an existing opaque:

ecx.eq(param_env, candidate_ty, ty)?;
ecx.add_item_bounds_for_hidden_type(
candidate_key.def_id.to_def_id(),
candidate_key.args,
param_env,
candidate_ty,
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it works (see new commit), but I haven't run any logs yet to see what it is doing, and whether anything is different.

Copy link
Member

Choose a reason for hiding this comment

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

Wonder why it's not cycling. I bet it's because of lazy norm. Anyways, I guess it shouldn't matter, unless we make sure we don't commit to something that breaks the new solver.

@lcnr
Copy link
Contributor

lcnr commented Jul 27, 2023

I don't like this approach but can't quite put into words why 😅 want to look into this in more detail later this/next week

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 27, 2023

I don't like this approach but can't quite put into words why

Well, I don't like it because it makes the order of hidden type registrations meaningful.

I looked into the original proposal you had, but it didn't look like we could actually do that without adding special casing for opaque types $somewhere.

@compiler-errors compiler-errors removed their assignment Jul 27, 2023
@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 31, 2023

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 31, 2023
@bors
Copy link
Collaborator

bors commented Jul 31, 2023

⌛ Trying commit ab01463 with merge 3c4e2f5ff62c4193137fa44aa1dc9373aca1f4cc...

@bors
Copy link
Collaborator

bors commented Jul 31, 2023

☀️ Try build successful - checks-actions
Build commit: 3c4e2f5ff62c4193137fa44aa1dc9373aca1f4cc (3c4e2f5ff62c4193137fa44aa1dc9373aca1f4cc)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3c4e2f5ff62c4193137fa44aa1dc9373aca1f4cc): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

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

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
Improvements ✅
(secondary)
-2.3% [-2.3%, -2.3%] 1
All ❌✅ (primary) - - 0

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)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 651.412s -> 650.446s (-0.15%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 1, 2023
@lcnr
Copy link
Contributor

lcnr commented Aug 11, 2023

Finally getting to this 😅 sorry for taking so long.

As you said, this makes stuff order dependent and I don't think there's a theoretical reason for why this is correct. I don't want to have this behavior in the new solver so this is a chance for the old and new solver to diverge in behavior which is very :/

I personally don't think #109268 should block the stabilization of TAIT, so for me it would be acceptable to not fix this in the old solver at all.

I tried to instead only replace opaques with infer vars if can_eq would otherwise fail: master...lcnr:rust:project-opaques. This doesn't seem to work because we don't normalize the opaque when checking its trait bounds. The hack is necessary to constrain the projection_ty infer var to the hidden type instead of the opaque :<

I also can't think of how we'd fix this except by adding more lazy norm for opaques. This is difficult as long as we have Bubble 😁

@lcnr lcnr 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 Aug 11, 2023
@oli-obk oli-obk closed this Aug 11, 2023
@oli-obk oli-obk deleted the stuck branch August 11, 2023 09:42
@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 11, 2023

sgtm. I marked the issue as "can do after stabilization"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

infinite recursion with TAIT and replace_opaque_types_with_inference_vars in project
7 participants