|
| 1 | +// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types -module-name test -Xllvm -sil-full-demangle -swift-version 6 %s | %FileCheck %s |
| 2 | + |
| 3 | +// We weren't adjusting offsets around isolated default arguments |
| 4 | +// properly, and it broke when presented with a non-isolated or |
| 5 | +// non-defaulted argument between two isolated default arguments. |
| 6 | + |
| 7 | +@MainActor |
| 8 | +func main_actor_int_x() -> Int { |
| 9 | + return 0 |
| 10 | +} |
| 11 | + |
| 12 | +@MainActor |
| 13 | +func main_actor_int_y() -> Int { |
| 14 | + return 0 |
| 15 | +} |
| 16 | + |
| 17 | +@MainActor |
| 18 | +func main_actor_int_z() -> Int { |
| 19 | + return 0 |
| 20 | +} |
| 21 | + |
| 22 | +@MainActor |
| 23 | +func main_actor_void() -> () { |
| 24 | +} |
| 25 | + |
| 26 | +@MainActor |
| 27 | +func main_actor_int_pair() -> (Int, Int) { |
| 28 | + return (0,0) |
| 29 | +} |
| 30 | + |
| 31 | +// This test breaks because the intermediate argument is `nil`, which |
| 32 | +// we treat as non-isolated. |
| 33 | +@MainActor |
| 34 | +func nonIsolatedDefaultArg(x: Int = main_actor_int_x(), |
| 35 | + y: Int? = nil, |
| 36 | + z: Int = main_actor_int_z()) {} |
| 37 | + |
| 38 | +// CHECK-LABEL: sil hidden [ossa] @$s4test0A21NonIsolatedDefaultArgyyYaF : |
| 39 | +// CHECK: [[ARG1:%.*]] = enum $Optional<Int>, #Optional.none |
| 40 | +// CHECK: hop_to_executor {{%.*}} : $MainActor |
| 41 | +// CHECK-NEXT: // function_ref default argument 0 of |
| 42 | +// CHECK-NEXT: [[ARG0FN:%.*]] = function_ref @$s4test21nonIsolatedDefaultArg1x1y1zySi_SiSgSitFfA_ |
| 43 | +// CHECK-NEXT: [[ARG0:%.*]] = apply [[ARG0FN]]() |
| 44 | +// CHECK-NEXT: // function_ref default argument 2 of |
| 45 | +// CHECK-NEXT: [[ARG2FN:%.*]] = function_ref @$s4test21nonIsolatedDefaultArg1x1y1zySi_SiSgSitFfA1_ |
| 46 | +// CHECK-NEXT: [[ARG2:%.*]] = apply [[ARG2FN]]() |
| 47 | +// CHECK-NEXT: // function_ref test.nonIsolatedDefaultArg |
| 48 | +// CHECK-NEXT: [[FN:%.*]] = function_ref @$s4test21nonIsolatedDefaultArg1x1y1zySi_SiSgSitF : |
| 49 | +// CHECK: apply [[FN]]([[ARG0]], [[ARG1]], [[ARG2]]) |
| 50 | +func testNonIsolatedDefaultArg() async { |
| 51 | + await nonIsolatedDefaultArg() |
| 52 | +} |
| 53 | + |
| 54 | +// This test breaks because the intermediate argument is non-defaulted |
| 55 | +// and so gets evaluated in the non-delayed argument pass. |
| 56 | +@MainActor |
| 57 | +func isolatedDefaultArgs(x: Int = main_actor_int_x(), |
| 58 | + y: Int = main_actor_int_y(), |
| 59 | + z: Int = main_actor_int_z()) {} |
| 60 | + |
| 61 | +// CHECK-LABEL: sil hidden [ossa] @$s4test0A13NonDefaultArgyyYaF : |
| 62 | +// CHECK: [[LITERAL_FN:%.*]] = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : |
| 63 | +// CHECK-NEXT: [[ARG1:%.*]] = apply [[LITERAL_FN]]( |
| 64 | +// CHECK: hop_to_executor {{%.*}} : $MainActor |
| 65 | +// CHECK-NEXT: // function_ref default argument 0 of |
| 66 | +// CHECK-NEXT: [[ARG0FN:%.*]] = function_ref @$s4test19isolatedDefaultArgs1x1y1zySi_S2itFfA_ |
| 67 | +// CHECK-NEXT: [[ARG0:%.*]] = apply [[ARG0FN]]() |
| 68 | +// CHECK-NEXT: // function_ref default argument 2 of |
| 69 | +// CHECK-NEXT: [[ARG2FN:%.*]] = function_ref @$s4test19isolatedDefaultArgs1x1y1zySi_S2itFfA1_ |
| 70 | +// CHECK-NEXT: [[ARG2:%.*]] = apply [[ARG2FN]]() |
| 71 | +// CHECK-NEXT: // function_ref test.isolatedDefaultArgs |
| 72 | +// CHECK-NEXT: [[FN:%.*]] = function_ref @$s4test19isolatedDefaultArgs1x1y1zySi_S2itF : |
| 73 | +// CHECK: apply [[FN]]([[ARG0]], [[ARG1]], [[ARG2]]) |
| 74 | +func testNonDefaultArg() async { |
| 75 | + await isolatedDefaultArgs(y: 0) |
| 76 | +} |
| 77 | + |
| 78 | +// Exercise our handling of isolated default arguments that expand to |
| 79 | +// empty or multiple arguments. |
| 80 | +@MainActor |
| 81 | +func voidIsolatedDefaultArg(x: () = main_actor_void(), |
| 82 | + y: Int = main_actor_int_y(), |
| 83 | + z: Int = main_actor_int_z()) {} |
| 84 | + |
| 85 | +// CHECK-LABEL: sil hidden [ossa] @$s4test0A22VoidIsolatedDefaultArgyyYaF : |
| 86 | +// CHECK: [[LITERAL_FN:%.*]] = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : |
| 87 | +// CHECK-NEXT: [[ARG1:%.*]] = apply [[LITERAL_FN]]( |
| 88 | +// CHECK: hop_to_executor {{%.*}} : $MainActor |
| 89 | +// CHECK-NEXT: // function_ref default argument 0 of |
| 90 | +// CHECK-NEXT: [[ARG0FN:%.*]] = function_ref @$s4test22voidIsolatedDefaultArg1x1y1zyyt_S2itFfA_ |
| 91 | +// CHECK-NEXT: [[ARG0:%.*]] = apply [[ARG0FN]]() |
| 92 | +// CHECK-NEXT: // function_ref default argument 2 of |
| 93 | +// CHECK-NEXT: [[ARG2FN:%.*]] = function_ref @$s4test22voidIsolatedDefaultArg1x1y1zyyt_S2itFfA1_ |
| 94 | +// CHECK-NEXT: [[ARG2:%.*]] = apply [[ARG2FN]]() |
| 95 | +// CHECK-NEXT: // function_ref test.voidIsolatedDefaultArg |
| 96 | +// CHECK-NEXT: [[FN:%.*]] = function_ref @$s4test22voidIsolatedDefaultArg1x1y1zyyt_S2itF : |
| 97 | +// CHECK: apply [[FN]]([[ARG1]], [[ARG2]]) |
| 98 | +func testVoidIsolatedDefaultArg() async { |
| 99 | + await voidIsolatedDefaultArg(y: 0) |
| 100 | +} |
| 101 | + |
| 102 | +@MainActor |
| 103 | +func tupleIsolatedDefaultArg(x: (Int,Int) = main_actor_int_pair(), |
| 104 | + y: Int = main_actor_int_y(), |
| 105 | + z: Int = main_actor_int_z()) {} |
| 106 | + |
| 107 | +// CHECK-LABEL: sil hidden [ossa] @$s4test0A23TupleIsolatedDefaultArgyyYaF : |
| 108 | +// CHECK: [[LITERAL_FN:%.*]] = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : |
| 109 | +// CHECK-NEXT: [[ARG1:%.*]] = apply [[LITERAL_FN]]( |
| 110 | +// CHECK: hop_to_executor {{%.*}} : $MainActor |
| 111 | +// CHECK-NEXT: // function_ref default argument 0 of |
| 112 | +// CHECK-NEXT: [[ARG0FN:%.*]] = function_ref @$s4test23tupleIsolatedDefaultArg1x1y1zySi_Sit_S2itFfA_ |
| 113 | +// CHECK-NEXT: [[ARG0:%.*]] = apply [[ARG0FN]]() |
| 114 | +// CHECK-NEXT: ([[ARG0_0:%.*]], [[ARG0_1:%.*]]) = destructure_tuple [[ARG0]] : $(Int, Int) |
| 115 | +// CHECK-NEXT: // function_ref default argument 2 of |
| 116 | +// CHECK-NEXT: [[ARG2FN:%.*]] = function_ref @$s4test23tupleIsolatedDefaultArg1x1y1zySi_Sit_S2itFfA1_ |
| 117 | +// CHECK-NEXT: [[ARG2:%.*]] = apply [[ARG2FN]]() |
| 118 | +// CHECK-NEXT: // function_ref test.tupleIsolatedDefaultArg |
| 119 | +// CHECK-NEXT: [[FN:%.*]] = function_ref @$s4test23tupleIsolatedDefaultArg1x1y1zySi_Sit_S2itF : |
| 120 | +// CHECK: apply [[FN]]([[ARG0_0]], [[ARG0_1]], [[ARG1]], [[ARG2]]) |
| 121 | +func testTupleIsolatedDefaultArg() async { |
| 122 | + await tupleIsolatedDefaultArg(y: 0) |
| 123 | +} |
0 commit comments