File: partial_specialization.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 (154 lines) | stat: -rw-r--r-- 6,750 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
// RUN: %target-sil-opt -enable-sil-verify-all -generic-specializer -sil-partial-specialization -sil-partial-specialization-with-generic-substitutions  %s | %FileCheck %s

// Test different cases of partial specialization.
// In particular, test the correctness of partial specializations where substitutions may be generic.

sil_stage canonical

import Builtin
import Swift
import SwiftShims

@_silgen_name("use")
public func use<T>(_ t: T)

public protocol P {
}

public struct S<T> {
  @inline(never) public init(_ t: T)
}

@inline(never) public func simple_generic_callee<U, V>(_ u: U, _ v: V)

public func simple_generic_caller1<U>(_ u: U)

public func simple_generic_caller2<U>(_ u: U)

// use
sil @use : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()

// S.init(_:)
sil [noinline] @$s22partial_specialization1SVyACyxGxcfC : $@convention(method) <T> (@in T, @thin S<T>.Type) -> S<T>

// simple_generic_callee<A, B>(_:_:)
sil [noinline] @simple_generic_callee : $@convention(thin) <U, V> (@in U, @in V) -> () {
bb0(%0 : $*U, %1 : $*V):
  // function_ref use
  %4 = function_ref @use : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
  %5 = alloc_stack $U
  copy_addr %0 to [init] %5 : $*U
  %7 = apply %4<U>(%5) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
  dealloc_stack %5 : $*U
  // function_ref use
  %9 = function_ref @use : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
  %10 = alloc_stack $V
  copy_addr %1 to [init] %10 : $*V
  %12 = apply %9<V>(%10) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
  dealloc_stack %10 : $*V
  destroy_addr %1 : $*V
  destroy_addr %0 : $*U
  %16 = tuple ()
  return %16 : $()
} // end sil function 'simple_generic_callee'

// simple_generic_caller1<A>(_:)
sil @simple_generic_caller1 : $@convention(thin) <U> (@in U) -> () {
bb0(%0 : $*U):
  // function_ref simple_generic_callee<A, B>(_:_:)
  %2 = function_ref @simple_generic_callee : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0, @in τ_0_1) -> ()
  %3 = alloc_stack $U
  copy_addr %0 to [init] %3 : $*U
  %5 = integer_literal $Builtin.Int32, 1
  %6 = struct $Int32 (%5 : $Builtin.Int32)
  %7 = alloc_stack $Int32
  store %6 to %7 : $*Int32
  %9 = apply %2<U, Int32>(%3, %7) : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0, @in τ_0_1) -> ()
  dealloc_stack %7 : $*Int32
  dealloc_stack %3 : $*U
  destroy_addr %0 : $*U
  %13 = tuple ()
  return %13 : $()
} // end sil function 'simple_generic_caller1'

// simple_generic_caller2<A>(_:)
sil @simple_generic_caller2 : $@convention(thin) <U> (@in U) -> () {
bb0(%0 : $*U):
  // function_ref simple_generic_callee<A, B>(_:_:)
  %2 = function_ref @simple_generic_callee : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0, @in τ_0_1) -> ()
  // function_ref S.init(_:)
  %3 = function_ref @$s22partial_specialization1SVyACyxGxcfC : $@convention(method) <τ_0_0> (@in τ_0_0, @thin S<τ_0_0>.Type) -> S<τ_0_0>
  %4 = metatype $@thin S<U>.Type
  %5 = alloc_stack $U
  copy_addr %0 to [init] %5 : $*U
  %7 = apply %3<U>(%5, %4) : $@convention(method) <τ_0_0> (@in τ_0_0, @thin S<τ_0_0>.Type) -> S<τ_0_0>
  dealloc_stack %5 : $*U
  %9 = alloc_stack $S<U>
  store %7 to %9 : $*S<U>
  %11 = integer_literal $Builtin.Int32, 1
  %12 = struct $Int32 (%11 : $Builtin.Int32)
  %13 = alloc_stack $Int32
  store %12 to %13 : $*Int32
  %15 = apply %2<S<U>, Int32>(%9, %13) : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0, @in τ_0_1) -> ()
  dealloc_stack %13 : $*Int32
  dealloc_stack %9 : $*S<U>
  destroy_addr %0 : $*U
  %19 = tuple ()
  return %19 : $()
} // end sil function 'simple_generic_caller2'

