Skip to content

[SourceKit] Workaround a bug that parameterized protocols without 'any' cannot be mangled #60765

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
Aug 26, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Aug 25, 2022

typealias is currently allowed to refer to a protocol without the any keyword. This breaks mangling the typealias type into a USR will crash because parameterized protocols are expected to be any types.

Implement a SourceKit-specific minimal workaround for that problem by not computing USRs for parameterized protocols.

rdar://98623438

@ahoppen ahoppen requested review from rintaro and CodaFi August 25, 2022 11:10
@ahoppen
Copy link
Member Author

ahoppen commented Aug 25, 2022

@swift-ci Please smoke test

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable, but I think @CodaFi should verify this

Copy link
Contributor

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite correct. The reason this isn't handled by appendType is because you should never see a ParameterizedProtocolType that isn't wrapped in an ExistentialType or in an existential metatype type AST.

@ahoppen ahoppen changed the title [CodeComplete] Fix mangling of protocols with primary associated types for cached type relations [CodeComplete] Workaround a bug that parameterized protocols without 'any' cannot be mangled Aug 26, 2022
@ahoppen
Copy link
Member Author

ahoppen commented Aug 26, 2022

OK, I’ve decided to use this PR to implement a minimal workaround to avoid the crash on the SourceKit side so the underlying issue can be fixed independently.

@ahoppen ahoppen changed the title [CodeComplete] Workaround a bug that parameterized protocols without 'any' cannot be mangled [SourceKit] Workaround a bug that parameterized protocols without 'any' cannot be mangled Aug 26, 2022
@ahoppen
Copy link
Member Author

ahoppen commented Aug 26, 2022

@swift-ci Please smoke test

// declarations. rdar://99176683
// To avoid crashing in USR generation, return an error for now.
if (auto Ty = DInfo.VD->getInterfaceType()) {
if (auto MetaTy = Ty->getAs<MetatypeType>()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to look through all layers of metatype you can get.

…y' cannot be mangled

`typealias` is currently allowed to refer to a protocol without the `any` keyword. This breaks mangling the typealias type into a USR will crash because parameterized protocols are expected to be `any` types.

Implement a SourceKit-specific minimal workaround for that problem by not computing USRs for parameterized protocols.

rdar://98623438
@ahoppen
Copy link
Member Author

ahoppen commented Aug 26, 2022

@swift-ci Please smoke test

@ahoppen ahoppen merged commit b6377ff into swiftlang:main Aug 26, 2022
@ahoppen ahoppen deleted the pr/rdar98623438 branch August 26, 2022 22:36
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