1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
struct SimpleTest {
var stored: String
var readable: String {
// CHECK-LABEL: sil hidden [ossa] @$s13read_accessor10SimpleTestV8readableSSvr
// CHECK-SAME: : $@yield_once @convention(method) (@guaranteed SimpleTest) -> @yields @guaranteed String {
// CHECK: [[T0:%.*]] = struct_extract %0 : $SimpleTest, #SimpleTest.stored
// CHECK-NEXT: yield [[T0]] : $String, resume bb1, unwind bb2
// CHECK: bb1:
// CHECK-NEXT: [[RET:%.*]] = tuple ()
// CHECK-NEXT: return [[RET]] : $()
// CHECK: bb2:
// CHECK-NEXT: unwind
_read {
yield stored
}
}
// CHECK-LABEL: sil hidden [ossa] @$s13read_accessor10SimpleTestV3getSSyF
// CHECK: [[T0:%.*]] = begin_access [read] [unknown] %0
// CHECK-NEXT: [[SELF:%.*]] = load [copy] [[T0]] : $*SimpleTest
// CHECK-NEXT: end_access [[T0]]
// CHECK-NEXT: [[SELF_BORROW:%.*]] = begin_borrow [[SELF]]
// CHECK-NEXT: // function_ref
// CHECK-NEXT: [[READFN:%.*]] = function_ref @$s13read_accessor10SimpleTestV8readableSSvr : $@yield_once @convention(method) (@guaranteed SimpleTest) -> @yields @guaranteed String
// CHECK-NEXT: ([[VALUE:%.*]], [[TOKEN:%.*]]) = begin_apply [[READFN]]([[SELF_BORROW]])
// CHECK-NEXT: [[RET:%.*]] = copy_value [[VALUE]] : $String
// CHECK-NEXT: end_apply [[TOKEN]]
// CHECK-NEXT: end_borrow [[SELF_BORROW]]
// CHECK-NEXT: destroy_value [[SELF]]
// CHECK-NEXT: return [[RET]] : $String
mutating func get() -> String {
return readable
}
}
class GetterSynthesis {
var stored: String = "hello"
var readable: String {
// CHECK-LABEL: sil hidden [transparent] [ossa] @$s13read_accessor15GetterSynthesisC8readableSSvg
// CHECK: [[READFN:%.*]] = function_ref @$s13read_accessor15GetterSynthesisC8readableSSvr
// CHECK-NEXT: ([[VALUE:%.*]], [[TOKEN:%.*]]) = begin_apply [[READFN]](%0)
// CHECK-NEXT: [[RET:%.*]] = copy_value [[VALUE]] : $String
// CHECK-NEXT: end_apply [[TOKEN]]
// CHECK-NEXT: return [[RET]] : $String
_read {
yield stored
}
}
}
func void() {}
struct TupleReader {
var stored: String
subscript(i: Int) -> String {
_read { yield stored }
}
func compute() -> String { return stored }
func index() -> Int { return 0 }
var readable: ((String, ()), String, ()) {
// CHECK-LABEL: sil hidden [ossa] @$s13read_accessor11TupleReaderV8readableSS_ytt_SSyttvr
// CHECK: debug_value %0
// CHECK-NEXT: // function_ref
// CHECK-NEXT: [[INDEXFN:%.*]] = function_ref @$s13read_accessor11TupleReaderV5indexSiyF
// CHECK-NEXT: [[INDEX:%.*]] = apply [[INDEXFN]](%0)
// CHECK-NEXT: // function_ref
// CHECK-NEXT: [[COMPUTEFN:%.*]] = function_ref @$s13read_accessor11TupleReaderV7computeSSyF
// CHECK-NEXT: [[COMPUTE:%.*]] = apply [[COMPUTEFN]](%0)
// CHECK-NEXT: // function_ref
// CHECK-NEXT: [[VOIDFN:%.*]] = function_ref @$s13read_accessor4voidyyF
// CHECK-NEXT: apply [[VOIDFN]]()
// CHECK-NEXT: // function_ref
// CHECK-NEXT: [[SUBREADFN:%.*]] = function_ref @$s13read_accessor11TupleReaderVySSSicir
// CHECK-NEXT: ([[SUBREAD:%.*]], [[SUBTOKEN:%.*]]) = begin_apply [[SUBREADFN]]([[INDEX]], %0)
// CHECK-NEXT: yield ([[SUBREAD]] : $String, [[COMPUTE]] : $String), resume bb1, unwind bb2
// CHECK: bb1:
// CHECK-NEXT: end_apply [[SUBTOKEN]]
// CHECK-NEXT: destroy_value [[COMPUTE]] : $String
// CHECK-NEXT: [[T0:%.*]] = tuple ()
// CHECK-NEXT: return [[T0]] : $()
// CHECK: bb2:
// Should this be an abort_apply?
// CHECK-NEXT: end_apply [[SUBTOKEN]]
// CHECK-NEXT: destroy_value [[COMPUTE]] : $String
// CHECK-NEXT: unwind
// CHECK-LABEL: } // end sil function '$s13read_accessor11TupleReaderV8readableSS_ytt_SSyttvr'
_read {
yield (((self[index()], ()), compute(), void()))
}
}
// CHECK-LABEL: sil hidden [ossa] @$s13read_accessor11TupleReaderV11useReadableyyF
// CHECK: [[READFN:%.*]] = function_ref @$s13read_accessor11TupleReaderV8readableSS_ytt_SSyttvr
// CHECK-NEXT: ([[FIRST:%.*]], [[SECOND:%.*]], [[TOKEN:%.*]]) = begin_apply [[READFN]](%0)
// FIXME: this materialization is silly
// CHECK-NEXT: [[TEMP:%.*]] = alloc_stack $((String, ()), String, ())
// CHECK-NEXT: [[TEMP_0:%.*]] = tuple_element_addr [[TEMP]] : $*((String, ()), String, ()), 0
// CHECK-NEXT: [[TEMP_1:%.*]] = tuple_element_addr [[TEMP]] : $*((String, ()), String, ()), 1
// CHECK-NEXT: [[TEMP_2:%.*]] = tuple_element_addr [[TEMP]] : $*((String, ()), String, ()), 2
// CHECK-NEXT: [[TEMP_0_0:%.*]] = tuple_element_addr [[TEMP_0]] : $*(String, ()), 0
// CHECK-NEXT: [[TEMP_0_1:%.*]] = tuple_element_addr [[TEMP_0]] : $*(String, ()), 1
// CHECK-NEXT: [[T0:%.*]] = copy_value [[FIRST]] : $String
// CHECK-NEXT: store [[T0]] to [init] [[TEMP_0_0]]
// CHECK-NEXT: [[T0:%.*]] = copy_value [[SECOND]] : $String
// CHECK-NEXT: store [[T0]] to [init] [[TEMP_1]]
// CHECK-NEXT: [[TUPLE:%.*]] = load [copy] [[TEMP]]
// CHECK-NEXT: destructure_tuple
// CHECK-NEXT: destructure_tuple
// CHECK-NEXT: destroy_addr [[TEMP]]
// CHECK-NEXT: end_apply
// CHECK-LABEL: } // end sil function '$s13read_accessor11TupleReaderV11useReadableyyF'
func useReadable() {
var v = readable
}
var computed: String {
return compute()
}
// CHECK-LABEL: sil hidden [ossa] @$s13read_accessor11TupleReaderV0A8ComputedSSvr
// CHECK: [[GETTER:%.*]] = function_ref @$s13read_accessor11TupleReaderV8computedSSvg
// CHECK-NEXT: [[VALUE:%.]] = apply [[GETTER]](%0)
// CHECK-NEXT: [[BORROW:%.*]] = begin_borrow [[VALUE]] : $String
// CHECK-NEXT: yield [[BORROW]] : $String, resume bb1
// CHECK: bb1:
// CHECK-NEXT: end_borrow [[BORROW]] : $String
// CHECK-NEXT: destroy_value [[VALUE]] : $String
var readComputed : String {
_read {
yield computed
}
}
}
struct TestKeyPath {
var readable: String {
_read {
yield ""
}
}
func useKeyPath() -> String {
return self[keyPath: \.readable]
}
}
// Key-path getter for TestKeyPath.readable
// CHECK-LABEL: sil shared [thunk] [ossa] @$s13read_accessor11TestKeyPathV8readableSSvpACTK
// CHECK: bb0(%0 : $*String, %1 : $*TestKeyPath):
// CHECK-NEXT: [[SELF:%.*]] = load [trivial] %1
// CHECK-NEXT: // function_ref
// CHECK-NEXT: [[READ:%.*]] = function_ref @$s13read_accessor11TestKeyPathV8readableSSvr
// CHECK-NEXT: ([[VALUE:%.*]], [[TOKEN:%.*]]) = begin_apply [[READ]]([[SELF]])
// CHECK-NEXT: [[COPY:%.*]] = copy_value [[VALUE]]
// CHECK-NEXT: end_apply [[TOKEN]]
// CHECK-NEXT: store [[COPY]] to [init] %0 : $*String
// CHECK-NEXT: [[RET:%.*]] = tuple ()
// CHECK-NEXT: return [[RET]] : $()
// CHECK-LABEL: } // end sil function '$s13read_accessor11TestKeyPathV8readableSSvpACTK'
// Check that we emit a read coroutine but not a getter for this.
// This test assumes that we emit accessors in a particular order.
// CHECK-LABEL: sil [transparent] [ossa] @$s13read_accessor20TestBorrowedPropertyV14borrowedStringSSvpfi
// CHECK-NOT: sil [transparent] [serialized] [ossa] @$s13read_accessor20TestBorrowedPropertyV14borrowedStringSSvg
// CHECK: sil [transparent] [serialized] [ossa] @$s13read_accessor20TestBorrowedPropertyV14borrowedStringSSvr
// CHECK-NOT: sil [transparent] [serialized] [ossa] @$s13read_accessor20TestBorrowedPropertyV14borrowedStringSSvg
// CHECK-LABEL: sil [transparent] [serialized] [ossa] @$s13read_accessor20TestBorrowedPropertyV14borrowedStringSSvs
public struct TestBorrowedProperty {
@_borrowed
public var borrowedString = ""
}
protocol ReadableTitle {
@_borrowed
var title: String { get }
}
class OverridableGetter : ReadableTitle {
var title: String = ""
}
// The read witness thunk does a direct call to the concrete read accessor.
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s13read_accessor17OverridableGetterCAA13ReadableTitleA2aDP5titleSSvrTW
// CHECK: function_ref @$s13read_accessor17OverridableGetterC5titleSSvr
// CHECK-LABEL: // end sil function '$s13read_accessor17OverridableGetterCAA13ReadableTitleA2aDP5titleSSvrTW'
// The concrete read accessor is generated on-demand and does a class dispatch to the getter.
// CHECK-LABEL: sil shared [ossa] @$s13read_accessor17OverridableGetterC5titleSSvr
// CHECK: class_method %0 : $OverridableGetter, #OverridableGetter.title!getter
// CHECK-LABEL: // end sil function '$s13read_accessor17OverridableGetterC5titleSSvr'
protocol GettableTitle {
var title: String { get }
}
class OverridableReader : GettableTitle {
@_borrowed
var title: String = ""
}
// The getter witness thunk does a direct call to the concrete getter.
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s13read_accessor17OverridableReaderCAA13GettableTitleA2aDP5titleSSvgTW
// CHECK: function_ref @$s13read_accessor17OverridableReaderC5titleSSvg
// CHECK-LABEL: // end sil function '$s13read_accessor17OverridableReaderCAA13GettableTitleA2aDP5titleSSvgTW'
// The concrete getter is generated on-demand and does a class dispatch to the read accessor.
// CHECK-LABEL: sil shared [ossa] @$s13read_accessor17OverridableReaderC5titleSSvg
// CHECK: class_method %0 : $OverridableReader, #OverridableReader.title!read
// CHECK-LABEL: // end sil function '$s13read_accessor17OverridableReaderC5titleSSvg'
|