Skip to content

Commit 647f65e

Browse files
authored
swift-api-digester: teach the tool to output constructors' parameter type changes. (#5351)
1 parent 2f89495 commit 647f65e

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

test/api-digester/Inputs/cake1.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
public struct S1 {
2-
mutating public func foo1() {}
2+
public init(_ : Int) {}
3+
public func foo1() {}
34
mutating public func foo2() {}
45
}

test/api-digester/Inputs/cake2.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public struct S1 {
2+
public init(_ : Double) {}
3+
mutating public func foo1() {}
4+
mutating public func foo2() {}
5+
}

test/api-digester/Outputs/Cake.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
==================================================== Renamed Decls ====================================================
77

88
==================================================== Type Changes ====================================================
9+
Constructor S1.init(_:) has 1st parameter type change from Int to Double
910

1011
==================================================== Decl Attribute changes ====================================================
11-
FuncS1.foo1() is now mutating
12+
Func S1.foo1() is now mutating

test/api-digester/compare-dump.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: rm -rf %t.mod && mkdir -p %t.mod
22
// RUN: rm -rf %t.sdk && mkdir -p %t.sdk
33
// RUN: rm -rf %t.module-cache && mkdir -p %t.module-cache
4-
// RUN: %swift -emit-module -o %t.mod/cake.swiftmodule %S/Inputs/cake.swift -parse-as-library
54
// RUN: %swift -emit-module -o %t.mod/cake1.swiftmodule %S/Inputs/cake1.swift -parse-as-library
6-
// RUN: %api-digester -dump-sdk -module cake -o %t.dump.json -module-cache-path %t.module-cache -sdk %t.sdk -swift-version 3.0 -I %t.mod
5+
// RUN: %swift -emit-module -o %t.mod/cake2.swiftmodule %S/Inputs/cake2.swift -parse-as-library
76
// RUN: %api-digester -dump-sdk -module cake1 -o %t.dump1.json -module-cache-path %t.module-cache -sdk %t.sdk -swift-version 3.0 -I %t.mod
8-
// RUN: %api-digester -diagnose-sdk --input-paths %t.dump.json -input-paths %t.dump1.json > %t.result
7+
// RUN: %api-digester -dump-sdk -module cake2 -o %t.dump2.json -module-cache-path %t.module-cache -sdk %t.sdk -swift-version 3.0 -I %t.mod
8+
// RUN: %api-digester -diagnose-sdk --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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ class SDKNodeAbstractFunc : public SDKNodeDecl {
668668
Optional<uint8_t> getSelfIndexOptional() const { return SelfIndex; }
669669
bool hasSelfIndex() const { return SelfIndex.hasValue(); }
670670
static bool classof(const SDKNode *N);
671+
static StringRef getTypeRoleDescription(unsigned Index);
671672
};
672673

673674
bool SDKNodeAbstractFunc::classof(const SDKNode *N) {
@@ -689,10 +690,9 @@ class SDKNodeFunction : public SDKNodeAbstractFunc {
689690
SDKNodeKind::Function) {}
690691
SDKNode *getReturnType() { return (*getChildBegin()).get(); }
691692
static bool classof(const SDKNode *N);
692-
static StringRef getTypeRoleDescription(unsigned Index);
693693
};
694694

695-
StringRef SDKNodeFunction::getTypeRoleDescription(unsigned Index) {
695+
StringRef SDKNodeAbstractFunc::getTypeRoleDescription(unsigned Index) {
696696
if (Index == 0) {
697697
return InsertToBuffer("return");
698698
} else if (Index == 1) {
@@ -2814,7 +2814,7 @@ bool DiagnosisEmitter::DeclAttrDiag::operator<(DeclAttrDiag Other) const {
28142814
}
28152815

28162816
void DiagnosisEmitter::DeclAttrDiag::output() const {
2817-
llvm::outs() << Kind << "" << printName(DeclName) << " is now " <<
2817+
llvm::outs() << Kind << " " << printName(DeclName) << " is now " <<
28182818
printDiagKeyword(AttrName) << "\n";
28192819
}
28202820

@@ -2867,10 +2867,11 @@ void DiagnosisEmitter::visitType(SDKNodeType *Node) {
28672867
auto *Count = UpdateMap.findUpdateCounterpart(Node)->getAs<SDKNodeType>();
28682868
StringRef Descriptor;
28692869
switch (Parent->getKind()) {
2870+
case SDKNodeKind::Constructor:
28702871
case SDKNodeKind::Function:
28712872
case SDKNodeKind::Var:
2872-
Descriptor = Parent->getKind() == SDKNodeKind::Function ?
2873-
SDKNodeFunction::getTypeRoleDescription(Parent->getChildIndex(Node)) :
2873+
Descriptor = isa<SDKNodeAbstractFunc>(Parent) ?
2874+
SDKNodeAbstractFunc::getTypeRoleDescription(Parent->getChildIndex(Node)) :
28742875
InsertToBuffer("declared");
28752876
TypeChangedDecls.Diags.emplace_back(Parent->getDeclKind(),
28762877
Parent->getFullyQualifiedName(),

0 commit comments

Comments
 (0)