Skip to content

Commit 0f152af

Browse files
committed
Add a Builtin.Executor type to abstract executor references.
1 parent 986d033 commit 0f152af

17 files changed

+62
-17
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ Types
517517
type ::= 'BB' // Builtin.UnsafeValueBuffer
518518
type ::= 'Bc' // Builtin.RawUnsafeContinuation
519519
type ::= 'BD' // Builtin.DefaultActorStorage
520+
type ::= 'Be' // Builtin.ExecutorRef
520521
type ::= 'Bf' NATURAL '_' // Builtin.Float<n>
521522
type ::= 'Bi' NATURAL '_' // Builtin.Int<n>
522523
type ::= 'BI' // Builtin.IntLiteral

include/swift/AST/ASTSynthesis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum SingletonTypeSynthesizer {
4141
_any,
4242
_bridgeObject,
4343
_error,
44+
_executor,
4445
_job,
4546
_nativeObject,
4647
_never,
@@ -54,6 +55,7 @@ inline Type synthesizeType(SynthesisContext &SC,
5455
case _any: return SC.Context.TheAnyType;
5556
case _bridgeObject: return SC.Context.TheBridgeObjectType;
5657
case _error: return SC.Context.getExceptionType();
58+
case _executor: return SC.Context.TheExecutorType;
5759
case _job: return SC.Context.TheJobType;
5860
case _nativeObject: return SC.Context.TheNativeObjectType;
5961
case _never: return SC.Context.getNeverType();

include/swift/AST/Builtins.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ BUILTIN_MISC_OPERATION(DestroyDefaultActor, "destroyDefaultActor", "", Special)
736736
BUILTIN_MISC_OPERATION(Id, Name, Attrs, Overload)
737737
#endif
738738

739-
// getCurrentExecutor: () async -> Builtin.Word
739+
// getCurrentExecutor: () async -> Builtin.Executor
740740
//
741741
// Retrieve the ExecutorRef on which the current asynchronous
742742
// function is executing.

include/swift/AST/TypeNodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ ABSTRACT_TYPE(Builtin, Type)
103103
BUILTIN_TYPE(BuiltinInteger, AnyBuiltinIntegerType)
104104
BUILTIN_TYPE(BuiltinIntegerLiteral, AnyBuiltinIntegerType)
105105
TYPE_RANGE(AnyBuiltinInteger, BuiltinInteger, BuiltinIntegerLiteral)
106+
BUILTIN_TYPE(BuiltinExecutor, BuiltinType)
106107
BUILTIN_TYPE(BuiltinFloat, BuiltinType)
107108
BUILTIN_TYPE(BuiltinJob, BuiltinType)
108109
BUILTIN_TYPE(BuiltinRawPointer, BuiltinType)
@@ -181,6 +182,7 @@ LAST_TYPE(Dictionary) // Sugared types are last to make isa<SugarType>() fast.
181182
#ifdef SINGLETON_TYPE
182183
SINGLETON_TYPE(IntegerLiteral, BuiltinIntegerLiteral)
183184
SINGLETON_TYPE(Job, BuiltinJob)
185+
SINGLETON_TYPE(Executor, BuiltinExecutor)
184186
SINGLETON_TYPE(RawPointer, BuiltinRawPointer)
185187
SINGLETON_TYPE(RawUnsafeContinuation, BuiltinRawUnsafeContinuation)
186188
SINGLETON_TYPE(NativeObject, BuiltinNativeObject)

include/swift/AST/Types.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,19 @@ class BuiltinRawUnsafeContinuationType : public BuiltinType {
14161416
};
14171417
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinRawUnsafeContinuationType, BuiltinType);
14181418

1419+
/// BuiltinExecutorType - The builtin executor-ref type. In C, this
1420+
/// is the ExecutorRef struct type.
1421+
class BuiltinExecutorType : public BuiltinType {
1422+
friend class ASTContext;
1423+
BuiltinExecutorType(const ASTContext &C)
1424+
: BuiltinType(TypeKind::BuiltinExecutor, C) {}
1425+
public:
1426+
static bool classof(const TypeBase *T) {
1427+
return T->getKind() == TypeKind::BuiltinExecutor;
1428+
}
1429+
};
1430+
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinExecutorType, BuiltinType);
1431+
14191432
/// BuiltinJobType - The builtin job type. In C, this is a
14201433
/// non-null Job*. This pointer is completely unmanaged (the unscheduled
14211434
/// job is self-owning), but has more spare bits than Builtin.RawPointer.

