Skip to content

Commit 5fd4f1b

Browse files
asavonicasl
authored andcommitted
Do not emit a context placeholder for @error results
A placeholder goes instead of the context in case of error results, so that thin functions have the same number of arguments as thick ones. Coroutine lowering adds it as part of getCallEmission (via setFromCallee), so we don't need to do it in emitPartialApplicationForwarder.
1 parent 13beae7 commit 5fd4f1b

File tree

2 files changed

+58
-9
lines changed

2 files changed

+58
-9
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,7 @@ static llvm::Value *emitPartialApplicationForwarder(
22002200
}
22012201

22022202
// Pass a placeholder for thin function calls.
2203-
} else if (origType->hasErrorResult() && !origType->isAsync()) {
2203+
} else if (origType->hasErrorResult() && !origType->isAsync() && !origType->isCoroutine()) {
22042204
emission->addArgument(llvm::UndefValue::get(IGM.RefCountedPtrTy));
22052205
}
22062206

test/IRGen/partial_apply_coro.sil

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,14 +2223,44 @@ bb0(%thick : $@callee_guaranteed @yield_once @convention(thick) (Int64, Int32) -
22232223
return %pa_f : $@yield_once @callee_guaranteed (Int64) -> Int64
22242224
}
22252225

2226-
// FIXME: Assertion `LastArgWritten >= adjusted.size()' failed.
2227-
// sil @external_closure : $@convention(thin) @yield_once (Int, Int) -> (Int, @error Error)
2228-
// sil @dont_crash : $@convention(thin) (Int) -> @owned @yield_once @callee_guaranteed (Int) -> (Int, @error Error) {
2229-
// bb0(%0 : $Int):
2230-
// %2 = function_ref @external_closure : $@convention(thin) @yield_once (Int, Int) -> (Int, @error Error)
2231-
// %3 = partial_apply [callee_guaranteed] %2(%0) : $@convention(thin) @yield_once (Int, Int) -> (Int, @error Error)
2232-
// return %3 : $@yield_once @callee_guaranteed (Int) -> (Int, @error Error)
2233-
// }
2226+
// CHECK: define {{.*}} { ptr, ptr } @dont_crash
2227+
// CHECK-SAME: (i64 %[[ARG:.*]])
2228+
// CHECK: entry:
2229+
// CHECK: %[[BOX:.*]] = call noalias ptr @swift_allocObject(ptr getelementptr inbounds (%swift.full_boxmetadata
2230+
// CHECK: %[[BOXPTR:.*]] = getelementptr inbounds <{ %swift.refcounted, %TSi }>, ptr %1, i32 0, i32 1
2231+
// CHECK: %[[ARGPTR:.*]] = getelementptr inbounds %TSi, ptr %2, i32 0, i32 0
2232+
// CHECK: store i64 %[[ARG]], ptr %[[ARGPTR]]
2233+
// CHECK: %[[RET:.*]] = insertvalue { ptr, ptr } { ptr @"$s16external_closureTA", ptr undef }, ptr %[[BOX]], 1
2234+
// CHECK: ret { ptr, ptr } %[[RET]]
2235+
// CHECK: }
2236+
//
2237+
// CHECK: define {{.*}} ptr @"$s16external_closureTA"
2238+
// CHECK-SAME: (ptr noalias {{.*}} %[[CTX:.*]], i64 %[[ARG1:.*]], ptr swiftself %[[PA_CTX_BOX:.*]], ptr noalias nocapture swifterror {{.*}} %[[ERROR:.*]])
2239+
// CHECK: entry:
2240+
// CHECK: %[[SPILL:.*]] = call ptr @malloc(i64 40)
2241+
// CHECK: store ptr %[[SPILL]], ptr %[[CTX]]
2242+
// CHECK: %[[FRAME:.*]] = getelementptr inbounds %"$s16external_closureTA.Frame", ptr %[[SPILL]], i32 0, i32 0
2243+
// CHECK: %[[PA_CTX:.*]] = getelementptr inbounds <{ %swift.refcounted, %TSi }>, ptr %[[PA_CTX_BOX]], i32 0, i32 1
2244+
// CHECK: %[[PA_ARG:.*]] = getelementptr inbounds %TSi, ptr %[[PA_CTX]], i32 0, i32 0
2245+
// CHECK: %[[ARG2:.*]] = load i64, ptr %[[PA_ARG]]
2246+
// CHECK: %[[FRAMEPTR:.*]] = getelementptr inbounds [32 x i8], ptr %[[FRAME]], i32 0, i32 0
2247+
// CHECK: call void @llvm.lifetime.start.p0(i64 32, ptr %[[FRAMEPTR]])
2248+
// CHECK: store ptr null, ptr %[[ERROR]]
2249+
// CHECK: %[[YIELD_PAIR:.*]] = call swiftcc ptr @external_closure(ptr noalias {{.*}} %[[FRAMEPTR]], i64 %[[ARG1]], i64 %[[ARG2]], ptr swiftself undef, ptr noalias nocapture swifterror {{.*}} %[[ERROR]])
2250+
// CHECK: %[[SPILL1:.*]] = getelementptr inbounds %"$s16external_closureTA.Frame", ptr %[[SPILL]], i32 0, i32 1
2251+
// CHECK: store ptr %[[YIELD_PAIR]], ptr %[[SPILL1]]
2252+
// CHECK: %[[ERRORVAL:.*]] = load ptr, ptr %[[ERROR]]
2253+
// CHECK: store ptr %[[ERRORVAL]], ptr %[[ERROR]]
2254+
// CHECK: ret ptr @"$s16external_closureTA.resume.0"
2255+
// CHECK: }
2256+
//
2257+
sil @external_closure : $@convention(thin) @yield_once (Int, Int) -> (Int, @error Error)
2258+
sil @dont_crash : $@convention(thin) (Int) -> @owned @yield_once @callee_guaranteed (Int) -> (Int, @error Error) {
2259+
bb0(%0 : $Int):
2260+
%2 = function_ref @external_closure : $@convention(thin) @yield_once (Int, Int) -> (Int, @error Error)
2261+
%3 = partial_apply [callee_guaranteed] %2(%0) : $@convention(thin) @yield_once (Int, Int) -> (Int, @error Error)
2262+
return %3 : $@yield_once @callee_guaranteed (Int) -> (Int, @error Error)
2263+
}
22342264

