swift-api-digester: detect API changes due to undoing NS_TYPED_EXTENSIBLE_ENUM. rdar://39498127

This commit is contained in:
Xi Ge
2018-04-20 16:48:11 -07:00
parent 643adf5528
commit 9b8cd0dc15
4 changed files with 276 additions and 20 deletions

View File

@@ -81,7 +81,12 @@ NODE_ANNOTATION_CHANGE_KIND(ArrayMemberUpdate)
NODE_ANNOTATION_CHANGE_KIND(OptionalArrayMemberUpdate)
NODE_ANNOTATION_CHANGE_KIND(SimpleStringRepresentableUpdate)
NODE_ANNOTATION_CHANGE_KIND(SimpleOptionalStringRepresentableUpdate)
NODE_ANNOTATION_CHANGE_KIND(RevertDictionaryKeyUpdate)
NODE_ANNOTATION_CHANGE_KIND(RevertOptionalDictionaryKeyUpdate)
NODE_ANNOTATION_CHANGE_KIND(RevertArrayMemberUpdate)
NODE_ANNOTATION_CHANGE_KIND(RevertOptionalArrayMemberUpdate)
NODE_ANNOTATION_CHANGE_KIND(RevertSimpleStringRepresentableUpdate)
NODE_ANNOTATION_CHANGE_KIND(RevertSimpleOptionalStringRepresentableUpdate)
DECL_ATTR(deprecated)
DECL_ATTR(fixedLayout)

View File

@@ -0,0 +1,238 @@
[
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "TypeRewritten",
"ChildIndex": "1:0",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributes:",
"LeftComment": "AnimalAttributeName",
"RightUsr": "",
"RightComment": "String",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "RevertDictionaryKeyUpdate",
"ChildIndex": "1",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributes:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "TypeRewritten",
"ChildIndex": "1:0",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributes:",
"LeftComment": "AnimalAttributeName",
"RightUsr": "",
"RightComment": "String",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "RevertDictionaryKeyUpdate",
"ChildIndex": "1",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributes:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "TypeRewritten",
"ChildIndex": "1:0:0",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributes:",
"LeftComment": "AnimalAttributeName",
"RightUsr": "",
"RightComment": "String",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "RevertOptionalDictionaryKeyUpdate",
"ChildIndex": "1",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributes:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "TypeRewritten",
"ChildIndex": "1:0:0",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributes:",
"LeftComment": "AnimalAttributeName",
"RightUsr": "",
"RightComment": "String",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "RevertOptionalDictionaryKeyUpdate",
"ChildIndex": "1",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributes:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "TypeRewritten",
"ChildIndex": "1:0",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributesArray:",
"LeftComment": "AnimalAttributeName",
"RightUsr": "",
"RightComment": "String",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "RevertArrayMemberUpdate",
"ChildIndex": "1",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributesArray:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "TypeRewritten",
"ChildIndex": "1:0",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributesArray:",
"LeftComment": "AnimalAttributeName",
"RightUsr": "",
"RightComment": "String",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "RevertArrayMemberUpdate",
"ChildIndex": "1",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributesArray:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "TypeRewritten",
"ChildIndex": "1:0:0",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributesArray:",
"LeftComment": "AnimalAttributeName",
"RightUsr": "",
"RightComment": "String",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "RevertOptionalArrayMemberUpdate",
"ChildIndex": "1",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributesArray:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "TypeRewritten",
"ChildIndex": "1:0:0",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributesArray:",
"LeftComment": "AnimalAttributeName",
"RightUsr": "",
"RightComment": "String",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "RevertOptionalArrayMemberUpdate",
"ChildIndex": "1",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributesArray:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "TypeRewritten",
"ChildIndex": "1:0",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(cm)animalStatusSingleOptionalAttribute:",
"LeftComment": "AnimalAttributeName",
"RightUsr": "",
"RightComment": "String",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "RevertSimpleOptionalStringRepresentableUpdate",
"ChildIndex": "1",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(cm)animalStatusSingleOptionalAttribute:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "TypeRewritten",
"ChildIndex": "1",
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(cm)animalStatusSingleAttribute:",
"LeftComment": "AnimalAttributeName",
"RightUsr": "",
"RightComment": "String",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "TypeDecl",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "c:objc(pl)TypeWithMethod",
"LeftComment": "SwiftTypeWithMethodRight",
"RightUsr": "",
"RightComment": "SwiftTypeWithMethodLeft",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "TypeMemberDiffItem",
"Usr": "c:@ANTGlobalValue",
"OldPrintedName": "newMember",
"OldTypeName": "NewType",
"NewPrintedName": "oldMember",
"NewTypeName": "OldType"
},
{
"DiffItemKind": "TypeMemberDiffItem",
"Usr": "c:objc(pl)TypeWithMethod(cm)plusPrint",
"OldPrintedName": "plusPrint()",
"OldTypeName": "SwiftTypeWithMethodRight",
"NewPrintedName": "plusPrint()",
"NewTypeName": "SwiftTypeWithMethodLeft"
}
]

View File

