Skip to content

swift-api-digester: detect the move of static members only. #10005

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
May 31, 2017
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
1 change: 1 addition & 0 deletions include/swift/IDE/APIDigesterData.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ struct CommonDiffItem: public APIDiffItem {
//
enum class TypeMemberDiffItemSubKind {
SimpleReplacement,
QualifiedReplacement,
GlobalFuncToStaticProperty,
HoistSelfOnly,
HoistSelfAndRemoveParam,
Expand Down
5 changes: 4 additions & 1 deletion lib/IDE/APIDigesterData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,12 @@ swift::ide::api::TypeMemberDiffItem::getSubKind() const {
} else if (ToProperty) {
assert(OldName.argSize() == 1);
return TypeMemberDiffItemSubKind::HoistSelfAndUseProperty;
} else {
} else if (oldTypeName.empty()) {
assert(NewName.argSize() + 1 == OldName.argSize());
return TypeMemberDiffItemSubKind::HoistSelfOnly;
} else {
assert(NewName.argSize() == OldName.argSize());
return TypeMemberDiffItemSubKind::QualifiedReplacement;
}
} else if (ToProperty) {
assert(OldName.argSize() == 0);
Expand Down
4 changes: 3 additions & 1 deletion lib/Migrator/APIDiffMigratorPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
}
if (!Item)
return false;
if (Item->Subkind == TypeMemberDiffItemSubKind::SimpleReplacement)
if (Item->Subkind == TypeMemberDiffItemSubKind::SimpleReplacement ||
Item->Subkind == TypeMemberDiffItemSubKind::QualifiedReplacement)
return false;

if (Item->Subkind == TypeMemberDiffItemSubKind::GlobalFuncToStaticProperty) {
Expand Down Expand Up @@ -490,6 +491,7 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
switch (Item->Subkind) {
case TypeMemberDiffItemSubKind::GlobalFuncToStaticProperty:
case TypeMemberDiffItemSubKind::SimpleReplacement:
case TypeMemberDiffItemSubKind::QualifiedReplacement:
llvm_unreachable("should be handled elsewhere");
case TypeMemberDiffItemSubKind::HoistSelfOnly:
// we are done here.
Expand Down
3 changes: 3 additions & 0 deletions test/api-digester/Inputs/APINotesLeft/APINotesTest.apinotes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ Name: APINotesTest
Globals:
- Name: ANTGlobalValue
SwiftName: OldType.oldMember
Protocols:
- Name: TypeWithMethod
SwiftName: SwiftTypeWithMethodLeft
5 changes: 5 additions & 0 deletions test/api-digester/Inputs/APINotesLeft/APINotesTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ extern int ANTGlobalValue;
@end
@interface OldType
@end

@protocol TypeWithMethod
-(void) minusPrint;
+(void) plusPrint;
@end
3 changes: 3 additions & 0 deletions test/api-digester/Inputs/APINotesRight/APINotesTest.apinotes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ Name: APINotesTest
Globals:
- Name: ANTGlobalValue
SwiftName: NewType.newMember
Protocols:
- Name: TypeWithMethod
SwiftName: SwiftTypeWithMethodRight
7 changes: 6 additions & 1 deletion test/api-digester/Inputs/APINotesRight/APINotesTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ extern int ANTGlobalValue;
@interface NewType
@end
@interface OldType
@end
@end

@protocol TypeWithMethod
-(void) minusPrint;
+(void) plusPrint;
@end
8 changes: 8 additions & 0 deletions test/api-digester/Outputs/apinotes-migrator-gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
"OldTypeName": "OldType",
"NewPrintedName": "newMember",
"NewTypeName": "NewType"
},
{
"DiffItemKind": "TypeMemberDiffItem",
"Usr": "c:objc(pl)TypeWithMethod(cm)plusPrint",
"OldPrintedName": "plusPrint()",
"OldTypeName": "SwiftTypeWithMethodLeft",
"NewPrintedName": "plusPrint()",
"NewTypeName": "SwiftTypeWithMethodRight"
}
]
52 changes: 27 additions & 25 deletions tools/swift-api-digester/swift-api-digester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ class SDKTreeDiffPass {
virtual ~SDKTreeDiffPass() {}
};

using NodePairVector = std::vector<std::pair<NodePtr, NodePtr>>;
using NodePairVector = llvm::MapVector<NodePtr, NodePtr>;

// This map keeps track of updated nodes; thus we can conveniently find out what
// is the counterpart of a node before or after being updated.
Expand All @@ -1947,7 +1947,7 @@ class UpdatedNodesMap : public MatchedNodeListener {
public:
void foundMatch(NodePtr Left, NodePtr Right) override {
assert(Left && Right && "Not update operation.");
MapImpl.push_back(std::make_pair(Left, Right));
MapImpl.insert({Left, Right});
}

NodePtr findUpdateCounterpart(const SDKNode *Node) const {
Expand Down Expand Up @@ -2133,6 +2133,26 @@ class MapUSRToNode : public SDKNodeVisitor {
MapUSRToNode &operator=(MapUSRToNode &) = delete;
};

static StringRef constructFullTypeName(NodePtr Node) {
assert(Node->getKind() == SDKNodeKind::TypeDecl);
std::vector<NodePtr> TypeChain;
for (auto C = Node; C->getKind() == SDKNodeKind::TypeDecl; C = C->getParent()) {
TypeChain.insert(TypeChain.begin(), C);
}
assert(TypeChain.front()->getParent()->getKind() == SDKNodeKind::Root);
llvm::SmallString<64> Buffer;
bool First = true;
for (auto N : TypeChain) {
if (First) {
First = false;
} else {
Buffer.append(".");
}
Buffer.append(N->getName());
}
return Node->getSDKContext().buffer(Buffer.str());
}

// Class to build up a diff of structurally different nodes, based on the given
// USR map for the left (original) side of the diff, based on parent types.
class TypeMemberDiffFinder : public SDKNodeVisitor {
Expand Down Expand Up @@ -2162,11 +2182,13 @@ class TypeMemberDiffFinder : public SDKNodeVisitor {
// Move from global variable to a member variable.
if (nodeParent->getKind() == SDKNodeKind::TypeDecl &&
diffParent->getKind() == SDKNodeKind::Root)
TypeMemberDiffs.push_back({diffNode, node});
TypeMemberDiffs.insert({diffNode, node});
// Move from a member variable to another member variable
if (nodeParent->getKind() == SDKNodeKind::TypeDecl &&
diffParent->getKind() == SDKNodeKind::TypeDecl)
TypeMemberDiffs.push_back({diffNode, node});
diffParent->getKind() == SDKNodeKind::TypeDecl &&
declNode->isStatic() &&
constructFullTypeName(nodeParent) != constructFullTypeName(diffParent))
TypeMemberDiffs.insert({diffNode, node});
// Move from a getter/setter function to a property
else if (node->getKind() == SDKNodeKind::Getter &&
diffNode->getKind() == SDKNodeKind::Function &&
Expand Down Expand Up @@ -2943,26 +2965,6 @@ class OverloadMemberFunctionEmitter : public SDKNodeVisitor {
namespace fs = llvm::sys::fs;
namespace path = llvm::sys::path;

static StringRef constructFullTypeName(NodePtr Node) {
assert(Node->getKind() == SDKNodeKind::TypeDecl);
std::vector<NodePtr> TypeChain;
for (auto C = Node; C->getKind() == SDKNodeKind::TypeDecl; C = C->getParent()) {
TypeChain.insert(TypeChain.begin(), C);
}
assert(TypeChain.front()->getParent()->getKind() == SDKNodeKind::Root);
llvm::SmallString<64> Buffer;
bool First = true;
for (auto N : TypeChain) {
if (First) {
First = false;
} else {
Buffer.append(".");
}
Buffer.append(N->getName());
}
return Node->getSDKContext().buffer(Buffer.str());
}

struct RenameDetectorForMemberDiff : public MatchedNodeListener {
void foundMatch(NodePtr Left, NodePtr Right) override {
detectRename(Left, Right);
Expand Down