Skip to content

Commit

Permalink
ABI Checker: use lower-cased decl keywords to be consistent with sour…
Browse files Browse the repository at this point in the history
…ce. NFC
  • Loading branch information
nkcsgexi committed Sep 12, 2020
1 parent 7dcb0ea commit 950eb74
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion include/swift/IDE/APIDigesterData.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ raw_ostream &operator<<(raw_ostream &Out, const NodeAnnotation Value);
// Redefine << so that we can output the name of the node kind.
raw_ostream &operator<<(raw_ostream &Out, const SDKNodeKind Value);

StringRef getDeclKindStr(const DeclKind Value);
StringRef getDeclKindStr(const DeclKind Value, bool lower);

// Redefine << so that we can output the name of decl kind.
raw_ostream &operator<<(raw_ostream &Out, const DeclKind Value);
Expand Down
21 changes: 17 additions & 4 deletions lib/IDE/APIDigesterData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,30 @@ operator<<(raw_ostream &Out, const NodeAnnotation Value) {
llvm_unreachable("Undefined SDK node kind.");
}

StringRef swift::ide::api::getDeclKindStr(const DeclKind Value) {
static StringRef getDeclKindStrRaw(const DeclKind Value) {
switch (Value) {
#define DECL(X, PARENT) case DeclKind::X: return #X;
#include "swift/AST/DeclNodes.def"
}
llvm_unreachable("Unhandled DeclKind in switch.");
}

raw_ostream &swift::ide::api::operator<<(raw_ostream &Out,
const DeclKind Value) {
return Out << getDeclKindStr(Value);
StringRef swift::ide::api::getDeclKindStr(const DeclKind Value, bool lower) {
if (lower) {
switch (Value) {
#define DECL(X, PARENT) case DeclKind::X: { \
static std::string lowered = StringRef(#X).lower(); \
return lowered; \
}
#include "swift/AST/DeclNodes.def"
}
} else {
return getDeclKindStrRaw(Value);
}
}

raw_ostream &swift::ide::api::operator<<(raw_ostream &Out, const DeclKind Value) {
return Out << getDeclKindStrRaw(Value);
}

Optional<SDKNodeKind> swift::ide::api::parseSDKNodeKind(StringRef Content) {
Expand Down
6 changes: 3 additions & 3 deletions test/api-digester/breakage-allowlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
// RUN: echo "public func foo() {}" > %t.mod1/Foo.swift
// RUN: echo "public func bar() {}" > %t.mod2/Foo.swift

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

// 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

Expand Down
4 changes: 2 additions & 2 deletions test/api-digester/compare-dump-abi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
// 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
// RUN: %FileCheck %s < %t.abi.compiler.diags

// CHECK: cake_current/cake.swift:39:15: error: cake: Struct C6 is now with @frozen
// CHECK: cake_current/cake.swift:41:13: error: cake: Enum IceKind is now without @frozen
// CHECK: cake_current/cake.swift:39:15: error: cake: struct C6 is now with @frozen
// CHECK: cake_current/cake.swift:41:13: error: cake: enum IceKind is now without @frozen
10 changes: 6 additions & 4 deletions tools/swift-api-digester/ModuleAnalyzerNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,12 @@ StringRef SDKNodeDecl::getScreenInfo() const {
if (auto *TD = dyn_cast<SDKNodeDeclType>(this)) {
IsExtension = TD->isExternal();
}
if (IsExtension)
OS << "Extension";
else
OS << getDeclKind();

// There is no particular reasons why we don't use lower-cased keyword names
// in non-CompilerStyle mode. This is to be backward compatible so clients
// don't need to update existing known breakages.
OS << getDeclKindStr(IsExtension? DeclKind::Extension : getDeclKind(),
getSDKContext().getOpts().CompilerStyle);
OS << " " << getFullyQualifiedName();
return Ctx.buffer(OS.str());
}
Expand Down
1 change: 1 addition & 0 deletions tools/swift-api-digester/ModuleAnalyzerNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ struct CheckerOptions {
bool PrintModule;
bool SwiftOnly;
bool SkipOSCheck;
bool CompilerStyle;
bool Migrator;
StringRef LocationFilter;
std::vector<std::string> ToolArgs;
Expand Down
17 changes: 12 additions & 5 deletions tools/swift-api-digester/swift-api-digester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,8 @@ void swift::ide::api::SDKNodeDeclType::diagnose(SDKNode *Right) {
return;
auto Loc = R->getLoc();
if (getDeclKind() != R->getDeclKind()) {
emitDiag(Loc, diag::decl_kind_changed, getDeclKindStr(R->getDeclKind()));
emitDiag(Loc, diag::decl_kind_changed, getDeclKindStr(R->getDeclKind(),
getSDKContext().getOpts().CompilerStyle));
return;
}

Expand Down Expand Up @@ -986,7 +987,8 @@ void swift::ide::api::SDKNodeDeclOperator::diagnose(SDKNode *Right) {
return;
auto Loc = RO->getLoc();
if (getDeclKind() != RO->getDeclKind()) {
emitDiag(Loc, diag::decl_kind_changed, getDeclKindStr(RO->getDeclKind()));
emitDiag(Loc, diag::decl_kind_changed, getDeclKindStr(RO->getDeclKind(),
getSDKContext().getOpts().CompilerStyle));
}
}

Expand Down Expand Up @@ -2121,7 +2123,8 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
if (auto *Added = findAddedDecl(Node)) {
if (Node->getDeclKind() != DeclKind::Constructor) {
Node->emitDiag(Added->getLoc(), diag::moved_decl,
Ctx.buffer((Twine(getDeclKindStr(Added->getDeclKind())) + " " +
Ctx.buffer((Twine(getDeclKindStr(Added->getDeclKind(),
Ctx.getOpts().CompilerStyle)) + " " +
Added->getFullyQualifiedName()).str()));
return;
}
Expand All @@ -2133,7 +2136,8 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
[&](TypeMemberDiffItem &Item) { return Item.usr == Node->getUsr(); });
if (It != MemberChanges.end()) {
Node->emitDiag(SourceLoc(), diag::renamed_decl,
Ctx.buffer((Twine(getDeclKindStr(Node->getDeclKind())) + " " +
Ctx.buffer((Twine(getDeclKindStr(Node->getDeclKind(),
Ctx.getOpts().CompilerStyle)) + " " +
It->newTypeName + "." + It->newPrintedName).str()));
return;
}
Expand Down Expand Up @@ -2190,7 +2194,8 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
DiagLoc = CD->getLoc();
}
Node->emitDiag(DiagLoc, diag::renamed_decl,
Ctx.buffer((Twine(getDeclKindStr(Node->getDeclKind())) + " " +
Ctx.buffer((Twine(getDeclKindStr(Node->getDeclKind(),
Ctx.getOpts().CompilerStyle)) + " " +
Node->getAnnotateComment(NodeAnnotation::RenameNewName)).str()));
return;
}
Expand Down Expand Up @@ -2701,6 +2706,8 @@ static CheckerOptions getCheckOpts(int argc, char *argv[]) {
// the checking logics are language-specific.
Opts.SwiftOnly = options::Abi || options::SwiftOnly;
Opts.SkipOSCheck = options::DisableOSChecks;
Opts.CompilerStyle = options::CompilerStyleDiags ||
!options::SerializedDiagPath.empty();
for (int i = 1; i < argc; ++i)
Opts.ToolArgs.push_back(argv[i]);

Expand Down

0 comments on commit 950eb74

Please sign in to comment.