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

add TypingMode::Borrowck #138785

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Mar 21, 2025

First two commits are from #139191.

Introduces TypingMode::Borrowck which unlike TypingMode::Analysis, uses the hidden type computed by HIR typeck as the initial value of opaques instead of an unconstrained infer var. This is a part of rust-lang/types-team#129.

Using this new TypingMode is unfortunately a breaking change for now, see tests/ui/impl-trait/non-defining-uses/as-projection-term.rs. Using an inference variable as the initial value results in non-defining uses in the defining scope. We therefore only enable it if with -Znext-solver=globally or -Ztyping-mode-borrowck

To do that the PR contains the following changes:

  • TypeckResults::concrete_opaque_type are already mapped to the definition of the opaque type
    • writeback now checks that the non-lifetime parameters of the opaque are universal
    • for this, fn check_opaque_type_parameter_valid is moved from rustc_borrowck to rustc_trait_selection
  • we add a new query type_of_opaque_hir_typeck which, using the same visitors as MIR typeck, attempts to merge the hidden types from HIR typeck from all defining scopes
    • done by adding a DefiningScopeKind flag to toggle between using borrowck and HIR typeck
    • the visitors stop checking that the MIR type matches the HIR type. This is trivial as the HIR type are now used as the initial hidden types of the opaque. This check is useful as a safeguard when not using TypingMode::Borrowck, but adding it to the new structure is annoying and it's not soundness critical, so I intend to not add it back.
  • add a TypingMode::Borrowck which behaves just like TypingMode::Analysis except when normalizing opaque types
    • it uses type_of_opaque_hir_typeck(opaque) as the initial value after replacing its regions with new inference vars
    • it uses structural lookup in the new solver

fixes #112201, fixes #132335, fixes #137751

r? @compiler-errors @oli-obk

@rustbot rustbot added A-tidy Area: The tidy tool S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Mar 21, 2025
@lcnr

This comment was marked as outdated.

@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 Mar 21, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 21, 2025
add `TypingMode::Borrowck`

Still not quite ready

Based on rust-lang#138492 and rust-lang#138719

r? `@compiler-errors` `@oli-obk`
@bors

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@bors

This comment was marked as outdated.

@rust-timer

This comment has been minimized.

@rust-timer

This comment was marked as outdated.

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 21, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 27, 2025
increment depth of nested obligations

properly fixes the root cause of rust-lang#109268. While we didn't get hangs here before, I ended up encountering its root cause again with rust-lang#138785.

r? types
@lcnr lcnr force-pushed the typing-mode-borrowck branch 2 times, most recently from 78732a8 to 9b611a3 Compare March 27, 2025 15:35
@lcnr

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@lcnr

This comment was marked as outdated.

Zalathar added a commit to Zalathar/rust that referenced this pull request Apr 1, 2025
increment depth of nested obligations

properly fixes the root cause of rust-lang#109268. While we didn't get hangs here before, I ended up encountering its root cause again with rust-lang#138785.

r? types
Zalathar added a commit to Zalathar/rust that referenced this pull request Apr 1, 2025
increment depth of nested obligations

properly fixes the root cause of rust-lang#109268. While we didn't get hangs here before, I ended up encountering its root cause again with rust-lang#138785.

r? types
@lcnr lcnr force-pushed the typing-mode-borrowck branch from 0b44108 to d7cf428 Compare April 1, 2025 13:09
@lcnr
Copy link
Contributor Author

lcnr commented Apr 1, 2025

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 1, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 1, 2025
add `TypingMode::Borrowck`

Still not quite ready

Based on rust-lang#138492

r? `@compiler-errors` `@oli-obk`
@bors
Copy link
Collaborator

bors commented Apr 1, 2025

⌛ Trying commit d7cf428 with merge f8ad33e35a8aba1c9928e3c863abba2373e0d978...

@lcnr lcnr force-pushed the typing-mode-borrowck branch 2 times, most recently from b9c1319 to a23f7df Compare April 1, 2025 13:41
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 1, 2025
increment depth of nested obligations

properly fixes the root cause of rust-lang#109268. While we didn't get hangs here before, I ended up encountering its root cause again with rust-lang#138785.

r? types
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 1, 2025
increment depth of nested obligations

properly fixes the root cause of rust-lang#109268. While we didn't get hangs here before, I ended up encountering its root cause again with rust-lang#138785.

r? types
@lcnr lcnr force-pushed the typing-mode-borrowck branch from a23f7df to cbcc802 Compare April 1, 2025 21:40
@lcnr
Copy link
Contributor Author

lcnr commented Apr 1, 2025

@rustbot ready

@lcnr lcnr marked this pull request as ready for review April 1, 2025 21:41
@rustbot
Copy link
Collaborator

rustbot commented Apr 1, 2025

Some changes occurred to the core trait solver

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

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

Some changes occurred in exhaustiveness checking

cc @Nadrieril

@lcnr lcnr force-pushed the typing-mode-borrowck branch from cbcc802 to 83109dd Compare April 1, 2025 21:48
//~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
|| ()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unfortunate side-effect from HIR typeck eagerly replacing the return type with an inference var. This will be partially fixed when removing this eager normalization call. The new solver does point to the closure instead.

However, as we're still normalizing away opaques to infer vars during generalization, there may still be span regressions where we point at the place introducing the opaque instead of the place which actually constrains it. This feels unavoidable without major changes to the way we track spans for opaques/in the type system in general.

@@ -7,8 +7,7 @@ fn main() {
fn test<T: Display>(t: T, recurse: bool) -> impl Display {
let f = || {
let i: u32 = test::<i32>(-1, false);
//~^ ERROR concrete type differs from previous defining opaque type use
//~| ERROR expected generic type parameter, found `i32`
//~^ ERROR expected generic type parameter, found `i32`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

error tainting 🎉

@lcnr lcnr force-pushed the typing-mode-borrowck branch from 83109dd to 6e4f81e Compare April 1, 2025 21:55
@lcnr
Copy link
Contributor Author

lcnr commented Apr 1, 2025

@rust-timer build d7cf428

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2025
Rollup merge of rust-lang#139022 - lcnr:incr-obligation-depth, r=oli-obk

increment depth of nested obligations

properly fixes the root cause of rust-lang#109268. While we didn't get hangs here before, I ended up encountering its root cause again with rust-lang#138785.

r? types
Zalathar added a commit to Zalathar/rust that referenced this pull request Apr 2, 2025
…errors

small opaque type/borrowck cleanup

pulled out of rust-lang#138785
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tidy Area: The tidy tool perf-regression Performance regression. S-waiting-on-perf Status: Waiting on a perf run to be completed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library 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
6 participants