Skip to content

Commit 227c2ba

Browse files
committed
ABI checker: adding protocol requirement with default implementation should not be flagged as breakage
rdar://98583968
1 parent feecc51 commit 227c2ba

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/DriverTool/swift_api_digester_main.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,21 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
691691
// to the allowlist.
692692
ShouldComplain = false;
693693
}
694+
if (ShouldComplain) {
695+
// Providing a default implementation via a protocol extension for
696+
// a protocol requirement is both ABI and API safe.
697+
if (auto *PD = dyn_cast<SDKNodeDecl>(D->getParent())) {
698+
for (auto *SIB: PD->getChildren()) {
699+
if (auto *SIBD = dyn_cast<SDKNodeDecl>(SIB)) {
700+
if (SIBD->isFromExtension() &&
701+
SIBD->getPrintedName() == D->getPrintedName()) {
702+
ShouldComplain = false;
703+
break;
704+
}
705+
}
706+
}
707+
}
708+
}
694709
if (ShouldComplain)
695710
D->emitDiag(D->getLoc(), diag::protocol_req_added);
696711
}
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)