| // 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 [initialization] %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 [initialization] %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 [initialization] %2 : $*I // id: %3 |
| %4 = witness_method $I, #FooProto.value!getter.1 : $@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 |
| 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 |
| } |