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

Don't call type_of on TAIT in defining scope in new solver #112825

Merged
merged 1 commit into from
Jul 7, 2023

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jun 20, 2023

It's never productive to call consider_auto_trait_candidate on a TAIT in the defining scope, since it will always lead to a query cycle since we call type_of on the TAIT. So let's just don't.

I've reserved this behavior just to SolverMode::Normal just to avoid any future problems, since this is technically incomplete since we're discarding a candidate that could theoretically apply. But given such candidate assembly always leads to a query cycle, I think it's relatively low risk, and I could be convinced otherwise and make this apply to both solver mode. I assume it's far less likely to be encountered in coherence, though.

This is much more likely to encounter in the new solver, though it can also be encountered in the old solver too, so I'm happy to discuss whether this new behavior we even want in the first place...

I encountered this in a couple of failing UI tests:

  • tests/ui/type-alias-impl-trait/issue-62000-associate-impl-trait-lifetimes.rs
  • tests/ui/type-alias-impl-trait/issue-93411.rs

r? @lcnr

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jun 20, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jun 20, 2023

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@rust-cloud-vms rust-cloud-vms bot force-pushed the tait-defining-cycle branch from 5cc5b09 to 950ad25 Compare June 28, 2023 17:44
@rust-cloud-vms rust-cloud-vms bot force-pushed the tait-defining-cycle branch from 950ad25 to 31cdf94 Compare June 29, 2023 17:25
@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms rust-cloud-vms bot force-pushed the tait-defining-cycle branch 2 times, most recently from 1946723 to 8725c5d Compare June 30, 2023 06:27
Comment on lines +124 to +136
// Don't call `type_of` on a local TAIT that's in the defining scope,
// since that may require calling `typeck` on the same item we're
// currently type checking, which will result in a fatal cycle that
// ideally we want to avoid, since we can make progress on this goal
// via an alias bound or a locally-inferred hidden type instead.
//
// Also, don't call `type_of` on a TAIT in `Reveal::All` mode, since
// we already normalize the self type in
// `assemble_candidates_after_normalizing_self_ty`, and we'd
// just be registering an identical candidate here.
//
// Returning `Err(NoSolution)` here is ok in `SolverMode::Coherence`
// since we'll always be registering an ambiguous candidate in
// `assemble_candidates_after_normalizing_self_ty` due to normalizing
// the TAIT.
Copy link
Contributor

Choose a reason for hiding this comment

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

I personally don't like this perspective on why we do this. Imo the query cycles are a side effect of something more fundamental:

  • instantiate_constituent_tys_for_auto_trait for opaque types is a hacky, pseudo normalization-routine which does not check item bounds of the opaque
  • if we're able to normalize the opaque in a different way, either because we're able to define it or because we're in Reveal::All, using regular normalization is strictly preferable to auto trait leakage

I would like you to rewrite this comment to reflect that, but also fine to wait and chat about it in sync a bit if you don't consider this perspective to be helpful or maybe even correct

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'm not particularly attached to any specific comment here, though I think the best way to settle this is for you to just write what you'd like for this comment to say as an inline suggestion.

I'm not sure if we share the exact mental model for why this "hack" is not as much of a hack as it seems, but what I wrote above is how I see it at least from an implementation perspective.

Copy link
Contributor

Choose a reason for hiding this comment

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

the comment I would like to write would also require some general code changes, put that in my notes and will look at it at some later point and open a separate PR

@lcnr
Copy link
Contributor

lcnr commented Jul 6, 2023

@bors r+ rollup (new solver)

@bors
Copy link
Contributor

bors commented Jul 6, 2023

📌 Commit 8725c5d has been approved by lcnr

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 6, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 6, 2023
…e, r=lcnr

Don't call `type_of` on TAIT in defining scope in new solver

It's *never* productive to call `consider_auto_trait_candidate` on a TAIT in the defining scope, since it will always lead to a query cycle since we call `type_of` on the TAIT. So let's just don't.

I've reserved this behavior just to `SolverMode::Normal` just to avoid any future problems, since this is *technically* incomplete since we're discarding a candidate that could *theoretically* apply. But given such candidate assembly *always* leads to a query cycle, I think it's relatively low risk, and I could be convinced otherwise and make this apply to both solver mode. I assume it's far less likely to be encountered in coherence, though.

This is much more likely to encounter in the new solver, though it can also be encountered in the old solver too, so I'm happy to discuss whether this new behavior we even want in the first place...

I encountered this in a couple of failing UI tests:
* `tests/ui/type-alias-impl-trait/issue-62000-associate-impl-trait-lifetimes.rs`
* `tests/ui/type-alias-impl-trait/issue-93411.rs`

r? `@lcnr`
@compiler-errors
Copy link
Member Author

@bors r-

@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 6, 2023
@rust-cloud-vms rust-cloud-vms bot force-pushed the tait-defining-cycle branch from 8725c5d to 388c230 Compare July 6, 2023 20:13
@compiler-errors
Copy link
Member Author

@bors r=lcnr

blessed

@bors
Copy link
Contributor

bors commented Jul 6, 2023

📌 Commit 388c230 has been approved by lcnr

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 Jul 6, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 7, 2023
…mpiler-errors

Rollup of 8 pull requests

Successful merges:

 - rust-lang#111917 (Simplify duplicate checks for mir validator)
 - rust-lang#112008 (Fix incorrect documented default bufsize in bufreader/writer)
 - rust-lang#112825 (Don't call `type_of` on TAIT in defining scope in new solver)
 - rust-lang#113164 (Add a regression test for rust-lang#109054)
 - rust-lang#113318 (Revert "alloc: Allow comparing Boxs over different allocators", add regression test)
 - rust-lang#113397 (Prefer object candidates in new selection)
 - rust-lang#113419 (Avoid calling item_name for RPITIT)
 - rust-lang#113421 (Do not assert >1 RPITITs on collect_return_position_impl_trait_in_trait_tys)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit de49a9f into rust-lang:master Jul 7, 2023
@rustbot rustbot added this to the 1.72.0 milestone Jul 7, 2023
@compiler-errors compiler-errors deleted the tait-defining-cycle branch August 11, 2023 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants