Skip to content

Commit 2fa3908

Browse files
committed
[concurrency] Add a new type Builtin.ImplicitActor.
This is currently not wired up to anything. I am going to wire it up in subsequent commits. The reason why we are introducing this new Builtin type is to represent that we are going to start stealing bits from the protocol witness table pointer of the Optional<any Actor> that this type is bitwise compatible with. The type will ensure that this value is only used in places where we know that it will be properly masked out giving us certainty that this value will not be used in any manner without it first being bit cleared and transformed back to Optional<any Actor>.
1 parent de14247 commit 2fa3908

26 files changed

+300
-20
lines changed

docs/ABI/Mangling.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,9 @@ Types
705705
type ::= type 'Bv' NATURAL '_' // Builtin.Vec<n>x<type>
706706
type ::= type type 'BV' // Builtin.FixedArray<N, T>
707707
type ::= 'Bw' // Builtin.Word
708+
#if SWIFT_RUNTIME_VERSION >= 6.2
709+
type ::= 'BA' // Builtin.ImplicitActor
710+
#endif
708711
type ::= function-signature 'c' // function type (escaping)
709712
type ::= function-signature 'X' FUNCTION-KIND // special function type
710713
type ::= bound-generic-type

include/swift/AST/TypeNodes.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ ABSTRACT_TYPE(Builtin, Type)
143143
BUILTIN_CONCRETE_TYPE(BuiltinVector, BuiltinType)
144144
BUILTIN_GENERIC_TYPE(BuiltinFixedArray, BuiltinType)
145145
BUILTIN_CONCRETE_TYPE(BuiltinUnboundGeneric, BuiltinType)
146-
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinUnboundGeneric)
146+
BUILTIN_CONCRETE_TYPE(BuiltinImplicitActor, BuiltinType)
147+
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinImplicitActor)
147148
TYPE(Tuple, Type)
148149
ABSTRACT_TYPE(ReferenceStorage, Type)
149150
#define REF_STORAGE(Name, ...) \
@@ -233,6 +234,7 @@ SINGLETON_TYPE(RawPointer, BuiltinRawPointer)
233234
SINGLETON_TYPE(RawUnsafeContinuation, BuiltinRawUnsafeContinuation)
234235
SINGLETON_TYPE(NativeObject, BuiltinNativeObject)
235236
SINGLETON_TYPE(BridgeObject, BuiltinBridgeObject)
237+
SINGLETON_TYPE(ImplicitActor, BuiltinImplicitActor)
236238
SINGLETON_TYPE(UnsafeValueBuffer, BuiltinUnsafeValueBuffer)
237239
SINGLETON_TYPE(DefaultActorStorage, BuiltinDefaultActorStorage)
238240
SINGLETON_TYPE(NonDefaultDistributedActorStorage, BuiltinNonDefaultDistributedActorStorage)

include/swift/AST/Types.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,13 @@ class alignas(1 << TypeAlignInBits) TypeBase
10031003
/// Determines whether this type is an any actor type.
10041004
bool isAnyActorType();
10051005

1006+
/// Is this a type whose value is a value that a function can use in an
1007+
/// isolated parameter position. This could be a type that actually conforms
1008+
/// to AnyActor or it could be a type like any Actor, Optional<any Actor> or
1009+
/// Builtin.ImplicitActor that do not conform to Actor but from which we can
1010+
/// derive a value that conforms to the Actor protocol.
1011+
bool canBeIsolatedTo();
1012+
10061013
/// Returns true if this type conforms to Sendable, or if its a function type
10071014
/// that is @Sendable.
10081015
bool isSendableType();
@@ -2019,6 +2026,19 @@ BEGIN_CAN_TYPE_WRAPPER(BuiltinVectorType, BuiltinType)
20192026
PROXY_CAN_TYPE_SIMPLE_GETTER(getElementType)
20202027
END_CAN_TYPE_WRAPPER(BuiltinVectorType, BuiltinType)
20212028

2029+
class BuiltinImplicitActorType : public BuiltinType {
2030+
friend class ASTContext;
2031+
2032+
BuiltinImplicitActorType(const ASTContext &context)
2033+
: BuiltinType(TypeKind::BuiltinImplicitActor, context) {}
2034+
2035+
public:
2036+
static bool classof(const TypeBase *T) {
2037+
return T->getKind() == TypeKind::BuiltinImplicitActor;
2038+
}
2039+
};
2040+
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinImplicitActorType, BuiltinType)
2041+
20222042
/// Size descriptor for a builtin integer type. This is either a fixed bit
20232043
/// width or an abstract target-dependent value such as "size of a pointer".
20242044
class BuiltinIntegerWidth {

include/swift/SIL/SILBuilder.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,13 @@ class SILBuilder {
23342334
getSILDebugLocation(Loc), Operand, Kind));
23352335
}
23362336

