Skip to content

Commit 950eb74

Browse files
committedSep 12, 2020
ABI Checker: use lower-cased decl keywords to be consistent with source. NFC
1 parent 7dcb0ea commit 950eb74

File tree

7 files changed

+42
-19
lines changed

7 files changed

+42
-19
lines changed
 

‎include/swift/IDE/APIDigesterData.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ raw_ostream &operator<<(raw_ostream &Out, const NodeAnnotation Value);
6565
// Redefine << so that we can output the name of the node kind.
6666
raw_ostream &operator<<(raw_ostream &Out, const SDKNodeKind Value);
6767

68-
StringRef getDeclKindStr(const DeclKind Value);
68+
StringRef getDeclKindStr(const DeclKind Value, bool lower);
6969

7070
// Redefine << so that we can output the name of decl kind.
7171
raw_ostream &operator<<(raw_ostream &Out, const DeclKind Value);

‎lib/IDE/APIDigesterData.cpp

+17-4
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,30 @@ operator<<(raw_ostream &Out, const NodeAnnotation Value) {
3939
llvm_unreachable("Undefined SDK node kind.");
4040
}
4141

42-
StringRef swift::ide::api::getDeclKindStr(const DeclKind Value) {
42+
static StringRef getDeclKindStrRaw(const DeclKind Value) {
4343
switch (Value) {
4444
#define DECL(X, PARENT) case DeclKind::X: return #X;
4545
#include "swift/AST/DeclNodes.def"
4646
}
4747
llvm_unreachable("Unhandled DeclKind in switch.");
4848
}
4949

50-
raw_ostream &swift::ide::api::operator<<(raw_ostream &Out,
51-
const DeclKind Value) {
52-
return Out << getDeclKindStr(Value);
50+
StringRef swift::ide::api::getDeclKindStr(const DeclKind Value, bool lower) {
51+
if (lower) {
52+
switch (Value) {
53+
#define DECL(X, PARENT) case DeclKind::X: { \
54+
static std::string lowered = StringRef(#X).lower(); \
55+
return lowered; \
56+
}
57+
#include "swift/AST/DeclNodes.def"
58+
}
59+
} else {
60+
return getDeclKindStrRaw(Value);
61+
}
62+
}
63+
64+
raw_ostream &swift::ide::api::operator<<(raw_ostream &Out, const DeclKind Value) {
65+
return Out << getDeclKindStrRaw(Value);
5366
}
5467

5568
Optional<SDKNodeKind> swift::ide::api::parseSDKNodeKind(StringRef Content) {

‎test/api-digester/breakage-allowlist.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
// RUN: echo "public func foo() {}" > %t.mod1/Foo.swift
1111
// RUN: echo "public func bar() {}" > %t.mod2/Foo.swift
1212

13-
// RUN: echo "Foo: Func foo() has been removed" > %t/incomplete-allowlist.txt
14-
// RUN: echo "Foo: Func foo() has been removed" > %t/complete-allowlist.txt
15-
// RUN: echo "Foo: Func bar() is a new API without @available attribute" >> %t/complete-allowlist.txt
13+
// RUN: echo "Foo: func foo() has been removed" > %t/incomplete-allowlist.txt
14+
// RUN: echo "Foo: func foo() has been removed" > %t/complete-allowlist.txt
15+
// RUN: echo "Foo: func bar() is a new API without @available attribute" >> %t/complete-allowlist.txt
1616

1717
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -emit-module -o %t.mod1/Foo.swiftmodule %t.mod1/Foo.swift -parse-as-library -enable-library-evolution -emit-module-source-info -emit-module-source-info-path %t.mod1/Foo.swiftsourceinfo -emit-module-interface-path %t.mod1/Foo.swiftinterface -module-name Foo -swift-version 5
1818

‎test/api-digester/compare-dump-abi.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
// RUN: not %api-digester -diagnose-sdk -print-module -baseline-dir %t.baseline -module cake -I %t.mod2 -I %S/Inputs/APINotesLeft -module-cache-path %t.module-cache %clang-importer-sdk-nosource -abi -o %t.result -compiler-style-diags 2> %t.abi.compiler.diags
1919
// RUN: %FileCheck %s < %t.abi.compiler.diags
2020

21-
// CHECK: cake_current/cake.swift:39:15: error: cake: Struct C6 is now with @frozen
22-
// CHECK: cake_current/cake.swift:41:13: error: cake: Enum IceKind is now without @frozen
21+
// CHECK: cake_current/cake.swift:39:15: error: cake: struct C6 is now with @frozen
22+
// CHECK: cake_current/cake.swift:41:13: error: cake: enum IceKind is now without @frozen

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,12 @@ StringRef SDKNodeDecl::getScreenInfo() const {
419419
if (auto *TD = dyn_cast<SDKNodeDeclType>(this)) {
420420
IsExtension = TD->isExternal();
421421
}
422-
if (IsExtension)
423-
OS << "Extension";
424-
else
425-
OS << getDeclKind();
422+
423+
// There is no particular reasons why we don't use lower-cased keyword names
424+
// in non-CompilerStyle mode. This is to be backward compatible so clients
425+
// don't need to update existing known breakages.
426+
OS << getDeclKindStr(IsExtension? DeclKind::Extension : getDeclKind(),
427+
getSDKContext().getOpts().CompilerStyle);
426428
OS << " " << getFullyQualifiedName();
427429
return Ctx.buffer(OS.str());
428430
}

‎tools/swift-api-digester/ModuleAnalyzerNodes.h

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ struct CheckerOptions {
154154
bool PrintModule;
155155
bool SwiftOnly;
156156
bool SkipOSCheck;
157+
bool CompilerStyle;
157158
bool Migrator;
158159
StringRef LocationFilter;
159160
std::vector<std::string> ToolArgs;

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

+12-5
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,8 @@ void swift::ide::api::SDKNodeDeclType::diagnose(SDKNode *Right) {
794794
return;
795795
auto Loc = R->getLoc();
796796
if (getDeclKind() != R->getDeclKind()) {
797-
emitDiag(Loc, diag::decl_kind_changed, getDeclKindStr(R->getDeclKind()));
797+
emitDiag(Loc, diag::decl_kind_changed, getDeclKindStr(R->getDeclKind(),
798+
getSDKContext().getOpts().CompilerStyle));
798799
return;
799800
}
800801

@@ -986,7 +987,8 @@ void swift::ide::api::SDKNodeDeclOperator::diagnose(SDKNode *Right) {
986987
return;
987988
auto Loc = RO->getLoc();
988989
if (getDeclKind() != RO->getDeclKind()) {
989-
emitDiag(Loc, diag::decl_kind_changed, getDeclKindStr(RO->getDeclKind()));
990+
emitDiag(Loc, diag::decl_kind_changed, getDeclKindStr(RO->getDeclKind(),
991+
getSDKContext().getOpts().CompilerStyle));
990992
}
991993
}
992994

@@ -2121,7 +2123,8 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
21212123
if (auto *Added = findAddedDecl(Node)) {
21222124
if (Node->getDeclKind() != DeclKind::Constructor) {
21232125
Node->emitDiag(Added->getLoc(), diag::moved_decl,
2124-
Ctx.buffer((Twine(getDeclKindStr(Added->getDeclKind())) + " " +
2126+
Ctx.buffer((Twine(getDeclKindStr(Added->getDeclKind(),
2127+
Ctx.getOpts().CompilerStyle)) + " " +
21252128
Added->getFullyQualifiedName()).str()));
21262129
return;
21272130
}
@@ -2133,7 +2136,8 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
21332136
[&](TypeMemberDiffItem &Item) { return Item.usr == Node->getUsr(); });
21342137
if (It != MemberChanges.end()) {
21352138
Node->emitDiag(SourceLoc(), diag::renamed_decl,
2136-
Ctx.buffer((Twine(getDeclKindStr(Node->getDeclKind())) + " " +
2139+
Ctx.buffer((Twine(getDeclKindStr(Node->getDeclKind(),
2140+
Ctx.getOpts().CompilerStyle)) + " " +
21372141
It->newTypeName + "." + It->newPrintedName).str()));
21382142
return;
21392143
}
@@ -2190,7 +2194,8 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
21902194
DiagLoc = CD->getLoc();
21912195
}
21922196
Node->emitDiag(DiagLoc, diag::renamed_decl,
2193-
Ctx.buffer((Twine(getDeclKindStr(Node->getDeclKind())) + " " +
2197+
Ctx.buffer((Twine(getDeclKindStr(Node->getDeclKind(),
2198+
Ctx.getOpts().CompilerStyle)) + " " +
21942199
Node->getAnnotateComment(NodeAnnotation::RenameNewName)).str()));
21952200
return;
21962201
}
@@ -2701,6 +2706,8 @@ static CheckerOptions getCheckOpts(int argc, char *argv[]) {
27012706
// the checking logics are language-specific.
27022707
Opts.SwiftOnly = options::Abi || options::SwiftOnly;
27032708
Opts.SkipOSCheck = options::DisableOSChecks;
2709+
Opts.CompilerStyle = options::CompilerStyleDiags ||
2710+
!options::SerializedDiagPath.empty();
27042711
for (int i = 1; i < argc; ++i)
27052712
Opts.ToolArgs.push_back(argv[i]);
27062713

0 commit comments

Comments
 (0)