Skip to content

Commit da4fc05

Browse files
committed
swift-module-digester: model ProcotolConformance as a standalone node.
Modeling ProtocolConformance as a standalone node allows us to keep track of all type witnesses and re-use existing matching algorithm to diagnose type witness changes.
1 parent c3a9498 commit da4fc05

File tree

10 files changed

+669
-144
lines changed

10 files changed

+669
-144
lines changed

include/swift/IDE/DigesterEnums.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
#endif
5656

5757
NODE_KIND(Root, Root)
58+
NODE_KIND(Conformance, Conformance)
59+
NODE_KIND(TypeWitness, TypeWitness)
5860
NODE_KIND(TypeNominal, TypeNominal)
5961
NODE_KIND(TypeFunc, TypeFunc)
6062
NODE_KIND(TypeAlias, TypeNameAlias)
@@ -146,12 +148,12 @@ KEY_STRING(FuncSelfKind, funcSelfKind)
146148
KEY_STRING(ParamValueOwnership, paramValueOwnership)
147149

148150
KEY_STRING_ARR(SuperclassNames, superclassNames)
149-
KEY_STRING_ARR(ConformingProtocols, conformingProtocols)
150151

151152
KEY_UINT(SelfIndex, selfIndex)
152153
KEY_UINT(FixedBinaryOrder, fixedbinaryorder)
153154

154155
KEY(children)
156+
KEY(conformances)
155157
KEY(typeAttributes)
156158
KEY(declAttributes)
157159
KEY(declKind)

