File: big_types.sil

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (184 lines) | stat: -rw-r--r-- 7,875 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
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
// RUN: %target-sil-opt -loadable-address -enable-sil-verify-all %s | %FileCheck %s

// REQUIRES: PTRSIZE=64
// REQUIRES: OS=macosx

sil_stage canonical
import Builtin
import Swift

public struct BigStruct {
  var i0 : Int32 = 0
  var i1 : Int32 = 1
  var i2 : Int32 = 2
  var i3 : Int32 = 3
  var i4 : Int32 = 4
  var i5 : Int32 = 5
  var i6 : Int32 = 6
  var i7 : Int32 = 7
  var i8 : Int32 = 8
}

public struct ContainsClosure {
  let c: () -> BigStruct
}

sil @make_big_struct : $@convention(thin) () -> BigStruct
sil @use_big_struct : $@convention(thin) (BigStruct) -> ()

sil @takeClosure : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> ()) -> ()

typealias Invocation = @convention(thin) (BigStruct) -> ()

struct InvocationWrapper {
  let invocation: Invocation
}

sil_global hidden [let] @invocation : $InvocationWrapper

sil @invocationClosure : $@convention(thin) (BigStruct) -> ()

// CHECK-LABEL: sil_global @globalWithClosureInStruct : $ContainsClosure = {
// CHECK:         %0 = function_ref @make_big_struct : $@convention(thin) () -> @out BigStruct
// CHECK-NEXT:    %1 = thin_to_thick_function %0 : $@convention(thin) () -> @out BigStruct to $@callee_guaranteed () -> @out BigStruct
// CHECK-NEXT:    %initval = struct $ContainsClosure (%1 : $@callee_guaranteed () -> @out BigStruct)
// CHECK-NEXT:  } 
sil_global @globalWithClosureInStruct : $ContainsClosure = {
  %0 = function_ref @make_big_struct : $@convention(thin) () -> BigStruct
  %1 = thin_to_thick_function %0 : $@convention(thin) () -> BigStruct to $@callee_guaranteed () -> BigStruct
  %initval = struct $ContainsClosure (%1 : $@callee_guaranteed () -> BigStruct)
}

// CHECK-LABEL: sil @test_yield_big : $@yield_once @convention(thin) () -> @yields @in_guaranteed BigStruct {
// CHECK:       bb0:
// CHECK-NEXT:    [[TEMP:%.*]] = alloc_stack $BigStruct
// CHECK-NEXT:    // function_ref
// CHECK-NEXT:    [[MAKE:%.*]] = function_ref @make_big_struct : $@convention(thin) () -> @out BigStruct
// CHECK-NEXT:    apply [[MAKE]]([[TEMP]])
// CHECK-NEXT:    yield [[TEMP]] : $*BigStruct, resume bb1, unwind bb2
// CHECK:       bb1:
// CHECK-NEXT:    [[RET:%.*]] = tuple ()
// CHECK-NEXT:    dealloc_stack [[TEMP]] : $*BigStruct
// CHECK-NEXT:    return [[RET]] : $()
// CHECK:       bb2:
// CHECK-NEXT:    dealloc_stack [[TEMP]] : $*BigStruct
// CHECK-NEXT:    unwind
sil @test_yield_big : $@convention(thin) @yield_once() -> (@yields BigStruct) {
entry:
  %make = function_ref @make_big_struct : $@convention(thin) () -> BigStruct
  %big = apply %make() : $@convention(thin) () -> BigStruct
  yield %big : $BigStruct, resume resume, unwind unwind

resume:
  %ret = tuple ()
  return %ret : $()

unwind:
  unwind
}

// CHECK-LABEL: sil @use_yield_big : $@convention(thin) () -> () {
// CHECK:       bb0:
// CHECK-NEXT:    [[TEMP:%.*]] = alloc_stack $BigStruct
// CHECK-NEXT:    [[TEMP2:%.*]] = alloc_stack $BigStruct
// CHECK-NEXT:    // function_ref
// CHECK-NEXT:    [[CORO:%.*]] = function_ref @test_yield_big : $@yield_once @convention(thin) () -> @yields @in_guaranteed BigStruct
// CHECK-NEXT:    ([[ADDR:%.*]], [[TOKEN:%.*]]) = begin_apply [[CORO]]()
// CHECK-NEXT:   copy_addr [take] [[ADDR]] to [init] [[TEMP]] : $*BigStruct
// CHECK-NEXT:   copy_addr [take] [[TEMP]] to [init] [[TEMP2]] : $*BigStruct
// CHECK-NEXT:    // function_ref
// CHECK-NEXT:    [[USE:%.*]] = function_ref @use_big_struct : $@convention(thin) (@in_guaranteed BigStruct) -> ()
// CHECK-NEXT:    apply [[USE]]([[TEMP2]])
// CHECK-NEXT:    [[RET:%.*]] = end_apply [[TOKEN]] as $()
// CHECK-NEXT:    dealloc_stack [[TEMP2]] : $*BigStruct
// CHECK-NEXT:    dealloc_stack [[TEMP]] : $*BigStruct
// CHECK-NEXT:    return [[RET]] : $()
sil @use_yield_big : $@convention(thin) () -> () {
entry:
  %yield_big = function_ref @test_yield_big : $@convention(thin) @yield_once() -> (@yields BigStruct)
  (%big, %token) = begin_apply %yield_big() : $@convention(thin) @yield_once() -> (@yields BigStruct)
  %use_big = function_ref @use_big_struct : $@convention(thin) (BigStruct) -> ()
  apply %use_big(%big) : $@convention(thin) (BigStruct) -> ()
  %ret = end_apply %token as $()
  return %ret : $()
}

