Skip to content

Commit b8305cc

Browse files
committed
[sending] Make Builtin.withUnsafe{,Throwing}Continuation return a sending result.
1 parent c7124e4 commit b8305cc

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

include/swift/AST/Builtins.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,14 @@ BUILTIN_SIL_OPERATION(ApplyDerivative, "applyDerivative", Special)
517517
/// applyTranspose
518518
BUILTIN_SIL_OPERATION(ApplyTranspose, "applyTranspose", Special)
519519

520-
/// withUnsafeContinuation<T> : (Builtin.RawUnsafeContinuation -> ()) async -> T
520+
/// withUnsafeContinuation<T> : (Builtin.RawUnsafeContinuation -> ()) async -> sending T
521521
///
522522
/// Unsafely capture the current continuation and pass it to the given
523523
/// function value. Returns a value of type T when the continuation is
524524
/// resumed.
525525
BUILTIN_SIL_OPERATION(WithUnsafeContinuation, "withUnsafeContinuation", Special)
526526

527-
/// withUnsafeThrowingContinuation<T> : (Builtin.RawUnsafeContinuation -> ()) async throws -> T
527+
/// withUnsafeThrowingContinuation<T> : (Builtin.RawUnsafeContinuation -> ()) async throws -> sending T
528528
///
529529
/// Unsafely capture the current continuation and pass it to the given
530530
/// function value. Returns a value of type T or throws an error when

lib/AST/Builtins.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,10 @@ enum class BuiltinThrowsKind : uint8_t {
422422
}
423423

424424
/// Build a builtin function declaration.
425-
static FuncDecl *
426-
getBuiltinGenericFunction(Identifier Id,
427-
ArrayRef<AnyFunctionType::Param> ArgParamTypes,
428-
Type ResType,
429-
GenericParamList *GenericParams,
430-
GenericSignature Sig,
431-
bool Async, BuiltinThrowsKind Throws) {
425+
static FuncDecl *getBuiltinGenericFunction(
426+
Identifier Id, ArrayRef<AnyFunctionType::Param> ArgParamTypes, Type ResType,
427+
GenericParamList *GenericParams, GenericSignature Sig, bool Async,
428+
BuiltinThrowsKind Throws, bool SendingResult) {
432429
assert(GenericParams && "Missing generic parameters");
433430
auto &Context = ResType->getASTContext();
434431

@@ -460,6 +457,7 @@ getBuiltinGenericFunction(Identifier Id,
460457
Throws != BuiltinThrowsKind::None, /*thrownType=*/Type(),
461458
GenericParams, paramList, ResType, DC);
462459

460+
func->setSendingResult(SendingResult);
463461
func->setAccess(AccessLevel::Public);
464462
func->setGenericSignature(Sig);
465463
if (Throws == BuiltinThrowsKind::Rethrows)
@@ -681,6 +679,7 @@ namespace {
681679
Type InterfaceResult;
682680
bool Async = false;
683681
BuiltinThrowsKind Throws = BuiltinThrowsKind::None;
682+
bool SendingResult = false;
684683

685684
// Accumulate params and requirements here, so that we can call
686685
// `buildGenericSignature()` when `build()` is called.
@@ -745,16 +744,17 @@ namespace {
745744
Throws = BuiltinThrowsKind::Rethrows;
746745
}
747746

747+
void setSendingResult() { SendingResult = true; }
748+
748749
FuncDecl *build(Identifier name) {
749750
auto GenericSig = buildGenericSignature(
750751
Context, GenericSignature(),
751752
std::move(genericParamTypes),
752753
std::move(addedRequirements),
753754
/*allowInverses=*/false);
754-
return getBuiltinGenericFunction(name, InterfaceParams,
755-
InterfaceResult,
756-
TheGenericParamList, GenericSig,
757-
Async, Throws);
755+
return getBuiltinGenericFunction(name, InterfaceParams, InterfaceResult,
756+
TheGenericParamList, GenericSig, Async,
757+
Throws, SendingResult);
758758
}
759759

760760
// Don't use these generator classes directly; call the make{...}
@@ -2073,6 +2073,7 @@ static ValueDecl *getWithUnsafeContinuation(ASTContext &ctx,
20732073
builder.setAsync();
20742074
if (throws)
20752075
builder.setThrows();
2076+
builder.setSendingResult();
20762077

20772078
return builder.build(id);
20782079
}

0 commit comments

Comments
 (0)