mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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 2fa3908e94)
Conflicts:
lib/AST/ASTPrinter.cpp
lib/IRGen/IRGenModule.cpp
This commit is contained in:
@@ -144,7 +144,8 @@ ABSTRACT_TYPE(Builtin, Type)
|
||||
BUILTIN_CONCRETE_TYPE(BuiltinVector, BuiltinType)
|
||||
BUILTIN_GENERIC_TYPE(BuiltinFixedArray, BuiltinType)
|
||||
BUILTIN_CONCRETE_TYPE(BuiltinUnboundGeneric, BuiltinType)
|
||||
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinUnboundGeneric)
|
||||
BUILTIN_CONCRETE_TYPE(BuiltinImplicitActor, BuiltinType)
|
||||
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinImplicitActor)
|
||||
TYPE(Tuple, Type)
|
||||
ABSTRACT_TYPE(ReferenceStorage, Type)
|
||||
#define REF_STORAGE(Name, ...) \
|
||||
@@ -234,6 +235,7 @@ SINGLETON_TYPE(RawPointer, BuiltinRawPointer)
|
||||
SINGLETON_TYPE(RawUnsafeContinuation, BuiltinRawUnsafeContinuation)
|
||||
SINGLETON_TYPE(NativeObject, BuiltinNativeObject)
|
||||
SINGLETON_TYPE(BridgeObject, BuiltinBridgeObject)
|
||||
SINGLETON_TYPE(ImplicitActor, BuiltinImplicitActor)
|
||||
SINGLETON_TYPE(UnsafeValueBuffer, BuiltinUnsafeValueBuffer)
|
||||
SINGLETON_TYPE(DefaultActorStorage, BuiltinDefaultActorStorage)
|
||||
SINGLETON_TYPE(NonDefaultDistributedActorStorage, BuiltinNonDefaultDistributedActorStorage)
|
||||
|
||||
@@ -988,6 +988,13 @@ public:
|
||||
/// Determines whether this type is an any actor type.
|
||||
bool isAnyActorType();
|
||||
|
||||
/// Is this a type whose value is a value that a function can use in an
|
||||
/// isolated parameter position. This could be a type that actually conforms
|
||||
/// to AnyActor or it could be a type like any Actor, Optional<any Actor> or
|
||||
/// Builtin.ImplicitActor that do not conform to Actor but from which we can
|
||||
/// derive a value that conforms to the Actor protocol.
|
||||
bool canBeIsolatedTo();
|
||||
|
||||
/// Returns true if this type conforms to Sendable, or if its a function type
|
||||
/// that is @Sendable.
|
||||
bool isSendableType();
|
||||
@@ -1999,6 +2006,19 @@ BEGIN_CAN_TYPE_WRAPPER(BuiltinVectorType, BuiltinType)
|
||||
PROXY_CAN_TYPE_SIMPLE_GETTER(getElementType)
|
||||
END_CAN_TYPE_WRAPPER(BuiltinVectorType, BuiltinType)
|
||||
|
||||
class BuiltinImplicitActorType : public BuiltinType {
|
||||
friend class ASTContext;
|
||||
|
||||
BuiltinImplicitActorType(const ASTContext &context)
|
||||
: BuiltinType(TypeKind::BuiltinImplicitActor, context) {}
|
||||
|
||||
public:
|
||||
static bool classof(const TypeBase *T) {
|
||||
return T->getKind() == TypeKind::BuiltinImplicitActor;
|
||||
}
|
||||
};
|
||||
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinImplicitActorType, BuiltinType)
|
||||
|
||||
/// Size descriptor for a builtin integer type. This is either a fixed bit
|
||||
/// width or an abstract target-dependent value such as "size of a pointer".
|
||||
class BuiltinIntegerWidth {
|
||||
|
||||
@@ -2331,6 +2331,13 @@ public:
|
||||
getSILDebugLocation(Loc), Operand, Kind));
|
||||
}
|
||||
|
||||
SILValue emitUncheckedOwnershipConversion(SILLocation Loc, SILValue Operand,
|
||||
ValueOwnershipKind Kind) {
|
||||
if (!hasOwnership())
|
||||
return Operand;
|
||||
return createUncheckedOwnershipConversion(Loc, Operand, Kind);
|
||||
}
|
||||
|
||||
FixLifetimeInst *createFixLifetime(SILLocation Loc, SILValue Operand) {
|
||||
return insert(new (getModule())
|
||||
FixLifetimeInst(getSILDebugLocation(Loc), Operand));
|
||||
@@ -2350,6 +2357,18 @@ public:
|
||||
dependenceKind);
|
||||
}
|
||||
|
||||
/// Emit a mark_dependence instruction placing the kind only if ownership is
|
||||
/// set in the current function.
|
||||
///
|
||||
/// This is intended to be used in code that is generic over Ownership SSA and
|
||||
/// non-Ownership SSA code.
|
||||
SILValue emitMarkDependence(SILLocation Loc, SILValue value, SILValue base,
|
||||
MarkDependenceKind dependenceKind) {
|
||||
return createMarkDependence(Loc, value, base, value->getOwnershipKind(),
|
||||
hasOwnership() ? dependenceKind
|
||||
: MarkDependenceKind::Escaping);
|
||||
}
|
||||
|
||||
MarkDependenceInst *
|
||||
createMarkDependence(SILLocation Loc, SILValue value, SILValue base,
|
||||
ValueOwnershipKind forwardingOwnershipKind,
|
||||
|
||||
@@ -266,6 +266,8 @@ public:
|
||||
|
||||
bool isBuiltinBridgeObject() const { return is<BuiltinBridgeObjectType>(); }
|
||||
|
||||
bool isBuiltinImplicitActor() const { return is<BuiltinImplicitActorType>(); }
|
||||
|
||||
SILType getBuiltinVectorElementType() const {
|
||||
auto vector = castTo<BuiltinVectorType>();
|
||||
return getPrimitiveObjectType(vector.getElementType());
|
||||
@@ -957,6 +959,13 @@ public:
|
||||
/// Returns true if this type is an actor or a distributed actor.
|
||||
bool isAnyActor() const { return getASTType()->isAnyActorType(); }
|
||||
|
||||
/// Is this a type whose value is a value that a function can use in an
|
||||
/// isolated parameter position. This could be a type that actually conforms
|
||||
/// to AnyActor or it could be a type like any Actor, Optional<any Actor> or
|
||||
/// Builtin.ImplicitActor that do not conform to Actor but from which we can
|
||||
/// derive a value that conforms to the Actor protocol.
|
||||
bool canBeIsolatedTo() const { return getASTType()->canBeIsolatedTo(); }
|
||||
|
||||
/// Returns true if this function conforms to the Sendable protocol.
|
||||
///
|
||||
/// NOTE: For diagnostics this is not always the correct thing to check since
|
||||
@@ -1022,9 +1031,29 @@ public:
|
||||
/// Return '()'
|
||||
static SILType getEmptyTupleType(const ASTContext &C);
|
||||
|
||||
/// Return (elementTypes) with control of category.
|
||||
static SILType getTupleType(const ASTContext &ctx,
|
||||
ArrayRef<SILType> elementTypes,
|
||||
SILValueCategory category);
|
||||
|
||||
/// Return $(elementTypes)
|
||||
static SILType getTupleObjectType(const ASTContext &ctx,
|
||||
ArrayRef<SILType> elementTypes) {
|
||||
return getTupleType(ctx, elementTypes, SILValueCategory::Object);
|
||||
}
|
||||
|
||||
/// Return $*(elementTypes)
|
||||
static SILType getTupleAddressType(const ASTContext &ctx,
|
||||
ArrayRef<SILType> elementTypes) {
|
||||
return getTupleType(ctx, elementTypes, SILValueCategory::Address);
|
||||
}
|
||||
|
||||
/// Get the type for opaque actor isolation values.
|
||||
static SILType getOpaqueIsolationType(const ASTContext &C);
|
||||
|
||||
/// Return Builtin.ImplicitActor.
|
||||
static SILType getBuiltinImplicitActorType(const ASTContext &ctx);
|
||||
|
||||
//
|
||||
// Utilities for treating SILType as a pointer-like type.
|
||||
//
|
||||
|
||||
@@ -144,6 +144,8 @@ constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_NATIVEOBJECT = {
|
||||
/// The name of the Builtin type for BridgeObject
|
||||
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_BRIDGEOBJECT = {
|
||||
"Builtin.BridgeObject"};
|
||||
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_IMPLICITACTOR = {
|
||||
"Builtin.ImplicitActor"};
|
||||
/// The name of the Builtin type for RawPointer
|
||||
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_RAWPOINTER = {
|
||||
"Builtin.RawPointer"};
|
||||
|
||||
Reference in New Issue
Block a user