Skip to content

Commit b0237c6

Browse files
committed
Drop task options from the createAsyncTask SIL builtin.
We'll keep the task options entirely as a contract between IRGen and the concurrency runtime, so Swift code need not deal with them.
1 parent 88fa5ed commit b0237c6

File tree

10 files changed

+31
-33
lines changed

10 files changed

+31
-33
lines changed

include/swift/AST/Builtins.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,6 @@ BUILTIN_MISC_OPERATION_WITH_SILGEN(EndAsyncLet, "endAsyncLet", "", Special)
796796

797797
/// createAsyncTask(): (
798798
/// Int, // task-creation flags
799-
/// Builtin.RawPointer?, // options (TaskOptionRecord*)
800799
/// @escaping () async throws -> T // function
801800
/// ) -> Builtin.NativeObject
802801
///

lib/AST/Builtins.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,11 +1428,9 @@ static ValueDecl *getCreateAsyncTask(ASTContext &ctx, Identifier id) {
14281428
BuiltinFunctionBuilder builder(ctx);
14291429
auto genericParam = makeGenericParam().build(builder);
14301430
builder.addParameter(makeConcrete(ctx.getIntType())); // 0 flags
1431-
builder.addParameter(
1432-
makeConcrete(OptionalType::get(ctx.TheRawPointerType))); // 1 options
14331431
auto extInfo = ASTExtInfoBuilder().withAsync().withThrows().build();
14341432
builder.addParameter(
1435-
makeConcrete(FunctionType::get({ }, genericParam, extInfo))); // 2 operation
1433+
makeConcrete(FunctionType::get({ }, genericParam, extInfo))); // 1 operation
14361434
builder.setResult(makeConcrete(getAsyncTaskAndContextType(ctx)));
14371435
return builder.build(id);
14381436
}

lib/IRGen/GenBuiltin.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,6 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
278278
(Builtin.ID == BuiltinValueKind::CreateAsyncTaskInGroup)
279279
? args.claimNext()
280280
: nullptr;
281-
llvm::Value *taskOptions =
282-
(Builtin.ID == BuiltinValueKind::CreateAsyncTask)
283-
? args.claimNext()
284-
: llvm::ConstantInt::get(IGF.IGM.SwiftTaskOptionRecordPtrTy, 0);
285281
auto futureResultType = args.claimNext();
286282
auto taskFunction = args.claimNext();
287283
auto taskContext = args.claimNext();
@@ -290,7 +286,6 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
290286
IGF,
291287
flags,
292288
taskGroup,
293-
taskOptions,
294289
futureResultType,
295290
taskFunction, taskContext,
296291
substitutions);

lib/IRGen/GenCall.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3860,16 +3860,14 @@ llvm::Value *irgen::emitTaskCreate(
38603860
IRGenFunction &IGF,
38613861
llvm::Value *flags,
38623862
llvm::Value *taskGroup,
3863-
llvm::Value *taskOptions,
38643863
llvm::Value *futureResultType,
38653864
llvm::Value *taskFunction,
38663865
llvm::Value *localContextInfo,
38673866
SubstitutionMap subs) {
3868-
taskOptions = IGF.Builder.CreateBitOrPointerCast(
3869-
taskOptions, IGF.IGM.SwiftTaskOptionRecordPtrTy);
3870-
38713867
// If there is a task group, emit a task group option structure to contain
38723868
// it.
3869+
llvm::Value *taskOptions = llvm::ConstantInt::get(
3870+
IGF.IGM.SwiftTaskOptionRecordPtrTy, 0);
38733871
if (taskGroup) {
38743872
TaskOptionRecordFlags optionsFlags(TaskOptionRecordKind::TaskGroup);
38753873
llvm::Value *optionsFlagsVal = llvm::ConstantInt::get(

lib/IRGen/GenCall.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ namespace irgen {
230230
IRGenFunction &IGF,
231231
llvm::Value *flags,
232232
llvm::Value *taskGroup,
233-
llvm::Value *taskOptions,
234233
llvm::Value *futureResultType,
235234
llvm::Value *taskFunction,
236235
llvm::Value *localContextInfo,

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, DestroyTaskGroup)
753753
BUILTIN_OPERAND_OWNERSHIP(ForwardingConsume, COWBufferForReading)
754754
BUILTIN_OPERAND_OWNERSHIP(ForwardingConsume, UnsafeGuaranteed)
755755

756-
const int PARAMETER_INDEX_CREATE_ASYNC_TASK_FUTURE_FUNCTION = 3;
756+
const int PARAMETER_INDEX_CREATE_ASYNC_TASK_FUTURE_FUNCTION = 2;
757757
const int PARAMETER_INDEX_CREATE_ASYNC_TASK_GROUP_FUTURE_FUNCTION = 3;
758758

759759
OperandOwnership

lib/SILGen/SILGenBuiltin.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,9 +1426,6 @@ static ManagedValue emitBuiltinCreateAsyncTask(
14261426
SGF.B.createMetatype(loc, SGF.getLoweredType(futureResultType)));
14271427
}).borrow(SGF, loc).forward(SGF);
14281428

1429-
// Task options
1430-
auto taskOptions = args[1].borrow(SGF, loc).forward(SGF);;
1431-
14321429
// Ensure that the closure has the appropriate type.
14331430
auto extInfo =
14341431
ASTExtInfoBuilder()
@@ -1445,7 +1442,7 @@ static ManagedValue emitBuiltinCreateAsyncTask(
14451442
AbstractionPattern origParam(genericSig, functionTy);
14461443
CanType substParamType = functionTy.subst(subs)->getCanonicalType();
14471444
auto reabstractedFun =
1448-
SGF.emitSubstToOrigValue(loc, args[2], origParam, substParamType);
1445+
SGF.emitSubstToOrigValue(loc, args[1], origParam, substParamType);
14491446

14501447
auto function = emitFunctionArgumentForAsyncTaskEntryPoint(
14511448
SGF, loc, reabstractedFun, futureResultType);
@@ -1454,7 +1451,7 @@ static ManagedValue emitBuiltinCreateAsyncTask(
14541451
loc,
14551452
ctx.getIdentifier(getBuiltinName(BuiltinValueKind::CreateAsyncTask)),
14561453
SGF.getLoweredType(getAsyncTaskAndContextType(ctx)), subs,
1457-
{ flags, taskOptions, futureResultMetadata, function.forward(SGF) });
1454+
{ flags, futureResultMetadata, function.forward(SGF) });
14581455
return SGF.emitManagedRValueWithCleanup(apply);
14591456
}
14601457

