Skip to content

Commit cd3b34c

Browse files
authored
swift-api-digester: for each source-breaking item, we should output its framework name to help screening. rdar://35421724 (#14068)
The framework name is behind a flag "print-module". We should print them during whole-sdk checks however not in the per-framework diffing tool.
1 parent 98fc073 commit cd3b34c

File tree

3 files changed

+72
-45
lines changed

3 files changed

+72
-45
lines changed

test/api-digester/Outputs/Cake.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11

22
/* Removed Decls */
3-
Constructor Somestruct2.init(_:) has been removed
4-
Func C4.foo() has been removed
3+
cake1: Constructor Somestruct2.init(_:) has been removed
4+
cake1: Func C4.foo() has been removed
55

66
/* Moved Decls */
77

88
/* Renamed Decls */
9-
Struct Somestruct2 has been renamed to Struct NSSomestruct2
10-
Func S1.foo5(x:y:) has been renamed to Func S1.foo5(x:y:z:)
9+
cake1: Struct Somestruct2 has been renamed to Struct NSSomestruct2
10+
cake1: Func S1.foo5(x:y:) has been renamed to Func S1.foo5(x:y:z:)
1111

1212
/* Type Changes */
13-
Constructor S1.init(_:) has parameter 0 type change from Int to Double
14-
Func C1.foo2(_:) has parameter 0 type change from Int to () -> ()
13+
cake1: Constructor S1.init(_:) has parameter 0 type change from Int to Double
14+
cake1: Func C1.foo2(_:) has parameter 0 type change from Int to () -> ()
1515

1616
/* Decl Attribute changes */
17-
Var C1.CIIns1 changes from weak to strong
18-
Var C1.CIIns2 changes from strong to weak
19-
Func C1.foo1() is now not static
20-
Func S1.foo3() is now static
21-
Func S1.foo1() is now mutating
17+
cake1: Var C1.CIIns1 changes from weak to strong
18+
cake1: Var C1.CIIns2 changes from strong to weak
19+
cake1: Func C1.foo1() is now not static
20+
cake1: Func S1.foo3() is now static
21+
cake1: Func S1.foo1() is now mutating

