Skip to content

Commit 7024813

Browse files
authored
Merge pull request #60562 from nkcsgexi/98583968
ABI checker: adding protocol requirement with default implementation should not be flagged as breakage
2 parents 8366183 + 3b522c7 commit 7024813

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/DriverTool/swift_api_digester_main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ static void diagnoseRemovedDecl(const SDKNodeDecl *D) {
558558
if (Ctx.getOpts().SkipRemoveDeprecatedCheck &&
559559
D->isDeprecated())
560560
return;
561+
// Don't complain about removing importation of SwiftOnoneSupport.
562+
if (D->getKind() == SDKNodeKind::DeclImport &&
563+
D->getName() == "SwiftOnoneSupport") {
564+
return;
565+
}
561566
D->emitDiag(SourceLoc(), diag::removed_decl, false);
562567
}
563568

@@ -691,6 +696,21 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
691696
// to the allowlist.
692697
ShouldComplain = false;
693698
}
699+
if (ShouldComplain) {
700+
// Providing a default implementation via a protocol extension for
701+
// a protocol requirement is both ABI and API safe.
702+
if (auto *PD = dyn_cast<SDKNodeDecl>(D->getParent())) {
703+
for (auto *SIB: PD->getChildren()) {
704+
if (auto *SIBD = dyn_cast<SDKNodeDecl>(SIB)) {
705+
if (SIBD->isFromExtension() &&
706+
SIBD->getPrintedName() == D->getPrintedName()) {
707+
ShouldComplain = false;
708+
break;
709+
}
710+
}
711+
}
712+
}
713+
}
694714
if (ShouldComplain)
695715
D->emitDiag(D->getLoc(), diag::protocol_req_added);
696716
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: echo "public protocol P {}" > %t/Foo-1.swift
4+
// RUN: echo "public protocol P { func f() }" > %t/Foo-2.swift
5+
// RUN: echo "public extension P { func f() {} }" >> %t/Foo-2.swift
6+
7+
// RUN: %target-swift-frontend -emit-module %t/Foo-1.swift -module-name Foo -emit-module-interface-path %t/Foo1.swiftinterface
8+
// RUN: %target-swift-frontend -emit-module %t/Foo-2.swift -module-name Foo -emit-module-interface-path %t/Foo2.swiftinterface
9+
10+
// RUN: %target-swift-frontend -compile-module-from-interface %t/Foo1.swiftinterface -o %t/Foo1.swiftmodule -module-name Foo -emit-abi-descriptor-path %t/Foo1.json
11+
12+
// RUN: %target-swift-frontend -compile-module-from-interface %t/Foo2.swiftinterface -o %t/Foo2.swiftmodule -module-name Foo -emit-abi-descriptor-path %t/Foo2.json
13+
14+
// RUN: %api-digester -diagnose-sdk -print-module --input-paths %t/Foo1.json -input-paths %t/Foo2.json -abi -o %t/result.txt
15+
16+
// RUN: %FileCheck %s < %t/result.txt
17+
18+
// CHECK-NOT: added as a protocol requirement

0 commit comments

Comments
 (0)