Skip to content

Commit f4fc022

Browse files
Merge pull request swiftlang#36810 from nate-chandler/concurrency/irgen/rdar76372871
[IRGen] Restored single refcounted object opt for async partial applies.
2 parents 4c81f06 + 13bef6b commit f4fc022

File tree

5 files changed

+14
-280
lines changed

5 files changed

+14
-280
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,8 @@ static llvm::Value *emitPartialApplicationForwarder(IRGenModule &IGM,
15111511
auto argIndex = emission->getCurrentArgumentIndex();
15121512
if (haveContextArgument)
15131513
argIndex += polyArgs.size();
1514+
if (origType->isAsync())
1515+
argIndex += 1;
15141516

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

@@ -1858,13 +1860,6 @@ Optional<StackAddress> irgen::emitFunctionPartialApplication(
18581860
auto bindings = NecessaryBindings::forPartialApplyForwarder(
18591861
IGF.IGM, origType, subs, considerParameterSources);
18601862

1861-
// TODO: Revisit. Now that async thick functions are always represented with
1862-
// an async function pointer, it should again be possible to allow
1863-
// contexts that consist of only a single swift refcounted value.
1864-
if (origType->isAsync()) {
1865-
hasSingleSwiftRefcountedContext = No;
1866-
}
1867-
18681863
if (!bindings.empty()) {
18691864
hasSingleSwiftRefcountedContext = No;
18701865
auto bindingsSize = bindings.getBufferSize(IGF.IGM);
@@ -2025,13 +2020,8 @@ Optional<StackAddress> irgen::emitFunctionPartialApplication(
20252020
emitPartialApplicationForwarder(IGF.IGM, staticFn, fnContext != nullptr,
20262021
origSig, origType, substType,
20272022
outType, subs, nullptr, argConventions);
2028-
if (origType->isAsync()) {
2029-
llvm_unreachable(
2030-
"async functions never have a single refcounted context");
2031-
} else {
2032-
forwarder = emitPointerAuthSign(IGF, forwarder, outAuthInfo);
2033-
forwarder = IGF.Builder.CreateBitCast(forwarder, IGF.IGM.Int8PtrTy);
2034-
}
2023+
forwarder = emitPointerAuthSign(IGF, forwarder, outAuthInfo);
2024+
forwarder = IGF.Builder.CreateBitCast(forwarder, IGF.IGM.Int8PtrTy);
20352025
out.add(forwarder);
20362026

20372027
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>

test/IRGen/async/run-partialapply-capture-classinstance_generic-and-int-to-string.sil

Lines changed: 0 additions & 262 deletions
This file was deleted.

0 commit comments

Comments
 (0)