You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ConstraintSystem] New "stable" disjunction selection algorithm
Prelude.
The core idea behind `shrink` is simple - reduce overload sets via
a bottom-up walk'n'solve that would utilize previously discovered
solutions along the way. This helps in some circumstances but requires
rollbacks and AST modification (if choices produced by previous steps
fail to produce solutions higher up). For some expressions, especially
ones with multiple generic overload sets, `shrink` is actively harmful
because it would never be able to produce useful results.
The Algorithm.
These changes integrate core idea of local information propagation
from `shrink` into the disjunction selection algorithm itself.
The algorithm itself is as follows - at the beginning use existing
selection algorithm (based on favoring, active choices, etc.) to
select the first disjunction to attempt, and push it to the stack
of "selected" disjunctions; next time solver requests a disjunction,
use the last selected one to pick the closest disjunction to it in
the AST order preferring parents over children.
For example:
```
+
/ \
* Float(<some variable e.g. `r` = 10))
/ \
exp Float(1.0)
|
2.0
```
If solver starts by picking `Float(r)` first, it would then
attempt `+`, `exp` in that order. If it did pick `Float(1.0)`
then, the sequence is `*`, `+` and finally `exp`.
Since the main idea here to is keep everything as local as possible
along a given path, that means special handling for closures and tuples:
- Closures: if last disjunction is a call with a trailing closure argument,
and such argument is resolved (constraint are generate for the body) -
use selection algorithm to peek next disjunction from the body of the
closure, and solve everything inside before moving to the next member
in the chain (if any). This helps with linked member expressions e.g.
`.map { ... }.filter { ... }.reduce { ... }`;
- Tuples: The idea here is to keep solving local to a current element
until it runs out of disjunction, and then use selection algorithm to
peek from the pool of disjunctions associated with other elements of
the tuple.
Resolves: SR-10130
Resolves: rdar://48992848
Resolves: rdar://23682605
Resolves: rdar://46713933
0 commit comments