Commit Graph

2523 Commits

Author SHA1 Message Date
Guillaume Gomez
7c3cb5688d
Rollup merge of #142126 - compiler-errors:normalize-uv-via-relate, r=BoxyUwU
Treat normalizing consts like normalizing types in deeply normalize

...so that we don't end up putting a top-level normalizes-to goal in the fulfillment context, which ICEs. This basically just models the normalize-const code off of the normalize-ty code above it, which uses an alias-relate goal instead.

Fixes rust-lang/rust#140571

r? lcnr
2025-06-07 22:22:58 +02:00
Michael Goulet
aa1b296dd6 Unify normalization of terms in deeply normalize 2025-06-07 02:35:28 +00:00
Michael Goulet
3418d5db3a Fast path for stalled obligations on self ty 2025-06-02 19:23:20 +00:00
bors
5f025f363d Auto merge of #141581 - lcnr:fold-clauses, r=compiler-errors
add additional `TypeFlags` fast paths

Some crates, e.g. `diesel`, have items with a lot of where-clauses (more than 150). In these cases checking the `TypeFlags` of the whole `param_env` can be very beneficial.

This adds `fn fold_clauses` to mirror the existing `fn visit_clauses` and then uses this in folders which fold `ParamEnv`s.

Split out from rust-lang/rust#141451, depends on rust-lang/rust#141442.

r? `@compiler-errors`
2025-05-29 02:29:01 +00:00
Michael Goulet
5f3ae06db0 Fix some var names 2025-05-27 11:14:47 +00:00
Michael Goulet
29c3babd7c Rename unpack to kind 2025-05-27 11:14:45 +00:00
bors
2805e1dc4c Auto merge of #141605 - jieyouxu:rollup-3gjqh5l, r=jieyouxu
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#140898 (minor improvements on running miri)
 - rust-lang/rust#141392 (Avoid obligation construction dance with query region constraints)
 - rust-lang/rust#141431 (Emit dummy open drop for unsafe binder)
 - rust-lang/rust#141433 (Properly analyze captures from unsafe binders)
 - rust-lang/rust#141439 (Deduplicate dyn compatibility violations due to coercion)
 - rust-lang/rust#141449 (further deduplicate ast visitor code)
 - rust-lang/rust#141513 (interpret: add allocation parameters to `AllocBytes`)
 - rust-lang/rust#141516 (speed up charsearcher for ascii chars)
 - rust-lang/rust#141526 (add a dedicated section for compiler environment variables in the unstable book)
 - rust-lang/rust#141550 (Fix `unused_braces` lint suggestion when encountering attributes)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-26 20:30:06 +00:00
lcnr
c56efaedfa add additional TypeFlags fast paths 2025-05-26 19:57:48 +00:00
许杰友 Jieyou Xu (Joe)
aa9978229e
Rollup merge of #141392 - compiler-errors:query-outlives, r=lcnr
Avoid obligation construction dance with query region constraints

And some renaming...
2025-05-27 01:29:17 +08:00
bors
40d2563ea2 Auto merge of #141500 - compiler-errors:rerun-cache-2, r=lcnr
Don't rerun goals if none of their vars have changed

r? `@ghost`

Alternative to rust-lang/rust#141488. I'm pretty sure that we don't need to re-run the goal at all if the inputs don't change... 🤔
2025-05-26 17:02:43 +00:00
bors
9c0bcb514f Auto merge of #141442 - compiler-errors:fast-path-pred, r=lcnr
Fold predicate fast path in canonicalizer and eager resolver

See individual commits.

r? lcnr
2025-05-26 13:42:30 +00:00
Michael Goulet
e2215a8ad9 Don't rerun goals if none of its vars have changed 2025-05-26 10:10:03 +00:00
Michael Goulet
9d742eea25 Rename 2025-05-26 08:48:19 +00:00
Michael Goulet
3efd885927 Avoid obligation construction dance with query region constraints 2025-05-26 08:28:45 +00:00
Michael Goulet
84a3255cc3 Fast path fold_predicate in old canonicalizer 2025-05-25 14:12:17 +00:00
Michael Goulet
7820d2caba Don't use relation just to equate regions in response 2025-05-25 10:37:43 +00:00
lcnr
326b7e9a6b yeet CanonicalVarInfo 2025-05-23 12:10:53 +00:00
Michael Goulet
98cdb829a8 Fast path for register_region_obligation 2025-05-17 19:35:05 +00:00
Pietro Albini
2ce08ca5d6
update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
Matthias Krüger
aace48811b
Rollup merge of #140641 - lcnr:opaque-type-storage-entries, r=compiler-errors
detect additional uses of opaques after writeback