stdlib/public/Concurrency/Task.swift

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ extension Task where Failure == Never {
538538
priority: TaskPriority? = nil,
539539
@_inheritActorContext @_implicitSelfCapture operation: __owned @Sendable @escaping () async -> Success
540540
) {
541+
#if compiler(>=5.5) && $BuiltinCreateAsyncTaskInGroup
541542
// Set up the job flags for a new task.
542543
var flags = TaskCreateFlags()
543544
flags.priority = priority ?? Task<Never, Never>.currentPriority._downgradeUserInteractive
@@ -546,10 +547,12 @@ extension Task where Failure == Never {
546547
flags.enqueueJob = true
547548

548549
// Create the asynchronous task.
549-
let (task, _) = Builtin.createAsyncTask(
550-
Int(flags.bits), /*options*/nil, operation)
550+
let (task, _) = Builtin.createAsyncTask(Int(flags.bits), operation)
551551

552552
self._task = task
553+
#else
554+
fatalError("Unsupported Swift compiler")
555+
#endif
553556
}
554557
}
555558

@@ -572,6 +575,7 @@ extension Task where Failure == Error {
572575
priority: TaskPriority? = nil,
573576
@_inheritActorContext @_implicitSelfCapture operation: __owned @Sendable @escaping () async throws -> Success
574577
) {
578+
#if compiler(>=5.5) && $BuiltinCreateAsyncTaskInGroup
575579
// Set up the job flags for a new task.
576580
var flags = TaskCreateFlags()
577581
flags.priority = priority ?? Task<Never, Never>.currentPriority._downgradeUserInteractive
@@ -580,10 +584,12 @@ extension Task where Failure == Error {
580584
flags.enqueueJob = true
581585

582586
// Create the asynchronous task future.
583-
let (task, _) = Builtin.createAsyncTask(
584-
Int(flags.bits), /*options*/nil, operation)
587+
let (task, _) = Builtin.createAsyncTask(Int(flags.bits), operation)
585588

586589
self._task = task
590+
#else
591+
fatalError("Unsupported Swift compiler")
592+
#endif
587593
}
588594
}
589595

@@ -625,16 +631,19 @@ extension Task where Failure == Never {
625631
priority: TaskPriority? = nil,
626632
operation: __owned @Sendable @escaping () async -> Success
627633
) -> Task<Success, Failure> {
634+
#if compiler(>=5.5) && $BuiltinCreateAsyncTaskInGroup
628635
// Set up the job flags for a new task.
629636
var flags = TaskCreateFlags()
630637
flags.priority = priority ?? .unspecified
631638
flags.enqueueJob = true
632639

633640
// Create the asynchronous task future.
634-
let (task, _) = Builtin.createAsyncTask(
635-
Int(flags.bits), /*options*/nil, operation)
641+
let (task, _) = Builtin.createAsyncTask(Int(flags.bits), operation)
636642

637643
return Task(task)
644+
#else
645+
fatalError("Unsupported Swift compiler")
646+
#endif
638647
}
639648
}
640649

