Skip to content

Sema: Associated type inference optimization #71862

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 1 commit into from
Feb 24, 2024

Conversation

slavapestov
Copy link
Contributor

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.

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.
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov merged commit 124df8e into swiftlang:main Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant