|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule |
| 3 | +// RUN: %target-codesign %t/%target-library-name(PrintShims) |
| 4 | +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL |
| 5 | +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) |
| 6 | +// RUN: %target-codesign %t/main |
| 7 | +// RUN: %target-run %t/main | %FileCheck %s |
| 8 | + |
| 9 | +// REQUIRES: executable_test |
| 10 | +// REQUIRES: swift_test_mode_optimize_none |
| 11 | +// UNSUPPORTED: use_os_stdlib |
| 12 | + |
| 13 | +import Builtin |
| 14 | +import Swift |
| 15 | +import PrintShims |
| 16 | + |
| 17 | +sil public_external @printGeneric : $@convention(thin) <T> (@in_guaranteed T) -> () |
| 18 | +sil public_external @printInt64 : $@convention(thin) (Int64) -> () |
| 19 | + |
| 20 | +protocol P { |
| 21 | + func printMe() -> Int64 |
| 22 | +} |
| 23 | + |
| 24 | +extension P { |
| 25 | + func callPrintMe() async -> Int64 |
| 26 | +} |
| 27 | + |
| 28 | +struct I : P { |
| 29 | + @_hasStorage let int: Int64 { get } |
| 30 | + func printMe() -> Int64 |
| 31 | + init(int: Int64) |
| 32 | +} |
| 33 | + |
| 34 | +// CHECK-LL: define hidden swiftcc void @callPrintMe(%swift.context* {{%[0-9]*}}) {{#[0-9]*}} { |
| 35 | +sil hidden @callPrintMe : $@async @convention(method) <Self where Self : P> (@in_guaranteed Self) -> Int64 { |
| 36 | +bb0(%self : $*Self): |
| 37 | + %P_printMe = witness_method $Self, #P.printMe : <Self where Self : P> (Self) -> () -> Int64 : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 |
| 38 | + %result = apply %P_printMe<Self>(%self) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 |
| 39 | + return %result : $Int64 |
| 40 | +} |
| 41 | + |
| 42 | +sil hidden @I_printMe : $@convention(method) (I) -> Int64 { |
| 43 | +bb0(%self : $I): |
| 44 | + %self_addr = alloc_stack $I |
| 45 | + store %self to %self_addr : $*I |
| 46 | + %printGeneric = function_ref @printGeneric : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () |
| 47 | + %printGeneric_result = apply %printGeneric<I>(%self_addr) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () |
| 48 | + dealloc_stack %self_addr : $*I |
| 49 | + %result = struct_extract %self : $I, #I.int |
| 50 | + return %result : $Int64 |
| 51 | +} |
| 52 | + |
| 53 | +sil private [transparent] [thunk] @I_P_printMe : $@convention(witness_method: P) (@in_guaranteed I) -> Int64 { |
| 54 | +bb0(%self_addr : $*I): |
| 55 | + %self = load %self_addr : $*I |
| 56 | + %I_printMe = function_ref @I_printMe : $@convention(method) (I) -> Int64 |
| 57 | + %result = apply %I_printMe(%self) : $@convention(method) (I) -> Int64 |
| 58 | + return %result : $Int64 |
| 59 | +} |
| 60 | + |
| 61 | +sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { |
| 62 | +bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): |
| 63 | + %i_type = metatype $@thin I.Type |
| 64 | + %i_int_literal = integer_literal $Builtin.Int64, 99 |
| 65 | + %i_int = struct $Int64 (%i_int_literal : $Builtin.Int64) |
| 66 | + %i = struct $I (%i_int : $Int64) |
| 67 | + %i_addr = alloc_stack $I |
| 68 | + store %i to %i_addr : $*I |
| 69 | + %callPrintMe = function_ref @callPrintMe : $@async @convention(method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 |
| 70 | + %result = apply %callPrintMe<I>(%i_addr) : $@async @convention(method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 // CHECK: I(int: 99) |
| 71 | + dealloc_stack %i_addr : $*I |
| 72 | + %printInt64 = function_ref @printInt64 : $@convention(thin) (Int64) -> () |
| 73 | + %printInt64_result = apply %printInt64(%result) : $@convention(thin) (Int64) -> () // CHECK: 99 |
| 74 | + |
| 75 | + %out_literal = integer_literal $Builtin.Int32, 0 |
| 76 | + %out = struct $Int32 (%out_literal : $Builtin.Int32) |
| 77 | + return %out : $Int32 |
| 78 | +} |
| 79 | + |
| 80 | +sil_witness_table hidden I: P module main { |
| 81 | + method #P.printMe: <Self where Self : P> (Self) -> () -> Int64 : @I_P_printMe |
| 82 | +} |
0 commit comments