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

small opaque type/borrowck cleanup #139191

Merged
merged 2 commits into from
Apr 2, 2025
Merged

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Mar 31, 2025

pulled out of #138785

@rustbot
Copy link
Collaborator

rustbot commented Mar 31, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Mar 31, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Mar 31, 2025

r? types

@rustbot rustbot added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Mar 31, 2025
@lcnr lcnr force-pushed the interner-opaques branch from 91e1313 to e3a8c85 Compare April 1, 2025 21:23
@rustbot
Copy link
Collaborator

rustbot commented Apr 1, 2025

Some changes occurred to the core trait solver

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

@lcnr lcnr force-pushed the interner-opaques branch from e3a8c85 to cb275d4 Compare April 1, 2025 21:24
@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Apr 1, 2025

📌 Commit cb275d4 has been approved by compiler-errors

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 Apr 1, 2025
@lcnr lcnr mentioned this pull request Apr 1, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2025
Rollup of 14 pull requests

Successful merges:

 - rust-lang#135295 (Check empty SIMD vector in inline asm)
 - rust-lang#138003 (Add the new `amx` target features and the `movrs` target feature)
 - rust-lang#138823 (rustc_target: RISC-V: add base `I`-related important extensions)
 - rust-lang#138913 (Remove even more instances of `@ts-expect-error` from search.js)
 - rust-lang#138941 (Do not mix normalized and unnormalized caller bounds when constructing param-env for `receiver_is_dispatchable`)
 - rust-lang#139060 (replace commit placeholder in vendor status with actual commit)
 - rust-lang#139102 (coverage: Avoid splitting spans during span extraction/refinement)
 - rust-lang#139191 (small opaque type/borrowck cleanup)
 - rust-lang#139200 (Skip suggest impl or dyn when poly trait is not a real trait)
 - rust-lang#139208 (fix dead link netbsd.md)
 - rust-lang#139210 (chore: remove redundant backtick)
 - rust-lang#139212 (Update mdbook to 0.4.48)
 - rust-lang#139214 (Tell rustfmt to use the 2024 edition in ./x.py fmt)
 - rust-lang#139225 (move autodiff from EnzymeAD/Enzyme to our rust-lang/Enzyme soft-fork)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2311b34 into rust-lang:master Apr 2, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 2, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2025
Rollup merge of rust-lang#139191 - lcnr:interner-opaques, r=compiler-errors

small opaque type/borrowck cleanup

pulled out of rust-lang#138785
@lcnr lcnr deleted the interner-opaques branch April 2, 2025 09:10
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2025
add `TypingMode::Borrowck`

First two commits are from rust-lang#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 rust-lang#112201, fixes rust-lang#132335, fixes rust-lang#137751

r? `@compiler-errors` `@oli-obk`
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. T-types Relevant to the types 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.

5 participants