22352265
// CHECK: define {{.*}} { ptr, ptr } @partially_apply_method_with_out_return
22362266
// CHECK-SAME: (ptr %[[ARG:.*]])
@@ -2246,3 +2276,22 @@ bb(%class : $SwiftClass):
22462276
%result = partial_apply [callee_guaranteed] %method_with_out_param(%class) : $@convention(method) @yield_once (SwiftClass) -> @out Int
22472277
return %result : $@callee_guaranteed @yield_once () -> @out Int
22482278
}
2279+
2280+
// CHECK: define {{.*}} { ptr, ptr } @convert_thin_test(i64 %[[ARG:.*]])
2281+
// CHECK: entry:
2282+
// CHECK: %[[PA_CTX_BOX:.*]] = call noalias ptr @swift_allocObject(ptr getelementptr inbounds (%swift.full_boxmetadata
2283+
// CHECK: %[[PA_ARG:.*]] = getelementptr inbounds <{ %swift.refcounted, %TSi }>, ptr %[[PA_CTX_BOX]], i32 0, i32 1
2284+
// CHECK: %[[ARG_PTR:.*]] = getelementptr inbounds %TSi, ptr %[[PA_ARG]], i32 0, i32 0
2285+
// CHECK: store i64 %[[ARG]], ptr %[[ARG_PTR]]
2286+
// CHECK: %[[RET:.*]] = insertvalue { ptr, ptr } { ptr @"$s4afunTA", ptr undef }, ptr %[[PA_CTX_BOX]], 1
2287+
// CHECK: ret { ptr, ptr } %[[RET]]
2288+
// CHECK: }
2289+
2290+
sil @afun : $@yield_once @convention(thin) (Int) -> (@error Error, @yields Int)
2291+
sil @convert_thin_test : $@convention(thin) (Int) -> @yield_once @callee_guaranteed () -> (@error Error, @yields Int) {
2292+
bb(%0 : $Int):
2293+
%f = function_ref @afun : $@yield_once @convention(thin) (Int) -> (@error Error, @yields Int)
2294+
%c = convert_function %f : $@yield_once @convention(thin) (Int) -> (@error Error, @yields Int) to $@yield_once @convention(thin) @noescape (Int) -> (@error Error, @yields Int)
2295+
%pa = partial_apply [callee_guaranteed] %c(%0) : $@yield_once @convention(thin) @noescape (Int) -> (@error Error, @yields Int)
2296+
return %pa : $@yield_once @callee_guaranteed () -> (@error Error, @yields Int)
2297+
}

0 commit comments

Comments
 (0)