Skip to content

Commit 03dce36

Browse files
authored
Merge pull request #15713 from nkcsgexi/refine-diags
2 parents bd79ba2 + 6ffad80 commit 03dce36

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

test/api-digester/Outputs/apinotes-diags.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
/* Removed Decls */
3-
APINotesTest(APINotesTest.h): Var OldType.oldMember has been removed
43
APINotesTest(APINotesTest.h): Func ObjcProt.protMemberFunc2() has been removed
54
APINotesTest(APINotesTest.h): Func ObjcProt.protMemberFunc3() has been removed
65
APINotesTest(APINotesTest.h): Func SwiftTypeWithMethodLeft.getPropertyA() has been removed
@@ -9,6 +8,7 @@ APINotesTest(APINotesTest.h): Func SwiftTypeWithMethodLeft.getPropertyA() has be
98

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

1313
/* Type Changes */
1414
APINotesTest(APINotesTest.h): Func AnimalStatusDescriptor.addingAttributes(_:) has parameter 0 type change from [String : Any] to [AnimalAttributeName : Any]

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,6 +2681,8 @@ typedef std::vector<TypeMemberDiffItem> TypeMemberDiffVector;
26812681

26822682
} // end anonymous namespace
26832683

2684+
static void findTypeMemberDiffs(NodePtr leftSDKRoot, NodePtr rightSDKRoot,
2685+
TypeMemberDiffVector &out);
26842686

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

30073009
UpdatedNodesMap &UpdateMap;
3008-
DiagnosisEmitter(UpdatedNodesMap &UpdateMap) : UpdateMap(UpdateMap) {}
3010+
TypeMemberDiffVector &MemberChanges;
3011+
DiagnosisEmitter(UpdatedNodesMap &UpdateMap,
3012+
TypeMemberDiffVector &MemberChanges):
3013+
UpdateMap(UpdateMap), MemberChanges(MemberChanges) {}
30093014
public:
30103015
static void diagnosis(NodePtr LeftRoot, NodePtr RightRoot,
30113016
UpdatedNodesMap &UpdateMap);
@@ -3126,7 +3131,10 @@ void DiagnosisEmitter::DeclAttrDiag::output() const {
31263131

31273132
void DiagnosisEmitter::diagnosis(NodePtr LeftRoot, NodePtr RightRoot,
31283133
UpdatedNodesMap &UpdateMap) {
3129-
DiagnosisEmitter Emitter(UpdateMap);
3134+
// Find member hoist changes to help refine diagnostics.
3135+
TypeMemberDiffVector MemberChanges;
3136+
findTypeMemberDiffs(LeftRoot, RightRoot, MemberChanges);
3137+
DiagnosisEmitter Emitter(UpdateMap, MemberChanges);
31303138
collectAddedDecls(RightRoot, Emitter.AddedDecls);
31313139
SDKNode::postorderVisit(LeftRoot, Emitter);
31323140
}
@@ -3152,6 +3160,17 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
31523160
}
31533161
}
31543162

3163+
// If we can find a hoisted member for this removed delcaration, we
3164+
// emit the diagnostics as rename instead of removal.
3165+
auto It = std::find_if(MemberChanges.begin(), MemberChanges.end(),
3166+
[&](TypeMemberDiffItem &Item) { return Item.usr == Node->getUsr(); });
3167+
if (It != MemberChanges.end()) {
3168+
RenamedDecls.Diags.emplace_back(ScreenInfo, Node->getDeclKind(),
3169+
Node->getDeclKind(), Node->getFullyQualifiedName(),
3170+
Ctx.buffer((Twine(It->newTypeName) + "." + It->newPrintedName).str()));
3171+
return;
3172+
}
3173+
31553174
// We should exlude those declarations that are pulled up to the super classes.
31563175
bool FoundInSuperclass = false;
31573176
if (auto PD = dyn_cast<SDKNodeDecl>(Node->getParent())) {

0 commit comments

Comments
 (0)