Skip to content

Commit 38e339d

Browse files
committed
Enable key path resilience test suite.
With a few modifications: - Changing computed get-only properties into 'let's breaks resilience in other ways we need to fix independent of key path resilience - Fix the tests not to ask for impossible lib-before--client-after compatibility for changes that add API
1 parent 7604dd5 commit 38e339d

File tree

3 files changed

+158
-71
lines changed

3 files changed

+158
-71
lines changed

validation-test/Evolution/Inputs/keypaths.swift.gyb

+29-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public enum AnEnum {
2525
}
2626
}
2727

28-
% for (name, kind, before, after) in testCases:
28+
% for (name, kind, before, after, addsAPI) in testCases:
2929

3030
% if kind == "mutating" or kind == "nonmutating":
3131

@@ -51,7 +51,7 @@ public struct AStruct {
5151

5252
public var sink: Int = 0
5353

54-
% for (name, kind, before, after) in testCases:
54+
% for (name, kind, before, after, addsAPI) in testCases:
5555

5656
% if kind == "mutating" or kind == "nonmutating" or kind == "stored":
5757

@@ -75,7 +75,7 @@ public class AClass {
7575

7676
public var sink: Int = 0
7777

78-
% for (name, kind, before, after) in testCases:
78+
% for (name, kind, before, after, addsAPI) in testCases:
7979

8080
% if kind == "nonmutating" or kind == "stored":
8181

@@ -97,3 +97,29 @@ public class AClass {
9797

9898
}
9999

100+
public final class AFinalClass {
101+
102+
public var sink: Int = 0
103+
104+
% for (name, kind, before, after, addsAPI) in testCases:
105+
106+
% if kind == "nonmutating" or kind == "stored":
107+
108+
#if BEFORE
109+
${before.format(name=name, nonmutating="")}
110+
#else
111+
${after.format(name=name, nonmutating="")}
112+
#endif
113+
114+
public static var keyPath_${name}: PartialKeyPath<AFinalClass> { return \AFinalClass.${name} }
115+
116+
% elif kind == "mutating":
117+
118+
% else:
119+
%{ raise ValueError("improper test case kind") }%
120+
% end
121+
122+
% end
123+
124+
}
125+

validation-test/Evolution/Inputs/keypaths_gyb.py

+91-63
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
# - property kind, one of:
55
# - stored (only makes sense in structs or classes)
66
# - mutating (only makes sense in structs or enums)
7-
# - struct (only makes sense in structs)
87
# - nonmutating (makes sense in classes, structs, and enums)
98
# - "before" definition
109
# - "after" definition
10+
# - whether the "after" definition adds API
1111
#
1212
# The definition strings are formatted with the following substitutions:
1313
# - {name}: property name
1414
# - {nonmutating}: nonmutating modifier spelling, if needed for context
15+
16+
AddsAPI = True
17+
DoesntAddAPI = False
18+
1519
testCases = [
1620
(
1721
"addsPrivateSetter",
@@ -25,6 +29,7 @@
2529
mutating set {{ self.sink = newValue }}
2630
}}
2731
""",
32+
DoesntAddAPI,
2833
),
2934
(
3035
"addsPublicSetter",
@@ -38,6 +43,7 @@
3843
mutating set {{ self.sink = newValue }}
3944
}}
4045
""",
46+
AddsAPI,
4147
),
4248
(
4349
"makesPrivateSetterPublic",
@@ -54,6 +60,7 @@
5460
mutating set {{ self.sink = newValue }}
5561
}}
5662
""",
63+
AddsAPI,
5764
),
5865
(
5966
"dropsPrivateSetter",
@@ -68,7 +75,8 @@
6875
public var {name}: Int {{
6976
get {{ return 0 }}
7077
}}
71-
"""
78+
""",
79+
DoesntAddAPI,
7280
),
7381
(
7482
"makesPrivateSetterNonmutating",
@@ -84,7 +92,8 @@
8492
get {{ return 0 }}
8593
{nonmutating} set {{ globalSink = newValue }}
8694
}}
87-
"""
95+
""",
96+
DoesntAddAPI,
8897
),
8998
(
9099
"makesPrivateSetterMutating",
@@ -100,7 +109,8 @@
100109
get {{ return 0 }}
101110
set {{ self.sink = newValue }}
102111
}}
103-
"""
112+
""",
113+
DoesntAddAPI,
104114
),
105115
(
106116
"addsPrivateNonmutatingSetter",
@@ -113,7 +123,8 @@
113123
get {{ return 0 }}
114124
{nonmutating} set {{ globalSink = newValue }}
115125
}}
116-
"""
126+
""",
127+
DoesntAddAPI,
117128
),
118129
(
119130
"addsPublicNonmutatingSetter",
@@ -126,7 +137,8 @@
126137
get {{ return 0 }}
127138
{nonmutating} set {{ globalSink = newValue }}
128139
}}
129-
"""
140+
""",
141+
AddsAPI,
130142
),
131143
(
132144
"makesPrivateNonmutatingSetterPublic",
@@ -142,7 +154,8 @@
142154
get {{ return 0 }}
143155
{nonmutating} set {{ globalSink = newValue }}
144156
}}
145-
"""
157+
""",
158+
AddsAPI,
146159
),
147160
(
148161
"makesPrivateNonmutatingSetterPublicMutating",
@@ -158,7 +171,8 @@
158171
get {{ return 0 }}
159172
set {{ self.sink = newValue }}
160173
}}
161-
"""
174+
""",
175+
AddsAPI,
162176
),
163177
(
164178
"makesPrivateMutatingSetterPublicNonmutating",
@@ -174,7 +188,8 @@
174188
get {{ return 0 }}
175189
{nonmutating} set {{ globalSink = newValue }}
176190
}}
177-
"""
191+
""",
192+
AddsAPI,
178193
),
179194
(
180195
"storedToComputed",
@@ -187,7 +202,8 @@
187202
get {{ return 0 }}
188203
set {{ self.sink = newValue }}
189204
}}
190-
"""
205+
""",
206+
DoesntAddAPI,
191207
),
192208
(
193209
"computedToStored",
@@ -200,7 +216,8 @@
200216
""",
201217
"""
202218
public var {name}: Int = 0
203-
"""
219+
""",
220+
DoesntAddAPI,
204221
),
205222
(
206223
"storedToComputedPrivateSet",
@@ -213,7 +230,8 @@
213230
get {{ return 0 }}
214231
set {{ self.sink = newValue }}
215232
}}
216-
"""
233+
""",
234+
DoesntAddAPI,
217235
),
218236
(
219237
"storedToComputedDroppingPrivateSet",
@@ -225,7 +243,8 @@
225243
public var {name}: Int {{
226244
get {{ return 0 }}
227245
}}
228-
"""
246+
""",
247+
DoesntAddAPI,
229248
),
230249
(
231250
"getOnlyComputedToSettableStored",
@@ -237,7 +256,8 @@
237256
""",
238257
"""
239258
public var {name}: Int = 0
240-
"""
259+
""",
260+
AddsAPI,
241261
),
242262
(
243263
"getOnlyComputedToPrivateSettableStored",
@@ -249,7 +269,8 @@
249269
""",
250270
"""
251271
public private(set) var {name}: Int = 0
252-
"""
272+
""",
273+
DoesntAddAPI,
253274
),
254275
(
255276
"storedMakesPrivateSetPublic",
@@ -259,54 +280,61 @@
259280
""",
260281
"""
261282
public var {name}: Int = 0
262-
"""
263-
),
264-
(
265-
"computedGetOnlyToLet",
266-
"stored",
267-
"""
268-
public var {name}: Int {{
269-
return 0
270-
}}
271-
""",
272-
"""
273-
public let {name}: Int = 0
274-
"""
275-
),
276-
(
277-
"computedPrivateSetToLet",
278-
"stored",
279-
"""
280-
public private(set) var {name}: Int {{
281-
get {{ return 0 }}
282-
set {{ self.sink = newValue }}
283-
}}
284283
""",
285-
"""
286-
public let {name}: Int = 0
287-
"""
288-
),
289-
(
290-
"computedPrivateNonmutatingSetToLet",
291-
"stored",
292-
"""
293-
public private(set) var {name}: Int {{
294-
get {{ return 0 }}
295-
{nonmutating} set {{ globalSink = newValue }}
296-
}}
297-
""",
298-
"""
299-
public let {name}: Int = 0
300-
"""
301-
),
302-
(
303-
"storedPrivateSetToLet",
304-
"stored",
305-
"""
306-
public private(set) var {name}: Int = 0
307-
""",
308-
"""
309-
public let {name}: Int = 0
310-
"""
284+
AddsAPI,
311285
),
286+
# TODO: Turning computed gets into lets without annotation drops method
287+
# dispatch thunks and other ABI artifacts currently.
288+
# TODO # (
289+
# TODO # "computedGetOnlyToLet",
290+
# TODO # "stored",
291+
# TODO # """
292+
# TODO # public var {name}: Int {{
293+
# TODO # return 0
294+
# TODO # }}
295+
# TODO # """,
296+
# TODO # """
297+
# TODO # public let {name}: Int = 0
298+
# TODO # """,
299+
# TODO # DoesntAddAPI,
300+
# TODO # ),
301+
# TODO # (
302+
# TODO # "computedPrivateSetToLet",
303+
# TODO # "stored",
304+
# TODO # """
305+
# TODO # public private(set) var {name}: Int {{
306+
# TODO # get {{ return 0 }}
307+
# TODO # set {{ self.sink = newValue }}
308+
# TODO # }}
309+
# TODO # """,
310+
# TODO # """
311+
# TODO # public let {name}: Int = 0
312+
# TODO # """,
313+
# TODO # DoesntAddAPI,
314+
# TODO # ),
315+
# TODO # (
316+
# TODO # "computedPrivateNonmutatingSetToLet",
317+
# TODO # "stored",
318+
# TODO # """
319+
# TODO # public private(set) var {name}: Int {{
320+
# TODO # get {{ return 0 }}
321+
# TODO # {nonmutating} set {{ globalSink = newValue }}
322+
# TODO # }}
323+
# TODO # """,
324+
# TODO # """
325+
# TODO # public let {name}: Int = 0
326+
# TODO # """,
327+
# TODO # DoesntAddAPI,
328+
# TODO # ),
329+
# TODO # (
330+
# TODO # "storedPrivateSetToLet",
331+
# TODO # "stored",
332+
# TODO # """
333+
# TODO # public private(set) var {name}: Int = 0
334+
# TODO # """,
335+
# TODO # """
336+
# TODO # public let {name}: Int = 0
337+
# TODO # """,
338+
# TODO # DoesntAddAPI,
339+
# TODO # ),
312340
]

0 commit comments

Comments
 (0)