summary refs log tree commit diff
path: root/compiler/rustc_next_trait_solver/src
AgeCommit message (Collapse)AuthorLines
2024-10-12Shallowly match opaque key in storageMichael Goulet-43/+42
2024-10-11remove outdated FIXMEslcnr-15/+4
2024-10-10Auto merge of #131263 - compiler-errors:solver-relating, r=lcnrbors-51/+3
Introduce SolverRelating type relation to the new solver Redux of #128744. Splits out relate for the new solver so that implementors don't need to implement it themselves. r? lcnr
2024-10-10impossible obligations check fast pathlcnr-21/+62
2024-10-10Use SolverRelating in favor of TypeRelating in the old solver where possibleMichael Goulet-1/+1
2024-10-10Use SolverRelating in new solverMichael Goulet-0/+2
2024-10-10Uplift super_combineMichael Goulet-50/+0
2024-10-02Auto merge of #130821 - lcnr:nalgebra-hang-2, r=compiler-errorsbors-124/+190
add caching to most type folders, rm region uniquification Fixes the new minimization of the hang in nalgebra and nalgebra itself :3 this is a bit iffy, especially the cache in `TypeRelating`. I believe all the caches are correct, but it definitely adds some non-local complexity in places. The first commit removes region uniquification, reintroducing the ICE from https://github.com/rust-lang/trait-system-refactor-initiative/issues/27. This does not affect coherence and I would like to fix this by introducing OR-region constraints r? `@compiler-errors`
2024-10-02reviewlcnr-12/+17
2024-10-01add caches to multiple type folderslcnr-15/+47
2024-09-30canonicalizer: rm region uniquification, add cachinglcnr-109/+138
2024-09-28Rollup merge of #130866 - compiler-errors:dyn-instantiate-binder, r=lcnrMatthias Krüger-27/+38
Allow instantiating object trait binder when upcasting This PR fixes two bugs (that probably need an FCP). ### We use equality rather than subtyping for upcasting dyn conversions This code should be valid: ```rust #![feature(trait_upcasting)] trait Foo: for<'h> Bar<'h> {} trait Bar<'a> {} fn foo(x: &dyn Foo) { let y: &dyn Bar<'static> = x; } ``` But instead: ``` error[E0308]: mismatched types --> src/lib.rs:7:32 | 7 | let y: &dyn Bar<'static> = x; | ^ one type is more general than the other | = note: expected existential trait ref `for<'h> Bar<'h>` found existential trait ref `Bar<'_>` ``` And so should this: ```rust #![feature(trait_upcasting)] fn foo(x: &dyn for<'h> Fn(&'h ())) { let y: &dyn FnOnce(&'static ()) = x; } ``` But instead: ``` error[E0308]: mismatched types --> src/lib.rs:4:39 | 4 | let y: &dyn FnOnce(&'static ()) = x; | ^ one type is more general than the other | = note: expected existential trait ref `for<'h> FnOnce<(&'h (),)>` found existential trait ref `FnOnce<(&(),)>` ``` Specifically, both of these fail because we use *equality* when comparing the supertrait to the *target* of the unsize goal. For the first example, since our supertrait is `for<'h> Bar<'h>` but our target is `Bar<'static>`, there's a higher-ranked type mismatch even though we *should* be able to instantiate that supertrait binder when upcasting. Similarly for the second example. ### New solver uses equality rather than subtyping for no-op (i.e. non-upcasting) dyn conversions This code should be valid in the new solver, like it is with the old solver: ```rust // -Znext-solver fn foo<'a>(x: &mut for<'h> dyn Fn(&'h ())) { let _: &mut dyn Fn(&'a ()) = x; } ``` But instead: ``` error: lifetime may not live long enough --> <source>:2:11 | 1 | fn foo<'a>(x: &mut dyn for<'h> Fn(&'h ())) { | -- lifetime `'a` defined here 2 | let _: &mut dyn Fn(&'a ()) = x; | ^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` | = note: requirement occurs because of a mutable reference to `dyn Fn(&())` ``` Specifically, this fails because we try to coerce `&mut dyn for<'h> Fn(&'h ())` to `&mut dyn Fn(&'a ())`, which registers an `dyn for<'h> Fn(&'h ()): dyn Fn(&'a ())` goal. This fails because the new solver uses *equating* rather than *subtyping* in `Unsize` goals. This is *mostly* not a problem... You may wonder why the same code passes on the new solver for immutable references: ``` // -Znext-solver fn foo<'a>(x: &dyn Fn(&())) { let _: &dyn Fn(&'a ()) = x; // works } ``` That's because in this case, we first try to coerce via `Unsize`, but due to the leak check the goal fails. Then, later in coercion, we fall back to a simple subtyping operation, which *does* work. Since `&T` is covariant over `T`, but `&mut T` is invariant, that's where the discrepancy between these two examples crops up. --- r? lcnr or reassign :D
2024-09-27Instantiate binders when checking supertrait upcastingMichael Goulet-27/+38
2024-09-26Check allow instantiating object trait binder when upcasting and in new solverMichael Goulet-3/+3
2024-09-25Compiler: Rename "object safe" to "dyn compatible"León Orell Valerian Liehr-8/+8
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-92/+68
2024-09-20add commentlcnr-0/+4
2024-09-20bail if there are too many non-region infer varslcnr-0/+7
2024-09-12Rollup merge of #130273 - lcnr:overflow-no-constraints, r=compiler-errorsMatthias Krüger-26/+22
more eagerly discard constraints on overflow We always discard the results of overflowing goals inside of the trait solver. We previously did so when instantiating the response in `evaluate_goal`. Canonicalizing results only to later discard them is also inefficient :shrug: It's simpler and nicer to debug to eagerly discard constraints inside of the query itself. r? ``@compiler-errors``
2024-09-12more eagerly discard constraints on overflowlcnr-26/+22
2024-09-12Rollup merge of #130250 - compiler-errors:useless-conversion, r=jieyouxuStuart Cook-1/+0
Fix `clippy::useless_conversion` Self-explanatory. Probably the last clippy change I'll actually put up since this is the only other one I've actually seen in the wild.
2024-09-11clippy::useless_conversionMichael Goulet-1/+0
2024-09-11Simplify some nested if statementsMichael Goulet-4/+2
2024-09-06Auto merge of #128776 - Bryanskiy:deep-reject-ctxt, r=lcnrbors-4/+17
Use `DeepRejectCtxt` to quickly reject `ParamEnv` candidates The description is on the [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/.5Basking.20for.20help.5D.20.60DeepRejectCtxt.60.20for.20param.20env.20candidates) r? `@lcnr`
2024-09-03do not attempt to prove unknowable goalslcnr-34/+32
2024-09-02Rollup merge of #129877 - Sajjon:sajjon_fix_typos_batch_2, r=fee1-deadMatthias Krüger-3/+3
chore: Fix typos in 'compiler' (batch 2) Batch 2/3: Fixes typos in `compiler` (See [issue](https://github.com/rust-lang/rust/issues/129874) tracking all PRs with typos fixes)
2024-09-02Use `DeepRejectCtxt` to quickly reject `ParamEnv` candidatesBryanskiy-4/+17
2024-09-02chore: Fix typos in 'compiler' (batch 2)Alexander Cyon-3/+3
2024-09-01Deny imports of rustc_type_ir::inherent outside of type ir + new trait solverMichael Goulet-0/+1
2024-08-29Add `warn(unreachable_pub)` to `rustc_next_trait_solver`.Nicholas Nethercote-26/+37
2024-08-27safe transmute: Rename `BikeshedIntrinsicFrom` to `TransmuteFrom`Jack Wrenn-1/+1
As our implementation of MCP411 nears completion and we begin to solicit testing, it's no longer reasonable to expect testers to type or remember `BikeshedIntrinsicFrom`. The name degrades the ease-of-reading of documentation, and the overall experience of using compiler safe transmute. Tentatively, we'll instead adopt `TransmuteFrom`. This name seems to be the one most likely to be stabilized, after discussion on Zulip [1]. We may want to revisit the ordering of `Src` and `Dst` before stabilization, at which point we'd likely consider `TransmuteInto` or `Transmute`. [1] https://rust-lang.zulipchat.com/#narrow/stream/216762-project-safe-transmute/topic/What.20should.20.60BikeshedIntrinsicFrom.60.20be.20named.3F
2024-08-14Rollup merge of #128828 - lcnr:search-graph-11, r=compiler-errors许杰友 Jieyou Xu (Joe)-114/+58
`-Znext-solver` caching This PR has two major changes while also fixing multiple issues found via fuzzing. The main optimization is the ability to not discard provisional cache entries when popping the highest cycle head the entry depends on. This fixes the hang in Fuchsia with `-Znext-solver=coherence`. It also bails if the result of a fixpoint iteration is ambiguous, even without reaching a fixpoint. This is necessary to avoid exponential blowup if a coinductive cycle results in ambiguity, e.g. due to unknowable candidates in coherence. Updating stack entries pretty much exclusively happens lazily now, so `fn check_invariants` ended up being mostly useless and I've removed it. See https://gist.github.com/lcnr/8de338fdb2685581e17727bbfab0622a for the invariants we would be able to assert with it. For a general overview, see the in-process update of the relevant rustc-dev-guide chapter: https://hackmd.io/1ALkSjKlSCyQG-dVb_PUHw r? ```@compiler-errors```
2024-08-13implement a performant and fuzzed solver cachelcnr-21/+31
2024-08-12expand fuzzing supportlcnr-0/+9
this allows us to only sometimes disable the global cache.
2024-08-12do not use the global solver cache for proof treeslcnr-94/+19
doing so requires overwriting global cache entries and generally adds significant complexity to the solver. This is also only ever done for root goals, so it feels easier to wrap the `evaluate_canonical_goal` in an ordinary query if necessary.
2024-08-12Remove some unnecessary `skip_binder` calls.Nicholas Nethercote-2/+2
`is_fn_trait_compatible` is defined on both `FnSig` and `Binder<FnSig>`.
2024-08-09Shrink `TyKind::FnPtr`.Nicholas Nethercote-9/+10
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI.
2024-08-08Don't implement AsyncFn for FnDef/FnPtr that wouldnt implement FnMichael Goulet-21/+39
2024-08-05Elaborate supertraits in dyn candidatesMichael Goulet-6/+14
2024-08-05Enforce supertrait outlives obligations hold when confirming implMichael Goulet-0/+13
2024-07-30Rollup merge of #127574 - lcnr:coherence-check-supertrait, r=compiler-errorsMatthias Krüger-0/+12
elaborate unknowable goals A reimplemented version of #124532 affecting only the new solver. Always trying to prove super traits ends up causing a fatal overflow error in diesel, so we cannot land this in the old solver. The following test currently does not pass coherence: ```rust trait Super {} trait Sub<T>: Super {} trait Overlap<T> {} impl<T, U: Sub<T>> Overlap<T> for U {} impl<T> Overlap<T> for () {} fn main() {} ``` We check whether `(): Sub<?t>` holds. This stalls with ambiguity as downstream crates may add an impl for `(): Sub<Local>`. However, its super trait bound `(): Super` cannot be implemented downstream, so this one is known not to hold. By trying to prove that all the super bounds of a trait before adding a coherence unknowable candidate, this compiles. This is necessary to prevent breakage from enabling `-Znext-solver=coherence` (#121848), see tests/ui/coherence/super-traits/super-trait-knowable-2.rs for more details. The idea is that while there may be an impl of the trait itself we don't know about, if we're able to prove that a super trait is definitely not implemented, then that impl would also never apply/not be well-formed. This approach is different from #124532 as it allows tests/ui/coherence/super-traits/super-trait-knowable-3.rs to compile. The approach in #124532 only elaborating the root obligations while this approach tries it for all unknowable trait goals. r? `@compiler-errors`
2024-07-29Reformat `use` declarations.Nicholas Nethercote-12/+10
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-26Make coroutine-closures possible to be clonedMichael Goulet-1/+4
2024-07-12rustc_next_trait_solver: derivative -> derive-wherePavel Grigorenko-24/+17
2024-07-12enable fuzzing of `SearchGraph`lcnr-592/+114
fully move it into `rustc_type_ir` and make it independent of `Interner`.
2024-07-10elaborate unknowable goalslcnr-0/+12
if a trait is unknowable, but its super trait is definitely not implemented, then the trait itself is definitely also not implemented.
2024-07-10Rollup merge of #127508 - lcnr:search-graph-prep, r=compiler-errorsJacob Pratt-34/+32
small search graph refactor small improvements which shouldn't impact behavior. r? ``````@compiler-errors``````
2024-07-09cycle_participants to nested_goalslcnr-11/+11
2024-07-09use `update_parent_goal` for lazy updateslcnr-20/+10
2024-07-09exhaustively destructure external constraintslcnr-3/+11