mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
dc5d5f714b
- **Explanation**: When Clang's indexer encounters a compatibility alias reference, it actually emits the reference to the underlying type. I've verified the behavior by building indexstores for Objc decls and refs, but I'm honestly not positive how/where that happens interally in Clang. I suspect it's because `Sema::ClassifyName` [resolves the type when it finds a compatibility alias](https://github.com/swiftlang/llvm-project/blob/e1ac486ddde5f4ce162facd7d9dc90cb2d241588/clang/lib/Sema/SemaDecl.cpp#L1240-L1243). Before this patch, Swift would generate a typealias declaration when it encountered a reference to a name defined by a compatibility alias. Then emit a reference to that typealias. Unfortunately that typealias never has a definition so it's "dangling". To resolve that I considered some options: 1. (Selected) Match Clang's behavior and emit a reference directly to the underlying type. This has a downside in that it doesn't fully match the "actual" code. The reference really is for the compatibility alias, and if that alias and the underlying declaration are in separate headers or even separate modules it can be confusing. This implementation is simpler though and apparently the behavior has been close enough for Clang. 2. (Not selected) Emit a definition occurrence for the generated typealias used by Swift when referencing the alias name. This seems like a robust and fully correct solution, but I didn't see any prior art for creating definitions like this. Specifically, the synthesized typealias only exists _when it's referenced_ from Swift so it wouldn't appear if someone compiled a PCM from an objc module with indexing enabled. Given those limitations, this didn't seem like a good solution. - **Scope**: This change impacts the indexstore output when using index-while-building for Swift modules that reference `@compatibility_alias` declarations from Objective-C. - **Issues**: https://github.com/swiftlang/swift/issues/88653 - **Risk**: Downstream use cases for indexstore data can be impacted, e.g. Swift's language services (SourceKit and SourceKit-LSP). Those downstream indexstore consumers could fail to resolve impacted symbols properly. - **Testing**: Ran Swift project tests.