include/swift/Strings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_UNSAFEVALUEBUFFER =
122122
/// The name of the Builtin type for Job
123123
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_JOB = {
124124
"Builtin.Job"};
125+
/// The name of the Builtin type for ExecutorRef
126+
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_EXECUTOR = {
127+
"Builtin.ExecutorRef"};
125128
/// The name of the Builtin type for DefaultActorStorage
126129
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_DEFAULTACTORSTORAGE = {
127130
"Builtin.DefaultActorStorage"};

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3577,6 +3577,7 @@ namespace {
35773577

35783578
TRIVIAL_TYPE_PRINTER(BuiltinIntegerLiteral, builtin_integer_literal)
35793579
TRIVIAL_TYPE_PRINTER(BuiltinJob, builtin_job)
3580+
TRIVIAL_TYPE_PRINTER(BuiltinExecutor, builtin_executor_ref)
35803581
TRIVIAL_TYPE_PRINTER(BuiltinDefaultActorStorage, builtin_default_actor_storage)
35813582
TRIVIAL_TYPE_PRINTER(BuiltinRawPointer, builtin_raw_pointer)
35823583
TRIVIAL_TYPE_PRINTER(BuiltinRawUnsafeContinuation, builtin_raw_unsafe_continuation)

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,8 @@ void ASTMangler::appendType(Type type, const ValueDecl *forDecl) {
10471047
return appendOperator("BI");
10481048
case TypeKind::BuiltinJob:
10491049
return appendOperator("Bj");
1050+
case TypeKind::BuiltinExecutor:
1051+
return appendOperator("Be");
10501052
case TypeKind::BuiltinDefaultActorStorage:
10511053
return appendOperator("BD");
10521054
case TypeKind::BuiltinRawPointer:

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4407,6 +4407,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
44074407
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinRawPointerType)
44084408
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinRawUnsafeContinuationType)
44094409
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinJobType)
4410+
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinExecutorType)
44104411
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinDefaultActorStorageType)
44114412
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinNativeObjectType)
44124413
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinBridgeObjectType)

lib/AST/Builtins.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,10 +1351,9 @@ static ValueDecl *getGetCurrentAsyncTask(ASTContext &ctx, Identifier id) {
13511351
}
13521352

13531353
static ValueDecl *getGetCurrentExecutor(ASTContext &ctx, Identifier id) {
1354-
BuiltinFunctionBuilder builder(ctx);
1355-
builder.setResult(makeConcrete(BuiltinIntegerType::getWordType(ctx)));
1356-
builder.setAsync();
1357-
return builder.build(id);
1354+
return getBuiltinFunction(ctx, id, _async(_thin),
1355+
_parameters(),
1356+
_executor);
13581357
}
13591358

13601359
static ValueDecl *getCancelAsyncTask(ASTContext &ctx, Identifier id) {
@@ -2692,6 +2691,9 @@ StringRef BuiltinType::getTypeName(SmallVectorImpl<char> &result,
26922691
case BuiltinTypeKind::BuiltinJob:
26932692
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_JOB);
26942693
break;
2694+
case BuiltinTypeKind::BuiltinExecutor:
2695+
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_EXECUTOR);
2696+
break;
26952697
case BuiltinTypeKind::BuiltinDefaultActorStorage:
26962698
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_DEFAULTACTORSTORAGE);
26972699
break;

0 commit comments

Comments
 (0)