test/api-digester/Inputs/cake.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public protocol P1 {}
44
public protocol P2 {}
5-
5+
public protocol P3: P2, P1 {}
66
@_fixed_layout
77
public struct S1: P1 {
88
public static func foo1() {}

test/api-digester/Outputs/Cake-abi.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ cake2: Var fixedLayoutStruct.lazy_d.storage is added to a non-resilient type
7272
/* Conformance changes */
7373
cake1: Func ObjCProtocol.addOptional() is now an optional requirement
7474
cake1: Func ObjCProtocol.removeOptional() is no longer an optional requirement
75-
cake1: Protocol P3 has added inherited protocol P4
7675
cake1: Protocol P3 has removed inherited protocol P2
7776
cake1: Struct fixedLayoutStruct has removed conformance to P1
77+
cake2: Protocol P3 has added inherited protocol P4
7878

7979
/* Protocol Requirement Change */
8080
cake1: AssociatedType AssociatedTypePro.T1 has removed default type Int

test/api-digester/Outputs/Cake.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ cake1: Var C1.CIIns2 changes from strong to weak
4545

4646
/* Conformance changes */
4747
cake1: Func ObjCProtocol.removeOptional() is no longer an optional requirement
48-
cake1: Protocol P3 has added inherited protocol P4
4948
cake1: Protocol P3 has removed inherited protocol P2
5049
cake1: Struct fixedLayoutStruct has removed conformance to P1
50+
cake2: Protocol P3 has added inherited protocol P4
5151

5252
/* Protocol Requirement Change */
5353
cake1: AssociatedType AssociatedTypePro.T1 has removed default type Int

test/api-digester/Outputs/cake-abi.json

Lines changed: 235 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,27 @@
5252
"usr": "s:4cake2P2P",
5353
"moduleName": "cake"
5454
},
55+
{
56+
"kind": "TypeDecl",
57+
"name": "P3",
58+
"printedName": "P3",
59+
"declKind": "Protocol",
60+
"usr": "s:4cake2P3P",
61+
"moduleName": "cake",
62+
"genericSig": "<τ_0_0 : P1, τ_0_0 : P2>",
63+
"conformances": [
64+
{
65+
"kind": "Conformance",
66+
"name": "P2",
67+
"printedName": "P2"
68+
},
69+
{
70+
"kind": "Conformance",
71+
"name": "P1",
72+
"printedName": "P1"
73+
}
74+
]
75+
},
5576
{
5677
"kind": "TypeDecl",
5778
"name": "S1",
@@ -131,9 +152,17 @@
131152
"declAttributes": [
132153
"FixedLayout"
133154
],
134-
"conformingProtocols": [
135-
"P1",
136-
"P2"
155+
"conformances": [
156+
{
157+
"kind": "Conformance",
158+
"name": "P1",
159+
"printedName": "P1"
160+
},
161+
{
162+
"kind": "Conformance",
163+
"name": "P2",
164+
"printedName": "P2"
165+
}
137166
]
138167
},
139168
{
@@ -652,10 +681,37 @@
652681
"usr": "s:4cake6NumberO",
653682
"moduleName": "cake",
654683
"enumRawTypeName": "Int",
655-
"conformingProtocols": [
656-
"Equatable",
657-
"Hashable",
658-
"RawRepresentable"
684+
"conformances": [
685+
{
686+
"kind": "Conformance",
687+
"name": "Equatable",
688+
"printedName": "Equatable"
689+
},
690+
{
691+
"kind": "Conformance",
692+
"name": "Hashable",
693+
"printedName": "Hashable"
694+
},
695+
{
696+
"kind": "Conformance",
697+
"name": "RawRepresentable",
698+
"printedName": "RawRepresentable",
699+
"children": [
700+
{
701+
"kind": "TypeWitness",
702+
"name": "RawValue",
703+
"printedName": "RawValue",
704+
"children": [
705+
{
706+
"kind": "TypeNominal",
707+
"name": "Int",
708+
"printedName": "Int",
709+
"usr": "s:Si"
710+
}
711+
]
712+
}
713+
]
714+
}
659715
]
660716
},
661717
{
@@ -1182,8 +1238,12 @@
11821238
"usr": "s:4cake4PSubP",
11831239
"moduleName": "cake",
11841240
"genericSig": "<τ_0_0 : PSuper>",
1185-
"conformingProtocols": [
1186-
"PSuper"
1241+
"conformances": [
1242+
{
1243+
"kind": "Conformance",
1244+
"name": "PSuper",
1245+
"printedName": "PSuper"
1246+
}
11871247
]
11881248
},
11891249
{
@@ -1336,28 +1396,172 @@
13361396
"declAttributes": [
13371397
"FixedLayout"
13381398
],
1339-
"conformingProtocols": [
1340-
"Comparable",
1341-
"SignedInteger",
1342-
"_ExpressibleByBuiltinIntegerLiteral",
1343-
"BinaryInteger",
1344-
"LosslessStringConvertible",
1345-
"SignedNumeric",
1346-
"Numeric",
1347-
"CustomStringConvertible",
1348-
"Strideable",
1349-
"ExpressibleByIntegerLiteral",
1350-
"FixedWidthInteger",
1351-
"P1",
1352-
"Encodable",
1353-
"Decodable",
1354-
"Hashable",
1355-
"Equatable",
1356-
"_HasCustomAnyHashableRepresentation",
1357-
"CustomReflectable",
1358-
"_CustomPlaygroundQuickLookable",
1359-
"MirrorPath",
1360-
"CVarArg"
1399+
"conformances": [
1400+
{
1401+
"kind": "Conformance",
1402+
"name": "Comparable",
1403+
"printedName": "Comparable"
1404+
},
1405+
{
1406+
"kind": "Conformance",
1407+
"name": "SignedInteger",
1408+
"printedName": "SignedInteger"
1409+
},
1410+
{
1411+
"kind": "Conformance",
1412+
"name": "_ExpressibleByBuiltinIntegerLiteral",
1413+
"printedName": "_ExpressibleByBuiltinIntegerLiteral"
1414+
},
1415+
{
1416+
"kind": "Conformance",
1417+
"name": "BinaryInteger",
1418+
"printedName": "BinaryInteger",
1419+
"children": [
1420+
{
1421+
"kind": "TypeWitness",
1422+
"name": "Words",
1423+
"printedName": "Words",
1424+
"children": [
1425+
{
1426+
"kind": "TypeNominal",
1427+
"name": "Words",
1428+
"printedName": "Int.Words",
1429+
"usr": "s:Si5WordsV"
1430+
}
1431+
]
1432+
}
1433+
]
1434+
},
1435+
{
1436+
"kind": "Conformance",
1437+
"name": "LosslessStringConvertible",
1438+
"printedName": "LosslessStringConvertible"
1439+
},
1440+
{
1441+
"kind": "Conformance",
1442+
"name": "SignedNumeric",
1443+
"printedName": "SignedNumeric"
1444+
},
1445+
{
1446+
"kind": "Conformance",
1447+
"name": "Numeric",
1448+
"printedName": "Numeric",
1449+
"children": [
1450+
{
1451+
"kind": "TypeWitness",
1452+
"name": "Magnitude",
1453+
"printedName": "Magnitude",
1454+
"children": [
1455+
{
1456+
"kind": "TypeNominal",
1457+
"name": "UInt",
1458+
"printedName": "UInt",
1459+
"usr": "s:Su"
1460+
}
1461+
]
1462+
}
1463+
]
1464+
},
1465+
{
1466+
"kind": "Conformance",
1467+
"name": "CustomStringConvertible",
1468+
"printedName": "CustomStringConvertible"
1469+
},
1470+
{
1471+
"kind": "Conformance",
1472+
"name": "Strideable",
1473+
"printedName": "Strideable",
1474+
"children": [
1475+
{
1476+
"kind": "TypeWitness",
1477+
"name": "Stride",
1478+
"printedName": "Stride",
1479+
"children": [
1480+
{
1481+
"kind": "TypeNominal",
1482+
"name": "Int",
1483+
"printedName": "Int",
1484+
"usr": "s:Si"
1485+
}
1486+
]
1487+
}
1488+
]
1489+
},
1490+
{
1491+
"kind": "Conformance",
1492+
"name": "ExpressibleByIntegerLiteral",
1493+
"printedName": "ExpressibleByIntegerLiteral",
1494+
"children": [
1495+
{
1496+
"kind": "TypeWitness",
1497+
"name": "IntegerLiteralType",
1498+
"printedName": "IntegerLiteralType",
1499+
"children": [
1500+
{
1501+
"kind": "TypeNominal",
1502+
"name": "Int",
1503+
"printedName": "Int",
1504+
"usr": "s:Si"
1505+
}
1506+
]
1507+
}
1508+
]
1509+
},
1510+
{
1511+
"kind": "Conformance",
1512+
"name": "FixedWidthInteger",
1513+
"printedName": "FixedWidthInteger"
1514+
},
1515+
{
1516+
"kind": "Conformance",
1517+
"name": "P1",
1518+
"printedName": "P1"
1519+
},
1520+
{
1521+
"kind": "Conformance",
1522+
"name": "Encodable",
1523+
"printedName": "Encodable"
1524+
},
1525+
{
1526+
"kind": "Conformance",
1527+
"name": "Decodable",
1528+
"printedName": "Decodable"
1529+
},
1530+
{
1531+
"kind": "Conformance",
1532+
"name": "Hashable",
1533+
"printedName": "Hashable"
1534+
},
1535+
{
1536+
"kind": "Conformance",
1537+
"name": "Equatable",
1538+
"printedName": "Equatable"
1539+
},
1540+
{
1541+
"kind": "Conformance",
1542+
"name": "_HasCustomAnyHashableRepresentation",
1543+
"printedName": "_HasCustomAnyHashableRepresentation"
1544+
},
1545+
{
1546+
"kind": "Conformance",
1547+
"name": "CustomReflectable",
1548+
"printedName": "CustomReflectable"
1549+
},
1550+
{
1551+
"kind": "Conformance",
1552+
"name": "_CustomPlaygroundQuickLookable",
1553+
"printedName": "_CustomPlaygroundQuickLookable"
1554+
},
1555+
{
1556+
"kind": "Conformance",
1557+
"name": "MirrorPath",
1558+
"printedName": "MirrorPath"
1559+
},
1560+
{
1561+
"kind": "Conformance",
1562+
"name": "CVarArg",
1563+
"printedName": "CVarArg"
1564+
}
13611565
]
13621566
}
13631567
]

0 commit comments

Comments
 (0)