Skip to content

swift-api-digester: mark hoisted global declarations as renamed instead of removed. #15713

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 1 commit into from
Apr 3, 2018
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
2 changes: 1 addition & 1 deletion test/api-digester/Outputs/apinotes-diags.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

/* Removed Decls */
APINotesTest(APINotesTest.h): Var OldType.oldMember has been removed
APINotesTest(APINotesTest.h): Func ObjcProt.protMemberFunc2() has been removed
APINotesTest(APINotesTest.h): Func ObjcProt.protMemberFunc3() has been removed
APINotesTest(APINotesTest.h): Func SwiftTypeWithMethodLeft.getPropertyA() has been removed
Expand All @@ -9,6 +8,7 @@ APINotesTest(APINotesTest.h): Func SwiftTypeWithMethodLeft.getPropertyA() has be

/* Renamed Decls */
APINotesTest(APINotesTest.h): Protocol SwiftTypeWithMethodLeft has been renamed to Protocol SwiftTypeWithMethodRight
APINotesTest(APINotesTest.h): Var OldType.oldMember has been renamed to Var NewType.newMember

/* Type Changes */
APINotesTest(APINotesTest.h): Func AnimalStatusDescriptor.addingAttributes(_:) has parameter 0 type change from [String : Any] to [AnimalAttributeName : Any]
Expand Down
23 changes: 21 additions & 2 deletions tools/swift-api-digester/swift-api-digester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2681,6 +2681,8 @@ typedef std::vector<TypeMemberDiffItem> TypeMemberDiffVector;

} // end anonymous namespace

static void findTypeMemberDiffs(NodePtr leftSDKRoot, NodePtr rightSDKRoot,
TypeMemberDiffVector &out);

static void printNode(llvm::raw_ostream &os, NodePtr node) {
os << "{" << node->getName() << " " << node->getKind() << " "
Expand Down Expand Up @@ -3005,7 +3007,10 @@ class DiagnosisEmitter : public SDKNodeVisitor {
DiagBag<RemovedDeclDiag> RemovedDecls;

UpdatedNodesMap &UpdateMap;
DiagnosisEmitter(UpdatedNodesMap &UpdateMap) : UpdateMap(UpdateMap) {}
TypeMemberDiffVector &MemberChanges;
DiagnosisEmitter(UpdatedNodesMap &UpdateMap,
TypeMemberDiffVector &MemberChanges):
UpdateMap(UpdateMap), MemberChanges(MemberChanges) {}
public:
static void diagnosis(NodePtr LeftRoot, NodePtr RightRoot,
UpdatedNodesMap &UpdateMap);
Expand Down Expand Up @@ -3126,7 +3131,10 @@ void DiagnosisEmitter::DeclAttrDiag::output() const {

void DiagnosisEmitter::diagnosis(NodePtr LeftRoot, NodePtr RightRoot,
UpdatedNodesMap &UpdateMap) {
DiagnosisEmitter Emitter(UpdateMap);
// Find member hoist changes to help refine diagnostics.
TypeMemberDiffVector MemberChanges;
findTypeMemberDiffs(LeftRoot, RightRoot, MemberChanges);
DiagnosisEmitter Emitter(UpdateMap, MemberChanges);
collectAddedDecls(RightRoot, Emitter.AddedDecls);
SDKNode::postorderVisit(LeftRoot, Emitter);
}
Expand All @@ -3152,6 +3160,17 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
}
}

// If we can find a hoisted member for this removed delcaration, we
// emit the diagnostics as rename instead of removal.
auto It = std::find_if(MemberChanges.begin(), MemberChanges.end(),
[&](TypeMemberDiffItem &Item) { return Item.usr == Node->getUsr(); });
if (It != MemberChanges.end()) {
RenamedDecls.Diags.emplace_back(ScreenInfo, Node->getDeclKind(),
Node->getDeclKind(), Node->getFullyQualifiedName(),
Ctx.buffer((Twine(It->newTypeName) + "." + It->newPrintedName).str()));
return;
}

// We should exlude those declarations that are pulled up to the super classes.
bool FoundInSuperclass = false;
if (auto PD = dyn_cast<SDKNodeDecl>(Node->getParent())) {
Expand Down