Skip to content

Commit 7a4bc72

Browse files
committed
[SILGen]: fix a bug in isolated default argument handling
Changes in #81370 addressed a number of issues with isolated default argument handling. However, there seemed to still be a problem when dealing with isolated default arguments of instance/static methods under the following conditions: - The method contained an isolated default parameter - The method contained a defaulted parameter that expanded to 0 or >1 values - Said parameter was followed by another defaulted parameter The attempted fix here was to adjust the isolated default argument iteration bookkeeping.
1 parent d532448 commit 7a4bc72

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,6 +3202,7 @@ static void emitDelayedArguments(SILGenFunction &SGF,
32023202
// Otherwise, reset the current index adjustment.
32033203
} else {
32043204
indexAdjustment = 0;
3205+
indexAdjustmentSite = site;
32053206
}
32063207

32073208
assert(!siteArgs[argIndex] &&

test/SILGen/isolated_default_arguments.swift

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,66 @@ func useCallerIsolatedDefaultArg() async {
161161
// CHECK: // function_ref default argument 0 of
162162
// CHECK-NEXT: [[GEN:%.*]] = function_ref @$s4test24callerIsolatedDefaultArg1xySi_tYaFfA_ :
163163
// CHECK-NEXT: [[ARG:%.*]] = apply [[GEN]]()
164+
165+
// The following tests failed due to a book-keeping error when processing delayed
166+
// isolated arguments in methods with:
167+
//
168+
// - a `self` parameter
169+
// - delayed arguments that expanded to zero or greater than one value
170+
// - a subsequent delayed argument
171+
//
172+
// https://github.com/swiftlang/swift/issues/84647
173+
174+
@MainActor
175+
enum E {
176+
static func tupleIsolatedDefaultArgStatic(
177+
_: Int,
178+
x: Int = main_actor_int_x(),
179+
// need not be isolated defaults
180+
tup: (Int, Int) = (1, 2),
181+
i: Int = 0
182+
) {}
183+
184+
static func voidIsolatedDefaultArgStatic(
185+
_: Int,
186+
v: Void = main_actor_void(),
187+
// need not be isolated defaults
188+
tup: (Int, Int) = (1, 2),
189+
i: Int = 0
190+
) {}
191+
}
192+
193+
func testTupleIsolatedDefaultArgStatic() async {
194+
await E.tupleIsolatedDefaultArgStatic(0)
195+
}
196+
197+
func testVoidIsolatedDefaultArgStatic() async {
198+
await E.voidIsolatedDefaultArgStatic(0)
199+
}
200+
201+
@MainActor
202+
final class Klazz {
203+
func tupleIsolatedDefaultArgInstanceMethod(
204+
_: Int,
205+
x: Int = main_actor_int_x(),
206+
// need not be isolated defaults
207+
tup: (Int, Int) = (1, 2),
208+
i: Int = 0
209+
) {}
210+
211+
func voidIsolatedDefaultArgInstanceMethod(
212+
_: Int,
213+
v: Void = main_actor_void(),
214+
// need not be isolated defaults
215+
tup: (Int, Int) = (1, 2),
216+
i: Int = 0
217+
) {}
218+
}
219+
220+
func testTupleIsolatedDefaultArgInstanceMethod(_ klazz: Klazz) async {
221+
await klazz.tupleIsolatedDefaultArgInstanceMethod(0)
222+
}
223+
224+
func testVoidIsolatedDefaultArgInstanceMethod(_ klazz: Klazz) async {
225+
await klazz.voidIsolatedDefaultArgInstanceMethod(0)
226+
}

0 commit comments

Comments
 (0)