or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
non-fatal overflow in the new solver
this is a collection of notes for the final overflow doc
The new solver should avoid hangs as much as possible. It must consider constraints from overflowing branches because of https://github.com/rust-lang/trait-system-refactor-initiative/issues/70.
Overflow can happen in multiple places:
try_normalize_ty
try_evaluate_added_goals
The main concern with non-fatal overflow is how we should handle exponential blowup. This can be caused in multiple different ways yet again:
more complex overflow issues
These blowup and overflow sources can be combined for even more fun.
solver fixpoint + try_evaluate_added_goals
https://github.com/rust-lang/rust/pull/118774
solver cycle fixpoint at each level + multiple nested goals
solver cycle fixpoint at each level + multiple candidates
overflow in
try_evaluate_added_goals
and anything elseRerunning overflowing goals after applying their constraints very easily result in hangs, because we recompute the overflowing goal at each loop, increasing the size of the inferred type even more, e.g:
ui/traits/new-solver/overflow/exponential-trait-goals.rs
This also results in unstable results. Stopping to apply inference constraints because of overflow allows the solver to make additional progress the next time the goal is computed.
assemble_candidates_after_normalizing_self_ty
andtry_normalize_ty
blowupFor cyclic projections, normalizing the self type results in
recursion_depth
nestedProjection(Alias, ?new_infer)
goals.?new_infer
gets instantiated asAlias
which (due to the way the current impl is set up, ends up resulting in a nestedAliasRelate(Alias, Alias)
goal, which again normalizes the alias resulting inrecursion_depth
many nested goals.This results in nested alias relate goals because when generalizing, the generalized types has no unresolved inference variables while the original one does, preventing the structural eq fast path from firing when equating at the end of
CombineFields::instantiate
. The following diff prevents that overflowrandom thoughts and summary
try_evaluate_added_goals
causes other overflow to very quickly result in hangs. Overflowing nested goals have to be heavily penalized or avoided.new idea
try_evaluate_added_goals
and avoid evaluating them in following evaluationscache usage of the new solver
current implementation (without dependencies) as of 2023.12.04.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →IDEA: Learning from CTFE
Trait solving has similar constraints to CTFE. We can use a similar approach to CTFE to avoid hangs in a backwards compatible way.
Have a simple counter in the trait solver, which is incremented whenever we evaluate a nested goal. If that counter hits some arbitrary limit, we emit a
deny
by default lint telling the user that the solver seems to be hanging due to their code. If that lint results in an error (i.e. has not been changed to allow/warn), we abort compilation.If it has been allowed or changed to warn, we repeatedly emit a warning with some exponential backoff.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →typenum
has 95000 uncached goal evaluations in less than a second.tests/ui/traits/new-solver/cycles/coinduction/fixpoint-exponential-growth.rs
hangs with less than 700 uncached goal evaluations- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →The time needed to evaluate a single goal can differ widely depending on the amount and size of inference constraints from nested goals. However, we can combine this counter with a size check of constraints, or include the size of constraints when incrementing the counter.
IDEA: split "overflow" and "recursion limit based overflow"
Only yeet constraints from recursion limit based overflow. This does not avoid the hang in
tests/ui/traits/new-solver/cycles/coinduction/fixpoint-exponential-growth.rs
.Many crates depend on the "overflow project where bounds" behavior
https://github.com/rust-lang/trait-system-refactor-initiative/issues/70 may just be acceptable breakage. It may be very positive for perf, at least doing it for recursion limit based overflow.
https://github.com/rust-lang/rust/issues/90662 was originally caused by only causing this pattern to error for global goals (if it otherwise cycles), this broke https://github.com/AzureMarker/shaku. It feels likely that always doing so is too impactful.
IDEA: checking the size of the var_values constraints
When canonicalizing a response, check the size of the
var_values
and discard them if they grow too large, resulting in overflow.This can result in bistable cycle fixpoint computations, but that seems alright.
TODO: impl header eq constraints old solver
Write tests where we rely on these constraints both for Projection and Trait goals, nested goals either resulting in inductive cycle or hitting the recurison limit (should also be fine if there's just a single candidate).
also write tests where we rely on these constraints from a nested goal. So we need the impl header eq constraints of a goal from the where-bounds.
QUESTION: Can we delay stabilizing our non-fatal overflow behavior
I personally think it is acceptable to delay the stabilization of a "ready" implementation of
-Ztrait-solver=next-coherence
to collect more data while working on full-Ztrait-solver=next
. We should still publish a blogpost asking for testing and stating that it is ready for stabilization.We cannot completly avoid non-fatal overflow in
Ztrait-solver=next-coherence
astypenum
should continue to compile. We could emit adeny
-by default lint when people depend on our current overflow handling. This lint would hit quite a few crates however, so it's not ideal.There's also the question of whether and where to drop constraints from overflow. If this behavior should affect non-recursion depth based overflow, e.g. inductive cycle fixpoints, then we either have to pretty much decide on that behavior already.
Advantages of stabilizing
-Ztrait-solver=next-coherence