Skip to content

Commit 5b77b32

Browse files
authored
Merge pull request #59273 from nkcsgexi/92032848
ABIChecker: add an option to avoid diagnosing about certain given SPI groups
2 parents e05f68c + dfb5321 commit 5b77b32

File tree

9 files changed

+70
-3
lines changed

9 files changed

+70
-3
lines changed

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ struct CheckerOptions {
161161
bool Migrator;
162162
StringRef LocationFilter;
163163
std::vector<std::string> ToolArgs;
164+
llvm::StringSet<> SPIGroupNamesToIgnore;
164165
};
165166

166167
class SDKContext {
@@ -346,6 +347,7 @@ class SDKNodeDecl: public SDKNode {
346347
StringRef Location;
347348
StringRef ModuleName;
348349
std::vector<DeclAttrKind> DeclAttributes;
350+
std::vector<StringRef> SPIGroups;
349351
bool IsImplicit;
350352
bool IsStatic;
351353
bool IsDeprecated;
@@ -373,6 +375,7 @@ class SDKNodeDecl: public SDKNode {
373375
StringRef getModuleName() const {return ModuleName;}
374376
StringRef getHeaderName() const;
375377
ArrayRef<DeclAttrKind> getDeclAttributes() const;
378+
ArrayRef<StringRef> getSPIGroups() const { return SPIGroups; }
376379
bool hasAttributeChange(const SDKNodeDecl &Another) const;
377380
swift::ReferenceOwnership getReferenceOwnership() const {
378381
return swift::ReferenceOwnership(ReferenceOwnership);
@@ -415,6 +418,12 @@ class SDKNodeDecl: public SDKNode {
415418
if (isObjc())
416419
return;
417420
}
421+
// Don't emit SPIs if the group name is out-out.
422+
for (auto spi: getSPIGroups()) {
423+
if (Ctx.getOpts().SPIGroupNamesToIgnore.contains(spi)) {
424+
return;
425+
}
426+
}
418427
Ctx.getDiags(Loc).diagnose(Loc, ID, getScreenInfo(), std::move(Args)...);
419428
}
420429
};

include/swift/IDE/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ KEY_STRING(InitKind, init_kind)
162162

163163
KEY_STRING_ARR(SuperclassNames, superclassNames)
164164
KEY_STRING_ARR(ToolArgs, tool_arguments)
165+
KEY_STRING_ARR(SPIGroups, spi_group_names)
165166

166167
KEY_UINT(SelfIndex, selfIndex)
167168
KEY_UINT(FixedBinaryOrder, fixedbinaryorder)

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,10 @@ def ignored_usrs: Separate<["-", "--"], "ignored-usrs">,
13991399
HelpText<"the file containing USRs of removed decls that the digester should ignore">,
14001400
MetaVarName<"<path>">;
14011401

1402+
def ignore_spi_groups : Separate<["-", "--"], "ignore-spi-group">,
1403+
Flags<[NoDriverOption, SwiftAPIDigesterOption]>,
1404+
HelpText<"SPI group name to not diagnose about">;
1405+
14021406
def protocol_requirement_allow_list: Separate<["-", "--"], "protocol-requirement-allow-list">,
14031407
Flags<[NoDriverOption, SwiftAPIDigesterOption, ArgumentIsPath]>,
14041408
HelpText<"File containing a new-line separated list of protocol names">,

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ SDKNodeDecl::SDKNodeDecl(SDKNodeInitInfo Info, SDKNodeKind Kind)
114114
: SDKNode(Info, Kind), DKind(Info.DKind), Usr(Info.Usr),
115115
MangledName(Info.MangledName), Loc(Info.Loc),
116116
Location(Info.Location), ModuleName(Info.ModuleName),
117-
DeclAttributes(Info.DeclAttrs), IsImplicit(Info.IsImplicit),
117+
DeclAttributes(Info.DeclAttrs),
118+
SPIGroups(Info.SPIGroups),
119+
IsImplicit(Info.IsImplicit),
118120
IsStatic(Info.IsStatic), IsDeprecated(Info.IsDeprecated),
119121
IsProtocolReq(Info.IsProtocolReq),
120122
IsOverriding(Info.IsOverriding),
@@ -1436,7 +1438,12 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Decl *D):
14361438
IsDeprecated(D->getAttrs().getDeprecated(D->getASTContext())),
14371439
IsABIPlaceholder(isABIPlaceholderRecursive(D)),
14381440
IsFromExtension(isDeclaredInExtension(D)),
1439-
DeclAttrs(collectDeclAttributes(D)) {}
1441+
DeclAttrs(collectDeclAttributes(D)) {
1442+
// Keep track of SPI group names
1443+
for (auto id: D->getSPIGroups()) {
1444+
SPIGroups.push_back(id.str());
1445+
}
1446+
}
14401447

14411448
SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, OperatorDecl *OD):
14421449
SDKNodeInitInfo(Ctx, cast<Decl>(OD)) {
@@ -2083,6 +2090,7 @@ void SDKNodeDecl::jsonize(json::Output &out) {
20832090
out.mapRequired(getKeyContent(Ctx, KeyKind::KK_ownership).data(), Raw);
20842091
}
20852092
output(out, KeyKind::KK_isFromExtension, IsFromExtension);
2093+
out.mapOptional(getKeyContent(Ctx, KeyKind::KK_spi_group_names).data(), SPIGroups);
20862094
}
20872095

