|
| 1 | +// RUN: %target-swift-emit-silgen %s | %FileCheck %s |
| 2 | + |
| 3 | +public struct Projection<T> { |
| 4 | + public var wrappedValue: T |
| 5 | +} |
| 6 | + |
| 7 | +@propertyWrapper |
| 8 | +public struct Wrapper<T> { |
| 9 | + public var wrappedValue: T |
| 10 | + |
| 11 | + // CHECK-LABEL: sil [ossa] @$s26property_wrapper_parameter7WrapperV12wrappedValueACyxGx_tcfC : $@convention(method) <T> (@in T, @thin Wrapper<T>.Type) -> @out Wrapper<T> |
| 12 | + public init(wrappedValue: T) { |
| 13 | + self.wrappedValue = wrappedValue |
| 14 | + } |
| 15 | + |
| 16 | + public var projectedValue: Projection<T> { |
| 17 | + Projection(wrappedValue: wrappedValue) |
| 18 | + } |
| 19 | + |
| 20 | + // CHECK-LABEL: sil [ossa] @$s26property_wrapper_parameter7WrapperV14projectedValueACyxGAA10ProjectionVyxG_tcfC : $@convention(method) <T> (@in Projection<T>, @thin Wrapper<T>.Type) -> @out Wrapper<T> |
| 21 | + public init(projectedValue: Projection<T>) { |
| 22 | + self.wrappedValue = projectedValue.wrappedValue |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +// CHECK-LABEL: sil [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tF : $@convention(thin) (Wrapper<Int>) -> () |
| 27 | +public func testSimpleWrapperParameter(@Wrapper value: Int) { |
| 28 | + _ = value |
| 29 | + _ = _value |
| 30 | + _ = $value |
| 31 | + |
| 32 | + // getter of $value #1 in testSimpleWrapperParameter(value:) |
| 33 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tF6$valueL_AA10ProjectionVySiGvg : $@convention(thin) (Wrapper<Int>) -> Projection<Int> |
| 34 | + |
| 35 | + // getter of value #1 in testSimpleWrapperParameter(value:) |
| 36 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tFACL_Sivg : $@convention(thin) (Wrapper<Int>) -> Int |
| 37 | +} |
| 38 | + |
| 39 | +// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter28simpleWrapperParameterCaller10projectionyAA10ProjectionVySiG_tF : $@convention(thin) (Projection<Int>) -> () |
| 40 | +func simpleWrapperParameterCaller(projection: Projection<Int>) { |
| 41 | + testSimpleWrapperParameter(value: projection.wrappedValue) |
| 42 | + // CHECK: function_ref @$s26property_wrapper_parameter7WrapperV12wrappedValueACyxGx_tcfC : $@convention(method) <τ_0_0> (@in τ_0_0, @thin Wrapper<τ_0_0>.Type) -> @out Wrapper<τ_0_0> |
| 43 | + |
| 44 | + testSimpleWrapperParameter($value: projection) |
| 45 | + // CHECK: function_ref @$s26property_wrapper_parameter7WrapperV14projectedValueACyxGAA10ProjectionVyxG_tcfC : $@convention(method) <τ_0_0> (@in Projection<τ_0_0>, @thin Wrapper<τ_0_0>.Type) -> @out Wrapper<τ_0_0> |
| 46 | +} |
| 47 | + |
| 48 | +// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter33testSimpleClosureWrapperParameteryyF : $@convention(thin) () -> () |
| 49 | +func testSimpleClosureWrapperParameter() { |
| 50 | + let closure: (Int) -> Void = { (@Wrapper value) in |
| 51 | + _ = value |
| 52 | + _ = _value |
| 53 | + _ = $value |
| 54 | + } |
| 55 | + |
| 56 | + closure(10) |
| 57 | + |
| 58 | + // implicit closure #1 in testSimpleClosureWrapperParameter() |
| 59 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter33testSimpleClosureWrapperParameteryyFySicfu_ : $@convention(thin) (Int) -> () |
| 60 | + |
| 61 | + // closure #1 in implicit closure #1 in testSimpleClosureWrapperParameter() |
| 62 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter33testSimpleClosureWrapperParameteryyFySicfu_yAA0G0VySiGcfU_ : $@convention(thin) (Wrapper<Int>) -> () |
| 63 | + |
| 64 | + // getter of $value #1 in closure #1 in implicit closure #1 in testSimpleClosureWrapperParameter() |
| 65 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter33testSimpleClosureWrapperParameteryyFySicfu_yAA0G0VySiGcfU_6$valueL_AA10ProjectionVySiGvg : $@convention(thin) (Wrapper<Int>) -> Projection<Int> |
| 66 | + |
| 67 | + // getter of value #1 in closure #1 in implicit closure #1 in testSimpleClosureWrapperParameter() |
| 68 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter33testSimpleClosureWrapperParameteryyFySicfu_yAA0G0VySiGcfU_5valueL_Sivg : $@convention(thin) (Wrapper<Int>) -> Int |
| 69 | +} |
| 70 | + |
| 71 | +@propertyWrapper |
| 72 | +struct NonMutatingSetterWrapper<Value> { |
| 73 | + private var value: Value |
| 74 | + |
| 75 | + var wrappedValue: Value { |
| 76 | + get { value } |
| 77 | + nonmutating set { } |
| 78 | + } |
| 79 | + |
| 80 | + init(wrappedValue: Value) { |
| 81 | + self.value = wrappedValue |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +@propertyWrapper |
| 86 | +class ClassWrapper<Value> { |
| 87 | + var wrappedValue: Value |
| 88 | + |
| 89 | + init(wrappedValue: Value) { |
| 90 | + self.wrappedValue = wrappedValue |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter21testNonMutatingSetter6value16value2yAA0efG7WrapperVySSG_AA05ClassJ0CySiGtF : $@convention(thin) (@guaranteed NonMutatingSetterWrapper<String>, @guaranteed ClassWrapper<Int>) -> () |
| 95 | +func testNonMutatingSetter(@NonMutatingSetterWrapper value1: String, @ClassWrapper value2: Int) { |
| 96 | + _ = value1 |
| 97 | + value1 = "hello!" |
| 98 | + |
| 99 | + // getter of value1 #1 in testNonMutatingSetter(value1:value2:) |
| 100 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter21testNonMutatingSetter6value16value2yAA0efG7WrapperVySSG_AA05ClassJ0CySiGtFACL_SSvg : $@convention(thin) (@guaranteed NonMutatingSetterWrapper<String>) -> @owned String |
| 101 | + |
| 102 | + // setter of value1 #1 in testNonMutatingSetter(value1:value2:) |
| 103 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter21testNonMutatingSetter6value16value2yAA0efG7WrapperVySSG_AA05ClassJ0CySiGtFACL_SSvs : $@convention(thin) (@owned String, @guaranteed NonMutatingSetterWrapper<String>) -> () |
| 104 | + |
| 105 | + _ = value2 |
| 106 | + value2 = 10 |
| 107 | + |
| 108 | + // getter of value2 #1 in testNonMutatingSetter(value1:value2:) |
| 109 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter21testNonMutatingSetter6value16value2yAA0efG7WrapperVySSG_AA05ClassJ0CySiGtFADL_Sivg : $@convention(thin) (@guaranteed ClassWrapper<Int>) -> Int |
| 110 | + |
| 111 | + // setter of value2 #1 in testNonMutatingSetter(value1:value2:) |
| 112 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter21testNonMutatingSetter6value16value2yAA0efG7WrapperVySSG_AA05ClassJ0CySiGtFADL_Sivs : $@convention(thin) (Int, @guaranteed ClassWrapper<Int>) -> () |
| 113 | +} |
| 114 | + |
| 115 | +@propertyWrapper |
| 116 | +struct ProjectionWrapper<Value> { |
| 117 | + var wrappedValue: Value |
| 118 | + |
| 119 | + var projectedValue: ProjectionWrapper<Value> { self } |
| 120 | + |
| 121 | + init(wrappedValue: Value) { self.wrappedValue = wrappedValue } |
| 122 | + |
| 123 | + init(projectedValue: ProjectionWrapper<Value>) { |
| 124 | + self.wrappedValue = projectedValue.wrappedValue |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter27testImplicitPropertyWrapper10projectionyAA010ProjectionG0VySiG_tF : $@convention(thin) (ProjectionWrapper<Int>) -> () |
| 129 | +func testImplicitPropertyWrapper(projection: ProjectionWrapper<Int>) { |
| 130 | + let multiStatement: (ProjectionWrapper<Int>) -> Void = { $value in |
| 131 | + _ = value |
| 132 | + _ = _value |
| 133 | + _ = $value |
| 134 | + } |
| 135 | + |
| 136 | + multiStatement(projection) |
| 137 | + |
| 138 | + // implicit closure #1 in testImplicitPropertyWrapper(projection:) |
| 139 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter27testImplicitPropertyWrapper10projectionyAA010ProjectionG0VySiG_tFyAFcfu_ : $@convention(thin) (ProjectionWrapper<Int>) -> () |
| 140 | + |
| 141 | + // closure #1 in implicit closure #1 in testImplicitPropertyWrapper(projection:) |
| 142 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter27testImplicitPropertyWrapper10projectionyAA010ProjectionG0VySiG_tFyAFcfu_yAFcfU_ : $@convention(thin) (ProjectionWrapper<Int>) -> () |
| 143 | + |
| 144 | + // getter of $value #1 in closure #1 in implicit closure #1 in testImplicitPropertyWrapper(projection:) |
| 145 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter27testImplicitPropertyWrapper10projectionyAA010ProjectionG0VySiG_tFyAFcfu_yAFcfU_6$valueL_AFvg : $@convention(thin) (ProjectionWrapper<Int>) -> ProjectionWrapper<Int> |
| 146 | + |
| 147 | + // getter of value #1 in closure #1 in implicit closure #1 in testImplicitPropertyWrapper(projection:) |
| 148 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter27testImplicitPropertyWrapper10projectionyAA010ProjectionG0VySiG_tFyAFcfu_yAFcfU_5valueL_Sivg : $@convention(thin) () -> Int |
| 149 | + |
| 150 | + let _: (ProjectionWrapper<Int>) -> (Int, ProjectionWrapper<Int>) = { $value in |
| 151 | + (value, $value) |
| 152 | + } |
| 153 | + |
| 154 | + // implicit closure #2 in testImplicitPropertyWrapper(projection:) |
| 155 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter27testImplicitPropertyWrapper10projectionyAA010ProjectionG0VySiG_tFSi_AFtAFcfu0_ : $@convention(thin) (ProjectionWrapper<Int>) -> (Int, ProjectionWrapper<Int>) |
| 156 | + |
| 157 | + // closure #2 in implicit closure #2 in testImplicitPropertyWrapper(projection:) |
| 158 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter27testImplicitPropertyWrapper10projectionyAA010ProjectionG0VySiG_tFSi_AFtAFcfu0_Si_AFtAFcfU0_ : $@convention(thin) (ProjectionWrapper<Int>) -> (Int, ProjectionWrapper<Int>) |
| 159 | + |
| 160 | + // getter of $value #1 in closure #2 in implicit closure #2 in testImplicitPropertyWrapper(projection:) |
| 161 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter27testImplicitPropertyWrapper10projectionyAA010ProjectionG0VySiG_tFSi_AFtAFcfu0_Si_AFtAFcfU0_6$valueL_AFvg : $@convention(thin) (ProjectionWrapper<Int>) -> ProjectionWrapper<Int> |
| 162 | + |
| 163 | + // getter of value #1 in closure #2 in implicit closure #2 in testImplicitPropertyWrapper(projection:) |
| 164 | + // CHECK: sil private [ossa] @$s26property_wrapper_parameter27testImplicitPropertyWrapper10projectionyAA010ProjectionG0VySiG_tFSi_AFtAFcfu0_Si_AFtAFcfU0_5valueL_Sivg : $@convention(thin) () -> Int |
| 165 | +} |
0 commit comments