Skip to content

Commit

Permalink
Survive using SDK which does not have TaskExecutor declared when
Browse files Browse the repository at this point in the history
creating tasks with new builtin defaulted "owned" task executor
parameter.
  • Loading branch information
ktoso committed Jun 10, 2024
1 parent 55cf283 commit c310d08
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
7 changes: 5 additions & 2 deletions include/swift/AST/ASTSynthesis.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ inline Type synthesizeType(SynthesisContext &SC,
return SC.Context.getProtocol(KnownProtocolKind::SerialExecutor)
->getDeclaredInterfaceType();
case _taskExecutor:
return SC.Context.getProtocol(KnownProtocolKind::TaskExecutor)
->getDeclaredInterfaceType();
if (auto ty = SC.Context.getProtocol(KnownProtocolKind::TaskExecutor)) {
return ty->getDeclaredInterfaceType();
} else {
return nullptr;
}
case _actor:
return SC.Context.getProtocol(KnownProtocolKind::Actor)
->getDeclaredInterfaceType();
Expand Down
13 changes: 11 additions & 2 deletions lib/SIL/Verifier/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2393,8 +2393,17 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
"third argument of createAsyncTask");
requireType(arguments[3]->getType(), _object(_optional(_executor)),
"fourth argument of createAsyncTask");
requireType(arguments[4]->getType(), _object(_optional(_existential(_taskExecutor))),
"fifth argument of createAsyncTask");
if (F.getASTContext().getProtocol(swift::KnownProtocolKind::TaskExecutor)) {
requireType(arguments[4]->getType(),
_object(_optional(_existential(_taskExecutor))),
"fifth argument of createAsyncTask");
} else {
// This is just a placeholder type for being able to pass 'nil' for it
// with SDKs which do not have the TaskExecutor type.
requireType(arguments[4]->getType(),
_object(_optional(_executor)),
"fifth argument of createAsyncTask");
}
auto fnType = requireObjectType(SILFunctionType, arguments[5],
"result of createAsyncTask");
auto expectedExtInfo =
Expand Down
9 changes: 6 additions & 3 deletions lib/SILGen/SILGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1607,11 +1607,14 @@ static ManagedValue emitCreateAsyncTask(SILGenFunction &SGF, SILLocation loc,
ManagedValue taskExecutorConsuming = [&] {
if (options & CreateTaskOptions::OptionalEverything) {
return nextArg().getAsSingleValue(SGF);
} else {
auto theTaskExecutorProto = ctx.getProtocol(KnownProtocolKind::TaskExecutor);
assert(theTaskExecutorProto && "Could not find TaskExecutor");
} else if (auto theTaskExecutorProto = ctx.getProtocol(KnownProtocolKind::TaskExecutor)) {
return emitOptionalNone(theTaskExecutorProto->getDeclaredExistentialType()
->getCanonicalType());
} else {
// This builtin executor type here is just a placeholder type for being
// able to pass 'nil' for it with SDKs which do not have the TaskExecutor
// type.
return emitOptionalNone(ctx.TheExecutorType);
}
}();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -emit-silgen -Xfrontend -disable-availability-checking %import-libdispatch -parse-as-library %s -o %t/a.out
// RUN: %target-build-swift -Xfrontend -disable-availability-checking %import-libdispatch -parse-as-library %s -o %t/a.out
// RUN: %env-SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=swift6 %target-run %t/a.out

// REQUIRES: executable_test
Expand Down

0 comments on commit c310d08

Please sign in to comment.