20882096
void SDKNodeDeclAbstractFunc::jsonize(json::Output &out) {

lib/DriverTool/swift_api_digester_main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2338,7 +2338,8 @@ class SwiftAPIDigesterInvocation {
23382338
CompilerStyleDiags || !SerializedDiagPath.empty();
23392339
for (auto Arg : Args)
23402340
CheckerOpts.ToolArgs.push_back(Arg);
2341-
2341+
for(auto spi: ParsedArgs.getAllArgValues(OPT_ignore_spi_groups))
2342+
CheckerOpts.SPIGroupNamesToIgnore.insert(spi);
23422343
if (!SDK.empty()) {
23432344
auto Ver = getSDKBuildVersion(SDK);
23442345
if (!Ver.empty()) {

test/api-digester/Inputs/cake.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ public func silgenNamedFunc() {}
148148

149149
@available(OSX 10.7, *)
150150
@_originallyDefinedIn(module: "Bread", OSX 10.9)
151+
@_spi(top_secret_1)
152+
@_spi(top_secret_2)
151153
public class SinkingClass {
152154
public init() {}
153155
}

test/api-digester/Outputs/cake-abi.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,10 @@
16561656
"usr": "s:4cake12SinkingClassCACycfc",
16571657
"mangledName": "$s5Bread12SinkingClassCACycfc",
16581658
"moduleName": "cake",
1659+
"spi_group_names": [
1660+
"top_secret_2",
1661+
"top_secret_1"
1662+
],
16591663
"init_kind": "Designated"
16601664
}
16611665
],
@@ -1665,8 +1669,14 @@
16651669
"moduleName": "cake",
16661670
"intro_Macosx": "10.7",
16671671
"declAttributes": [
1672+
"SPIAccessControl",
1673+
"SPIAccessControl",
16681674
"OriginallyDefinedIn",
16691675
"Available"
1676+
],
1677+
"spi_group_names": [
1678+
"top_secret_2",
1679+
"top_secret_1"
16701680
]
16711681
},
16721682
{

test/api-digester/Outputs/cake.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,10 @@
15171517
"usr": "s:4cake12SinkingClassCACycfc",
15181518
"mangledName": "$s5Bread12SinkingClassCACycfc",
15191519
"moduleName": "cake",
1520+
"spi_group_names": [
1521+
"top_secret_2",
1522+
"top_secret_1"
1523+
],
15201524
"init_kind": "Designated"
15211525
}
15221526
],
@@ -1526,8 +1530,14 @@
15261530
"moduleName": "cake",
15271531
"intro_Macosx": "10.7",
15281532
"declAttributes": [
1533+
"SPIAccessControl",
1534+
"SPIAccessControl",
15291535
"OriginallyDefinedIn",
15301536
"Available"
1537+
],
1538+
"spi_group_names": [
1539+
"top_secret_2",
1540+
"top_secret_1"
15311541
]
15321542
},
15331543
{
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -emit-module -o %t/Foo.swiftmodule -emit-abi-descriptor-path %t/abi-before.json %s -enable-library-evolution -DBASELINE -emit-tbd-path %t/abi-before.tbd
4+
// RUN: %target-swift-frontend -emit-module -o %t/Foo.swiftmodule -emit-abi-descriptor-path %t/abi-after.json %s -enable-library-evolution -emit-tbd-path %t/abi-after.tbd
5+
// RUN: %api-digester -diagnose-sdk --input-paths %t/abi-before.json -input-paths %t/abi-after.json -abi -o %t/result.txt
6+
// RUN: %FileCheck %s -check-prefix CHECK_INCLUDE_SPI < %t/result.txt
7+
8+
// RUN: %api-digester -diagnose-sdk --input-paths %t/abi-before.json -input-paths %t/abi-after.json -abi -o %t/result.txt -ignore-spi-group secret
9+
// RUN: %FileCheck -check-prefix CHECK_EXCLUDE_SPI %s < %t/result.txt
10+
11+
#if BASELINE
12+
13+
@_spi(secret)
14+
public func foo() {}
15+
16+
#else
17+
18+
19+
#endif
20+
21+
// CHECK_INCLUDE_SPI: Func foo() has been removed
22+
// CHECK_EXCLUDE_SPI-NOT: foo()

0 commit comments

Comments
 (0)