-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
[CSSolver] Implementation of disjunction choice favoring algorithm #63585
base: main
Are you sure you want to change the base?
Conversation
@swift-ci please test source compatibility |
b45df09
to
2a3a206
Compare
@swift-ci please test source compatibility |
Please test with following pull request: @swift-ci please test source compatibility |
Please test with following pull request: @swift-ci please test source compatibility |
Please test with following pull request: @swift-ci please test compiler performance |
1 similar comment
Please test with following pull request: @swift-ci please test compiler performance |
@swift-ci please test source compatibility |
@swift-ci please test source compatibility |
@swift-ci please test source compatibility |
@swift-ci please test compiler performance |
Summary for main fullRegressions found (see below) Debug-batchdebug-batch briefRegressed (0)
Improved (1)
Unchanged (delta < 1.0% or delta < 100.0ms) (1)
debug-batch detailedRegressed (7)
Improved (18)
Unchanged (delta < 1.0% or delta < 100.0ms) (285)
Releaserelease briefRegressed (0)
Improved (1)
Unchanged (delta < 1.0% or delta < 100.0ms) (1)
release detailedRegressed (6)
Improved (17)
Unchanged (delta < 1.0% or delta < 100.0ms) (287)
|
Slightly better - 60% reduction in |
@swift-ci please test source compatibility |
1 similar comment
@swift-ci please test source compatibility |
@swift-ci please test compiler performance |
@swift-ci please test source compatibility release |
Summary for main fullRegressions found (see below) Debug-batchdebug-batch briefRegressed (0)
Improved (1)
Unchanged (delta < 1.0% or delta < 100.0ms) (1)
debug-batch detailedRegressed (13)
Improved (19)
Unchanged (delta < 1.0% or delta < 100.0ms) (278)
Releaserelease briefRegressed (1)
Improved (0)
Unchanged (delta < 1.0% or delta < 100.0ms) (1)
release detailedRegressed (25)
Improved (14)
Unchanged (delta < 1.0% or delta < 100.0ms) (271)
|
@swift-ci please test source compatibility |
1 similar comment
@swift-ci please test source compatibility |
@swift-ci please build toolchain macOS |
1 similar comment
@swift-ci please build toolchain macOS |
@swift-ci please test source compatibility |
@swift-ci please test source compatibility |
@swift-ci please test source compatibility |
…lgorithm This algorithm attempts to ensure that the solver always picks a disjunction it knows the most about given the previously deduced type information. For example in chains of operators like: `let _: (Double) -> Void = { 1 * 2 + $0 - 5 }` The solver is going to start from `2 + $0` because `$0` is known to be `Double` and then proceed to `1 * ...` and only after that to `... - 5`. The algorithm is pretty simple: - Collect "candidate" types for each argument - If argument is bound then the set going to be represented by just one type - Otherwise: - Collect all the possible bindings - Add default literal type (if any) - Collect "candidate" types for result - For each disjunction in the current scope: - Compute a favoring score for each viable* overload choice: - Compute score for each parameter: - Match parameter flags to argument flags - Match parameter types to a set of candidate argument types - If it's an exact match - Concrete type: score = 1.0 - Literal default: score = 0.3 - Highest scored candidate type wins. - If none of the candidates match and they are all non-literal remove overload choice from consideration. - Average the score by dividing it by the number of parameters to avoid disfavoring disjunctions with fewer arguments. - Match result type to a set of candidates; add 1 to the score if one of the candidate types matches exactly. - The best choice score becomes a disjunction score - Compute disjunction scores for all of the disjunctions in scope. - Pick disjunction with the best overall score and favor choices with the best local candidate scores (if some candidates have equal scores). - Viable overloads include: - non-disfavored - non-disabled - available - non-generic (with current exception to SIMD)
…ent is SIMD<N> type
…ken(s) in argument position
…eter relationships This helps to find defaulted parameter positions as well.
…of no-impact conversions Candidate is viable (with some score) if: - Candidate is exactly equal to a parameter type - Candidate type differs from a parameter type only in optionality - Parameter is a generic parameter type and all conformances are matched by a candidate type - Candidate tuples matches a parameter tuple on arity - Candidate is an `Array<T>` and parameter is an `Unsafe*Pointer` - Candidate is a subclass of a parameter class type - Candidate is a concrete type and parameter is its existential value (except Any)
Since old favoring mechanism has been removed this is dead code now because nothing is going to equate disjunction constraints.
Dependent members just like generic parameter types could have associated protocol conformances which give us a glimpse into whether arguments could possibly match.
…:lookupConformance`
Since erasure of a concrete type into an existential value yields score of 1, we need to bump the score in cases where a type passed to a generic parameter satisfies all of its protocol conformance requirements and that parameter represents an opaque type.
@swift-ci please build toolchain macOS |
This algorithm attempts to ensure that the solver always picks a disjunction
it knows the most about given the previously deduced type information.
For example in chains of operators like:
let _: (Double) -> Void = { 1 * 2 + $0 - 5 }
The solver is going to start from
2 + $0
because$0
is known to beDouble
andthen proceed to
1 * ...
and only after that to... - 5
.The algorithm is pretty simple:
Resolves: rdar://60347805
Resolves: rdar://74387235
Resolves: rdar://78845822
Resolves: rdar://23682605
Resolves: rdar://18994321
Resolves: rdar://107263264