Skip to content

Commit 08f5aae

Browse files
committed
[IRGen] Restored single refcounted object opt for async partial applies.
As part of bringup, specifically in order to support storing the size of the async context as the first entry in the thick context, the optimization that allows the partial application of a single refcounted object to avoid the allocation of a thick context was disabled. Now that we have async function pointers for partial application forwarders, that rationale is moot, so, here, the optimization is restored. rdar://76372871
1 parent 6c11713 commit 08f5aae

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,8 @@ static llvm::Value *emitPartialApplicationForwarder(IRGenModule &IGM,
15061506
auto argIndex = emission->getCurrentArgumentIndex();
15071507
if (haveContextArgument)
15081508
argIndex += polyArgs.size();
1509+
if (origType->isAsync())
1510+
argIndex += 1;
15091511

15101512
llvm::Type *expectedArgTy = origSig.getType()->getParamType(argIndex);
15111513

@@ -1853,13 +1855,6 @@ Optional<StackAddress> irgen::emitFunctionPartialApplication(
18531855
auto bindings = NecessaryBindings::forPartialApplyForwarder(
18541856
IGF.IGM, origType, subs, considerParameterSources);
18551857

1856-
// TODO: Revisit. Now that async thick functions are always represented with
1857-
// an async function pointer, it should again be possible to allow
1858-
// contexts that consist of only a single swift refcounted value.
1859-
if (origType->isAsync()) {
1860-
hasSingleSwiftRefcountedContext = No;
1861-
}
1862-
18631858
if (!bindings.empty()) {
18641859
hasSingleSwiftRefcountedContext = No;
18651860
auto bindingsSize = bindings.getBufferSize(IGF.IGM);
@@ -2020,13 +2015,8 @@ Optional<StackAddress> irgen::emitFunctionPartialApplication(
20202015
emitPartialApplicationForwarder(IGF.IGM, staticFn, fnContext != nullptr,
20212016
origSig, origType, substType,
20222017
outType, subs, nullptr, argConventions);
2023-
if (origType->isAsync()) {
2024-
llvm_unreachable(
2025-
"async functions never have a single refcounted context");
2026-
} else {
2027-
forwarder = emitPointerAuthSign(IGF, forwarder, outAuthInfo);
2028-
forwarder = IGF.Builder.CreateBitCast(forwarder, IGF.IGM.Int8PtrTy);
2029-
}
2018+
forwarder = emitPointerAuthSign(IGF, forwarder, outAuthInfo);
2019+
forwarder = IGF.Builder.CreateBitCast(forwarder, IGF.IGM.Int8PtrTy);
20302020
out.add(forwarder);
20312021

20322022
llvm::Value *ctx = args.claimNext();

lib/IRGen/IRGenSIL.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,9 +3215,6 @@ static bool isSimplePartialApply(IRGenFunction &IGF, PartialApplyInst *i) {
32153215
// The callee type must use the `method` convention.
32163216
auto calleeTy = i->getCallee()->getType().castTo<SILFunctionType>();
32173217
auto resultTy = i->getFunctionType();
3218-
3219-
if (calleeTy->isAsync())
3220-
return false;
32213218

32223219
if (calleeTy->getRepresentation() != SILFunctionTypeRepresentation::Method)
32233220
return false;

test/IRGen/async/partial_apply.sil

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,3 +617,13 @@ bb0(%0 : $Int):
617617
%3 = partial_apply [callee_guaranteed] %2(%0) : $@convention(thin) @async (Int, Int) -> (Int, @error Error)
618618
return %3 : $@async @callee_guaranteed (Int) -> (Int, @error Error)
619619
}
620+
621+
sil @method_with_out_return : $@convention(method) @async (SwiftClass) -> @out Int
622+
623+
sil @partially_apply_method_with_out_return : $@convention(thin) (SwiftClass) -> @async @callee_guaranteed () -> @out Int {
624+
bb(%class : $SwiftClass):
625+
%method_with_out_param = function_ref @method_with_out_return : $@convention(method) @async (SwiftClass) -> @out Int
626+
%result = partial_apply [callee_guaranteed] %method_with_out_param(%class) : $@convention(method) @async (SwiftClass) -> @out Int
627+
return %result : $@callee_guaranteed @async () -> @out Int
628+
}
629+

test/IRGen/async/partial_apply_forwarder.sil

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ bb0(%0 : $*S):
2929
return %2 : $@async @callee_guaranteed (@in O) -> ()
3030
}
3131

32-
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s23unspecialized_uncurriedTA"(
3332
sil hidden @specialized_curried : $@async @convention(thin) (@owned E) -> @owned @async @callee_guaranteed () -> @owned D<C> {
3433
bb0(%0 : $E):
3534
%1 = function_ref @unspecialized_uncurried : $@async @convention(method) <τ_0_0 where τ_0_0 : P> (@guaranteed E) -> @owned D<τ_0_0>

0 commit comments

Comments
 (0)