Based on #140607. It's a lot harder to encounter in practice than I though 😅 😁 I've still added it with the expectation that somebody will encounter it at some point.

Also modifies the `EvalCtxt` to use the same impl to detect newly added opaque types.

r? ``@compiler-errors``
2025-05-08 08:14:18 +02:00
lcnr
e7979eab89 detect additional uses of opaques after writeback 2025-05-07 17:59:51 +00:00
lcnr
fc0ef54fd9 opaque_type_storage to InferCtxtLike 2025-05-07 17:58:20 +00:00
Michael Goulet
df13f7c1fa Require T: TypeFoldable in Binder<T> visit 2025-05-07 16:00:21 +00:00
Jacob Pratt
bda326f40c
Rollup merge of #140607 - lcnr:opaque-type-storage, r=compiler-errors
support duplicate entries in the opaque_type_storage

Necessary for the new solver as we may unify keys when eagerly resolving for canonical queries. See the relevant comment when instantiating query responses:
```rust
            // We eagerly resolve inference variables when computing the query response.
            // This can cause previously distinct opaque type keys to now be structurally equal.
            //
            // To handle this, we store any duplicate entries in a separate list to check them
            // at the end of typeck/borrowck. We could alternatively eagerly equate the hidden
            // types here. However, doing so is difficult as it may result in nested goals and
            // any errors may make it harder to track the control flow for diagnostics.
            if let Some(prev) = prev {
                self.delegate.add_duplicate_opaque_type(key, prev, self.origin_span);
            }
```

This will be far more relevant with #140497.

r? `@compiler-errors`
2025-05-07 00:29:23 +00:00
lcnr
431f02d531 support duplicates in the opaque_types_storage 2025-05-06 14:59:09 +00:00
Zalathar
9e7fb67838 Rename graph::implementation::Graph to LinkedGraph 2025-05-06 14:35:06 +10:00
Guillaume Gomez
224e3ca096
Rollup merge of #140559 - rperier:type-ir-to-type-middle, r=compiler-errors
Removing rustc_type_ir in the rustc_infer codebase

cc #138449

This is a second refactoring of rustc_type_ir to use rustc_middle instead, this time that's for rustc_infer
2025-05-05 21:32:32 +02:00
Romain Perier
6970813e78 Use less rustc_type_ir in the compiler codebase
This commit does the following:
  - Replaces use of rustc_type_ir by rustc_middle in rustc_infer.
  - The DelayedMap type is exposed by rustc_middle so everything can be
    accessed through rustc_middle in a coherent manner.
  - API-layer traits, like InferCtxtLike, Interner or inherent::* must be
    accessed via rustc_type_ir, not rustc_middle::ty. For this reason
    these are not reexported by rustc_middle::ty.
  - Replaces use of ty::Interner by rustc_type_ir::Interner in
    rustc_trait_selection
2025-05-02 09:37:06 +02:00
Boxy
238d113b07 Set groundwork for proper const normalization 2025-05-01 20:05:02 +01:00
Guillaume Gomez
7843686ffe
Rollup merge of #140249 - BoxyUwU:remove_weak_alias_terminology, r=oli-obk
Remove `weak` alias terminology

I find the "weak" alias terminology to be quite confusing. It implies the existence of "strong" aliases (which do not exist) and I'm not really sure what about weak aliases is "weak". I much prefer "free alias" as the term. I think it's much more obvious what it means as "free function" is a well defined term that already exists in rust.

It's also a little confusing given "weak alias" is already a term in linker/codegen spaces which are part of the compiler too. Though I'm not particularly worried about that as it's usually very obvious if you're talking about the type system or not lol. I'm also currently trying to write documentation about aliases and it's somewhat awkward/confusing to be talking about *weak* aliases, when I'm not really sure what the basis for that as the term actually *is*.

I would also be happy to just find out there's a nice meaning behind calling them "weak" aliases :-)

