From 2160f65283e7cb575a54a9eb13f56e458dfbba18 Mon Sep 17 00:00:00 2001 From: Xi Ge Date: Thu, 20 Jun 2019 16:08:06 -0700 Subject: [PATCH] [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. --- test/api-digester/Inputs/cake_baseline/color.swift | 1 + test/api-digester/Inputs/cake_current/color.swift | 6 ++++++ test/api-digester/Outputs/color.txt | 2 ++ test/api-digester/compare-dump.swift | 11 +++++++++++ tools/swift-api-digester/ModuleAnalyzerNodes.h | 4 ++++ tools/swift-api-digester/swift-api-digester.cpp | 12 ++++++++++++ 6 files changed, 36 insertions(+) create mode 100644 test/api-digester/Inputs/cake_baseline/color.swift create mode 100644 test/api-digester/Inputs/cake_current/color.swift create mode 100644 test/api-digester/Outputs/color.txt diff --git a/test/api-digester/Inputs/cake_baseline/color.swift b/test/api-digester/Inputs/cake_baseline/color.swift new file mode 100644 index 0000000000000..502e2ab6ec03c --- /dev/null +++ b/test/api-digester/Inputs/cake_baseline/color.swift @@ -0,0 +1 @@ +public enum Color { case Red } diff --git a/test/api-digester/Inputs/cake_current/color.swift b/test/api-digester/Inputs/cake_current/color.swift new file mode 100644 index 0000000000000..6a4aaad317d3c --- /dev/null +++ b/test/api-digester/Inputs/cake_current/color.swift @@ -0,0 +1,6 @@ +public enum Color { case Red } + +extension Color: RawRepresentable { + public var rawValue: String { return "" } + public init(rawValue: String) { self = .Red } +} diff --git a/test/api-digester/Outputs/color.txt b/test/api-digester/Outputs/color.txt new file mode 100644 index 0000000000000..5667013ba8b5c --- /dev/null +++ b/test/api-digester/Outputs/color.txt @@ -0,0 +1,2 @@ +color: Func Color.hash(into:) has been removed +color: Var Color.hashValue has been removed \ No newline at end of file diff --git a/test/api-digester/compare-dump.swift b/test/api-digester/compare-dump.swift index 05ec0ba1700a1..b9052bb28a7f2 100644 --- a/test/api-digester/compare-dump.swift +++ b/test/api-digester/compare-dump.swift @@ -11,3 +11,14 @@ // RUN: %clang -E -P -x c %S/Outputs/Cake.txt -o - | sed '/^\s*$/d' > %t.expected // RUN: %clang -E -P -x c %t.result -o - | sed '/^\s*$/d' > %t.result.tmp // RUN: diff -u %t.expected %t.result.tmp + +// Run another module API checking without -enable-library-evolution +// 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 +// 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 +// 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 +// 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 +// RUN: %api-digester -diagnose-sdk -print-module --input-paths %t.dump1.json -input-paths %t.dump2.json -o %t.result + +// RUN: %clang -E -P -x c %S/Outputs/color.txt -o - | sed '/^\s*$/d' > %t.expected +// RUN: %clang -E -P -x c %t.result -o - | sed '/^\s*$/d' > %t.result.tmp +// RUN: diff -u %t.expected %t.result.tmp diff --git a/tools/swift-api-digester/ModuleAnalyzerNodes.h b/tools/swift-api-digester/ModuleAnalyzerNodes.h index 3c472370bc1e7..499eb25afaa44 100644 --- a/tools/swift-api-digester/ModuleAnalyzerNodes.h +++ b/tools/swift-api-digester/ModuleAnalyzerNodes.h @@ -164,6 +164,10 @@ class SDKContext { std::vector BreakingAttrs; public: + // Define the set of known identifiers. +#define IDENTIFIER_WITH_NAME(Name, IdStr) StringRef Id_##Name = IdStr; +#include "swift/AST/KnownIdentifiers.def" + SDKContext(CheckerOptions Options); llvm::BumpPtrAllocator &allocator() { return Allocator; diff --git a/tools/swift-api-digester/swift-api-digester.cpp b/tools/swift-api-digester/swift-api-digester.cpp index 662e392ef3389..afedb41b76b2e 100644 --- a/tools/swift-api-digester/swift-api-digester.cpp +++ b/tools/swift-api-digester/swift-api-digester.cpp @@ -1959,6 +1959,18 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) { } if (FoundInSuperclass) return; + + // When diagnosing API changes, avoid complaining the removal of these + // synthesized functions since they are compiler implementation details. + // If an enum is no longer equatable, another diagnostic about removing + // conforming protocol will be emitted. + if (!Ctx.checkingABI()) { + if (Node->getName() == Ctx.Id_derived_struct_equals || + Node->getName() == Ctx.Id_derived_enum_equals) { + return; + } + } + Node->emitDiag(diag::removed_decl, Node->isDeprecated()); return; }