Skip to content

Commit 50b2bd4

Browse files
[clang][ExtractAPI] Remove symbols defined in categories to external types unless requested (#92522)
rdar://128259890
1 parent da6a0b7 commit 50b2bd4

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class SymbolGraphSerializer : public APISetVisitor<SymbolGraphSerializer> {
102102

103103
const bool EmitSymbolLabelsForTesting = false;
104104

105+
const bool SkipSymbolsInCategoriesToExternalTypes = false;
106+
105107
/// The object instantiated by the last call to serializeAPIRecord.
106108
Object *CurrentSymbol = nullptr;
107109

@@ -271,10 +273,13 @@ class SymbolGraphSerializer : public APISetVisitor<SymbolGraphSerializer> {
271273

272274
SymbolGraphSerializer(const APISet &API, const APIIgnoresList &IgnoresList,
273275
bool EmitSymbolLabelsForTesting = false,
274-
bool ForceEmitToMainModule = false)
276+
bool ForceEmitToMainModule = false,
277+
bool SkipSymbolsInCategoriesToExternalTypes = false)
275278
: Base(API), ForceEmitToMainModule(ForceEmitToMainModule),
276279
IgnoresList(IgnoresList),
277-
EmitSymbolLabelsForTesting(EmitSymbolLabelsForTesting) {}
280+
EmitSymbolLabelsForTesting(EmitSymbolLabelsForTesting),
281+
SkipSymbolsInCategoriesToExternalTypes(
282+
SkipSymbolsInCategoriesToExternalTypes) {}
278283
};
279284

280285
} // namespace extractapi

clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,10 @@ bool SymbolGraphSerializer::visitObjCInterfaceRecord(
925925

926926
bool SymbolGraphSerializer::traverseObjCCategoryRecord(
927927
const ObjCCategoryRecord *Record) {
928+
if (SkipSymbolsInCategoriesToExternalTypes &&
929+
!API.findRecordForUSR(Record->Interface.USR))
930+
return true;
931+
928932
auto *CurrentModule = ModuleForCurrentSymbol;
929933
if (Record->isExtendingExternalModule())
930934
ModuleForCurrentSymbol = &ExtendedModules[Record->Interface.Source];
@@ -1040,8 +1044,11 @@ void SymbolGraphSerializer::serializeGraphToStream(
10401044
void SymbolGraphSerializer::serializeMainSymbolGraph(
10411045
raw_ostream &OS, const APISet &API, const APIIgnoresList &IgnoresList,
10421046
SymbolGraphSerializerOption Options) {
1043-
SymbolGraphSerializer Serializer(API, IgnoresList,
1044-
Options.EmitSymbolLabelsForTesting);
1047+
SymbolGraphSerializer Serializer(
1048+
API, IgnoresList, Options.EmitSymbolLabelsForTesting,
1049+
/*ForceEmitToMainModule=*/true,
1050+
/*SkipSymbolsInCategoriesToExternalTypes=*/true);
1051+
10451052
Serializer.traverseAPISet();
10461053
Serializer.serializeGraphToStream(OS, Options, API.ProductName,
10471054
std::move(Serializer.MainModule));

clang/test/ExtractAPI/objc_external_category.m

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
// RUN: --emit-extension-symbol-graphs --symbol-graph-dir=%t/symbols \
55
// RUN: --product-name=Module -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules-cache \
66
// RUN: -triple arm64-apple-macosx -x objective-c-header %t/input.h -verify
7+
// RUN: %clang_cc1 -extract-api --pretty-sgf --emit-sgf-symbol-labels-for-testing \
8+
// RUN: --product-name=Module -o %t/ModuleNoExt.symbols.json -triple arm64-apple-macosx \
9+
// RUN: -x objective-c-header %t/input.h
710

811
//--- input.h
912
#include "ExternalModule.h"
@@ -28,15 +31,20 @@ @interface ExtInterface
2831
header "ExternalModule.h"
2932
}
3033

34+
// Main symbol graph from the build with extension SGFs
3135
// RUN: FileCheck %s --input-file %t/symbols/Module.symbols.json --check-prefix MOD
36+
3237
// MOD-NOT: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(py)Property $ c:objc(cs)ExtInterface"
3338
// MOD-NOT: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(im)InstanceMethod $ c:objc(cs)ExtInterface"
3439
// MOD-NOT: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(cm)ClassMethod $ c:objc(cs)ExtInterface"
35-
// MOD-NOT: "!testLabel": "c:objc(cs)ExtInterface(py)Property"
36-
// MOD-NOT: "!testLabel": "c:objc(cs)ExtInterface(im)InstanceMethod"
37-
// MOD-NOT: "!testLabel": "c:objc(cs)ExtInterface(cm)ClassMethod"
38-
// MOD-NOT: "!testLabel": "c:objc(cs)ExtInterface"
39-
// MOD-DAG: "!testLabel": "c:objc(cs)ModInterface"
40+
// MOD-NOT: "c:objc(cs)ExtInterface(py)Property"
41+
// MOD-NOT: "c:objc(cs)ExtInterface(im)InstanceMethod"
42+
// MOD-NOT: "c:objc(cs)ExtInterface(cm)ClassMethod"
43+
// MOD-NOT: "c:objc(cs)ExtInterface"
44+
// MOD-DAG: "c:objc(cs)ModInterface"
45+
46+
// Symbol graph from the build without extension SGFs should be identical to main symbol graph with extension SGFs
47+
// RUN: diff %t/symbols/Module.symbols.json %t/ModuleNoExt.symbols.json
4048

4149
// RUN: FileCheck %s --input-file %t/symbols/[email protected] --check-prefix EXT
4250
// EXT-DAG: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(py)Property $ c:objc(cs)ExtInterface"

0 commit comments

Comments
 (0)