-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][ExtractAPI] Remove symbols defined in categories to external types unless requested #92522
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
daniel-grumberg
merged 1 commit into
llvm:main
from
daniel-grumberg:categories-external-types-no-extension-sgf
May 20, 2024
Merged
[clang][ExtractAPI] Remove symbols defined in categories to external types unless requested #92522
daniel-grumberg
merged 1 commit into
llvm:main
from
daniel-grumberg:categories-external-types-no-extension-sgf
May 20, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…types unless requested rdar://128259890
@llvm/pr-subscribers-clang Author: Daniel Grumberg (daniel-grumberg) Changesrdar://128259890 Full diff: https://github.com/llvm/llvm-project/pull/92522.diff 3 Files Affected:
diff --git a/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h b/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
index 724b087f7aea9..27e9167ca1ad0 100644
--- a/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
+++ b/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
@@ -102,6 +102,8 @@ class SymbolGraphSerializer : public APISetVisitor<SymbolGraphSerializer> {
const bool EmitSymbolLabelsForTesting = false;
+ const bool SkipSymbolsInCategoriesToExternalTypes = false;
+
/// The object instantiated by the last call to serializeAPIRecord.
Object *CurrentSymbol = nullptr;
@@ -271,10 +273,13 @@ class SymbolGraphSerializer : public APISetVisitor<SymbolGraphSerializer> {
SymbolGraphSerializer(const APISet &API, const APIIgnoresList &IgnoresList,
bool EmitSymbolLabelsForTesting = false,
- bool ForceEmitToMainModule = false)
+ bool ForceEmitToMainModule = false,
+ bool SkipSymbolsInCategoriesToExternalTypes = false)
: Base(API), ForceEmitToMainModule(ForceEmitToMainModule),
IgnoresList(IgnoresList),
- EmitSymbolLabelsForTesting(EmitSymbolLabelsForTesting) {}
+ EmitSymbolLabelsForTesting(EmitSymbolLabelsForTesting),
+ SkipSymbolsInCategoriesToExternalTypes(
+ SkipSymbolsInCategoriesToExternalTypes) {}
};
} // namespace extractapi
diff --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index c16d4623f115d..08e711cafae28 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -925,6 +925,10 @@ bool SymbolGraphSerializer::visitObjCInterfaceRecord(
bool SymbolGraphSerializer::traverseObjCCategoryRecord(
const ObjCCategoryRecord *Record) {
+ if (SkipSymbolsInCategoriesToExternalTypes &&
+ !API.findRecordForUSR(Record->Interface.USR))
+ return true;
+
auto *CurrentModule = ModuleForCurrentSymbol;
if (Record->isExtendingExternalModule())
ModuleForCurrentSymbol = &ExtendedModules[Record->Interface.Source];
@@ -1040,8 +1044,11 @@ void SymbolGraphSerializer::serializeGraphToStream(
void SymbolGraphSerializer::serializeMainSymbolGraph(
raw_ostream &OS, const APISet &API, const APIIgnoresList &IgnoresList,
SymbolGraphSerializerOption Options) {
- SymbolGraphSerializer Serializer(API, IgnoresList,
- Options.EmitSymbolLabelsForTesting);
+ SymbolGraphSerializer Serializer(
+ API, IgnoresList, Options.EmitSymbolLabelsForTesting,
+ /*ForceEmitToMainModule=*/true,
+ /*SkipSymbolsInCategoriesToExternalTypes=*/true);
+
Serializer.traverseAPISet();
Serializer.serializeGraphToStream(OS, Options, API.ProductName,
std::move(Serializer.MainModule));
diff --git a/clang/test/ExtractAPI/objc_external_category.m b/clang/test/ExtractAPI/objc_external_category.m
index 47e699cb91c0e..8afc92489f28b 100644
--- a/clang/test/ExtractAPI/objc_external_category.m
+++ b/clang/test/ExtractAPI/objc_external_category.m
@@ -4,6 +4,9 @@
// RUN: --emit-extension-symbol-graphs --symbol-graph-dir=%t/symbols \
// RUN: --product-name=Module -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules-cache \
// RUN: -triple arm64-apple-macosx -x objective-c-header %t/input.h -verify
+// RUN: %clang_cc1 -extract-api --pretty-sgf --emit-sgf-symbol-labels-for-testing \
+// RUN: --product-name=Module -o %t/ModuleNoExt.symbols.json -triple arm64-apple-macosx \
+// RUN: -x objective-c-header %t/input.h
//--- input.h
#include "ExternalModule.h"
@@ -28,15 +31,20 @@ @interface ExtInterface
header "ExternalModule.h"
}
+// Main symbol graph from the build with extension SGFs
// RUN: FileCheck %s --input-file %t/symbols/Module.symbols.json --check-prefix MOD
+
// MOD-NOT: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(py)Property $ c:objc(cs)ExtInterface"
// MOD-NOT: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(im)InstanceMethod $ c:objc(cs)ExtInterface"
// MOD-NOT: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(cm)ClassMethod $ c:objc(cs)ExtInterface"
-// MOD-NOT: "!testLabel": "c:objc(cs)ExtInterface(py)Property"
-// MOD-NOT: "!testLabel": "c:objc(cs)ExtInterface(im)InstanceMethod"
-// MOD-NOT: "!testLabel": "c:objc(cs)ExtInterface(cm)ClassMethod"
-// MOD-NOT: "!testLabel": "c:objc(cs)ExtInterface"
-// MOD-DAG: "!testLabel": "c:objc(cs)ModInterface"
+// MOD-NOT: "c:objc(cs)ExtInterface(py)Property"
+// MOD-NOT: "c:objc(cs)ExtInterface(im)InstanceMethod"
+// MOD-NOT: "c:objc(cs)ExtInterface(cm)ClassMethod"
+// MOD-NOT: "c:objc(cs)ExtInterface"
+// MOD-DAG: "c:objc(cs)ModInterface"
+
+// Symbol graph from the build without extension SGFs should be identical to main symbol graph with extension SGFs
+// RUN: diff %t/symbols/Module.symbols.json %t/ModuleNoExt.symbols.json
// RUN: FileCheck %s --input-file %t/symbols/[email protected] --check-prefix EXT
// EXT-DAG: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(py)Property $ c:objc(cs)ExtInterface"
|
QuietMisdreavus
approved these changes
May 17, 2024
daniel-grumberg
added a commit
to daniel-grumberg/llvm-project
that referenced
this pull request
May 24, 2024
…types unless requested (llvm#92522) rdar://128259890
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
rdar://128259890