1
- // RUN: %target-swift-frontend -enable-sil-opaque-values -enable-sil-ownership -emit-sorted-sil -Xllvm -sil-full-demangle -emit-silgen -parse-stdlib -parse-as-library %s | %FileCheck %s
1
+ // RUN: %target-swift-frontend -enable-sil-opaque-values -enable-sil-ownership -emit-sorted-sil -Xllvm -sil-full-demangle -emit-silgen -parse-stdlib -parse-as-library -module-name Swift %s | %FileCheck %s
2
2
3
3
public protocol UnkeyedDecodingContainer {
4
4
var isAtEnd : Builtin . Int1 { get }
@@ -10,7 +10,7 @@ public protocol Decoder {
10
10
11
11
// Test open_existential_value ownership
12
12
// ---
13
- // CHECK-LABEL: sil @_T016opaque_ownership11takeDecoderBi1_AA0D0_p4from_tKF : $@convention(thin) (@in Decoder) -> (Builtin.Int1, @error Builtin.NativeObject) {
13
+ // CHECK-LABEL: sil @_T0s11takeDecoderBi1_s0B0_p4from_tKF : $@convention(thin) (@in Decoder) -> (Builtin.Int1, @error Builtin.NativeObject) {
14
14
// CHECK: bb0(%0 : @owned $Decoder):
15
15
// CHECK: [[BORROW1:%.*]] = begin_borrow %0 : $Decoder
16
16
// CHECK: [[OPENED:%.*]] = open_existential_value [[BORROW1]] : $Decoder to $@opened("{{.*}}") Decoder
@@ -27,8 +27,59 @@ public protocol Decoder {
27
27
// CHECK: destroy_value [[RET1]] : $UnkeyedDecodingContainer
28
28
// CHECK: destroy_value %0 : $Decoder
29
29
// CHECK: return [[RET2]] : $Builtin.Int1
30
- // CHECK-LABEL: } // end sil function '_T016opaque_ownership11takeDecoderBi1_AA0D0_p4from_tKF '
30
+ // CHECK-LABEL: } // end sil function '_T0s11takeDecoderBi1_s0B0_p4from_tKF '
31
31
public func takeDecoder( from decoder: Decoder ) throws -> Builtin . Int1 {
32
32
let container = try decoder. unkeyedContainer ( )
33
33
return container. isAtEnd
34
34
}
35
+
36
+ public enum Optional < Wrapped> {
37
+ case none
38
+ case some( Wrapped )
39
+ }
40
+
41
+ public protocol IP { }
42
+
43
+ public protocol Seq {
44
+ associatedtype Iterator : IP
45
+
46
+ func makeIterator( ) -> Iterator
47
+ }
48
+
49
+ extension Seq where Self. Iterator == Self {
50
+ public func makeIterator( ) -> Self {
51
+ return self
52
+ }
53
+ }
54
+
55
+ public struct EnumIter < Base : IP > : IP , Seq {
56
+ internal var _base : Base
57
+
58
+ public typealias Iterator = EnumIter < Base >
59
+ }
60
+
61
+ // Test passing a +1 RValue to @in_guaranteed.
62
+ // ---
63
+ // CHECK-LABEL: sil @_T0s7EnumSeqV12makeIterators0A4IterVy0D0QzGyF : $@convention(method) <Base where Base : Seq> (@in_guaranteed EnumSeq<Base>) -> @out EnumIter<Base.Iterator> {
64
+ // CHECK: bb0(%0 : @guaranteed $EnumSeq<Base>):
65
+ // CHECK: [[FN:%.*]] = function_ref @_T0s8EnumIterVAByxGx5_base_tcfC : $@convention(method) <τ_0_0 where τ_0_0 : IP> (@in τ_0_0, @thin EnumIter<τ_0_0>.Type) -> @out EnumIter<τ_0_0>
66
+ // CHECK: [[MT:%.*]] = metatype $@thin EnumIter<Base.Iterator>.Type
67
+ // CHECK: [[WT:%.*]] = witness_method $Base, #Seq.makeIterator!1 : <Self where Self : Seq> (Self) -> () -> Self.Iterator : $@convention(witness_method) <τ_0_0 where τ_0_0 : Seq> (@in_guaranteed τ_0_0) -> @out τ_0_0.Iterator
68
+ // CHECK: [[FIELD:%.*]] = struct_extract %0 : $EnumSeq<Base>, #EnumSeq._base
69
+ // CHECK: [[COPY:%.*]] = copy_value [[FIELD]] : $Base
70
+ // CHECK: [[BORROW:%.*]] = begin_borrow [[COPY]] : $Base
71
+ // CHECK: [[ITER:%.*]] = apply [[WT]]<Base>([[BORROW]]) : $@convention(witness_method) <τ_0_0 where τ_0_0 : Seq> (@in_guaranteed τ_0_0) -> @out τ_0_0.Iterator
72
+ // CHECK: end_borrow [[BORROW]] from [[COPY]] : $Base, $Base
73
+ // CHECK: destroy_value [[COPY]] : $Base
74
+ // CHECK: [[RET:%.*]] = apply [[FN]]<Base.Iterator>([[ITER]], [[MT]]) : $@convention(method) <τ_0_0 where τ_0_0 : IP> (@in τ_0_0, @thin EnumIter<τ_0_0>.Type) -> @out EnumIter<τ_0_0>
75
+ // CHECK: return [[RET]] : $EnumIter<Base.Iterator>
76
+ // CHECK-LABEL: } // end sil function '_T0s7EnumSeqV12makeIterators0A4IterVy0D0QzGyF'
77
+ public struct EnumSeq < Base : Seq > : Seq {
78
+ public typealias Iterator = EnumIter < Base . Iterator >
79
+
80
+ internal var _base : Base
81
+
82
+ public func makeIterator( ) -> Iterator {
83
+ return EnumIter ( _base: _base. makeIterator ( ) )
84
+ }
85
+ }
0 commit comments