File: property_wrapper_coroutine.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (76 lines) | stat: -rw-r--r-- 3,617 bytes parent folder | download
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
// RUN: %target-swift-emit-silgen %s | %FileCheck %s

@propertyWrapper
struct TestWrapper<ValueType> {
  var wrappedValue: ValueType
}

struct State {
  @TestWrapper var values: [String] = []
}

protocol StateProtocol {
  @_borrowed var someValues: [String] { get set }
}

struct State1: StateProtocol {
  @TestWrapper var someValues: [String] = []
}

var state = State()
state.values = Array(repeating: "", count: 20000)
state.values[1000] = "foo"

let state1 = State1()
_ = state1.someValues

// >> Check that the subscript assignment uses the _modify coroutine

// CHECK:  {{%.*}} = begin_access [modify] [dynamic] {{%.*}} : $*State
// CHECK:  [[REF_VALUES_MODIFY:%.*]] = function_ref @$s26property_wrapper_coroutine5StateV6valuesSaySSGvM : $@yield_once @convention(method) (@inout State) -> @yields @inout Array<String>
// CHECK:  ([[RES1:%.*]], {{%.*}}) = begin_apply [[REF_VALUES_MODIFY]]({{%.*}}) : $@yield_once @convention(method) (@inout State) -> @yields @inout Array<String>
// CHECK:  [[REF_ARRAY_SUBSCRIPT:%.*]] = function_ref @$sSayxSiciM : $@yield_once @convention(method) <τ_0_0> (Int, @inout Array<τ_0_0>) -> @yields @inout τ_0_0
// CHECK:  ({{%.*}}, {{%.*}}) = begin_apply [[REF_ARRAY_SUBSCRIPT]]<String>({{%.*}}, [[RES1]]) : $@yield_once @convention(method) <τ_0_0> (Int, @inout Array<τ_0_0>) -> @yields @inout τ_0_0

// >> Check that the _modify coroutine is synthesized properly

// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_coroutine5StateV6valuesSaySSGvM : $@yield_once @convention(method) (@inout State) -> @yields @inout Array<String> {
// CHECK: bb0([[STATE:%.*]] : $*State):
// CHECK:  debug_value [[STATE]] : $*State, var, name "self", argno {{.*}}, expr op_deref
// CHECK:  [[BEGIN_ACCESS:%.*]] = begin_access [modify] [unknown] [[STATE]] : $*State
// CHECK:  [[BACKING_ADDR:%.*]] = struct_element_addr [[BEGIN_ACCESS]] : $*State, #State._values
// CHECK:  [[VALUE_ADDR:%.*]] = struct_element_addr [[BACKING_ADDR]] : $*TestWrapper<Array<String>>, #TestWrapper.wrappedValue
// CHECK:  yield [[VALUE_ADDR]] : $*Array<String>, resume bb1, unwind bb2
//
// CHECK: bb1:
// CHECK:  end_access [[BEGIN_ACCESS]] : $*State
// CHECK:  [[RETURN:%.*]] = tuple ()
// CHECK:  return [[RETURN]] : $()
//
// CHECK: bb2:
// CHECK:  end_access [[BEGIN_ACCESS]] : $*State
// CHECK:  unwind
// CHECK-END: }

// >> Check that the _read coroutine is synthesized properly

// CHECK-LABEL: sil shared [ossa] @$s26property_wrapper_coroutine6State1V10someValuesSaySSGvr : $@yield_once @convention(method) (@guaranteed State1) -> @yields @guaranteed Array<String> {
// CHECK: bb0([[STATE1:%.*]] : @guaranteed $State1):
// CHECK:  debug_value [[SELF:%.*]] : $State1, let, name "self", argno {{.*}}
// CHECK:  [[EXTRACT_VALUE:%.*]] = struct_extract %0 : $State1, #State1._someValues
// CHECK:  [[COPY_VALUE:%.*]] = copy_value [[EXTRACT_VALUE]] : $TestWrapper<Array<String>>
// CHECK:  [[BEGIN_BORROW:%.*]] = begin_borrow [[COPY_VALUE]] : $TestWrapper<Array<String>>
// CHECK:  [[EXTRACT_WRAPPEDVALUE:%.*]] = struct_extract [[BEGIN_BORROW]] : $TestWrapper<Array<String>>, #TestWrapper.wrappedValue
// CHECK:  yield [[EXTRACT_WRAPPEDVALUE]] : $Array<String>, resume bb1, unwind bb2
//
// CHECK: bb1:
// CHECK:  end_borrow [[BEGIN_BORROW]] : $TestWrapper<Array<String>>
// CHECK:  destroy_value [[COPY_VALUE]] : $TestWrapper<Array<String>>
// CHECK:  [[RETURN:%.*]] = tuple ()
// CHECK:  return [[RETURN]] : $()
//
// CHECK: bb2:
// CHECK:  end_borrow [[BEGIN_BORROW]] : $TestWrapper<Array<String>>
// CHECK:  destroy_value [[COPY_VALUE]] : $TestWrapper<Array<String>>
// CHECK:  unwind
// CHECK-END: }