Skip to content

Commit ccb6085

Browse files
committed
Evolution: Code review feedback for backward deployment tests
1 parent 286be23 commit ccb6085

File tree

4 files changed

+50
-13
lines changed

4 files changed

+50
-13
lines changed

validation-test/Evolution/Inputs/backward_deploy_class.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,22 @@ open class OpenClass {
6464
}
6565

6666
// Inserting a superclass
67-
open class Bottom {
67+
open class Top {
6868
public init() {}
6969

70-
open func bottomMethod() {}
70+
open func topMethod() {}
7171
}
7272

7373
#if BEFORE
7474

75-
open class Top : Bottom {}
75+
open class Bottom : Top {}
7676

7777
#else
7878

79-
@_weakLinked open class Middle : Bottom {
79+
@_weakLinked open class Middle : Top {
8080
open func middleMethod() {}
8181
}
8282

83-
open class Top : Middle {}
83+
open class Bottom : Middle {}
8484

8585
#endif

validation-test/Evolution/Inputs/backward_deploy_protocol.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ public func getVersion() -> Int {
99
public protocol OtherProtocol {
1010
init()
1111
}
12-
public struct OtherConcrete : OtherProtocol {
12+
13+
#if AFTER
14+
// Protocol is always available, type is weak-linked
15+
@_weakLinked public struct OtherConforms : OtherProtocol {
1316
public init() {}
1417
}
18+
#endif
1519

1620
public protocol OldProtocol {
1721
#if AFTER
18-
@_weakLinked associatedtype NewType: OtherProtocol = OtherConcrete
22+
@_weakLinked associatedtype NewType: OtherProtocol = OtherConforms
1923
@_weakLinked func newMethod() -> NewType
2024
#endif
2125
}
@@ -28,6 +32,7 @@ extension OldProtocol {
2832
}
2933
#endif
3034

35+
// Protocol is weak-linked, type is always available
3136
#if AFTER
3237
@_weakLinked public protocol NewProtocol {
3338
func newMethod()
@@ -44,3 +49,12 @@ public struct NewConforms {
4449
}
4550
#endif
4651

52+
// Protocol and type are always available, conformace is weak-linked
53+
public struct NewConformanceConforms {
54+
public init() {}
55+
}
56+
public protocol NewConformanceProtocol {}
57+
58+
#if AFTER
59+
@_weakLinked extension NewConformanceConforms : NewConformanceProtocol {}
60+
#endif

validation-test/Evolution/test_backward_deploy_class.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ BackwardDeployClassTest.test("OpenClass") {
7070
}
7171

7272
BackwardDeployClassTest.test("InsertSuperclass") {
73-
class DerivedClass : Top {
73+
class DerivedClass : Bottom {
7474
var count: Int = 0
7575

76-
override func bottomMethod() {
76+
override func topMethod() {
7777
count += 1
78-
super.bottomMethod()
78+
super.topMethod()
7979
}
8080

8181
override func middleMethod() {
@@ -86,7 +86,7 @@ BackwardDeployClassTest.test("InsertSuperclass") {
8686

8787
let d = DerivedClass()
8888

89-
d.bottomMethod()
89+
d.topMethod()
9090
if getVersion() == 1 {
9191
d.middleMethod()
9292
expectEqual(d.count, 11)

validation-test/Evolution/test_backward_deploy_protocol.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ struct ConformsToOldWithNonDefault : OldProtocol {
1616

1717
BackwardDeployProtocolTest.test("OldProtocol") {
1818
if getVersion() == 1 {
19-
_ = ConformsToOldWithDefault().newMethod()
20-
_ = ConformsToOldWithNonDefault().newMethod()
19+
// FIXME: IRGen inserts the metadata load outside the version check
20+
// apparently. Work around that here. <rdar://problem/46438608>
21+
@inline(never) func helper() {
22+
_ = ConformsToOldWithDefault().newMethod()
23+
_ = ConformsToOldWithNonDefault().newMethod()
24+
}
25+
26+
helper()
2127
}
2228
}
2329

@@ -67,6 +73,23 @@ BackwardDeployProtocolTest.test("RefinedProtocol") {
6773
}
6874
}
6975

76+
// Witness tables that are weak-linked for various reasons
77+
BackwardDeployProtocolTest.test("WeakWitnessTables") {
78+
if getVersion() == 1 {
79+
// FIXME: IRGen inserts the metadata load outside the version check
80+
// apparently. Work around that here. <rdar://problem/46438608>
81+
@inline(never) func helper() {
82+
func f1<T : OtherProtocol>(_: T) {}
83+
func f2<T : NewProtocol>(_: T) {}
84+
func f3<T : NewConformanceProtocol>(_: T) {}
85+
86+
f1(OtherConforms())
87+
f2(NewConforms())
88+
f3(NewConformanceConforms())
89+
}
90+
}
91+
}
92+
7093
// Conditional conformance with weak-linked requirement
7194
struct Box<T> {}
7295

0 commit comments

Comments
 (0)