Sema: Associated type inference optimization #71862
Merged
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.
This addresses a performance regression from 83cb420.
In the old associated type inference implementation, we used to fold valid solutions by comparing type witnesses, but this was not correct as described in the commit message there.
After my fix we started to record more valid solutions from the same search space, and this caused a performance regression because we were already doing exponential work.
However in the program in question, each possible choice of witness for a requirement would introduce the same bindings, so there was nothing to gain from trying them all.
Since ranking only compares pairs of witnesses for the same requirement, we can optimize this problem another way: by folding identical terms in a disjunction, but only if all terms are identical, which avoids the correctness issue in the old search strategy.
Fixes rdar://problem/123334433.