sil @yield_fun_ptr2 : $@yield_once @convention(thin) () -> @yields @inout Optional<@callee_guaranteed (@guaranteed BigStruct) -> ()>

// CHECK-LABEL: sil @yield_funptr : $
// CHECK: (%1, %2) = begin_apply %0() : $@yield_once @convention(thin) () -> @yields @inout Optional<@callee_guaranteed (@in_guaranteed BigStruct) -> ()>
// CHECK: yield %1
sil @yield_funptr : $@yield_once @convention(thin) () -> @yields @inout Optional<@callee_guaranteed (@guaranteed BigStruct) -> ()> {
bb0:
  %2 = function_ref @yield_fun_ptr2 : $@yield_once @convention(thin) () -> @yields @inout Optional<@callee_guaranteed (@guaranteed BigStruct) -> ()>
  (%3, %4) = begin_apply %2() : $@yield_once @convention(thin) () -> @yields @inout Optional<@callee_guaranteed (@guaranteed BigStruct) -> ()>
  yield %3 : $*Optional<@callee_guaranteed (@guaranteed BigStruct) -> ()>, resume bb1, unwind bb2

bb1:
  end_apply %4 as $()
  %7 = tuple ()
  return %7 : $()

bb2:
  abort_apply %4
  unwind
}

// CHECK-LABEL: sil @test_yield_and_retain
// CHECK:   [[S:%[0-9]+]] = alloc_stack $BigStruct
// CHECK:   copy_addr [take] %0 to [init] [[S]]
// CHECK:   retain_value_addr [[S]]
// CHECK:   yield [[S]] : $*BigStruct
// CHECK: // end sil function 'test_yield_and_retain'
sil @test_yield_and_retain : $@convention(thin) @yield_once (@in_guaranteed BigStruct) -> @yields BigStruct {
entry(%0 : $*BigStruct):
  %big = load %0 : $*BigStruct
  retain_value %big : $BigStruct
  yield %big : $BigStruct, resume resume, unwind unwind

resume:
  %ret = tuple ()
  return %ret : $()

unwind:
  unwind
}

// Test that partial apply captured arguments are converted to
// @in_guaranteed, unless they are actually owned, which is not
// allowed for on-stack closures.
//
// CHECK-LABEL: sil hidden @testLoadableCapture : $@convention(thin) (@in_guaranteed BigStruct) -> () {
// CHECK: partial_apply [callee_guaranteed] [on_stack] %{{.*}}(%0) : $@convention(thin) (@in_guaranteed BigStruct) -> ()
// CHECK-LABEL: // end sil function 'testLoadableCapture'
sil hidden @testLoadableCapture : $@convention(thin) (BigStruct) -> () {
bb0(%0 : $BigStruct):
  %2 = function_ref @testLoadableCaptureClosure : $@convention(thin) (BigStruct) -> () // user: %3
  %3 = partial_apply [callee_guaranteed] [on_stack] %2(%0) : $@convention(thin) (BigStruct) -> () // users: %6, %5
  %4 = function_ref @takeClosure : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> ()) -> () // user: %5
  %5 = apply %4(%3) : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> ()) -> ()
  dealloc_stack %3 : $@noescape @callee_guaranteed () -> () // id: %6
  %7 = tuple ()                                   // user: %8
  return %7 : $()                                 // id: %8
}

sil private @testLoadableCaptureClosure : $@convention(thin) (BigStruct) -> () {
bb0(%0 : @closureCapture $BigStruct):
  %2 = tuple ()
  return %2 : $()
}

// Test a rewritten function_ref stored in a struct property.
// CHECK-LABEL: sil [global_init_once_fn] @test_invocation : $@convention(c) (Builtin.RawPointer) -> () {
// CHECK: [[F:%[0-9]+]] = function_ref @invocationClosure : $@convention(thin) (@in_guaranteed BigStruct) -> ()
// CHECK: = struct $InvocationWrapper ([[F]] : $@convention(thin) (@in_guaranteed BigStruct) -> ())
sil [global_init_once_fn] @test_invocation : $@convention(c) (Builtin.RawPointer) -> () {
bb0(%0 : $Builtin.RawPointer):
  alloc_global @invocation
  %g = global_addr @invocation : $*InvocationWrapper
  %f = function_ref @invocationClosure : $@convention(thin) (BigStruct) -> ()
  %s = struct $InvocationWrapper (%f : $@convention(thin) (BigStruct) -> ())
  store %s to %g : $*InvocationWrapper
  %r = tuple ()
  return %r : $()
}