about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/solve
AgeCommit message (Collapse)AuthorLines
2024-03-01Rollup merge of #121497 - lcnr:coherence-suggest-increasing-recursion-limit, ↵Matthias Krüger-121/+187
r=compiler-errors `-Znext-solver=coherence`: suggest increasing recursion limit r? `@compiler-errors`
2024-03-01normalizes-to: handle negative implslcnr-3/+16
2024-03-01Auto merge of #121462 - compiler-errors:eq-and-sub, r=lcnrbors-1/+0
Combine `Sub` and `Equate` Combine `Sub` and `Equate` into a new relation called `TypeRelating` (that name sounds familiar...) Tracks the difference between `Sub` and `Equate` via `ambient_variance: ty::Variance` much like the `NllTypeRelating` relation, but implemented slightly jankier because it's a more general purpose relation. r? lcnr
2024-03-01Auto merge of #121728 - tgross35:f16-f128-step1-ty-updates, r=compiler-errorsbors-1/+3
Add stubs in IR and ABI for `f16` and `f128` This is the very first step toward the changes in https://github.com/rust-lang/rust/pull/114607 and the [`f16` and `f128` RFC](https://rust-lang.github.io/rfcs/3453-f16-and-f128.html). It adds the types to `rustc_type_ir::FloatTy` and `rustc_abi::Primitive`, and just propagates those out as `unimplemented!` stubs where necessary. These types do not parse yet so there is no feature gate, and it should be okay to use `unimplemented!`. The next steps will probably be AST support with parsing and the feature gate. r? `@compiler-errors` cc `@Nilstrieb` suggested breaking the PR up in https://github.com/rust-lang/rust/pull/120645#issuecomment-1925900572
2024-03-01Get rid of some sub_exp and eq_expMichael Goulet-1/+0
2024-02-29Rollup merge of #121681 - jswrenn:nix-visibility-analysis, r=compiler-errorsMatthias Krüger-4/+1
Safe Transmute: Revise safety analysis This PR migrates `BikeshedIntrinsicFrom` to a simplified safety analysis (described [here](https://github.com/rust-lang/project-safe-transmute/issues/15)) that does not rely on analyzing the visibility of types and fields. The revised analysis treats primitive types as safe, and user-defined types as potentially carrying safety invariants. If Rust gains explicit (un)safe fields, this PR is structured so that it will be fairly easy to thread support for those annotations into the analysis. Notably, this PR removes the `Context` type parameter from `BikeshedIntrinsicFrom`. Most of the files changed by this PR are just UI tests tweaked to accommodate the removed parameter. r? `@compiler-errors`
2024-02-29stash overflowing obligations in fulfilllcnr-12/+75
2024-02-29extract fulfillment err creationlcnr-82/+73
2024-02-29distinguish recursion limit based overflow for diagnosticslcnr-35/+47
also change the number of allowed fixpoint steps to be fixed instead of using the `log` of the total recursion depth.
2024-02-28Add `f16` and `f128` to `rustc_type_ir::FloatTy` and `rustc_abi::Primitive`Trevor Gross-1/+3
Make changes necessary to support these types in the compiler.
2024-02-27Add a couple helpers, make return types less confusingMichael Goulet-116/+172
2024-02-27Support `{async closure}: Fn` in new solverMichael Goulet-1/+73
2024-02-27safe transmute: revise safety analysisJack Wrenn-4/+1
Migrate to a simplified safety analysis that does not use visibility. Closes https://github.com/rust-lang/project-safe-transmute/issues/15
2024-02-26consider placeholders in `fn term_is_fully_unconstrained`lcnr-37/+49
2024-02-26always emit `AliasRelate` goals when relating aliaseslcnr-219/+232
Add `StructurallyRelateAliases` to allow instantiating infer vars with rigid aliases. Change `instantiate_query_response` to be infallible in the new solver. This requires canonicalization to not hide any information used by the query, so weaken universe compression. It also modifies `term_is_fully_unconstrained` to allow region inference variables in a higher universe.
2024-02-26add additional logginglcnr-1/+7
2024-02-22Auto merge of #119989 - lcnr:sub_relations-bye-bye, r=compiler-errorsbors-3/+7
remove `sub_relations` from the `InferCtxt` While doing so, I tried to remove the `delay_span_bug` in `rematch_impl` again, which lead me to discover another `freshen` bug, fixing that one in the second commit. See commit descriptions for the reasoning behind each change. r? `@compiler-errors`
2024-02-22Rollup merge of #120598 - compiler-errors:no-rigid-check, r=lcnrMatthias Krüger-115/+1
No need to `validate_alias_bound_self_from_param_env` in `assemble_alias_bound_candidates` We already fully normalize the self type before we reach `assemble_alias_bound_candidates`, so there's no reason to double check that a projection is truly rigid by checking param-env bounds. I think this is also blocked on us making sure to always normalize opaques: #120549. r? lcnr
2024-02-22overflow errors: change source to a concrete enumlcnr-3/+7
2024-02-21Rollup merge of #121359 - lcnr:typesystem-cleanup, r=compiler-errorsLeón Orell Valerian Liehr-63/+62
miscellaneous type system improvements see review comments for rationale r? `@compiler-errors`
2024-02-20some type system cleanuplcnr-63/+62
2024-02-20Simply do not ICEMichael Goulet-1/+4
2024-02-19split `project` into multiple fileslcnr-3/+2
2024-02-17Rollup merge of #121193 - compiler-errors:coherence-fulfillment, r=lcnrMatthias Krüger-3/+5
Use fulfillment in next trait solver coherence Use fulfillment in the new trait solver's `impl_intersection_has_impossible_obligation` routine. This means that inference that falls out of processing other obligations can influence whether we can determine if an obligation is impossible to satisfy. See the committed test. This should be completely sound, since evaluation and fulfillment both respect intercrate mode equally. We run the risk of breaking coherence later if we were to change the rules of fulfillment and/or inference during coherence, but this is a problem which affects evaluation, as nested obligations from a trait goal are processed together and can influence each other in the same way. r? lcnr cc #114862 Also changed obligationctxt -> fulfillmentctxt because it feels kind of redundant to use an ocx here. I don't really care enough and can change it back if it really matters much.
2024-02-16Use fulfillment in next trait solver coherenceMichael Goulet-3/+5
2024-02-16Move trait into attr so it's greppableMichael Goulet-8/+8
2024-02-16Use extension trait deriveMichael Goulet-33/+7
2024-02-15Consider principal trait ref's auto-trait super-traits in dyn upcastingMichael Goulet-8/+15
2024-02-13Rollup merge of #121047 - compiler-errors:default-impls, r=lcnrMatthias Krüger-0/+14
Do not assemble candidates for default impls There is no reason (as far as I can tell?) that we should assemble an impl candidate for a default impl. This candidate itself does not prove that the impl holds, and any time that it *does* hold, there will be a more specializing non-default impl that also is assembled. This is because `default impl<T> Foo for T {}` actually expands to `impl<T> Foo for T where T: Foo {}`. The only way to satisfy that where clause (without coinduction) is via *another* implementation that does hold -- precisely an impl that specializes it. This should fix the specialization related regressions for #116494. That should lead to one root crate regression that doesn't have to do with specialization, which I think we can regress. r? lcnr cc ``@rust-lang/types`` cc #31844
2024-02-13Do not assemble candidates for default implsMichael Goulet-0/+14
2024-02-13Rollup merge of #120549 - lcnr:errs-showcase, r=compiler-errorsMatthias Krüger-179/+81
modify alias-relate to also normalize ambiguous opaques allows a bunch of further cleanups and generally simplifies the type system. To handle https://github.com/rust-lang/trait-system-refactor-initiative/issues/8 we'll have to add a some additional complexity to the `(Alias, Infer)` branches in alias-relate, so removing the opaque type special case here is really valuable. It does worsen `deduce_closure_signature` and friends even more as they now receive an inference variable which is only constrained via an `AliasRelate` goal. These probably have to look into alias relate goals somehow. Leaving that for a future PR as this is something we'll have to tackle regardless. r? `@compiler-errors`
2024-02-13use alias-relate to structurally normalize in the solverlcnr-92/+75
2024-02-13also try to normalize opaque types in alias-relatelcnr-97/+16
with this, alias-relate treats all aliases the same way and it can be used for structural normalization.
2024-02-13Auto merge of #120919 - oli-obk:impl_polarity, r=compiler-errorsbors-4/+7
Merge `impl_polarity` and `impl_trait_ref` queries Hopefully this is perf neutral. I want to finish https://github.com/rust-lang/rust/pull/120835 and stop using the HIR in `coherent_trait`, which should then give us a perf improvement.
2024-02-12Rollup merge of #120958 - ShoyuVanilla:remove-subst, r=oli-obkMatthias Krüger-21/+24
Dejargonize `subst` In favor of #110793, replace almost every occurence of `subst` and `substitution` from rustc codes, but they still remains in subtrees under `src/tools/` like clippy and test codes (I'd like to replace them after this)
2024-02-12Stop calling `impl_polarity` when `impl_trait_ref` was also calledOli Scherer-4/+7
2024-02-12Dejargnonize substShoyu Vanilla-21/+24
2024-02-10Gracefully handle non-WF alias in assemble_alias_bound_candidates_recurMichael Goulet-2/+6
2024-02-10Auto merge of #120712 - compiler-errors:async-closures-harmonize, r=oli-obkbors-55/+123
Harmonize `AsyncFn` implementations, make async closures conditionally impl `Fn*` traits This PR implements several changes to the built-in and libcore-provided implementations of `Fn*` and `AsyncFn*` to address two problems: 1. async closures do not implement the `Fn*` family traits, leading to breakage: https://crater-reports.s3.amazonaws.com/pr-120361/index.html 2. *references* to async closures do not implement `AsyncFn*`, as a consequence of the existing blanket impls of the shape `AsyncFn for F where F: Fn, F::Output: Future`. In order to fix (1.), we implement `Fn` traits appropriately for async closures. It turns out that async closures can: * always implement `FnOnce`, meaning that they're drop-in compatible with `FnOnce`-bound combinators like `Option::map`. * conditionally implement `Fn`/`FnMut` if they have no captures, which means that existing usages of async closures should *probably* work without breakage (crater checking this: https://github.com/rust-lang/rust/pull/120712#issuecomment-1930587805). In order to fix (2.), we make all of the built-in callables implement `AsyncFn*` via built-in impls, and instead adjust the blanket impls for `AsyncFn*` provided by libcore to match the blanket impls for `Fn*`.
2024-02-10Rollup merge of #120584 - compiler-errors:u, r=lcnrMatthias Krüger-9/+62
For a rigid projection, recursively look at the self type's item bounds to fix the `associated_type_bounds` feature Given a deeply nested rigid projection like `<<<T as Trait1>::Assoc1 as Trait2>::Assoc2 as Trait3>::Assoc3`, this PR adjusts both trait solvers to look at the item bounds for all of `Assoc3`, `Assoc2`, and `Assoc1` in order to satisfy a goal. We do this because the item bounds for projections may contain relevant bounds for *other* nested projections when the `associated_type_bounds` (ATB) feature is enabled. For example: ```rust #![feature(associated_type_bounds)] trait Trait1 { type Assoc1: Trait2<Assoc2: Foo>; // Item bounds for `Assoc1` are: // `<Self as Trait1>::Assoc1: Trait2` // `<<Self as Trait1>::Assoc1 as Trait2>::Assoc2: Foo` } trait Trait2 { type Assoc2; } trait Foo {} fn hello<T: Trait1>(x: <<T as Trait1>::Assoc1 as Trait2>::Assoc2) { fn is_foo(_: impl Foo) {} is_foo(x); // Currently fails with: // ERROR the trait bound `<<Self as Trait1>::Assoc1 as Trait2>::Assoc2: Foo` is not satisfied } ``` This has been a long-standing place of brokenness for ATBs, and is also part of the reason why ATBs currently desugar so differently in various positions (i.e. sometimes desugaring to param-env bounds, sometimes desugaring to RPITs, etc). For example, in RPIT and TAIT position, `impl Foo<Bar: Baz>` currently desugars to `impl Foo<Bar = impl Baz>` because we do not currently take advantage of these nested item bounds if we desugared them into a single set of item bounds on the opaque. This is obviously both strange and unnecessary if we just take advantage of these bounds as we should. ## Approach This PR repeatedly peels off each projection of a given goal's self type and tries to match its item bounds against a goal, repeating with the self type of the projection. This is pretty straightforward to implement in the new solver, only requiring us to loop on the self type of a rigid projection to discover inner rigid projections, and we also need to introduce an extra probe so we can normalize them. In the old solver, we can do essentially the same thing, however we rely on the fact that projections *should* be normalized already. This is obviously not always the case -- however, in the case that they are not fully normalized, such as a projection which has both infer vars and, we bail out with ambiguity if we hit an infer var for the self type. ## Caveats ⚠️ In the old solver, this has the side-effect of actually stalling some higher-ranked trait goals of the form `for<'a> <?0 as Tr<'a>>: Tr2`. Because we stall them, they no longer are eagerly treated as error -- this cause some existing `known-bug` tests to go from fail -> pass. I'm pretty unconvinced that this is a problem since we make code that we expect to pass in the *new* solver also pass in the *old* solver, though this obviously doesn't solve the *full* problem. ## And then also... We also adjust the desugaring of ATB to always desugar to a regular associated bound, rather than sometimes to an impl Trait **except** for when the ATB is present in a `dyn Trait`. We need to lower `dyn Trait<Assoc: Bar>` to `dyn Trait<Assoc = impl Bar>` because object types need all of their associated types specified. I would also be in favor of splitting out the ATB feature and/or removing support for object types in order to stabilize just the set of positions for which the ATB feature is consistent (i.e. always elaborates to a bound).
2024-02-09Rollup merge of #120836 - lcnr:param-env-hide-impl, r=BoxyUwUMatthias Krüger-46/+72
hide impls if trait bound is proven from env AVERT YOUR EYES `@compiler-errors` fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/76 and https://github.com/rust-lang/trait-system-refactor-initiative/issues/12#issuecomment-1865234925 this is kinda ugly and I hate it, but I wasn't able to think of a cleaner approach for now. I am also unsure whether we have to refine this filtering later on, so by making the change pretty minimal it should be easier to improve going forward. r? `@BoxyUwU`
2024-02-09Rollup merge of #120354 - lukas-code:metadata-normalize, r=lcnrMatthias Krüger-19/+10
improve normalization of `Pointee::Metadata` This PR makes it so that `<Wrapper<Tail> as Pointee>::Metadata` is normalized to `<Tail as Pointee>::Metadata` if we don't know `Wrapper<Tail>: Sized`. With that, the trait solver can prove projection predicates like `<Wrapper<Tail> as Pointee>::Metadata == <Tail as Pointee>::Metadata`, which makes it possible to use the metadata APIs to cast between the tail and the wrapper: ```rust #![feature(ptr_metadata)] use std::ptr::{self, Pointee}; fn cast_same_meta<T: ?Sized, U: ?Sized>(ptr: *const T) -> *const U where T: Pointee<Metadata = <U as Pointee>::Metadata>, { let (thin, meta) = ptr.to_raw_parts(); ptr::from_raw_parts(thin, meta) } struct Wrapper<T: ?Sized>(T); fn cast_to_wrapper<T: ?Sized>(ptr: *const T) -> *const Wrapper<T> { cast_same_meta(ptr) } ``` Previously, this failed to compile: ``` error[E0271]: type mismatch resolving `<Wrapper<T> as Pointee>::Metadata == <T as Pointee>::Metadata` --> src/lib.rs:16:5 | 15 | fn cast_to_wrapper<T: ?Sized>(ptr: *const T) -> *const Wrapper<T> { | - found this type parameter 16 | cast_same_meta(ptr) | ^^^^^^^^^^^^^^ expected `Wrapper<T>`, found type parameter `T` | = note: expected associated type `<Wrapper<T> as Pointee>::Metadata` found associated type `<T as Pointee>::Metadata` = note: an associated type was expected, but a different one was found ``` (Yes, you can already do this with `as` casts. But using functions is so much :sparkles: *safer* :sparkles:, because you can't change the metadata on accident.) --- This PR essentially changes the built-in impls of `Pointee` from this: ```rust // before impl Pointee for u8 { type Metadata = (); } impl Pointee for [u8] { type Metadata = usize; } // ... impl Pointee for Wrapper<u8> { type Metadata = (); } impl Pointee for Wrapper<[u8]> { type Metadata = usize; } // ... // This impl is only selected if `T` is a type parameter or unnormalizable projection or opaque type. fallback impl<T: ?Sized> Pointee for Wrapper<T> where Wrapper<T>: Sized { type Metadata = (); } // This impl is only selected if `T` is a type parameter or unnormalizable projection or opaque type. fallback impl<T /*: Sized */> Pointee for T { type Metadata = (); } ``` to this: ```rust // after impl Pointee for u8 { type Metadata = (); } impl Pointee for [u8] { type Metadata = usize; } // ... impl<T: ?Sized> Pointee for Wrapper<T> { // in the old solver this will instead project to the "deep" tail directly, // e.g. `Wrapper<Wrapper<T>>::Metadata = T::Metadata` type Metadata = <T as Pointee>::Metadata; } // ... // This impl is only selected if `T` is a type parameter or unnormalizable projection or opaque type. fallback impl<T /*: Sized */> Pointee for T { type Metadata = (); } ```
2024-02-09hide impls if trait bound is proven from envlcnr-46/+66
2024-02-09add commentlcnr-0/+6
2024-02-09make it recursiveMichael Goulet-84/+90
2024-02-09For a rigid projection, recursively look at the self type's item boundsMichael Goulet-41/+88
2024-02-08Rollup merge of #120590 - compiler-errors:dead, r=NilstriebMatthias Krüger-20/+1
Remove unused args from functions `#[instrument]` suppresses the unused arguments from a function, *and* suppresses unused methods too! This PR removes things which are only used via `#[instrument]` calls, and fixes some other errors (privacy?) that I will comment inline. It's possible that some of these arguments were being passed in for the purposes of being instrumented, but I am unconvinced by most of them.
2024-02-08reviews + rebaseBoxy-4/+3
2024-02-08rename `instantiate_binder_with_placeholders`Boxy-2/+2
2024-02-08introduce `enter_forall`Boxy-124/+143