Skip to content

Commit a4dca25

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>. (cherry picked from commit 2fa3908) Conflicts: lib/AST/ASTPrinter.cpp lib/IRGen/IRGenModule.cpp
1 parent bf524c4 commit a4dca25

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
@@ -701,6 +701,9 @@ Types
701701
type ::= type 'Bv' NATURAL '_' // Builtin.Vec<n>x<type>
702702
type ::= type type 'BV' // Builtin.FixedArray<N, T>
703703
type ::= 'Bw' // Builtin.Word
704+
#if SWIFT_RUNTIME_VERSION >= 6.2
705+
type ::= 'BA' // Builtin.ImplicitActor
706+
#endif
704707
type ::= function-signature 'c' // function type (escaping)
705708
type ::= function-signature 'X' FUNCTION-KIND // special function type
706709
type ::= bound-generic-type

include/swift/AST/TypeNodes.def

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

include/swift/AST/Types.h

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

991+
/// Is this a type whose value is a value that a function can use in an
992+
/// isolated parameter position. This could be a type that actually conforms
993+
/// to AnyActor or it could be a type like any Actor, Optional<any Actor> or
994+
/// Builtin.ImplicitActor that do not conform to Actor but from which we can
995+
/// derive a value that conforms to the Actor protocol.
996+
bool canBeIsolatedTo();
997+
991998
/// Returns true if this type conforms to Sendable, or if its a function type
992999
/// that is @Sendable.
9931000
bool isSendableType();
@@ -1999,6 +2006,19 @@ BEGIN_CAN_TYPE_WRAPPER(BuiltinVectorType, BuiltinType)
19992006
PROXY_CAN_TYPE_SIMPLE_GETTER(getElementType)
20002007
END_CAN_TYPE_WRAPPER(BuiltinVectorType, BuiltinType)
20012008

2009+
class BuiltinImplicitActorType : public BuiltinType {
2010+
friend class ASTContext;
2011+
2012+
BuiltinImplicitActorType(const ASTContext &context)
2013+
: BuiltinType(TypeKind::BuiltinImplicitActor, context) {}
2014+
2015+
public:
2016+
static bool classof(const TypeBase *T) {
2017+
return T->getKind() == TypeKind::BuiltinImplicitActor;
2018+
}
2019+
};
2020+
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinImplicitActorType, BuiltinType)
2021+
20022022
/// Size descriptor for a builtin integer type. This is either a fixed bit
20032023
/// width or an abstract target-dependent value such as "size of a pointer".
20042024
class BuiltinIntegerWidth {

include/swift/SIL/SILBuilder.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,13 @@ class SILBuilder {
23312331
getSILDebugLocation(Loc), Operand, Kind));
23322332
}
23332333

2334+
SILValue emitUncheckedOwnershipConversion(SILLocation Loc, SILValue Operand,
2335+
ValueOwnershipKind Kind) {
2336+
if (!hasOwnership())
2337+
return Operand;
2338+
return createUncheckedOwnershipConversion(Loc, Operand, Kind);
2339+
}
2340+
23342341
FixLifetimeInst *createFixLifetime(SILLocation Loc, SILValue Operand) {
23352342
return insert(new (getModule())
23362343
FixLifetimeInst(getSILDebugLocation(Loc), Operand));
@@ -2350,6 +2357,18 @@ class SILBuilder {
23502357
dependenceKind);
23512358
}
23522359

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

include/swift/SIL/SILType.h

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

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