@@ -6,3 +6,5 @@
// RUN: %api-digester -dump-sdk -module APINotesTest -o %t.dump2.json -module-cache-path %t.module-cache %clang-importer-sdk-nosource -swift-version 4 -I %S/Inputs/APINotesRight
// RUN: %api-digester -compare-sdk --input-paths %t.dump1.json -input-paths %t.dump2.json -o %t.result -json
// RUN: diff -u %S/Outputs/apinotes-migrator-gen.json %t.result
// RUN: %api-digester -compare-sdk --input-paths %t.dump2.json -input-paths %t.dump1.json -o %t.result -json
// RUN: diff -u %S/Outputs/apinotes-migrator-gen-revert.json %t.result

View File

@@ -2731,15 +2731,13 @@ class ChangeRefinementPass : public SDKTreeDiffPass, public SDKNodeVisitor {
}
bool detectDictionaryKeyChange(SDKNodeType *L, SDKNodeType *R) {
if (!IsVisitingLeft)
return false;
// We only care if this the top-level type node.
if (!L->isTopLevelType() || !R->isTopLevelType())
return false;
StringRef KeyChangedTo;
if (L->getTypeKind() == KnownTypeKind::Optional &&
R->getTypeKind() == KnownTypeKind::Optional) {
bool HasOptional = L->getTypeKind() == KnownTypeKind::Optional &&
R->getTypeKind() == KnownTypeKind::Optional;
if (HasOptional) {
// Detect [String: Any]? to [StringRepresentableStruct: Any]? Chnage
KeyChangedTo =
detectDictionaryKeyChangeInternal(L->getOnlyChild()->getAs<SDKNodeType>(),
@@ -2749,10 +2747,16 @@ class ChangeRefinementPass : public SDKTreeDiffPass, public SDKNodeVisitor {
KeyChangedTo = detectDictionaryKeyChangeInternal(L, R);
}
if (!KeyChangedTo.empty()) {
L->annotate(L->getTypeKind() == KnownTypeKind::Optional ?
if (IsVisitingLeft) {
L->annotate(HasOptional ?
NodeAnnotation::OptionalDictionaryKeyUpdate :
NodeAnnotation::DictionaryKeyUpdate);
L->annotate(NodeAnnotation::TypeRewrittenRight, KeyChangedTo);
L->annotate(NodeAnnotation::TypeRewrittenRight, KeyChangedTo);
} else {
R->annotate(HasOptional ?
NodeAnnotation::RevertOptionalDictionaryKeyUpdate :
NodeAnnotation::RevertDictionaryKeyUpdate);
}
return true;
}
return false;
@@ -2773,14 +2777,13 @@ class ChangeRefinementPass : public SDKTreeDiffPass, public SDKNodeVisitor {
}
bool detectArrayMemberChange(SDKNodeType* L, SDKNodeType *R) {
if (!IsVisitingLeft)
return false;
// We only care if this the top-level type node.
if (!L->isTopLevelType() || !R->isTopLevelType())
return false;
StringRef KeyChangedTo;
if (L->getTypeKind() == KnownTypeKind::Optional &&
R->getTypeKind() == KnownTypeKind::Optional) {
bool HasOptional = L->getTypeKind() == KnownTypeKind::Optional &&
R->getTypeKind() == KnownTypeKind::Optional;
if (HasOptional) {
// Detect [String]? to [StringRepresentableStruct]? Chnage
KeyChangedTo =
detectArrayMemberChangeInternal(L->getOnlyChild()->getAs<SDKNodeType>(),
@@ -2790,18 +2793,22 @@ class ChangeRefinementPass : public SDKTreeDiffPass, public SDKNodeVisitor {
KeyChangedTo = detectArrayMemberChangeInternal(L, R);
}
if (!KeyChangedTo.empty()) {
L->annotate(L->getTypeKind() == KnownTypeKind::Optional ?
if (IsVisitingLeft) {
L->annotate(HasOptional ?
NodeAnnotation::OptionalArrayMemberUpdate :
NodeAnnotation::ArrayMemberUpdate);
L->annotate(NodeAnnotation::TypeRewrittenRight, KeyChangedTo);
L->annotate(NodeAnnotation::TypeRewrittenRight, KeyChangedTo);
} else {
R->annotate(HasOptional ?
NodeAnnotation::RevertOptionalArrayMemberUpdate :
NodeAnnotation::RevertArrayMemberUpdate);
}
return true;
}
return false;
}
bool detectSimpleStringRepresentableUpdate(SDKNodeType *L, SDKNodeType *R) {
if (!IsVisitingLeft)
return false;
if (!L->isTopLevelType() || !R->isTopLevelType())
return false;
StringRef KeyChangedTo;
@@ -2817,11 +2824,15 @@ class ChangeRefinementPass : public SDKTreeDiffPass, public SDKNodeVisitor {
KeyChangedTo = getStringRepresentableChange(L, R);
}
if (!KeyChangedTo.empty()) {
L->annotate(NodeAnnotation::TypeRewrittenRight, KeyChangedTo);
if (HasOptional) {
L->annotate(NodeAnnotation::SimpleOptionalStringRepresentableUpdate);
if (IsVisitingLeft) {
L->annotate(NodeAnnotation::TypeRewrittenRight, KeyChangedTo);
L->annotate(HasOptional ?
NodeAnnotation::SimpleOptionalStringRepresentableUpdate:
NodeAnnotation::SimpleStringRepresentableUpdate);
} else {
L->annotate(NodeAnnotation::SimpleStringRepresentableUpdate);
R->annotate(HasOptional ?
NodeAnnotation::RevertSimpleOptionalStringRepresentableUpdate:
NodeAnnotation::RevertSimpleStringRepresentableUpdate);
}
return true;
}