r? `@oli-obk`

maybe we want a types MCP to decide on a specific naming here? or maybe we think its just too late to go back on this naming decision ^^'
2025-04-28 13:30:45 +02:00
lcnr
855035b038 convert some GenericArg to Term 2025-04-26 02:05:31 +00:00
Matthias Krüger
564e5ccb5c
Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr
Make #![feature(let_chains)] bootstrap conditional in compiler/

Let chains have been stabilized recently in #132833, so we can remove the gating from our uses in the compiler (as the compiler uses edition 2024).
2025-04-25 07:50:25 +02:00
Boxy
bdfeb8f36b Remove weak alias terminology 2025-04-24 11:59:20 +01:00
Michael Goulet
f943f73db4 More 2025-04-23 15:09:25 +00:00
est31
7493e1cdf6 Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
Michael Goulet
169955f3be Properly drain pending obligations for coroutines 2025-04-22 16:50:38 +00:00
bors
efb1e3d676 Auto merge of #139768 - compiler-errors:split-fold, r=lcnr
Split `TypeFolder` and `FallibleTypeFolder` atwain

Right now there is a coherence problem with `TypeFolder` and `FallibleTypeFolder`. Namely, it's impossible to implement a `FallibleTypeFolder` that is generic over interner, b/c it has a *downstream* conflict with the blanket impl:

```
impl<I, F> FallibleTypeFolder<I> for F where F: TypeFolder<I> {}
```

Because downstream crates may implement `TypeFolder<SomeLocalInterner>` for the fallible type folder.

This PR removes the relationship between `FallibleTypeFolder` and `TypeFolder`; it leads to *modest* code duplication, but otherwise does not affect perf and really doesn't matter in general.
2025-04-16 01:46:01 +00:00
Yotam Ofek
4b63362f3d Use newtype_index!-generated types more idiomatically 2025-04-14 16:17:06 +00:00
Michael Goulet
13b4734e31 Derive Obligation's fold impls 2025-04-14 14:47:59 +00:00
xizheyin
c7272a6cbc
clean code: remove Deref<Target=RegionKind> impl for Region and use .kind()
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-08 10:51:41 +08:00
bors
17ffbc81a3 Auto merge of #138785 - lcnr:typing-mode-borrowck, r=compiler-errors,oli-obk
add `TypingMode::Borrowck`

Shares the first commit with #138499, doesn't really matter which PR to land first 😊 😁

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 https://github.com/rust-lang/types-team/issues/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`
2025-04-04 19:54:42 +00:00
Michael Goulet
64b58dd13b Pass correct param-env to error_implies 2025-04-03 18:55:53 +00:00
lcnr
509a144eed add TypingMode::Borrowck 2025-04-03 11:13:10 +02:00
lcnr
cb275d4f26 simplify Interner opaque types API 2025-04-01 23:24:28 +02:00
Michael Goulet
575f129faa Obligation::as_goal 2025-03-23 18:18:47 +00:00
Michael Goulet
e5a2220327 Fold visit into ty 2025-03-15 06:34:36 +00:00
Michael Goulet
dc0cdfd753 Squash fold into ty 2025-03-15 06:34:36 +00:00
Nicholas Nethercote
ff0a5fe975 Remove #![warn(unreachable_pub)] from all compiler/ crates.
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-11 13:14:21 +11:00
许杰友 Jieyou Xu (Joe)
063ef18fdc Revert "Use workspace lints for crates in compiler/ #138084"
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to
consider options that avoids breaking downstream usages of cargo on
distributed `rustc-src` artifacts, where such cargo invocations fail due
to inability to inherit `lints` from workspace root manifest's
`workspace.lints` (this is only valid for the source rust-lang/rust
workspace, but not really the distributed `rustc-src` artifacts).

This breakage was reported in
<https://github.com/rust-lang/rust/issues/138304>.

This reverts commit 48caf81484, reversing
changes made to c6662879b2.
2025-03-10 18:12:47 +08:00
Nicholas Nethercote
8a3e03392e Remove #![warn(unreachable_pub)] from all compiler/ crates.
(Except for `rustc_codegen_cranelift`.)

It's no longer necessary now that `unreachable_pub` is in the workspace
lints.
2025-03-08 08:41:43 +11:00