2337+
SILValue emitUncheckedOwnershipConversion(SILLocation Loc, SILValue Operand,
2338+
ValueOwnershipKind Kind) {
2339+
if (!hasOwnership())
2340+
return Operand;
2341+
return createUncheckedOwnershipConversion(Loc, Operand, Kind);
2342+
}
2343+
23372344
FixLifetimeInst *createFixLifetime(SILLocation Loc, SILValue Operand) {
23382345
return insert(new (getModule())
23392346
FixLifetimeInst(getSILDebugLocation(Loc), Operand));
@@ -2353,6 +2360,18 @@ class SILBuilder {
23532360
dependenceKind);
23542361
}
23552362

2363+
/// Emit a mark_dependence instruction placing the kind only if ownership is
2364+
/// set in the current function.
2365+
///
2366+
/// This is intended to be used in code that is generic over Ownership SSA and
2367+
/// non-Ownership SSA code.
2368+
SILValue emitMarkDependence(SILLocation Loc, SILValue value, SILValue base,
2369+
MarkDependenceKind dependenceKind) {
2370+
return createMarkDependence(Loc, value, base, value->getOwnershipKind(),
2371+
hasOwnership() ? dependenceKind
2372+
: MarkDependenceKind::Escaping);
2373+
}
2374+
23562375
MarkDependenceInst *
23572376
createMarkDependence(SILLocation Loc, SILValue value, SILValue base,
23582377
ValueOwnershipKind forwardingOwnershipKind,

include/swift/SIL/SILType.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ class SILType {
267267

268268
bool isBuiltinBridgeObject() const { return is<BuiltinBridgeObjectType>(); }
269269

270+
bool isBuiltinImplicitActor() const { return is<BuiltinImplicitActorType>(); }
271+
270272
SILType getBuiltinVectorElementType() const {
271273
auto vector = castTo<BuiltinVectorType>();
272274
return getPrimitiveObjectType(vector.getElementType());
@@ -961,6 +963,13 @@ class SILType {
961963
/// Returns true if this type is an actor or a distributed actor.
962964
bool isAnyActor() const { return getASTType()->isAnyActorType(); }
963965

966+
/// Is this a type whose value is a value that a function can use in an
967+
/// isolated parameter position. This could be a type that actually conforms
968+
/// to AnyActor or it could be a type like any Actor, Optional<any Actor> or
969+
/// Builtin.ImplicitActor that do not conform to Actor but from which we can
970+
/// derive a value that conforms to the Actor protocol.
971+
bool canBeIsolatedTo() const { return getASTType()->canBeIsolatedTo(); }
972+
964973
/// Returns true if this function conforms to the Sendable protocol.
965974
///
966975
/// NOTE: For diagnostics this is not always the correct thing to check since
@@ -1026,9 +1035,29 @@ class SILType {
10261035
/// Return '()'
10271036
static SILType getEmptyTupleType(const ASTContext &C);
10281037

1038+
/// Return (elementTypes) with control of category.
1039+
static SILType getTupleType(const ASTContext &ctx,
1040+
ArrayRef<SILType> elementTypes,
1041+
SILValueCategory category);
1042+
1043+
/// Return $(elementTypes)
1044+
static SILType getTupleObjectType(const ASTContext &ctx,
1045+
ArrayRef<SILType> elementTypes) {
1046+
return getTupleType(ctx, elementTypes, SILValueCategory::Object);
1047+
}
1048+
1049+
/// Return $*(elementTypes)
1050+
static SILType getTupleAddressType(const ASTContext &ctx,
1051+
ArrayRef<SILType> elementTypes) {
1052+
return getTupleType(ctx, elementTypes, SILValueCategory::Address);
1053+
}
1054+
10291055
/// Get the type for opaque actor isolation values.
10301056
static SILType getOpaqueIsolationType(const ASTContext &C);
10311057

1058+
/// Return Builtin.ImplicitActor.
1059+
static SILType getBuiltinImplicitActorType(const ASTContext &ctx);
1060+
10321061
//
10331062
// Utilities for treating SILType as a pointer-like type.
10341063
//

include/swift/Strings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_NATIVEOBJECT = {
144144
/// The name of the Builtin type for BridgeObject
145145
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_BRIDGEOBJECT = {
146146
"Builtin.BridgeObject"};
147+
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_IMPLICITACTOR = {
148+
"Builtin.ImplicitActor"};
147149
/// The name of the Builtin type for RawPointer
148150
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_RAWPOINTER = {
149151
"Builtin.RawPointer"};

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6114,6 +6114,7 @@ namespace {
61146114
TRIVIAL_TYPE_PRINTER(BuiltinRawUnsafeContinuation, builtin_raw_unsafe_continuation)
61156115
TRIVIAL_TYPE_PRINTER(BuiltinNativeObject, builtin_native_object)
61166116
TRIVIAL_TYPE_PRINTER(BuiltinBridgeObject, builtin_bridge_object)
6117+
TRIVIAL_TYPE_PRINTER(BuiltinImplicitActor, builtin_implicit_isolated_actor)
61176118
TRIVIAL_TYPE_PRINTER(BuiltinUnsafeValueBuffer, builtin_unsafe_value_buffer)
61186119
TRIVIAL_TYPE_PRINTER(SILToken, sil_token)
61196120

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,8 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
14711471
auto loc = cast<LocatableType>(tybase);
14721472
return appendType(loc->getSinglyDesugaredType(), sig, forDecl);
14731473
}
1474+
case TypeKind::BuiltinImplicitActor:
1475+
return appendOperator("BA");
14741476
case TypeKind::BuiltinFixedArray: {
14751477
auto bfa = cast<BuiltinFixedArrayType>(tybase);
14761478
appendType(bfa->getSize(), sig, forDecl);

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6266,6 +6266,7 @@ class TypePrinter : public TypeVisitor<TypePrinter, void, NonRecursivePrintOptio
62666266
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinIntegerType)
62676267
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinFloatType)
62686268
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinUnboundGenericType)
6269+
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinImplicitActorType)
62696270
#undef ASTPRINTER_PRINT_BUILTINTYPE
62706271

62716272
void visitBuiltinFixedArrayType(BuiltinFixedArrayType *T,

lib/AST/Builtins.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Type swift::getBuiltinType(ASTContext &Context, StringRef Name) {
8383
.Case("Word", BuiltinTypeKind::BuiltinInteger)
8484
.Case("IntLiteral", BuiltinTypeKind::BuiltinIntegerLiteral)
8585
.StartsWith("Int", BuiltinTypeKind::BuiltinInteger)
86+
.Case("ImplicitActor", BuiltinTypeKind::BuiltinImplicitActor)
8687
.Default({});
8788

8889
// Handle types that are not BuiltinTypeKinds.
@@ -175,6 +176,8 @@ Type swift::getBuiltinType(ASTContext &Context, StringRef Name) {
175176
return Context.TheIntegerLiteralType;
176177
case BuiltinTypeKind::BuiltinUnboundGeneric:
177178
return Type();
179+
case BuiltinTypeKind::BuiltinImplicitActor:
180+
return Context.TheImplicitActorType;
178181
}
179182

180183
return Type();
@@ -3489,6 +3492,7 @@ bool BuiltinType::isBitwiseCopyable() const {
34893492
return true;
34903493
case BuiltinTypeKind::BuiltinNativeObject:
34913494
case BuiltinTypeKind::BuiltinBridgeObject:
3495+
case BuiltinTypeKind::BuiltinImplicitActor:
34923496
case BuiltinTypeKind::BuiltinUnsafeValueBuffer:
34933497
case BuiltinTypeKind::BuiltinDefaultActorStorage:
34943498
case BuiltinTypeKind::BuiltinNonDefaultDistributedActorStorage:
@@ -3544,6 +3548,9 @@ StringRef BuiltinType::getTypeName(SmallVectorImpl<char> &result,
35443548
case BuiltinTypeKind::BuiltinBridgeObject:
35453549
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_BRIDGEOBJECT);
35463550
break;
3551+
case BuiltinTypeKind::BuiltinImplicitActor:
3552+
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_IMPLICITACTOR);
3553+
break;
35473554
case BuiltinTypeKind::BuiltinUnsafeValueBuffer:
35483555
printer << MAYBE_GET_NAMESPACED_BUILTIN(
35493556
BUILTIN_TYPE_NAME_UNSAFEVALUEBUFFER);

0 commit comments

Comments
 (0)