Commit Graph

93 Commits

Author SHA1 Message Date
Matthias Krüger cb1d80d1e5
Rollup merge of #130273 - lcnr:overflow-no-constraints, r=compiler-errors
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 🤷

It's simpler and nicer to debug to eagerly discard constraints inside of the query itself.

r? ``@compiler-errors``
2024-09-12 19:03:43 +02:00
lcnr 675c99f4d5 more eagerly discard constraints on overflow 2024-09-12 14:32:44 +02:00
Stuart Cook 57020e0f8c
Rollup merge of #130250 - compiler-errors:useless-conversion, r=jieyouxu
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-12 20:37:17 +10:00
Michael Goulet 6d064295c8 clippy::useless_conversion 2024-09-11 17:52:53 -04:00
Michael Goulet 954419aab0 Simplify some nested if statements 2024-09-11 13:45:23 -04:00
bors 26b5599e4d Auto merge of #128776 - Bryanskiy:deep-reject-ctxt, r=lcnr
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-06 19:50:48 +00:00
lcnr 6188aae369 do not attempt to prove unknowable goals 2024-09-03 08:35:23 +02:00
Matthias Krüger 1d9eb9df7f
Rollup merge of #129877 - Sajjon:sajjon_fix_typos_batch_2, r=fee1-dead
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-02 22:35:21 +02:00
Bryanskiy c51953f4d8 Use `DeepRejectCtxt` to quickly reject `ParamEnv` candidates 2024-09-02 19:59:18 +03:00
Alexander Cyon 00de006f22
chore: Fix typos in 'compiler' (batch 2) 2024-09-02 07:50:22 +02:00
Michael Goulet 91854453f2 Deny imports of rustc_type_ir::inherent outside of type ir + new trait solver 2024-09-01 12:16:18 -04:00
Nicholas Nethercote 46ea798a94 Add `warn(unreachable_pub)` to `rustc_next_trait_solver`. 2024-08-29 20:13:06 +10:00
Jack Wrenn 1ad218f3af safe transmute: Rename `BikeshedIntrinsicFrom` to `TransmuteFrom`
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-27 14:05:54 +00:00
许杰友 Jieyou Xu (Joe) 59ad2aec49
Rollup merge of #128828 - lcnr:search-graph-11, r=compiler-errors
`-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-14 21:43:07 +08:00
lcnr 0aa17a4c4d implement a performant and fuzzed solver cache 2024-08-13 17:33:48 +02:00
lcnr 51338ca0eb expand fuzzing support
this allows us to only sometimes disable the global cache.
2024-08-12 10:33:04 +02:00
lcnr 7b86c98068 do not use the global solver cache for proof trees
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-12 10:33:04 +02:00
Nicholas Nethercote 9e95a2b9a5 Remove some unnecessary `skip_binder` calls.
`is_fn_trait_compatible` is defined on both `FnSig` and `Binder<FnSig>`.
2024-08-12 15:20:58 +10:00
Nicholas Nethercote c4717cc9d1 Shrink `TyKind::FnPtr`.
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-09 14:33:25 +10:00
Michael Goulet ec1c424293 Don't implement AsyncFn for FnDef/FnPtr that wouldnt implement Fn 2024-08-08 14:07:31 -04:00
Michael Goulet fa9ae7b9d3 Elaborate supertraits in dyn candidates 2024-08-05 10:03:17 -04:00
Michael Goulet 6a891ec4fe Enforce supertrait outlives obligations hold when confirming impl 2024-08-05 09:55:14 -04:00
Matthias Krüger ae92125a75
Rollup merge of #127574 - lcnr:coherence-check-supertrait, r=compiler-errors
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-30 04:31:54 +02:00
Nicholas Nethercote 84ac80f192 Reformat `use` declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Michael Goulet d5656059a1 Make coroutine-closures possible to be cloned 2024-07-26 12:53:53 -04:00
bors 2f26b2a99a Auto merge of #127042 - GrigorenkoPV:derivative, r=compiler-errors
Switch from `derivative` to `derive-where`

This is a part of the effort to get rid of `syn 1.*` in compiler's dependencies: #109302

Derivative has not been maintained in nearly 3 years[^1]. It also depends on `syn 1.*`.

This PR replaces `derivative` with `derive-where`[^2], a not dead alternative, which uses `syn 2.*`.

A couple of `Debug` formats have changed around the skipped fields[^3], but I doubt this is an issue.

[^1]: https://github.com/mcarton/rust-derivative/issues/117
[^2]: https://lib.rs/crates/derive-where
[^3]: See the changes in `tests/ui`
2024-07-25 22:50:58 +00:00
Michael Goulet 247ad3385c Use dep: for crate dependencies 2024-07-15 12:40:10 -04:00
Pavel Grigorenko 70a11c7ba9 rustc_next_trait_solver: derivative -> derive-where 2024-07-12 21:48:16 +03:00
lcnr 15f770b143 enable fuzzing of `SearchGraph`
fully move it into `rustc_type_ir` and make it
independent of `Interner`.
2024-07-12 06:30:19 -04:00
lcnr fe0bd76a8b elaborate unknowable goals
if a trait is unknowable, but its super trait
is definitely not implemented, then the trait
itself is definitely also not implemented.
2024-07-10 16:16:48 +02:00
Jacob Pratt 64695adbd7
Rollup merge of #127508 - lcnr:search-graph-prep, r=compiler-errors
small search graph refactor

small improvements which shouldn't impact behavior.

r? ``````@compiler-errors``````
2024-07-10 00:37:12 -04:00
lcnr dd175feb25 cycle_participants to nested_goals 2024-07-09 09:51:50 +02:00
lcnr e38109d7f0 use `update_parent_goal` for lazy updates 2024-07-09 09:22:58 +02:00
lcnr 7097dbc50c exhaustively destructure external constraints 2024-07-09 09:10:19 +02:00
许杰友 Jieyou Xu (Joe) ffb93361b4
Rollup merge of #127439 - compiler-errors:uplift-elaborate, r=lcnr
Uplift elaboration into `rustc_type_ir`

Allows us to deduplicate and consolidate elaboration (including these stupid elaboration duplicate fns i added for pretty printing like 3 years ago) so I'm pretty hyped about this change :3

r? lcnr
2024-07-08 13:04:33 +08:00
Michael Goulet 15d16f1cd6 Finish uplifting supertraits 2024-07-07 11:28:01 -04:00
Michael Goulet 66eb346770 Get rid of the redundant elaboration in middle 2024-07-07 11:28:01 -04:00
Michael Goulet 90423a7abb Uplift elaboration 2024-07-07 11:28:01 -04:00
Michael Goulet ab27c2fa77 Get rid of trait_ref_is_knowable from delegate 2024-07-07 11:10:48 -04:00
Michael Goulet a982471e07 Uplift trait_ref_is_knowable and friends 2024-07-07 11:10:32 -04:00
Michael Goulet e5d6a416e8 Uplift PredicateEmittingRelation first 2024-07-06 10:05:49 -04:00
Michael Goulet 27588d1de3 Split SolverDelegate back out from InferCtxtLike 2024-07-05 16:39:39 -04:00
Matthias Krüger 02916a3193
Rollup merge of #127145 - compiler-errors:as_lang_item, r=lcnr
Add `as_lang_item` to `LanguageItems`, new trait solver

Add `as_lang_item` which turns `DefId` into a `TraitSolverLangItem` in the new trait solver, so we can turn the large chain of if statements in `assemble_builtin_impl_candidates` into a match instead.

r? lcnr
2024-07-03 17:26:54 +02:00
Michael Goulet 5a837515f2 Make fn traits into first-class TraitSolverLangItems to avoid needing fn_trait_kind_from_def_id 2024-07-02 16:37:24 -04:00
Michael Goulet a21ba34896 add TyCtxt::as_lang_item, use in new solver 2024-07-02 16:16:52 -04:00
Matthias Krüger 36da46ab98
Rollup merge of #127146 - compiler-errors:fast-reject, r=lcnr
Uplift fast rejection to new solver

Self explanatory.

r? lcnr
2024-07-02 17:47:47 +02:00
Michael Goulet 53db64168f Uplift fast rejection to new solver 2024-06-30 00:27:35 -04:00
bors ba1d7f4a08 Auto merge of #120639 - fee1-dead-contrib:new-effects-desugaring, r=oli-obk
Implement new effects desugaring

cc `@rust-lang/project-const-traits.` Will write down notes once I have finished.

* [x] See if we want `T: Tr` to desugar into `T: Tr, T::Effects: Compat<true>`
* [x] Fix ICEs on `type Assoc: ~const Tr` and `type Assoc<T: ~const Tr>`
* [ ] add types and traits to minicore test
* [ ] update rustc-dev-guide

Fixes #119717
Fixes #123664
Fixes #124857
Fixes #126148
2024-06-29 20:08:10 +00:00
Deadbeef 65a0bee0b7 address review comments 2024-06-28 15:44:20 +00:00
Deadbeef 8b2fac9612 finishing touches, move fixed ICEs to ui tests 2024-06-28 10:57:35 +00:00