// Check that a partial specialization for simple_generic_callee<U, Int32> was created.
// CHECK-LABEL: sil shared [noinline] @$s21simple_generic_calleexs5Int32Vq_RszACRs0_r1_lIetiy_Tp5 : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2 where τ_0_0 == τ_0_1, τ_0_2 == Int32> (@in τ_0_0, Int32) -> ()


// Check that a partial specialization for simple_generic_callee<S<U>, Int32> was created.
// CHECK-LABEL: sil shared [noinline] @$s21simple_generic_callee4main1SVyxGs5Int32VAERs_AGRs0_r1_lIetyy_Tp5 : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2 where τ_0_1 == S<τ_0_0>, τ_0_2 == Int32> (S<τ_0_0>, Int32) -> ()

// Check that no partial specializations are produced if all substitutions in the substitution list
// are archetypes.
// CHECK-LABEL: sil @simple_generic_caller3 : $@convention(thin) <U> (@in U) -> ()
// CHECK-NOT: specialized
// CHECK: function_ref @simple_generic_callee : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0, @in τ_0_1) -> ()
// CHECK-NOT: specialized
// CHECK: // end sil function 'simple_generic_caller3' 
// simple_generic_caller3<A>(_:)
sil @simple_generic_caller3 : $@convention(thin) <U> (@in U) -> () {
bb0(%0 : $*U):
  // function_ref simple_generic_callee<A, B>(_:_:)
  %2 = function_ref @simple_generic_callee : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0, @in τ_0_1) -> ()
  %3 = alloc_stack $U
  copy_addr %0 to [init] %3 : $*U
  %5 = apply %2<U, U>(%3, %0) : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0, @in τ_0_1) -> ()
  dealloc_stack %3 : $*U
  %7 = tuple ()
  return %7 : $()
} // end sil function 'simple_generic_caller3'

// Check that partial specialization is not performed for generic type parameters where
// the substitution contains an open existential.
// CHECK-LABEL: sil @simple_generic_caller4 : $@convention(thin) (@in any P, Builtin.Int1) -> ()
// CHECK: function_ref @$s21simple_generic_calleexBi1_Bi1_Rs_r0_lIetiy_Tp5 : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_1 == Builtin.Int1> (@in τ_0_0, Builtin.Int1) -> ()
// CHECK: // end sil function 'simple_generic_caller4' 
sil @simple_generic_caller4 : $@convention(thin) (@in P, Builtin.Int1) -> () {
bb0(%0 : $*P, %1: $Builtin.Int1):
  cond_br %1, bb1, bb2
bb1:
  %2 = open_existential_addr mutable_access %0 : $*P to $*@opened("1B6851A6-4796-11E6-B7DF-B8E856428C60", P) Self
  %3 = alloc_stack $@opened("1B6851A6-4796-11E6-B7DF-B8E856428C60", P) Self
	copy_addr [take] %2 to [init] %3 : $*@opened("1B6851A6-4796-11E6-B7DF-B8E856428C60", P) Self
  %5 = alloc_stack $Builtin.Int1
  store %1 to %5 : $*Builtin.Int1
  // function_ref simple_generic_callee<A, B>(_:_:)
  %7 = function_ref @simple_generic_callee : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0, @in τ_0_1) -> ()
  %8 = apply %7<@opened("1B6851A6-4796-11E6-B7DF-B8E856428C60", P) Self, Builtin.Int1>(%3, %5) : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0, @in τ_0_1) -> ()
  dealloc_stack %5 : $*Builtin.Int1
  destroy_addr %3 : $*@opened("1B6851A6-4796-11E6-B7DF-B8E856428C60", P) Self
  dealloc_stack %3 : $*@opened("1B6851A6-4796-11E6-B7DF-B8E856428C60", P) Self
  br bb3
bb2:
  destroy_addr %0 : $*P
  br bb3
bb3:
  %13 = tuple ()
  return %13 : $()
} // end sil function 'simple_generic_caller4'