Skip to content

[CodeComplete] Compute type relations for global cached results (again) #41632

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

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Mar 2, 2022

Re-applies #41000, undoing the revert in #41627.

The fix was to use target-swift-ide-test instead of swift-ide-test in the test case (a4c18ed).

ahoppen added 4 commits March 2, 2022 23:13
Computing the type relation for every item in the code completion cache is way to expensive (~4x slowdown for global completion that imports `SwiftUI`). Instead, compute a type’s supertypes (protocol conformances and superclasses) once and write their USRs to the cache. To compute a type relation we can then check if the contextual type is in the completion item’s supertypes.

This reduces the overhead of computing the type relations (again global completion that imports `SwiftUI`) to ~6% – measured by instructions executed.

Technically, we might miss some conversions like
- retroactive conformances inside another module (because we can’t cache them if that other module isn’t imported)
- complex generic conversions (just too complicated to model using USRs)

Because of this, we never report an `unrelated` type relation for global items but always default to `unknown`.

But I believe this change covers the most common cases and is a good tradeoff between accuracy and performance.

rdar://83846531
Sendable conformances are lazily synthesized as they are needed by the compiler. Depending on whether we checked whether a type conforms to Sendable before constructing the USRBasedType, we get different results for its conformance, causing assertion failures. For now, always ignore the Sendable conformance. We need to come up with a better solution for this problem in the future.
…based types

Previously, for every type, we were reconstructing its entire supertype hierarchy as USRBasedTypes before checking the already computed USRBasedTypes. This lead to unneccary duplicated work.
@ahoppen ahoppen requested review from rintaro and hamishknight March 2, 2022 22:15
@ahoppen
Copy link
Member Author

ahoppen commented Mar 2, 2022

@swift-ci Please test

@ahoppen ahoppen changed the title Pr/compute global type relations again [CodeComplete] Compute type relations for global cached results (again) Mar 2, 2022
@ahoppen ahoppen merged commit f3119b8 into swiftlang:main Mar 3, 2022
@ahoppen ahoppen deleted the pr/compute-global-type-relations-again branch March 3, 2022 08:19
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.

3 participants