Skip to content

Commit 062646e

Browse files
committed
DI: Split off definite_init_failable_initializers_objc.swift test from definite_init_failable_initializers.swift
1 parent 16f9438 commit 062646e

File tree

2 files changed

+77
-15
lines changed

2 files changed

+77
-15
lines changed

test/SILOptimizer/definite_init_failable_initializers.swift

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -emit-sil -enable-sil-ownership -disable-objc-attr-requires-foundation-module %s | %FileCheck %s
1+
// RUN: %target-swift-frontend -emit-sil -enable-sil-ownership %s | %FileCheck %s
22

33
// High-level tests that DI handles early returns from failable and throwing
44
// initializers properly. The main complication is conditional release of self
@@ -1533,20 +1533,6 @@ extension P2 {
15331533
}
15341534
}
15351535

1536-
@objc protocol P3 {
1537-
init?(p3: Int64)
1538-
}
1539-
1540-
extension P3 {
1541-
init!(p3a: Int64) {
1542-
self.init(p3: p3a)! // unnecessary-but-correct '!'
1543-
}
1544-
1545-
init(p3b: Int64) {
1546-
self.init(p3: p3b)! // necessary '!'
1547-
}
1548-
}
1549-
15501536
// Delegating to failable initializers from a protocol extension to a
15511537
// protocol extension.
15521538
extension P1 {
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// RUN: %target-swift-frontend -emit-sil -enable-sil-ownership -disable-objc-attr-requires-foundation-module %s | %FileCheck %s
2+
3+
// FIXME: This needs more tests
4+
5+
@objc protocol P3 {
6+
init?(p3: Int64)
7+
}
8+
9+
extension P3 {
10+
// CHECK-LABEL: sil hidden @_T040definite_init_failable_initializers_objc2P3PAAESQyxGs5Int64V3p3a_tcfC : $@convention(method) <Self where Self : P3> (Int64, @thick Self.Type) -> @owned Optional<Self>
11+
init!(p3a: Int64) {
12+
self.init(p3: p3a)! // unnecessary-but-correct '!'
13+
}
14+
15+
// CHECK-LABEL: sil hidden @_T040definite_init_failable_initializers_objc2P3PAAExs5Int64V3p3b_tcfC : $@convention(method) <Self where Self : P3> (Int64, @thick Self.Type) -> @owned Self
16+
init(p3b: Int64) {
17+
self.init(p3: p3b)! // necessary '!'
18+
}
19+
}
20+
21+
class LifetimeTracked {
22+
init(_: Int) {}
23+
}
24+
25+
class FakeNSObject {
26+
@objc dynamic init() {}
27+
}
28+
29+
class Cat : FakeNSObject {
30+
let x: LifetimeTracked
31+
32+
// CHECK-LABEL: sil hidden @_T040definite_init_failable_initializers_objc3CatCACSgSi1n_Sb5aftertcfc : $@convention(method) (Int, Bool, @owned Cat) -> @owned Optional<Cat>
33+
// CHECK: bb0(%0 : $Int, %1 : $Bool, %2 : $Cat):
34+
// CHECK-NEXT: [[SELF_BOX:%.*]] = alloc_stack $Cat
35+
// CHECK: store %2 to [[SELF_BOX]] : $*Cat
36+
// CHECK: [[FIELD_ADDR:%.*]] = ref_element_addr %2 : $Cat, #Cat.x
37+
// CHECK-NEXT: [[ACCESS:%.*]] = begin_access [modify] [dynamic] %12 : $*LifetimeTracked
38+
// CHECK-NEXT: store {{%.*}} to [[ACCESS]] : $*LifetimeTracked
39+
// CHECK-NEXT: end_access [[ACCESS]] : $*LifetimeTracked
40+
// CHECK-NEXT: [[COND:%.*]] = struct_extract %1 : $Bool, #Bool._value
41+
// CHECK-NEXT: cond_br [[COND]], bb1, bb2
42+
43+
// CHECK: bb1:
44+
// CHECK-NEXT: br bb3
45+
46+
// CHECK: bb2:
47+
// CHECK-NEXT: [[SUPER:%.*]] = upcast %2 : $Cat to $FakeNSObject
48+
// CHECK-NEXT: [[SUB:%.*]] = unchecked_ref_cast [[SUPER]] : $FakeNSObject to $Cat
49+
// CHECK-NEXT: [[SUPER_FN:%.*]] = objc_super_method %20 : $Cat, #FakeNSObject.init!initializer.1.foreign : (FakeNSObject.Type) -> () -> FakeNSObject, $@convention(objc_method) (@owned FakeNSObject) -> @owned FakeNSObject
50+
// CHECK-NEXT: [[NEW_SUPER_SELF:%.*]] = apply [[SUPER_FN]]([[SUPER]]) : $@convention(objc_method) (@owned FakeNSObject) -> @owned FakeNSObject
51+
// CHECK-NEXT: [[NEW_SELF:%.*]] = unchecked_ref_cast [[NEW_SUPER_SELF]] : $FakeNSObject to $Cat
52+
// CHECK-NEXT: store [[NEW_SELF]] to [[SELF_BOX]] : $*Cat
53+
// CHECK-NEXT: [[RESULT:%.*]] = enum $Optional<Cat>, #Optional.some!enumelt.1, [[NEW_SELF]] : $Cat
54+
// CHECK-NEXT: dealloc_stack [[SELF_BOX]] : $*Cat
55+
// CHECK-NEXT: br bb4([[RESULT]] : $Optional<Cat>)
56+
57+
// CHECK: bb3:
58+
// CHECK-NEXT: [[FIELD_ADDR:%.*]] = ref_element_addr %2 : $Cat, #Cat.x
59+
// CHECK-NEXT: destroy_addr [[FIELD_ADDR]] : $*LifetimeTracked
60+
// CHECK-NEXT: [[METATYPE:%.*]] = metatype $@thick Cat.Type
61+
// CHECK-NEXT: dealloc_partial_ref %2 : $Cat, [[METATYPE]] : $@thick Cat.Type
62+
// CHECK-NEXT: dealloc_stack [[SELF_BOX]] : $*Cat
63+
// CHECK-NEXT: [[RESULT:%.*]] = enum $Optional<Cat>, #Optional.none!enumelt
64+
// CHECK-NEXT: br bb4([[RESULT]] : $Optional<Cat>)
65+
66+
// CHECK: bb4([[RESULT:%.*]] : $Optional<Cat>):
67+
// CHECK-NEXT: return [[RESULT]] : $Optional<Cat>
68+
69+
init?(n: Int, after: Bool) {
70+
self.x = LifetimeTracked(0)
71+
if after {
72+
return nil
73+
}
74+
super.init()
75+
}
76+
}

0 commit comments

Comments
 (0)