swift-api-digester: emit the diff items for changing from RawRepresentable struct to a type alias of raw type.

related: rdar://39498127
This commit is contained in:
Xi Ge
2018-06-15 11:55:04 -07:00
parent 8d43ec3ad7
commit 42127d9f68
3 changed files with 43 additions and 11 deletions

View File

@@ -252,6 +252,7 @@ class SDKContext {
llvm::BumpPtrAllocator Allocator;
UpdatedNodesMap UpdateMap;
NodeMap TypeAliasUpdateMap;
NodeMap RevertTypeAliasUpdateMap;
TypeMemberDiffVector TypeMemberDiffs;
public:
llvm::BumpPtrAllocator &allocator() {
@@ -266,6 +267,9 @@ public:
NodeMap &getTypeAliasUpdateMap() {
return TypeAliasUpdateMap;
}
NodeMap &getRevertTypeAliasUpdateMap() {
return RevertTypeAliasUpdateMap;
}
TypeMemberDiffVector &getTypeMemberDiffs() {
return TypeMemberDiffs;
}
@@ -3792,6 +3796,27 @@ static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath) {
return 0;
}
static void populateAliasChanges(NodeMap &AliasMap, DiffVector &AllItems,
const bool isRevert) {
for (auto Pair: AliasMap) {
auto UnderlyingType = Pair.first->getAs<SDKNodeDeclTypeAlias>()->
getUnderlyingType()->getPrintedName();
auto RawType = AliasMap[(SDKNode*)Pair.first]->getAs<SDKNodeDeclType>()->
getRawValueType()->getPrintedName();
if (isRevert) {
auto *D = Pair.second->getAs<SDKNodeDecl>();
AllItems.emplace_back(SDKNodeKind::DeclType,
NodeAnnotation::RevertTypeAliasDeclToRawRepresentable, "0",
D->getUsr(), "", RawType, UnderlyingType, D->getModuleName());
} else {
auto *D = Pair.first->getAs<SDKNodeDecl>();
AllItems.emplace_back(SDKNodeKind::DeclTypeAlias,
NodeAnnotation::TypeAliasDeclToRawRepresentable, "0",
D->getUsr(), "", UnderlyingType, RawType, D->getModuleName());
}
}
}
static int compareSDKs(StringRef LeftPath, StringRef RightPath,
StringRef DiffPath,
llvm::StringSet<> &IgnoredRemoveUsrs) {
@@ -3826,20 +3851,15 @@ static int compareSDKs(StringRef LeftPath, StringRef RightPath,
DiffVector AllItems;
DiffItemEmitter::collectDiffItems(LeftModule, AllItems);
auto &AliasMap = Ctx.getTypeAliasUpdateMap();
// Find type alias change first.
auto &AliasMap = Ctx.getTypeAliasUpdateMap();
TypeAliasDiffFinder(LeftModule, RightModule, AliasMap).search();
populateAliasChanges(AliasMap, AllItems, /*IsRevert*/false);
for (auto Pair: AliasMap) {
auto Left = Pair.first->getAs<SDKNodeDeclTypeAlias>()->getUnderlyingType()->
getPrintedName();
auto Right = AliasMap[(SDKNode*)Pair.first]->getAs<SDKNodeDeclType>()->
getRawValueType()->getPrintedName();
auto *D = Pair.first->getAs<SDKNodeDecl>();
AllItems.emplace_back(SDKNodeKind::DeclTypeAlias,
NodeAnnotation::TypeAliasDeclToRawRepresentable, "0",
D->getUsr(), "", Left, Right, D->getModuleName());
}
// Find type alias revert change.
auto &RevertAliasMap = Ctx.getRevertTypeAliasUpdateMap();
TypeAliasDiffFinder(RightModule, LeftModule, RevertAliasMap).search();
populateAliasChanges(RevertAliasMap, AllItems, /*IsRevert*/true);
AllItems.erase(std::remove_if(AllItems.begin(), AllItems.end(),
[&](CommonDiffItem &Item) {