@@ -677,16 +686,19 @@ extension Task where Failure == Error {
677686
priority: TaskPriority? = nil,
678687
operation: __owned @Sendable @escaping () async throws -> Success
679688
) -> Task<Success, Failure> {
689+
#if compiler(>=5.5) && $BuiltinCreateAsyncTaskInGroup
680690
// Set up the job flags for a new task.
681691
var flags = TaskCreateFlags()
682692
flags.priority = priority ?? .unspecified
683693
flags.enqueueJob = true
684694

685695
// Create the asynchronous task future.
686-
let (task, _) = Builtin.createAsyncTask(
687-
Int(flags.bits), /*options*/nil, operation)
696+
let (task, _) = Builtin.createAsyncTask(Int(flags.bits), operation)
688697

689698
return Task(task)
699+
#else
700+
fatalError("Unsupported Swift compiler")
701+
#endif
690702
}
691703
}
692704

test/IRGen/async/builtins.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bb0(%0 : $Int, %1 : $Optional<Builtin.RawPointer>, %2: @guaranteed $@async @call
3939
%9 = metatype $@thick T.Type
4040
%10 = init_existential_metatype %9 : $@thick T.Type, $@thick Any.Type
4141
// CHECK: [[NEW_TASK_AND_CONTEXT:%.*]] = call swift{{(tail)?}}cc %swift.async_task_and_context @swift_task_create(
42-
%20 = builtin "createAsyncTask"<T>(%0 : $Int, %1 : $Optional<Builtin.RawPointer>, %10 : $@thick Any.Type, %5 : $@async @callee_owned @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <T>) : $(Builtin.NativeObject, Builtin.RawPointer)
42+
%20 = builtin "createAsyncTask"<T>(%0 : $Int, %10 : $@thick Any.Type, %5 : $@async @callee_owned @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <T>) : $(Builtin.NativeObject, Builtin.RawPointer)
4343
destroy_value %20 : $(Builtin.NativeObject, Builtin.RawPointer)
4444
%21 = tuple ()
4545
return %21 : $()
@@ -78,7 +78,7 @@ bb0(%0 : $Int, %1 : $Optional<Builtin.RawPointer>, %2: @guaranteed $@async @call
7878
%8 = metatype $@thick ().Type // user: %9
7979
%9 = init_existential_metatype %8 : $@thick ().Type, $@thick Any.Type // user: %10
8080
// CHECK: [[NEW_TASK_AND_CONTEXT:%.*]] = call swift{{(tail)?}}cc %swift.async_task_and_context @swift_task_create(
81-
%20 = builtin "createAsyncTask"<()>(%0 : $Int, %1 : $Optional<Builtin.RawPointer>, %9 : $@thick Any.Type, %5 : $@async @callee_owned @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <()>) : $(Builtin.NativeObject, Builtin.RawPointer)
81+
%20 = builtin "createAsyncTask"<()>(%0 : $Int, %9 : $@thick Any.Type, %5 : $@async @callee_owned @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <()>) : $(Builtin.NativeObject, Builtin.RawPointer)
8282
destroy_value %20 : $(Builtin.NativeObject, Builtin.RawPointer)
8383
%21 = tuple ()
8484
return %21 : $()

test/SILGen/async_builtins.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public struct X {
1818

1919
// CHECK-LABEL: sil hidden [ossa] @$s4test1XV12launchFutureyyxlF : $@convention(method) <T> (@in_guaranteed T, X) -> ()
2020
func launchFuture<T>(_ value: T) {
21-
// CHECK: builtin "createAsyncTask"<T>([[ZERO:%.*]] : $Int, [[OPT:%.*]] : $Optional<Builtin.RawPointer>, [[FN:%.*]] : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <T>) : $(Builtin.NativeObject, Builtin.RawPointer)
22-
_ = Builtin.createAsyncTask(0, nil) { () async throws -> T in
21+
// CHECK: builtin "createAsyncTask"<T>([[ZERO:%.*]] : $Int, [[FN:%.*]] : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <T>) : $(Builtin.NativeObject, Builtin.RawPointer)
22+
_ = Builtin.createAsyncTask(0) { () async throws -> T in
2323
return value
2424
}
2525
}
@@ -33,7 +33,7 @@ public struct X {
3333
}
3434

3535
public func launchRocker<T>(closure: @escaping () async throws -> T) {
36-
_ = Builtin.createAsyncTask(0, nil, closure)
36+
_ = Builtin.createAsyncTask(0, closure)
3737
}
3838
}
3939

0 commit comments

Comments
 (0)