File: generics.sil

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 (113 lines) | stat: -rw-r--r-- 5,798 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
// RUN: %target-swift-frontend %s -emit-silgen | %FileCheck %s

sil_stage raw
import Builtin

// CHECK-LABEL: sil [ossa] @foo : $@convention(thin) <T> (@in T) -> @out T {
// CHECK: bb0(%0 : $*T, %1 : $*T):
// CHECK:   copy_addr [take] %1 to [init] %0 : $*T
// CHECK:   return undef : $()
// CHECK: }
sil [ossa] @foo : $@convention(thin) <T> (@in T) -> @out T {
entry(%o : $*T, %i : $*T):
  copy_addr [take] %i to [init] %o : $*T
  return undef : $()
}

struct Bar {}
struct Bas {}

// CHECK-LABEL: sil [ossa] @ref_foo_1 : $@convention(thin) () -> () {
// CHECK:   %2 = function_ref @foo : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0
// CHECK:   %3 = apply %2<Bar>(%1, %0) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0
sil [ossa] @ref_foo_1 : $@convention(thin) () -> () {
entry:
  %i = alloc_stack $Bar
  %o = alloc_stack $Bar
  %f = function_ref @foo : $@convention(thin) <XYZ> (@in XYZ) -> @out XYZ
  %z = apply %f<Bar>(%o, %i) : $@convention(thin) <ZYX> (@in ZYX) -> @out ZYX
  dealloc_stack %o : $*Bar
  dealloc_stack %i : $*Bar
  return %z : $()
}

// CHECK-LABEL: sil [ossa] @ref_foo_2 : $@convention(thin) () -> () {
// CHECK:  %2 = function_ref @foo : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0
// CHECK:  %3 = apply %2<Bas>(%1, %0) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0
sil [ossa] @ref_foo_2 : $@convention(thin) () -> () {
entry:
  %i = alloc_stack $Bas
  %o = alloc_stack $Bas
  %f = function_ref @foo : $@convention(thin) <ABC> (@in ABC) -> @out ABC
  %z = apply %f<Bas>(%o, %i) : $@convention(thin) <CBA> (@in CBA) -> @out CBA
  dealloc_stack %o : $*Bas
  dealloc_stack %i : $*Bas
  return %z : $()
}

// CHECK-LABEL: sil [ossa] @ref_foo_partial_apply : $@convention(thin) () -> @owned @callee_owned () -> @out Bas {
// CHECK:  %1 = function_ref @foo : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0
// CHECK:  %2 = partial_apply %1<Bas>(%0) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0
// CHECK:  return %2 : $@callee_owned () -> @out Bas
sil [ossa] @ref_foo_partial_apply : $@convention(thin) () -> @owned @callee_owned () -> @out Bas {
entry:
  %i = alloc_stack $Bas
  %f = function_ref @foo : $@convention(thin) <Z> (@in Z) -> @out Z
  %g = partial_apply %f<Bas>(%i) : $@convention(thin) <Y> (@in Y) -> @out Y
  dealloc_stack %i : $*Bas
  return %g : $@callee_owned () -> @out Bas
}

sil_global @zero: $Builtin.Int64
sil_global @f: $@callee_owned (Builtin.Int32) -> ()

// CHECK-LABEL: sil [ossa] @test_apply
sil [ossa] @test_apply : $@convention(thin) () -> () {
bb0:
  %0 = global_addr @zero : $*Builtin.Int64
  %1 = mark_uninitialized [var] %0 : $*Builtin.Int64
  %2 = global_addr @f : $*@callee_owned (Builtin.Int32) -> ()
  %3 = function_ref @_TF16generic_closures24generic_curried_functionU___FT1xQ__FT1yQ0__T_ : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0) -> @owned @callee_owned (@in τ_0_1) -> ()
  %4 = load [trivial] %1 : $*Builtin.Int64
  %5 = alloc_stack $Builtin.Int64
  store %4 to [trivial] %5 : $*Builtin.Int64
  // CHECK: apply %{{[0-9]+}}<{{.*}}Int64, {{.*}}Int32>(%{{.*}}) : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0) -> @owned @callee_owned (@in τ_0_1) -> ()
  %7 = apply %3<Builtin.Int64, Builtin.Int32>(%5) : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0) -> @owned @callee_owned (@in τ_0_1) -> ()
  %8 = function_ref @_TTRXFo_iBi32__dT__XFo_dBi32__dT__ : $@convention(thin) (Builtin.Int32, @owned @callee_owned (@in Builtin.Int32) -> ()) -> ()
  // CHECK: partial_apply %{{[0-9]+}}(%{{[0-9]+}}) : $@convention(thin) (Builtin.Int32, @owned @callee_owned (@in Builtin.Int32) -> ()) -> ()
  %9 = partial_apply %8(%7) : $@convention(thin) (Builtin.Int32, @owned @callee_owned (@in Builtin.Int32) -> ()) -> ()
  store %9 to [init] %2 : $*@callee_owned (Builtin.Int32) -> ()
  dealloc_stack %5 : $*Builtin.Int64
  %12 = tuple ()
  return %12 : $()
}

// generic_closures.generic_curried_function <A, B>(x : A) -> (y : B) -> ()
sil @_TF16generic_closures24generic_curried_functionU___FT1xQ__FT1yQ0__T_ : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0) -> @owned @callee_owned (@in τ_0_1) -> ()

// reabstraction thunk helper from @callee_owned (@in Builtin.Int32) -> (@unowned ()) to @callee_owned (@unowned Builtin.Int32) -> (@unowned ())
sil [transparent] @_TTRXFo_iBi32__dT__XFo_dBi32__dT__ : $@convention(thin) (Builtin.Int32, @owned @callee_owned (@in Builtin.Int32) -> ()) -> ()


protocol FooProtoHelper {}
protocol FooProto {
  associatedtype Assoc : FooProtoHelper
  var value: Assoc { get }
}

// These generic parameters used to crash the compiler.
sil [ossa] @protocol_extension_with_constrained_associated_type : $@convention(method) <Self where Self : FooProto, Self.Assoc : FooProtoHelper><I where I : FooProto, I.Assoc == Self.Assoc> (@in I, @in_guaranteed Self) -> () {
bb0(%0 : $*I, %1 : $*Self):
  %2 = alloc_stack $I                             // users: %3, %6, %7, %9
  copy_addr %0 to [init] %2 : $*I     // id: %3
  %4 = witness_method $I, #FooProto.value!getter : $@convention(witness_method: FooProto) <τ_0_0 where τ_0_0 : FooProto, τ_0_0.Assoc : FooProtoHelper> (@in_guaranteed τ_0_0) -> @out τ_0_0.Assoc // user: %6
  %5 = alloc_stack $Self.Assoc                    // users: %6, %8
  %6 = apply %4<I>(%5, %2) : $@convention(witness_method: FooProto) <τ_0_0 where τ_0_0 : FooProto, τ_0_0.Assoc : FooProtoHelper> (@in_guaranteed τ_0_0) -> @out τ_0_0.Assoc
  destroy_addr %2 : $*I                         // id: %7
  destroy_addr %5 : $*Self.Assoc // id: %8
  dealloc_stack %5 : $*Self.Assoc // id: %8
  dealloc_stack %2 : $*I         // id: %9
  destroy_addr %0 : $*I                           // id: %10
  %11 = tuple ()                                  // user: %12
  return %11 : $()                                // id: %12
}