Skip to content

Commit 7def279

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 e7e922e commit 7def279

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
@@ -807,7 +807,6 @@ BUILTIN_MISC_OPERATION_WITH_SILGEN(EndAsyncLet, "endAsyncLet", "", Special)
807807

808808
/// createAsyncTask(): (
809809
/// Int, // task-creation flags
810-
/// Builtin.RawPointer?, // options (TaskOptionRecord*)
811810
/// @escaping () async throws -> T // function
812811
/// ) -> Builtin.NativeObject
813812
///

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
@@ -3861,16 +3861,14 @@ llvm::Value *irgen::emitTaskCreate(
38613861
IRGenFunction &IGF,
38623862
llvm::Value *flags,
38633863
llvm::Value *taskGroup,
3864-
llvm::Value *taskOptions,
38653864
llvm::Value *futureResultType,
38663865
llvm::Value *taskFunction,
38673866
llvm::Value *localContextInfo,
38683867
SubstitutionMap subs) {
3869-
taskOptions = IGF.Builder.CreateBitOrPointerCast(
3870-
taskOptions, IGF.IGM.SwiftTaskOptionRecordPtrTy);
3871-
38723868
// If there is a task group, emit a task group option structure to contain
38733869
// it.
3870+
llvm::Value *taskOptions = llvm::ConstantInt::get(
3871+
IGF.IGM.SwiftTaskOptionRecordPtrTy, 0);
38743872
if (taskGroup) {
38753873
TaskOptionRecordFlags optionsFlags(TaskOptionRecordKind::TaskGroup);
38763874
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
@@ -765,7 +765,7 @@ BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, DestroyTaskGroup)
765765
BUILTIN_OPERAND_OWNERSHIP(ForwardingConsume, COWBufferForReading)
766766
BUILTIN_OPERAND_OWNERSHIP(ForwardingConsume, UnsafeGuaranteed)
767767

768-
const int PARAMETER_INDEX_CREATE_ASYNC_TASK_FUTURE_FUNCTION = 3;
768+
const int PARAMETER_INDEX_CREATE_ASYNC_TASK_FUTURE_FUNCTION = 2;
769769
const int PARAMETER_INDEX_CREATE_ASYNC_TASK_GROUP_FUTURE_FUNCTION = 3;
770770

771771
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
@@ -510,6 +510,7 @@ extension Task where Failure == Never {
510510
priority: TaskPriority? = nil,
511511
@_inheritActorContext @_implicitSelfCapture operation: __owned @Sendable @escaping () async -> Success
512512
) {
513+
#if compiler(>=5.5) && $BuiltinCreateAsyncTaskInGroup
513514
// Set up the job flags for a new task.
514515
var flags = TaskCreateFlags()
515516
flags.priority = priority ?? Task<Never, Never>.currentPriority._downgradeUserInteractive
@@ -518,10 +519,12 @@ extension Task where Failure == Never {
518519
flags.enqueueJob = true
519520

520521
// Create the asynchronous task.
521-
let (task, _) = Builtin.createAsyncTask(
522-
Int(flags.bits), /*options*/nil, operation)
522+
let (task, _) = Builtin.createAsyncTask(Int(flags.bits), operation)
523523

524524
self._task = task
525+
#else
526+
fatalError("Unsupported Swift compiler")
527+
#endif
525528
}
526529
}
527530

@@ -544,6 +547,7 @@ extension Task where Failure == Error {
544547
priority: TaskPriority? = nil,
545548
@_inheritActorContext @_implicitSelfCapture operation: __owned @Sendable @escaping () async throws -> Success
546549
) {
550+
#if compiler(>=5.5) && $BuiltinCreateAsyncTaskInGroup
547551
// Set up the job flags for a new task.
548552
var flags = TaskCreateFlags()
549553
flags.priority = priority ?? Task<Never, Never>.currentPriority._downgradeUserInteractive
@@ -552,10 +556,12 @@ extension Task where Failure == Error {
552556
flags.enqueueJob = true
553557

554558
// Create the asynchronous task future.
555-
let (task, _) = Builtin.createAsyncTask(
556-
Int(flags.bits), /*options*/nil, operation)
559+
let (task, _) = Builtin.createAsyncTask(Int(flags.bits), operation)
557560

558561
self._task = task
562+
#else
563+
fatalError("Unsupported Swift compiler")
564+
#endif
559565
}
560566
}
561567

@@ -597,16 +603,19 @@ extension Task where Failure == Never {
597603
priority: TaskPriority? = nil,
598604
operation: __owned @Sendable @escaping () async -> Success
599605
) -> Task<Success, Failure> {
606+
#if compiler(>=5.5) && $BuiltinCreateAsyncTaskInGroup
600607
// Set up the job flags for a new task.
601608
var flags = TaskCreateFlags()
602609
flags.priority = priority ?? .unspecified
603610
flags.enqueueJob = true
604611

605612
// Create the asynchronous task future.
606-
let (task, _) = Builtin.createAsyncTask(
607-
Int(flags.bits), /*options*/nil, operation)
613+
let (task, _) = Builtin.createAsyncTask(Int(flags.bits), operation)
608614

609615
return Task(task)
616+
#else
617+
fatalError("Unsupported Swift compiler")
618+
#endif
610619
}
611620
}
612621

@@ -649,16 +658,19 @@ extension Task where Failure == Error {
649658
priority: TaskPriority? = nil,
650659
operation: __owned @Sendable @escaping () async throws -> Success
651660
) -> Task<Success, Failure> {
661+
#if compiler(>=5.5) && $BuiltinCreateAsyncTaskInGroup
652662
// Set up the job flags for a new task.
653663
var flags = TaskCreateFlags()
654664
flags.priority = priority ?? .unspecified
655665
flags.enqueueJob = true
656666

657667
// Create the asynchronous task future.
658-
let (task, _) = Builtin.createAsyncTask(
659-
Int(flags.bits), /*options*/nil, operation)
668+
let (task, _) = Builtin.createAsyncTask(Int(flags.bits), operation)
660669

661670
return Task(task)
671+
#else
672+
fatalError("Unsupported Swift compiler")
673+
#endif
662674
}
663675
}
664676

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)