-
Notifications
You must be signed in to change notification settings - Fork 557
update new trait solver docs #1802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,140 @@ | ||||||
# Invariants of the type system | ||||||
|
||||||
FIXME: This file talks about invariants of the type system as a whole, not only the solver | ||||||
|
||||||
There are a lot of invariants - things the type system guarantees to be true at all times - | ||||||
which are desirable or expected from other languages and type systems. Unfortunately, quite | ||||||
a few of them do not hold in Rust right now. This is either a fundamental to its design or | ||||||
caused by bugs and something that may change in the future. | ||||||
|
||||||
It is important to know about the things you can assume while working on - and with - the | ||||||
type system, so here's an incomplete and inofficial list of invariants of | ||||||
the core type system: | ||||||
|
||||||
- ✅: this invariant mostly holds, with some weird exceptions, you can rely on it outside | ||||||
of these cases | ||||||
- ❌: this invariant does not hold, either due to bugs or by design, you must not rely on | ||||||
it for soundness or have to be incredibly careful when doing so | ||||||
|
||||||
### `wf(X)` implies `wf(normalize(X))` ✅ | ||||||
|
||||||
If a type containing aliases is well-formed, it should also be | ||||||
well-formed after normalizing said aliases. We rely on this as | ||||||
otherwise we would have to re-check for well-formedness for these | ||||||
types. | ||||||
|
||||||
This is invariantunfortunately broken for `<fndef as FnOnce<..>>::Output` due to implied bounds, resulting in [#114936]. | ||||||
|
||||||
### applying inference results from a goal does not change its result ❌ | ||||||
|
||||||
TODO: this invariant is formulated in a weird way and needs to be elaborated. Pretty much: I would like this check to only fail if there's a solver bug: https://github.com/rust-lang/rust/blob/2ffeb4636b4ae376f716dc4378a7efb37632dc2d/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs#L391-L407 | ||||||
|
||||||
If we prove some goal/equate types/whatever, apply the resulting inference constraints, and then redo the original action, the result should be the same. | ||||||
|
||||||
This unfortunately does not hold - at least in the new solver - due to a few annoying reasons. | ||||||
|
||||||
### The trait solver has to be *locally sound* ✅ | ||||||
|
||||||
This means that we must never return *success* for goals for which no `impl` exists. That would | ||||||
mean we assume a trait is implemented even though it is not, which is very likely to result in | ||||||
actual unsoundness. When using `where`-bounds to prove a goal, the `impl` will be provided by the | ||||||
user of the item. | ||||||
|
||||||
This invariant only holds if we check region constraints. As we do not check region constraints | ||||||
during implicit negative overlap check in coherence, this invariant is broken there. As this check | ||||||
relies on *completeness* of the trait solver, it is not able to use the current region constraints | ||||||
check - `InferCtxt::resolve_regions` - as its handling of type outlives goals is incomplete. | ||||||
|
||||||
### Normalization of semantically equal aliases empty environments results in a unique type ✅ | ||||||
|
### Normalization of semantically equal aliases empty environments results in a unique type ✅ | |
### Normalization of semantically equal aliases in empty environments results in a unique type ✅ |
lcnr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
lcnr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should distinguish "by design" or "due to bugs".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to distinguish yeah, maybe we can do that as a followup.