Skip to content

Commit b455ada

Browse files
committed
swift-api-digester: emit the diff items for changing from RawRepresentable struct to a type alias of raw type.
related: rdar://39498127
1 parent 9792d6e commit b455ada

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

include/swift/IDE/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ NODE_ANNOTATION_CHANGE_KIND(OptionalArrayMemberUpdate)
8080
NODE_ANNOTATION_CHANGE_KIND(SimpleStringRepresentableUpdate)
8181
NODE_ANNOTATION_CHANGE_KIND(SimpleOptionalStringRepresentableUpdate)
8282
NODE_ANNOTATION_CHANGE_KIND(TypeAliasDeclToRawRepresentable)
83+
NODE_ANNOTATION_CHANGE_KIND(RevertTypeAliasDeclToRawRepresentable)
8384

8485
NODE_ANNOTATION_CHANGE_KIND(RevertDictionaryKeyUpdate)
8586
NODE_ANNOTATION_CHANGE_KIND(RevertOptionalDictionaryKeyUpdate)

test/api-digester/Outputs/apinotes-migrator-gen-revert.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
[
2+
{
3+
"DiffItemKind": "CommonDiffItem",
4+
"NodeKind": "TypeDecl",
5+
"NodeAnnotation": "RevertTypeAliasDeclToRawRepresentable",
6+
"ChildIndex": "0",
7+
"LeftUsr": "c:APINotesTest.h@T@CatAttributeName",
8+
"LeftComment": "String",
9+
"RightUsr": "",
10+
"RightComment": "NSString",
11+
"ModuleName": "APINotesTest"
12+
},
213
{
314
"DiffItemKind": "CommonDiffItem",
415
"NodeKind": "Function",

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

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ class SDKContext {
252252
llvm::BumpPtrAllocator Allocator;
253253
UpdatedNodesMap UpdateMap;
254254
NodeMap TypeAliasUpdateMap;
255+
NodeMap RevertTypeAliasUpdateMap;
255256
TypeMemberDiffVector TypeMemberDiffs;
256257
public:
257258
llvm::BumpPtrAllocator &allocator() {
@@ -266,6 +267,9 @@ class SDKContext {
266267
NodeMap &getTypeAliasUpdateMap() {
267268
return TypeAliasUpdateMap;
268269
}
270+
NodeMap &getRevertTypeAliasUpdateMap() {
271+
return RevertTypeAliasUpdateMap;
272+
}
269273
TypeMemberDiffVector &getTypeMemberDiffs() {
270274
return TypeMemberDiffs;
271275
}
@@ -3793,6 +3797,27 @@ static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath) {
37933797
return 0;
37943798
}
37953799

3800+
static void populateAliasChanges(NodeMap &AliasMap, DiffVector &AllItems,
3801+
const bool isRevert) {
3802+
for (auto Pair: AliasMap) {
3803+
auto UnderlyingType = Pair.first->getAs<SDKNodeDeclTypeAlias>()->
3804+
getUnderlyingType()->getPrintedName();
3805+
auto RawType = AliasMap[(SDKNode*)Pair.first]->getAs<SDKNodeDeclType>()->
3806+
getRawValueType()->getPrintedName();
3807+
if (isRevert) {
3808+
auto *D = Pair.second->getAs<SDKNodeDecl>();
3809+
AllItems.emplace_back(SDKNodeKind::DeclType,
3810+
NodeAnnotation::RevertTypeAliasDeclToRawRepresentable, "0",
3811+
D->getUsr(), "", RawType, UnderlyingType, D->getModuleName());
3812+
} else {
3813+
auto *D = Pair.first->getAs<SDKNodeDecl>();
3814+
AllItems.emplace_back(SDKNodeKind::DeclTypeAlias,
3815+
NodeAnnotation::TypeAliasDeclToRawRepresentable, "0",
3816+
D->getUsr(), "", UnderlyingType, RawType, D->getModuleName());
3817+
}
3818+
}
3819+
}
3820+
37963821
static int compareSDKs(StringRef LeftPath, StringRef RightPath,
37973822
StringRef DiffPath,
37983823
llvm::StringSet<> &IgnoredRemoveUsrs) {
@@ -3827,20 +3852,15 @@ static int compareSDKs(StringRef LeftPath, StringRef RightPath,
38273852
DiffVector AllItems;
38283853
DiffItemEmitter::collectDiffItems(LeftModule, AllItems);
38293854

3830-
auto &AliasMap = Ctx.getTypeAliasUpdateMap();
38313855
// Find type alias change first.
3856+
auto &AliasMap = Ctx.getTypeAliasUpdateMap();
38323857
TypeAliasDiffFinder(LeftModule, RightModule, AliasMap).search();
3858+
populateAliasChanges(AliasMap, AllItems, /*IsRevert*/false);
38333859

3834-
for (auto Pair: AliasMap) {
3835-
auto Left = Pair.first->getAs<SDKNodeDeclTypeAlias>()->getUnderlyingType()->
3836-
getPrintedName();
3837-
auto Right = AliasMap[(SDKNode*)Pair.first]->getAs<SDKNodeDeclType>()->
3838-
getRawValueType()->getPrintedName();
3839-
auto *D = Pair.first->getAs<SDKNodeDecl>();
3840-
AllItems.emplace_back(SDKNodeKind::DeclTypeAlias,
3841-
NodeAnnotation::TypeAliasDeclToRawRepresentable, "0",
3842-
D->getUsr(), "", Left, Right, D->getModuleName());
3843-
}
3860+
// Find type alias revert change.
3861+
auto &RevertAliasMap = Ctx.getRevertTypeAliasUpdateMap();
3862+
TypeAliasDiffFinder(RightModule, LeftModule, RevertAliasMap).search();
3863+
populateAliasChanges(RevertAliasMap, AllItems, /*IsRevert*/true);
38443864

38453865
AllItems.erase(std::remove_if(AllItems.begin(), AllItems.end(),
38463866
[&](CommonDiffItem &Item) {

0 commit comments

Comments
 (0)