Skip to content

Commit 77502b5

Browse files
Merge pull request #60906 from apple/QuietMisdreavus/objc-synthesis
give inherited/synthesized objc symbols a synthesized base type
2 parents 7cc61eb + 8073a2a commit 77502b5

File tree

6 files changed

+35
-0
lines changed

6 files changed

+35
-0
lines changed

lib/SymbolGraphGen/SymbolGraphASTWalker.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,19 @@ bool SymbolGraphASTWalker::walkToDeclPre(Decl *D, CharSourceRange Range) {
237237
}
238238
}
239239

240+
// Clang decls that are inherited from protocols get the USR of the protocol
241+
// symbol, regardless of which class it's actually appearing on. To prevent
242+
// multiple of these symbols colliding with each other, treat them as
243+
// synthesized symbols and use their parent type as the base type.
244+
if (VD->isImplicit() && VD->hasClangNode() &&
245+
VD->getClangNode().getAsDecl()) {
246+
if (const auto *Parent =
247+
dyn_cast_or_null<NominalTypeDecl>(VD->getDeclContext())) {
248+
SG->recordNode(Symbol(SG, VD, Parent));
249+
return true;
250+
}
251+
}
252+
240253
// Otherwise, record this in the main module `M`'s symbol graph.
241254
SG->recordNode(Symbol(SG, VD, nullptr));
242255

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@import Foundation;
2+
3+
@interface MyClassA : NSObject <NSCoding>
4+
5+
@end
6+
7+
@interface MyClassB : NSObject <NSCoding>
8+
9+
@end

test/SymbolGraph/ClangImporter/Inputs/ObjcSynthesis/ObjcSynthesis.framework/Modules/ObjcSynthesis.swiftmodule/.keep

Whitespace-only changes.

test/SymbolGraph/ClangImporter/Inputs/ObjcSynthesis/ObjcSynthesis.framework/ObjcSynthesis

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework module ObjcSynthesis {
2+
header "ObjcSynthesis.h"
3+
export *
4+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp -r %S/Inputs/ObjcSynthesis/ObjcSynthesis.framework %t
3+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -emit-module -o %t/ObjcSynthesis.framework/Modules/ObjcSynthesis.swiftmodule/%target-swiftmodule-name -import-underlying-module -F %t -module-name ObjcSynthesis -disable-objc-attr-requires-foundation-module %s
4+
// RUN: %target-swift-symbolgraph-extract -sdk %clang-importer-sdk -module-name ObjcSynthesis -F %t -output-dir %t -pretty-print -v
5+
// RUN: %FileCheck %s --input-file %t/ObjcSynthesis.symbols.json
6+
7+
// REQUIRES: objc_interop
8+
9+
// CHECK-NOT: "precise": "c:objc(pl)NSCoding(im)initWithCoder"

0 commit comments

Comments
 (0)