Skip to content

Commit 9138b02

Browse files
committed
swift-api-digester: detect type to type alias change up-front to remove bogus dignostics. rdar://43425867
1 parent 697ba85 commit 9138b02

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

test/api-digester/source-stability.swift.expected

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11

22
/* Generic Signature Changes */
3-
Struct DictionaryIterator has generic signature change from <Key, Value where Key : Hashable> to <Element>
4-
Struct SetIterator has generic signature change from <Element where Element : Hashable> to <Key, Value>
53

64
/* RawRepresentable Changes */
75

86
/* Removed Decls */
97
TypeAlias AbsoluteValuable has been removed
108
TypeAlias BitwiseOperations has been removed (deprecated)
11-
TypeAlias DictionaryIterator.Element has been removed
129
TypeAlias IntMax has been removed
1310
TypeAlias Integer has been removed
1411
TypeAlias IntegerArithmetic has been removed
15-
TypeAlias SetIterator.Element has been removed
1612
TypeAlias SignedNumber has been removed
1713
TypeAlias StringProtocol.UTF16Index has been removed (deprecated)
1814
TypeAlias StringProtocol.UTF8Index has been removed (deprecated)
1915
TypeAlias StringProtocol.UnicodeScalarIndex has been removed (deprecated)
2016
TypeAlias UIntMax has been removed
21-
Var DictionaryIterator.customMirror has been removed
2217
Var FixedWidthInteger.allZeros has been removed (deprecated)
23-
Var SetIterator.customMirror has been removed
2418
Constructor Int.init(truncatingBitPattern:) has been removed
2519
Constructor Int16.init(truncatingBitPattern:) has been removed
2620
Constructor Int32.init(truncatingBitPattern:) has been removed
@@ -31,7 +25,6 @@ Constructor UInt16.init(truncatingBitPattern:) has been removed
3125
Constructor UInt32.init(truncatingBitPattern:) has been removed
3226
Constructor UInt8.init(truncatingBitPattern:) has been removed
3327
Func BinaryInteger.toIntMax() has been removed
34-
Func DictionaryIterator.next() has been removed
3528
Func FixedWidthInteger.addWithOverflow(_:_:) has been removed
3629
Func FixedWidthInteger.divideWithOverflow(_:_:) has been removed
3730
Func FixedWidthInteger.multiplyWithOverflow(_:_:) has been removed
@@ -53,7 +46,6 @@ Func Int32.toUIntMax() has been removed
5346
Func Int64.toUIntMax() has been removed
5447
Func Int8.toUIntMax() has been removed
5548
Func Sequence.flatMap(_:) has been removed
56-
Func SetIterator.next() has been removed
5749
Func SignedNumeric.abs(_:) has been removed
5850
Func String.UTF16View.distance(from:to:) has been removed
5951
Func String.UTF16View.index(_:offsetBy:) has been removed
@@ -76,8 +68,6 @@ Func UnsignedInteger.toUIntMax() has been removed
7668
/* Moved Decls */
7769

7870
/* Renamed Decls */
79-
Struct DictionaryIterator has been renamed to Struct Iterator
80-
Struct SetIterator has been renamed to Struct Iterator
8171
Func Dictionary.filter(_:obsoletedInSwift4:) has been renamed to Func Dictionary.filter(_:)
8272
Func Set.filter(_:obsoletedInSwift4:) has been renamed to Func Set.filter(_:)
8373

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ enum class NodeMatchReason: uint8_t {
250250

251251
// The first node is a global variable and the second node is an enum element.
252252
ModernizeEnum,
253+
254+
// The first node is a type declaration and the second node is a type alias
255+
// of another type declaration.
256+
TypeToTypeAlias,
253257
};
254258

255259
// During the matching phase, any matched node will be reported using this API.
@@ -2169,6 +2173,18 @@ class RemovedAddedNodeMatcher : public NodeMatcher, public MatchedNodeListener {
21692173
return N->getUsr().substr(LastPartIndex + 1);
21702174
}
21712175

2176+
bool detectTypeAliasChange(SDKNodeDecl *R, SDKNodeDecl *A) {
2177+
if (R->getPrintedName() != A->getPrintedName())
2178+
return false;
2179+
if (R->getKind() == SDKNodeKind::DeclType &&
2180+
A->getKind() == SDKNodeKind::DeclTypeAlias) {
2181+
foundMatch(R, A, NodeMatchReason::TypeToTypeAlias);
2182+
return true;
2183+
} else {
2184+
return false;
2185+
}
2186+
}
2187+
21722188
bool detectModernizeEnum(SDKNodeDecl *R, SDKNodeDecl *A) {
21732189
if (!isAnonymousEnum(R) || !isNominalEnum(A))
21742190
return false;
@@ -2295,7 +2311,7 @@ class RemovedAddedNodeMatcher : public NodeMatcher, public MatchedNodeListener {
22952311
auto RD = R->getAs<SDKNodeDecl>();
22962312
auto AD = A->getAs<SDKNodeDecl>();
22972313
if (detectFuncToProperty(RD, AD) || detectModernizeEnum(RD, AD) ||
2298-
detectSameAnonymousEnum(RD, AD)) {
2314+
detectSameAnonymousEnum(RD, AD) || detectTypeAliasChange(RD, AD)) {
22992315
break;
23002316
}
23012317
}
@@ -2564,6 +2580,7 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
25642580
return;
25652581
case NodeMatchReason::FuncToProperty:
25662582
case NodeMatchReason::ModernizeEnum:
2583+
case NodeMatchReason::TypeToTypeAlias:
25672584
Left->annotate(NodeAnnotation::Removed);
25682585
Right->annotate(NodeAnnotation::Added);
25692586
return;

0 commit comments

Comments
 (0)