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;

lib/AST/Type.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ bool CanType::isReferenceTypeImpl(CanType type, const GenericSignatureImpl *sig,
212212
case TypeKind::BuiltinRawPointer:
213213
case TypeKind::BuiltinRawUnsafeContinuation:
214214
case TypeKind::BuiltinJob:
215+
case TypeKind::BuiltinExecutor:
215216
case TypeKind::BuiltinDefaultActorStorage:
216217
case TypeKind::BuiltinUnsafeValueBuffer:
217218
case TypeKind::BuiltinVector:
@@ -5097,6 +5098,7 @@ ReferenceCounting TypeBase::getReferenceCounting() {
50975098
case TypeKind::BuiltinRawPointer:
50985099
case TypeKind::BuiltinRawUnsafeContinuation:
50995100
case TypeKind::BuiltinJob:
5101+
case TypeKind::BuiltinExecutor:
51005102
case TypeKind::BuiltinDefaultActorStorage:
51015103
case TypeKind::BuiltinUnsafeValueBuffer:
51025104
case TypeKind::BuiltinVector:

lib/IRGen/GenType.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,17 +1549,17 @@ const TypeInfo &TypeConverter::getTaskContinuationFunctionPtrTypeInfo() {
15491549
}
15501550

15511551
const TypeInfo &IRGenModule::getSwiftExecutorPtrTypeInfo() {
1552-
return Types.getSwiftExecutorPtrTypeInfo();
1552+
return Types.getExecutorTypeInfo();
15531553
}
15541554

1555-
const TypeInfo &TypeConverter::getSwiftExecutorPtrTypeInfo() {
1556-
if (SwiftExecutorPtrTI) return *SwiftExecutorPtrTI;
1557-
SwiftExecutorPtrTI = createUnmanagedStorageType(IGM.SwiftExecutorPtrTy,
1558-
ReferenceCounting::Unknown,
1559-
/*isOptional*/ false);
1560-
SwiftExecutorPtrTI->NextConverted = FirstType;
1561-
FirstType = SwiftExecutorPtrTI;
1562-
return *SwiftExecutorPtrTI;
1555+
const LoadableTypeInfo &TypeConverter::getExecutorTypeInfo() {
1556+
if (ExecutorTI) return *ExecutorTI;
1557+
ExecutorTI = createPrimitive(IGM.SwiftExecutorPtrTy,
1558+
IGM.getPointerSize(),
1559+
IGM.getPointerAlignment());
1560+
ExecutorTI->NextConverted = FirstType;
1561+
FirstType = ExecutorTI;
1562+
return *ExecutorTI;
15631563
}
15641564

15651565
const LoadableTypeInfo &
@@ -2081,6 +2081,8 @@ const TypeInfo *TypeConverter::convertType(CanType ty) {
20812081
return &getRawUnsafeContinuationTypeInfo();
20822082
case TypeKind::BuiltinJob:
20832083
return &getJobTypeInfo();
2084+
case TypeKind::BuiltinExecutor:
2085+
return &getExecutorTypeInfo();
20842086
case TypeKind::BuiltinIntegerLiteral:
20852087
return &getIntegerLiteralTypeInfo();
20862088
case TypeKind::BuiltinFloat:

lib/IRGen/GenType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ class TypeConverter {
105105
const LoadableTypeInfo *RawPointerTI = nullptr;
106106
const LoadableTypeInfo *RawUnsafeContinuationTI = nullptr;
107107
const LoadableTypeInfo *JobTI = nullptr;
108+
const LoadableTypeInfo *ExecutorTI = nullptr;
108109
const LoadableTypeInfo *WitnessTablePtrTI = nullptr;
109110
const TypeInfo *TypeMetadataPtrTI = nullptr;
110111
const TypeInfo *SwiftContextPtrTI = nullptr;
111112
const TypeInfo *TaskContinuationFunctionPtrTI = nullptr;
112-
const TypeInfo *SwiftExecutorPtrTI = nullptr;
113113
const TypeInfo *ObjCClassPtrTI = nullptr;
114114
const LoadableTypeInfo *EmptyTI = nullptr;
115115
const LoadableTypeInfo *IntegerLiteralTI = nullptr;
@@ -184,10 +184,10 @@ class TypeConverter {
184184
const LoadableTypeInfo &getRawPointerTypeInfo();
185185
const LoadableTypeInfo &getRawUnsafeContinuationTypeInfo();
186186
const LoadableTypeInfo &getJobTypeInfo();
187+
const LoadableTypeInfo &getExecutorTypeInfo();
187188
const TypeInfo &getTypeMetadataPtrTypeInfo();
188189
const TypeInfo &getSwiftContextPtrTypeInfo();
189190
const TypeInfo &getTaskContinuationFunctionPtrTypeInfo();
190-
const TypeInfo &getSwiftExecutorPtrTypeInfo();
191191
const TypeInfo &getObjCClassPtrTypeInfo();
192192
const LoadableTypeInfo &getWitnessTablePtrTypeInfo();
193193
const LoadableTypeInfo &getEmptyTypeInfo();

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
13391339
MangledName);
13401340
}
13411341

1342+
case TypeKind::BuiltinExecutor: {
1343+
unsigned PtrSize = CI.getTargetInfo().getPointerWidth(0);
1344+
return DBuilder.createPointerType(nullptr, PtrSize, 0,
1345+
/* DWARFAddressSpace */ None,
1346+
MangledName);
1347+
}
1348+
13421349
case TypeKind::DynamicSelf: {
13431350
// Self. We don't have a way to represent instancetype in DWARF,
13441351
// so we emit the static type instead. This is similar to what we

lib/IRGen/MetadataRequest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,12 @@ namespace {
13091309
return emitDirectMetadataRef(type);
13101310
}
13111311

1312+
MetadataResponse
1313+
visitBuiltinExecutorType(CanBuiltinExecutorType type,
1314+
DynamicMetadataRequest request) {
1315+
return emitDirectMetadataRef(type);
1316+
}
1317+
13121318
MetadataResponse
13131319
visitBuiltinFloatType(CanBuiltinFloatType type,
13141320
DynamicMetadataRequest request) {

lib/SIL/IR/TypeLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ namespace {
245245
IMPL(BuiltinRawPointer, Trivial)
246246
IMPL(BuiltinRawUnsafeContinuation, Trivial)
247247
IMPL(BuiltinJob, Trivial)
248+
IMPL(BuiltinExecutor, Trivial)
248249
IMPL(BuiltinNativeObject, Reference)
249250
IMPL(BuiltinBridgeObject, Reference)
250251
IMPL(BuiltinVector, Trivial)

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ SILValue SILGenFunction::emitGetCurrentExecutor(SILLocation loc) {
616616
return B.createBuiltin(
617617
loc,
618618
ctx.getIdentifier(getBuiltinName(BuiltinValueKind::GetCurrentExecutor)),
619-
getLoweredType(BuiltinIntegerType::getWordType(ctx)),
619+
getLoweredType(ctx.TheExecutorType),
620620
SubstitutionMap(), { });
621621
}
622622

0 commit comments

Comments
 (0)