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 PostBorrowckAnalysis for old solver #135899

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

branch name is typo'd

This "fixes" the PostBorrowckAnalysis mode for the old solver, and begins to use it in check_opaque_well_formed and check_coroutine_obligations.

There are several curiosities here that result.

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. labels Jan 22, 2025
@@ -36,5 +36,21 @@ note: this opaque type is in the signature
LL | type Bar = impl std::fmt::Display;
| ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors
error: the constant `N` is not of type `{type error}`
Copy link
Member Author

Choose a reason for hiding this comment

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

See the comment:

// FIXME: We should reveal the TAITs that end up in where clauses here, otherwise we
// will not be able to match param-env candidates in the old solver, since we don't
// have eq-modulo-normalization. This is less of a problem than it seems, since this
// only matters if we have TAITs in where where clauses, which isn't achievable with
// RPIT anyways.

@@ -6,5 +6,21 @@ LL | async fn test<const N: crate::Bar>() {
|
= note: the only supported types are integers, `bool`, and `char`

error: aborting due to 1 previous error
error: the constant `N` is not of type `u32`
Copy link
Member Author

Choose a reason for hiding this comment

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

See the comment:

See the comment:

// FIXME: We should reveal the TAITs that end up in where clauses here, otherwise we
// will not be able to match param-env candidates in the old solver, since we don't
// have eq-modulo-normalization. This is less of a problem than it seems, since this
// only matters if we have TAITs in where where clauses, which isn't achievable with
// RPIT anyways.

@@ -1,7 +1,5 @@
// ICE failed to resolve instance for ...
// issue: rust-lang/rust#123145
//@ build-fail
Copy link
Member Author

Choose a reason for hiding this comment

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

This now cycles in check_opaque_well_formed, since now we actually reveal impl Handler when proving that it satisfies its own item bounds. This seems desirable to me.

let generic_ty = self.cx().type_of(data.def_id);
let mut concrete_ty = generic_ty.instantiate(self.cx(), args);

if concrete_ty == ty {
Copy link
Member Author

Choose a reason for hiding this comment

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

This recursiveness check sucks, but it prevents bad error messages.

Ty::new_error_with_message(self.cx(), self.cause.span, "recursive opaque type");
}

let concrete_ty = fold_regions(self.cx(), concrete_ty, |re, _dbi| match re.kind() {
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 wonder if we should consolidate all of these "replace erasing with infer" so that we only need to change it in one place when we start using a real binder...

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, we probably should 😁

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
   Compiling quine-mc_cluskey v0.2.4
   Compiling is_terminal_polyfill v1.70.1
   Compiling anstyle-query v1.1.2
   Compiling unicode-script v0.5.7
error[E0311]: the parameter type `P` may not live long enough
    --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winnow-0.5.40/src/binary/bits/mod.rs:56:5
56   | /     trace(
57   | |         "bits",
57   | |         "bits",
58   | |         unpeek(move |input: I| {
59   | |             match parser.parse_peek((input, 0)) {
74   | |         }),
75   | |     )
     | |     ^
     | |     |
     | |     |
     | |_____the parameter type `P` must be valid for lifetime `'_`...
     |       ...so that the type `{closure@/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winnow-0.5.40/src/binary/bits/mod.rs:58:16: 58:31}` will meet its required lifetime bounds...
note: ...that is required by this bound
note: ...that is required by this bound
    --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winnow-0.5.40/src/parser.rs:1100:51
     |
1100 |     mut peek: impl FnMut(I) -> IResult<I, O, E> + 'a,
     |                                                   ^^
     = help: consider adding an explicit lifetime bound `P: anon`...
   Compiling anstream v0.6.18
error[E0311]: the parameter type `P` may not live long enough
error[E0311]: the parameter type `P` may not live long enough
  --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winnow-0.5.40/src/binary/bits/mod.rs:56:5
56 | /     trace(
57 | |         "bits",
57 | |         "bits",
58 | |         unpeek(move |input: I| {
59 | |             match parser.parse_peek((input, 0)) {
74 | |         }),
75 | |     )
   | |     ^
   | |     |
   | |     |
   | |_____the parameter type `P` must be valid for lifetime `'_`...
   |       ...so that the type `impl for<'a> FnMut(&'a mut I) -> Result<O, ErrMode<E2>>` will meet its required lifetime bounds...
note: ...that is required by this bound
note: ...that is required by this bound
  --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winnow-0.5.40/src/combinator/debug/mod.rs:45:18
   |
45 |     parser: impl Parser<I, O, E>,
   |                  ^^^^^^^^^^^^^^^
   = help: consider adding an explicit lifetime bound `P: anon`...
error[E0311]: the parameter type `P` may not live long enough
error[E0311]: the parameter type `P` may not live long enough
    --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winnow-0.5.40/src/binary/bits/mod.rs:115:5
115  | /     trace(
116  | |         "bytes",
116  | |         "bytes",
117  | |         unpeek(move |(input, offset): (I, usize)| {
118  | |             let (inner, _) = if offset % BYTE != 0 {
140  | |         }),
141  | |     )
     | |     ^
     | |     |
     | |     |
     | |_____the parameter type `P` must be valid for lifetime `'_`...
     |       ...so that the type `{closure@/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winnow-0.5.40/src/binary/bits/mod.rs:117:16: 117:50}` will meet its required lifetime bounds...
note: ...that is required by this bound
note: ...that is required by this bound
    --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winnow-0.5.40/src/parser.rs:1100:51
     |
1100 |     mut peek: impl FnMut(I) -> IResult<I, O, E> + 'a,
     |                                                   ^^
     = help: consider adding an explicit lifetime bound `P: anon`...
error[E0311]: the parameter type `P` may not live long enough
error[E0311]: the parameter type `P` may not live long enough
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winnow-0.5.40/src/binary/bits/mod.rs:115:5
115 | /     trace(
116 | |         "bytes",
116 | |         "bytes",
117 | |         unpeek(move |(input, offset): (I, usize)| {
118 | |             let (inner, _) = if offset % BYTE != 0 {
140 | |         }),
141 | |     )
    | |     ^
    | |     |
    | |     |
    | |_____the parameter type `P` must be valid for lifetime `'_`...
    |       ...so that the type `impl for<'a> FnMut(&'a mut (I, usize)) -> Result<O, ErrMode<E2>>` will meet its required lifetime bounds...
note: ...that is required by this bound
note: ...that is required by this bound
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winnow-0.5.40/src/combinator/debug/mod.rs:45:18
    |
45  |     parser: impl Parser<I, O, E>,
    |                  ^^^^^^^^^^^^^^^
    = help: consider adding an explicit lifetime bound `P: anon`...
   Compiling quote v1.0.38
   Compiling nom v7.1.3
   Compiling indexmap v2.7.0
   Compiling syn v2.0.96

@compiler-errors
Copy link
Member Author

💀

I guess I'll minimize that ^

@compiler-errors compiler-errors 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 Jan 27, 2025
@@ -128,10 +129,10 @@ pub(super) fn needs_normalization<'tcx, T: TypeVisitable<TyCtxt<'tcx>>>(
// so we can ignore those.
match infcx.typing_mode() {
// FIXME(#132279): We likely want to reveal opaques during post borrowck analysis
Copy link
Contributor

Choose a reason for hiding this comment

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

outdated

@@ -224,28 +258,20 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
// Only normalize `impl Trait` outside of type inference, usually in codegen.
match self.selcx.infcx.typing_mode() {
// FIXME(#132279): We likely want to reveal opaques during post borrowck analysis
Copy link
Contributor

Choose a reason for hiding this comment

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

outdated

@@ -973,9 +973,6 @@ impl<'tcx> InferCtxt<'tcx> {
TypingMode::Analysis { defining_opaque_types } => {
id.into().as_local().is_some_and(|def_id| defining_opaque_types.contains(&def_id))
}
// FIXME(#132279): This function is quite weird in post-analysis
// and post-borrowck analysis mode. We may need to modify its uses
// to support PostBorrowckAnalysis in the old solver as well.
Copy link
Contributor

Choose a reason for hiding this comment

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

why remove this FIXME 🤔 I feel like ideally we just never call this function outside of TypingMode::Analysis, not sure whether that's possible, might be kinda ugly to implement

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

some nits, i'd like to see a crater run here after u've figured out the ci failure

@bors
Copy link
Contributor

bors commented Jan 30, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

5 participants