Skip to content

Commit 2160f65

Browse files
committed
[SR-10972] swift-api-digester: avoid diagnosing the removal of __derived_enum_equals and __derived_struct_equals
These functions are compiler implementation details and diagnosing them is redundant and may be confusing to framework authors.
1 parent f4f2e2c commit 2160f65

File tree

6 files changed

+36
-0
lines changed

6 files changed

+36
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public enum Color { case Red }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public enum Color { case Red }
2+
3+
extension Color: RawRepresentable {
4+
public var rawValue: String { return "" }
5+
public init(rawValue: String) { self = .Red }
6+
}

test/api-digester/Outputs/color.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
color: Func Color.hash(into:) has been removed
2+
color: Var Color.hashValue has been removed

test/api-digester/compare-dump.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@
1111
// RUN: %clang -E -P -x c %S/Outputs/Cake.txt -o - | sed '/^\s*$/d' > %t.expected
1212
// RUN: %clang -E -P -x c %t.result -o - | sed '/^\s*$/d' > %t.result.tmp
1313
// RUN: diff -u %t.expected %t.result.tmp
14+
15+
// Run another module API checking without -enable-library-evolution
16+
// RUN: %swift -emit-module -o %t.mod1/color.swiftmodule %S/Inputs/cake_baseline/color.swift -parse-as-library -I %S/Inputs/APINotesLeft %clang-importer-sdk-nosource -module-name color
17+
// RUN: %swift -emit-module -o %t.mod2/color.swiftmodule %S/Inputs/cake_current/color.swift -parse-as-library -I %S/Inputs/APINotesRight %clang-importer-sdk-nosource -module-name color
18+
// RUN: %api-digester -dump-sdk -module color -o - -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %t.mod1 -I %S/Inputs/APINotesLeft > %t.dump1.json
19+
// RUN: %api-digester -dump-sdk -module color -o - -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %t.mod2 -I %S/Inputs/APINotesLeft > %t.dump2.json
20+
// RUN: %api-digester -diagnose-sdk -print-module --input-paths %t.dump1.json -input-paths %t.dump2.json -o %t.result
21+
22+
// RUN: %clang -E -P -x c %S/Outputs/color.txt -o - | sed '/^\s*$/d' > %t.expected
23+
// RUN: %clang -E -P -x c %t.result -o - | sed '/^\s*$/d' > %t.result.tmp
24+
// RUN: diff -u %t.expected %t.result.tmp

tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ class SDKContext {
164164
std::vector<BreakingAttributeInfo> BreakingAttrs;
165165

166166
public:
167+
// Define the set of known identifiers.
168+
#define IDENTIFIER_WITH_NAME(Name, IdStr) StringRef Id_##Name = IdStr;
169+
#include "swift/AST/KnownIdentifiers.def"
170+
167171
SDKContext(CheckerOptions Options);
168172
llvm::BumpPtrAllocator &allocator() {
169173
return Allocator;

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,18 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
19591959
}
19601960
if (FoundInSuperclass)
19611961
return;
1962+
1963+
// When diagnosing API changes, avoid complaining the removal of these
1964+
// synthesized functions since they are compiler implementation details.
1965+
// If an enum is no longer equatable, another diagnostic about removing
1966+
// conforming protocol will be emitted.
1967+
if (!Ctx.checkingABI()) {
1968+
if (Node->getName() == Ctx.Id_derived_struct_equals ||
1969+
Node->getName() == Ctx.Id_derived_enum_equals) {
1970+
return;
1971+
}
1972+
}
1973+
19621974
Node->emitDiag(diag::removed_decl, Node->isDeprecated());
19631975
return;
19641976
}

0 commit comments

Comments
 (0)