about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/solve
AgeCommit message (Collapse)AuthorLines
2023-06-22Migrate item_bounds to ty::ClauseMichael Goulet-7/+9
2023-06-21Rollup merge of #112772 - compiler-errors:clauses-1, r=lcnrNilstrieb-14/+14
Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind` Does two basic things before I put up a more delicate set of PRs (along the lines of #112714, but hopefully much cleaner) that migrate existing usages of `ty::Predicate` to `ty::Clause` (`predicates_of`/`item_bounds`/`ParamEnv::caller_bounds`). 1. Rename `Clause` to `ClauseKind`, so it's parallel with `PredicateKind`. 2. Add a new `Clause` type which is parallel to `Predicate`. * This type exposes `Clause::kind(self) -> Binder<'tcx, ClauseKind<'tcx>>` which is parallel to `Predicate::kind` 😸 The new `Clause` type essentially acts as a newtype wrapper around `Predicate` that asserts that it is specifically a `PredicateKind::Clause`. Turns out from experimentation[^1] that this is not negative performance-wise, which is wonderful, since this a much simpler design than something that requires encoding the discriminant into the alignment bits of a predicate kind, or something else like that... r? ``@lcnr`` or ``@oli-obk`` [^1]: https://github.com/rust-lang/rust/pull/112714#issuecomment-1595653910
2023-06-20Auto merge of #112835 - lcnr:proof-tree-nits, r=BoxyUwUbors-287/+298
proof tree nits r? `@BoxyUwU`
2023-06-20inspect nitslcnr-147/+158
2023-06-20cleanup importslcnr-13/+8
2023-06-20split probe into 2 functions for better readabilitylcnr-127/+132
2023-06-20Auto merge of #112320 - compiler-errors:do-not-impl-via-obj, r=lcnrbors-1/+5
Add `implement_via_object` to `rustc_deny_explicit_impl` to control object candidate assembly Some built-in traits are special, since they are used to prove facts about the program that are important for later phases of compilation such as codegen and CTFE. For example, the `Unsize` trait is used to assert to the compiler that we are able to unsize a type into another type. It doesn't have any methods because it doesn't actually *instruct* the compiler how to do this unsizing, but this is later used (alongside an exhaustive match of combinations of unsizeable types) during codegen to generate unsize coercion code. Due to this, these built-in traits are incompatible with the type erasure provided by object types. For example, the existence of `dyn Unsize<T>` does not mean that the compiler is able to unsize `Box<dyn Unsize<T>>` into `Box<T>`, since `Unsize` is a *witness* to the fact that a type can be unsized, and it doesn't actually encode that unsizing operation in its vtable as mentioned above. The old trait solver gets around this fact by having complex control flow that never considers object bounds for certain built-in traits: https://github.com/rust-lang/rust/blob/2f896da247e0ee8f0bef7cd7c54cfbea255b9f68/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs#L61-L132 However, candidate assembly in the new solver is much more lovely, and I'd hate to add this list of opt-out cases into the new solver. Instead of maintaining this complex and hard-coded control flow, instead we can make this a property of the trait via a built-in attribute. We already have such a build attribute that's applied to every single trait that we care about: `rustc_deny_explicit_impl`. This PR adds `implement_via_object` as a meta-item to that attribute that allows us to opt a trait out of object-bound candidate assembly as well. r? `@lcnr`
2023-06-20Add rustc_do_not_implement_via_objectMichael Goulet-1/+5
2023-06-19Fully fledged Clause typeMichael Goulet-6/+6
2023-06-19s/Clause/ClauseKindMichael Goulet-14/+14
2023-06-19Don't consider TAIT normalizable to hidden ty if it would result in ↵Michael Goulet-8/+29
impossible item bounds
2023-06-19create module so that RUSTC_LOG can filter to just proof treesBoxy-1/+9
2023-06-19allow caller to force proof tree generationBoxy-72/+89
2023-06-19show normalizes-to hack and response instantiation goalsBoxy-16/+43
2023-06-19introduce a separate set of types for finalized proof treesBoxy-160/+296
2023-06-19dont use a traitBoxy-139/+116
2023-06-19say what kind of cache hitBoxy-8/+14
2023-06-19add -Z flagBoxy-3/+11
2023-06-19initial info dumpBoxy-406/+763
2023-06-17Move ConstEvaluatable to ClauseMichael Goulet-2/+1
2023-06-17Move WF goal to clauseMichael Goulet-2/+1
2023-06-17Auto merge of #108860 - oli-obk:tait_alias, r=compiler-errorsbors-3/+25
Add `AliasKind::Weak` for type aliases. `type Foo<T: Debug> = Bar<T>;` does not check `T: Debug` at use sites of `Foo<NotDebug>`, because in contrast to a ```rust trait Identity { type Identity; } impl<T: Debug> Identity for T { type Identity = T; } <NotDebug as Identity>::Identity ``` type aliases do not exist in the type system, but are expanded to their aliased type immediately when going from HIR to the type layer. Similarly: * a private type alias for a public type is a completely fine thing, even though it makes it a bit hard to write out complex times sometimes * rustdoc expands the type alias, even though often times users use them for documentation purposes * diagnostics show the expanded type, which is confusing if the user wrote a type alias and the diagnostic talks about another type that they don't know about. For type alias impl trait, these issues do not actually apply in most cases, but sometimes you have a type alias impl trait like `type Foo<T: Debug> = (impl Debug, Bar<T>);`, which only really checks it for `impl Debug`, but by accident prevents `Bar<T>` from only being instantiated after proving `T: Debug`. This PR makes sure that we always check these bounds explicitly and don't rely on an implementation accident. To not break all the type aliases out there, we only use it when the type alias contains an opaque type. We can decide to do this for all type aliases over an edition. Or we can later extend this to more types if we figure out the back-compat concerns with suddenly checking such bounds. As a side effect, easily allows fixing https://github.com/rust-lang/rust/issues/108617, which I did. fixes https://github.com/rust-lang/rust/issues/108617
2023-06-16Rollup merge of #112665 - compiler-errors:assumption-takes-clause, r=lcnrMichael Goulet-26/+32
Make assumption functions in new solver take `Binder<'tcx, Clause<'tcx>>` We just use an if-let to match on an optional clause at all the places where we transition from `Predicate` -> `Clause`, but I assume that when things like item-bounds and param-env start to only store `Clause`s then those can just be trivially dropped. r? ``@lcnr``
2023-06-16Add `AliasKind::Weak` for type aliases.Oli Scherer-3/+25
Only use it when the type alias contains an opaque type. Also does wf-checking on such type aliases.
2023-06-16Rollup merge of #112443 - ↵Dylan DPC-3/+23
compiler-errors:next-solver-opportunistically-resolve-regions, r=lcnr Opportunistically resolve regions in new solver Use `opportunistic_resolve_var` during canonicalization to collapse some regions. We have to start using `CanonicalVarValues::is_identity_modulo_regions`. We also have to modify that function to consider responses like `['static, ^0, '^1, ^2]` to be an "identity" response, since because we opportunistically resolve regions, there's no longer a 1:1 mapping between canonical var values and bound var indices in the response... There's one nasty side-effect -- one test (`tests/ui/dyn-star/param-env-infer.rs`) starts to ICE because the certainty goes from `Yes` to `Maybe(Overflow)`... Not exactly sure why, though? Putting this up for discussion/investigation. r? ```@lcnr```
2023-06-15Make assumption functions in new solver take clauseMichael Goulet-26/+32
2023-06-14Auto merge of #110662 - bryangarza:safe-transmute-reference-types, ↵bors-5/+3
r=compiler-errors Safe Transmute: Enable handling references This patch enables support for references in Safe Transmute, by generating nested obligations during trait selection. Specifically, when we call `confirm_transmutability_candidate(...)`, we now recursively traverse the `rustc_transmute::Answer` tree and create obligations for all the `Answer` variants, some of which include multiple nested `Answer`s.
2023-06-13opportunistically resolve regionsMichael Goulet-3/+23
2023-06-12Safe Transmute: Refactor error handling and Answer typeBryan Garza-5/+3
- Create `Answer` type that is not just a type alias of `Result` - Remove a usage of `map_layouts` to make the code easier to read - Don't hide errors related to Unknown Layout when computing transmutability
2023-06-12update commentlcnr-1/+1
2023-06-11Auto merge of #112466 - lcnr:opaque-type-cleanup, r=compiler-errorsbors-35/+46
opaque type cleanup the commits are pretty self-contained. r? `@compiler-errors` cc `@oli-obk`
2023-06-09split opaque type handling in new solverlcnr-35/+46
be more explicit in where we only add new hidden types and where we also have to deal with item bounds.
2023-06-08deduplicate identical region constraintsMichael Goulet-1/+5
2023-06-07Rollup merge of #112122 - compiler-errors:next-coherence, r=lcnrDylan DPC-0/+1
Add `-Ztrait-solver=next-coherence` Flag that conditionally uses the trait solver *only* during coherence, for more testing and/or eventual partial-migration onto the trait solver (in the medium- to long-term). * This still uses the selection context in some of the coherence methods I think, so it's not "complete". Putting this up for review and/or for further work in-tree. * I probably need to spend a bit more time making sure that we don't sneakily create any other infcx's during coherence that also need the new solver enabled. r? `@lcnr`
2023-06-06Fall back to bidirectional normalizes-to if no subst-eq in alias-eq goalMichael Goulet-23/+72
2023-06-06Move alias-relate to its own moduleMichael Goulet-136/+147
2023-06-06New trait solver is a property of inference contextMichael Goulet-0/+1
2023-06-02Rollup merge of #112223 - compiler-errors:new-solver-auto-proj, r=BoxyUwUMichael Goulet-2/+6
Don't ICE in new solver when auto traits have associated types People can write malformed auto traits, and that shouldn't cause the new solver to ICE
2023-06-02Elaborate comment, make sure we do normalizes-to hack eventually for IATs, ↵Michael Goulet-26/+29
don't partially support const projection for impls
2023-06-02No const equate in new solverMichael Goulet-13/+7
2023-06-02Normalize anon consts in new solverMichael Goulet-17/+64
2023-06-02Don't ICE in new solver when auto traits have associated typesMichael Goulet-2/+6
2023-05-30update universe used by the leak checklcnr-1/+3
2023-05-30add the leak check to the new solverlcnr-0/+5
2023-05-29Rename `tcx.mk_re_*` => `Region::new_*`Maybe Waffle-2/+2
2023-05-28Make EarlyBinder's inner value private; and fix all of the resulting errorsKyle Matsuda-5/+1
2023-05-26remove unnecessary `.ok()` callslcnr-6/+14
2023-05-26do not prefer substs relate during coherencelcnr-3/+11
2023-05-25Match on both reveal and solver mode at the same timeMichael Goulet-41/+38
2023-05-25Add InferCtxt::register_hidden_type_in_new_solverMichael Goulet-40/+24