269+
bool isBuiltinImplicitActor() const { return is<BuiltinImplicitActorType>(); }
270+
269271
SILType getBuiltinVectorElementType() const {
270272
auto vector = castTo<BuiltinVectorType>();
271273
return getPrimitiveObjectType(vector.getElementType());
@@ -957,6 +959,13 @@ class SILType {
957959
/// Returns true if this type is an actor or a distributed actor.
958960
bool isAnyActor() const { return getASTType()->isAnyActorType(); }
959961

962+
/// Is this a type whose value is a value that a function can use in an
963+
/// isolated parameter position. This could be a type that actually conforms
964+
/// to AnyActor or it could be a type like any Actor, Optional<any Actor> or
965+
/// Builtin.ImplicitActor that do not conform to Actor but from which we can
966+
/// derive a value that conforms to the Actor protocol.
967+
bool canBeIsolatedTo() const { return getASTType()->canBeIsolatedTo(); }
968+
960969
/// Returns true if this function conforms to the Sendable protocol.
961970
///
962971
/// NOTE: For diagnostics this is not always the correct thing to check since
@@ -1022,9 +1031,29 @@ class SILType {
10221031
/// Return '()'
10231032
static SILType getEmptyTupleType(const ASTContext &C);
10241033

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

1054+
/// Return Builtin.ImplicitActor.
1055+
static SILType getBuiltinImplicitActorType(const ASTContext &ctx);
1056+
10281057
//
10291058
// Utilities for treating SILType as a pointer-like type.
10301059
//

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
@@ -6102,6 +6102,7 @@ namespace {
61026102
TRIVIAL_TYPE_PRINTER(BuiltinRawUnsafeContinuation, builtin_raw_unsafe_continuation)
61036103
TRIVIAL_TYPE_PRINTER(BuiltinNativeObject, builtin_native_object)
61046104
TRIVIAL_TYPE_PRINTER(BuiltinBridgeObject, builtin_bridge_object)
6105+
TRIVIAL_TYPE_PRINTER(BuiltinImplicitActor, builtin_implicit_isolated_actor)
61056106
TRIVIAL_TYPE_PRINTER(BuiltinUnsafeValueBuffer, builtin_unsafe_value_buffer)
61066107
TRIVIAL_TYPE_PRINTER(SILToken, sil_token)
61076108

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,8 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
14591459
auto loc = cast<LocatableType>(tybase);
14601460
return appendType(loc->getSinglyDesugaredType(), sig, forDecl);
14611461
}
1462+
case TypeKind::BuiltinImplicitActor:
1463+
return appendOperator("BA");
14621464
case TypeKind::BuiltinFixedArray: {
14631465
auto bfa = cast<BuiltinFixedArrayType>(tybase);
14641466
appendType(bfa->getSize(), sig, forDecl);

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6228,6 +6228,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
62286228
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinFloatType)
62296229
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinUnboundGenericType)
62306230
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinFixedArrayType)
6231+
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinImplicitActorType)
62316232
#undef ASTPRINTER_PRINT_BUILTINTYPE
62326233

62336234
void visitSILTokenType(SILTokenType *T) {

lib/AST/Builtins.cpp

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

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

179182
return Type();
@@ -3463,6 +3466,7 @@ bool BuiltinType::isBitwiseCopyable() const {
34633466
return true;
34643467
case BuiltinTypeKind::BuiltinNativeObject:
34653468
case BuiltinTypeKind::BuiltinBridgeObject:
3469+
case BuiltinTypeKind::BuiltinImplicitActor:
34663470
case BuiltinTypeKind::BuiltinUnsafeValueBuffer:
34673471
case BuiltinTypeKind::BuiltinDefaultActorStorage:
34683472
case BuiltinTypeKind::BuiltinNonDefaultDistributedActorStorage:
@@ -3518,6 +3522,9 @@ StringRef BuiltinType::getTypeName(SmallVectorImpl<char> &result,
35183522
case BuiltinTypeKind::BuiltinBridgeObject:
35193523
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_BRIDGEOBJECT);
35203524
break;
3525+
case BuiltinTypeKind::BuiltinImplicitActor:
3526+
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_IMPLICITACTOR);
3527+
break;
35213528
case BuiltinTypeKind::BuiltinUnsafeValueBuffer:
35223529
printer << MAYBE_GET_NAMESPACED_BUILTIN(
35233530
BUILTIN_TYPE_NAME_UNSAFEVALUEBUFFER);

0 commit comments

Comments
 (0)