Skip to content

swift-api-digester: teach the tool to output constructors' parameter type changes. #5351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/api-digester/Inputs/cake1.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
public struct S1 {
mutating public func foo1() {}
public init(_ : Int) {}
public func foo1() {}
mutating public func foo2() {}
}
5 changes: 5 additions & 0 deletions test/api-digester/Inputs/cake2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public struct S1 {
public init(_ : Double) {}
mutating public func foo1() {}
mutating public func foo2() {}
}
3 changes: 2 additions & 1 deletion test/api-digester/Outputs/Cake.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
==================================================== Renamed Decls ====================================================

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

==================================================== Decl Attribute changes ====================================================
FuncS1.foo1() is now mutating
Func S1.foo1() is now mutating
6 changes: 3 additions & 3 deletions test/api-digester/compare-dump.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// RUN: rm -rf %t.mod && mkdir -p %t.mod
// RUN: rm -rf %t.sdk && mkdir -p %t.sdk
// RUN: rm -rf %t.module-cache && mkdir -p %t.module-cache
// RUN: %swift -emit-module -o %t.mod/cake.swiftmodule %S/Inputs/cake.swift -parse-as-library
// RUN: %swift -emit-module -o %t.mod/cake1.swiftmodule %S/Inputs/cake1.swift -parse-as-library
// 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
// RUN: %swift -emit-module -o %t.mod/cake2.swiftmodule %S/Inputs/cake2.swift -parse-as-library
// 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
// RUN: %api-digester -diagnose-sdk --input-paths %t.dump.json -input-paths %t.dump1.json > %t.result
// 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
// RUN: %api-digester -diagnose-sdk --input-paths %t.dump1.json -input-paths %t.dump2.json > %t.result
// RUN: diff -u %S/Outputs/Cake.txt %t.result
11 changes: 6 additions & 5 deletions tools/swift-api-digester/swift-api-digester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ class SDKNodeAbstractFunc : public SDKNodeDecl {
Optional<uint8_t> getSelfIndexOptional() const { return SelfIndex; }
bool hasSelfIndex() const { return SelfIndex.hasValue(); }
static bool classof(const SDKNode *N);
static StringRef getTypeRoleDescription(unsigned Index);
};

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

StringRef SDKNodeFunction::getTypeRoleDescription(unsigned Index) {
StringRef SDKNodeAbstractFunc::getTypeRoleDescription(unsigned Index) {
if (Index == 0) {
return InsertToBuffer("return");
} else if (Index == 1) {
Expand Down Expand Up @@ -2814,7 +2814,7 @@ bool DiagnosisEmitter::DeclAttrDiag::operator<(DeclAttrDiag Other) const {
}

void DiagnosisEmitter::DeclAttrDiag::output() const {
llvm::outs() << Kind << "" << printName(DeclName) << " is now " <<
llvm::outs() << Kind << " " << printName(DeclName) << " is now " <<
printDiagKeyword(AttrName) << "\n";
}

Expand Down Expand Up @@ -2867,10 +2867,11 @@ void DiagnosisEmitter::visitType(SDKNodeType *Node) {
auto *Count = UpdateMap.findUpdateCounterpart(Node)->getAs<SDKNodeType>();
StringRef Descriptor;
switch (Parent->getKind()) {
case SDKNodeKind::Constructor:
case SDKNodeKind::Function:
case SDKNodeKind::Var:
Descriptor = Parent->getKind() == SDKNodeKind::Function ?
SDKNodeFunction::getTypeRoleDescription(Parent->getChildIndex(Node)) :
Descriptor = isa<SDKNodeAbstractFunc>(Parent) ?
SDKNodeAbstractFunc::getTypeRoleDescription(Parent->getChildIndex(Node)) :
InsertToBuffer("declared");
TypeChangedDecls.Diags.emplace_back(Parent->getDeclKind(),
Parent->getFullyQualifiedName(),
Expand Down