test/api-digester/compare-dump.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
// RUN: %swift -emit-module -o %t.mod/cake2.swiftmodule %S/Inputs/cake2.swift -parse-as-library -I %S/Inputs/APINotesRight
66
// RUN: %api-digester -dump-sdk -module cake1 -o %t.dump1.json -module-cache-path %t.module-cache -sdk %t.sdk -swift-version 3 -I %t.mod -I %S/Inputs/APINotesLeft
77
// RUN: %api-digester -dump-sdk -module cake2 -o %t.dump2.json -module-cache-path %t.module-cache -sdk %t.sdk -swift-version 3 -I %t.mod -I %S/Inputs/APINotesRight
8-
// RUN: %api-digester -diagnose-sdk --input-paths %t.dump1.json -input-paths %t.dump2.json > %t.result
8+
// RUN: %api-digester -diagnose-sdk -print-module --input-paths %t.dump1.json -input-paths %t.dump2.json > %t.result
99
// RUN: diff -u %S/Outputs/Cake.txt %t.result

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

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ AbortOnModuleLoadFailure("abort-on-module-fail",
115115
static llvm::cl::opt<bool>
116116
Verbose("v", llvm::cl::desc("Verbose"));
117117

118+
static llvm::cl::opt<bool>
119+
PrintModule("print-module", llvm::cl::desc("Print module names in diagnostics"));
120+
118121
static llvm::cl::opt<ActionType>
119122
Action(llvm::cl::desc("Mode:"), llvm::cl::init(ActionType::None),
120123
llvm::cl::values(
@@ -2656,79 +2659,95 @@ class DiagnosisEmitter : public SDKNodeVisitor {
26562659
llvm::outs() << " */\n";
26572660
removeRedundantAndSort(Diags);
26582661
std::for_each(Diags.begin(), Diags.end(), [](T &Diag) {
2662+
Diag.outputModule();
26592663
Diag.output();
26602664
});
26612665
}
26622666
};
26632667

2664-
struct RemovedDeclDiag {
2668+
struct DiagBase {
2669+
StringRef ModuleName;
2670+
DiagBase(StringRef ModuleName): ModuleName(ModuleName) {}
2671+
virtual ~DiagBase() = default;
2672+
void outputModule() const {
2673+
if (options::PrintModule)
2674+
llvm::outs() << ModuleName << ": ";
2675+
}
2676+
virtual void output() const = 0;
2677+
};
2678+
2679+
struct RemovedDeclDiag: public DiagBase {
26652680
DeclKind Kind;
26662681
StringRef Name;
26672682
bool IsDeprecated;
2668-
RemovedDeclDiag(DeclKind Kind, StringRef Name, bool IsDeprecated) :
2669-
Kind(Kind), Name(Name), IsDeprecated(IsDeprecated) {}
2683+
RemovedDeclDiag(StringRef ModuleName, DeclKind Kind, StringRef Name,
2684+
bool IsDeprecated): DiagBase(ModuleName), Kind(Kind),
2685+
Name(Name), IsDeprecated(IsDeprecated) {}
26702686
bool operator<(RemovedDeclDiag Other) const;
2671-
void output() const;
2687+
void output() const override;
26722688
static void theme(raw_ostream &OS) { OS << "Removed Decls"; };
26732689
};
26742690

2675-
struct MovedDeclDiag {
2691+
struct MovedDeclDiag: public DiagBase {
26762692
DeclKind RemovedKind;
26772693
DeclKind AddedKind;
26782694
StringRef RemovedName;
26792695
StringRef AddedName;
2680-
MovedDeclDiag(DeclKind RemovedKind, DeclKind AddedKind,
2681-
StringRef RemovedName, StringRef AddedName) :
2682-
RemovedKind(RemovedKind), AddedKind(AddedKind), RemovedName(RemovedName),
2683-
AddedName(AddedName) {}
2696+
MovedDeclDiag(StringRef ModuleName, DeclKind RemovedKind, DeclKind AddedKind,
2697+
StringRef RemovedName, StringRef AddedName):
2698+
DiagBase(ModuleName), RemovedKind(RemovedKind), AddedKind(AddedKind),
2699+
RemovedName(RemovedName), AddedName(AddedName) {}
26842700
bool operator<(MovedDeclDiag other) const;
2685-
void output() const;
2701+
void output() const override;
26862702
static void theme(raw_ostream &OS) { OS << "Moved Decls"; };
26872703
};
26882704

2689-
struct RenamedDeclDiag {
2705+
struct RenamedDeclDiag: public DiagBase {
26902706
DeclKind KindBefore;
26912707
DeclKind KindAfter;
26922708
StringRef NameBefore;
26932709
StringRef NameAfter;
2694-
RenamedDeclDiag(DeclKind KindBefore, DeclKind KindAfter,
2695-
StringRef NameBefore, StringRef NameAfter) :
2710+
RenamedDeclDiag(StringRef ModuleName, DeclKind KindBefore, DeclKind KindAfter,
2711+
StringRef NameBefore, StringRef NameAfter):
2712+
DiagBase(ModuleName),
26962713
KindBefore(KindBefore), KindAfter(KindAfter),
26972714
NameBefore(NameBefore), NameAfter(NameAfter) {}
26982715
bool operator<(RenamedDeclDiag Other) const;
2699-
void output() const;
2716+
void output() const override;
27002717
static void theme(raw_ostream &OS) { OS << "Renamed Decls"; };
27012718
};
27022719

2703-
struct DeclAttrDiag {
2720+
struct DeclAttrDiag: public DiagBase {
27042721
DeclKind Kind;
27052722
StringRef DeclName;
27062723
StringRef AttrBefore;
27072724
StringRef AttrAfter;
2708-
DeclAttrDiag(DeclKind Kind, StringRef DeclName, StringRef AttrBefore,
2709-
StringRef AttrAfter) : Kind(Kind), DeclName(DeclName),
2710-
AttrBefore(AttrBefore), AttrAfter(AttrAfter) {}
2711-
DeclAttrDiag(DeclKind Kind, StringRef DeclName, StringRef AttrAfter) :
2712-
DeclAttrDiag(Kind, DeclName, StringRef(), AttrAfter) {}
2725+
DeclAttrDiag(StringRef ModuleName, DeclKind Kind, StringRef DeclName,
2726+
StringRef AttrBefore, StringRef AttrAfter):
2727+
DiagBase(ModuleName), Kind(Kind), DeclName(DeclName),
2728+
AttrBefore(AttrBefore), AttrAfter(AttrAfter) {}
2729+
DeclAttrDiag(StringRef ModuleName, DeclKind Kind, StringRef DeclName,
2730+
StringRef AttrAfter): DeclAttrDiag(ModuleName, Kind, DeclName,
2731+
StringRef(), AttrAfter) {}
27132732

27142733
bool operator<(DeclAttrDiag Other) const;
2715-
void output() const;
2734+
void output() const override;
27162735
static void theme(raw_ostream &OS) { OS << "Decl Attribute changes"; };
27172736
};
27182737

2719-
struct DeclTypeChangeDiag {
2738+
struct DeclTypeChangeDiag: public DiagBase {
27202739
DeclKind Kind;
27212740
StringRef DeclName;
27222741
StringRef TypeNameBefore;
27232742
StringRef TypeNameAfter;
27242743
StringRef Description;
2725-
DeclTypeChangeDiag(DeclKind Kind, StringRef DeclName,
2744+
DeclTypeChangeDiag(StringRef ModuleName, DeclKind Kind, StringRef DeclName,
27262745
StringRef TypeNameBefore, StringRef TypeNameAfter,
2727-
StringRef Description) :
2746+
StringRef Description): DiagBase(ModuleName),
27282747
Kind(Kind), DeclName(DeclName), TypeNameBefore(TypeNameBefore),
27292748
TypeNameAfter(TypeNameAfter), Description(Description) {}
27302749
bool operator<(DeclTypeChangeDiag Other) const;
2731-
void output() const;
2750+
void output() const override;
27322751
static void theme(raw_ostream &OS) { OS << "Type Changes"; };
27332752
};
27342753

@@ -2877,7 +2896,8 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
28772896
return;
28782897
if (auto *Added = findAddedDecl(Node)) {
28792898
if (Node->getDeclKind() != DeclKind::Constructor) {
2880-
MovedDecls.Diags.emplace_back(Node->getDeclKind(),
2899+
MovedDecls.Diags.emplace_back(Node->getModuleName(),
2900+
Node->getDeclKind(),
28812901
Added->getDeclKind(),
28822902
Node->getFullyQualifiedName(),
28832903
Added->getFullyQualifiedName());
@@ -2900,32 +2920,37 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
29002920
}
29012921
if (FoundInSuperclass)
29022922
return;
2903-
RemovedDecls.Diags.emplace_back(Node->getDeclKind(),
2923+
RemovedDecls.Diags.emplace_back(Node->getModuleName(),
2924+
Node->getDeclKind(),
29042925
Node->getFullyQualifiedName(),
29052926
Node->isDeprecated());
29062927
return;
29072928
}
29082929
case NodeAnnotation::Rename: {
29092930
auto *Count = UpdateMap.findUpdateCounterpart(Node)->getAs<SDKNodeDecl>();
2910-
RenamedDecls.Diags.emplace_back(Node->getDeclKind(), Count->getDeclKind(),
2931+
RenamedDecls.Diags.emplace_back(Node->getModuleName(),
2932+
Node->getDeclKind(), Count->getDeclKind(),
29112933
Node->getFullyQualifiedName(),
29122934
Count->getFullyQualifiedName());
29132935
return;
29142936
}
29152937
case NodeAnnotation::NowMutating: {
2916-
AttrChangedDecls.Diags.emplace_back(Node->getDeclKind(),
2938+
AttrChangedDecls.Diags.emplace_back(Node->getModuleName(),
2939+
Node->getDeclKind(),
29172940
Node->getFullyQualifiedName(),
29182941
Ctx.buffer("mutating"));
29192942
return;
29202943
}
29212944
case NodeAnnotation::NowThrowing: {
2922-
AttrChangedDecls.Diags.emplace_back(Node->getDeclKind(),
2945+
AttrChangedDecls.Diags.emplace_back(Node->getModuleName(),
2946+
Node->getDeclKind(),
29232947
Node->getFullyQualifiedName(),
29242948
Ctx.buffer("throwing"));
29252949
return;
29262950
}
29272951
case NodeAnnotation::StaticChange: {
2928-
AttrChangedDecls.Diags.emplace_back(Node->getDeclKind(),
2952+
AttrChangedDecls.Diags.emplace_back(Node->getModuleName(),
2953+
Node->getDeclKind(),
29292954
Node->getFullyQualifiedName(),
29302955
Ctx.buffer(Node->isStatic() ? "not static" : "static"));
29312956
return;
@@ -2942,7 +2967,8 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
29422967
llvm_unreachable("Unhandled Ownership in switch.");
29432968
};
29442969
auto *Count = UpdateMap.findUpdateCounterpart(Node)->getAs<SDKNodeDecl>();
2945-
AttrChangedDecls.Diags.emplace_back(Node->getDeclKind(),
2970+
AttrChangedDecls.Diags.emplace_back(Node->getModuleName(),
2971+
Node->getDeclKind(),
29462972
Node->getFullyQualifiedName(),
29472973
getOwnershipDescription(Node->getOwnership()),
29482974
getOwnershipDescription(Count->getOwnership()));
@@ -2977,7 +3003,8 @@ void DiagnosisEmitter::visitType(SDKNodeType *Node) {
29773003
SDKNodeAbstractFunc::getTypeRoleDescription(Ctx, Parent->getChildIndex(Node)) :
29783004
Ctx.buffer("declared");
29793005
if (Node->getPrintedName() != Count->getPrintedName())
2980-
TypeChangedDecls.Diags.emplace_back(Parent->getDeclKind(),
3006+
TypeChangedDecls.Diags.emplace_back(Parent->getModuleName(),
3007+
Parent->getDeclKind(),
29813008
Parent->getFullyQualifiedName(),
29823009
Node->getPrintedName(),
29833010
Count->getPrintedName(),

0 commit comments

Comments
 (0)