Skip to content

[concurrency] Change #isolated to mask out the TBI bits of the witness pointer of the implicit isolated any Actor pointer so we can do optimizations on TBI supporting platforms in the future. #83346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/swift/AST/TypeNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -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(BuiltinImplicitIsolationActor, BuiltinType)
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinImplicitIsolationActor)
TYPE(Tuple, Type)
ABSTRACT_TYPE(ReferenceStorage, Type)
#define REF_STORAGE(Name, ...) \
Expand Down Expand Up @@ -234,6 +235,7 @@ SINGLETON_TYPE(RawPointer, BuiltinRawPointer)
SINGLETON_TYPE(RawUnsafeContinuation, BuiltinRawUnsafeContinuation)
SINGLETON_TYPE(NativeObject, BuiltinNativeObject)
SINGLETON_TYPE(BridgeObject, BuiltinBridgeObject)
SINGLETON_TYPE(ImplicitIsolationActor, BuiltinImplicitIsolationActor)
SINGLETON_TYPE(UnsafeValueBuffer, BuiltinUnsafeValueBuffer)
SINGLETON_TYPE(DefaultActorStorage, BuiltinDefaultActorStorage)
SINGLETON_TYPE(NonDefaultDistributedActorStorage, BuiltinNonDefaultDistributedActorStorage)
Expand Down
13 changes: 13 additions & 0 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,19 @@ BEGIN_CAN_TYPE_WRAPPER(BuiltinVectorType, BuiltinType)
PROXY_CAN_TYPE_SIMPLE_GETTER(getElementType)
END_CAN_TYPE_WRAPPER(BuiltinVectorType, BuiltinType)

class BuiltinImplicitIsolationActorType : public BuiltinType {
friend class ASTContext;

BuiltinImplicitIsolationActorType(const ASTContext &context)
: BuiltinType(TypeKind::BuiltinImplicitIsolationActor, context) {}

public:
static bool classof(const TypeBase *T) {
return T->getKind() == TypeKind::BuiltinImplicitIsolationActor;
}
};
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinImplicitIsolationActorType, 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 {
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,9 @@ namespace swift {
bool RestrictNonProductionExperimentalFeatures = false;
#endif

/// Set to true if we support AArch64TBI.
bool HasAArch64TBI = false;

bool isConcurrencyModelTaskToThread() const {
return ActiveConcurrencyModel == ConcurrencyModel::TaskToThread;
}
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class CompilerInvocation {
/// C++ stdlib is the default for the specified target.
void computeCXXStdlibOptions();

/// Compute whether or not we support aarch64TBI
void computeAArch64TBIOptions();

/// Computes the runtime resource path relative to the given Swift
/// executable.
static void computeRuntimeResourcePathFromExecutablePath(
Expand Down
40 changes: 40 additions & 0 deletions include/swift/SIL/ConcurrencyUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===--- ConcurrencyUtils.h -----------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_SIL_CONCURRENCYUTILS_H
#define SWIFT_SIL_CONCURRENCYUTILS_H

#include "swift/SIL/SILType.h"

namespace swift {

class SILValue;
class SILBuilder;
class SILLocation;

/// Clear the implicit isolated bits of value.
///
/// \p value must be Builtin.ImplicitIsolationActor
///
/// \p finalType if empty, we always return
/// Builtin.ImplicitIsolationActor. Otherwise we bitcast to finalType after
/// tieing the lifetime of the result to \p value.
SILValue clearImplicitIsolationActorBits(SILBuilder &b, SILLocation loc,
SILValue value,
SILType finalType = {});

SILValue setImplicitIsolationActorBits(SILBuilder &b, SILLocation loc,
SILValue value);

} // namespace swift

#endif
30 changes: 30 additions & 0 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,17 @@ class SILBuilder {
forwardingOwnershipKind));
}

/// Create an unchecked_value_cast when Ownership SSA is enabled and
/// unchecked_bitwise_cast otherwise.
///
/// Intended to be used in utility code that needs to support both Ownership
/// SSA and non-Ownership SSA code.
SILValue emitUncheckedValueCast(SILLocation loc, SILValue op, SILType ty) {
if (hasOwnership())
return createUncheckedValueCast(loc, op, ty);
return createUncheckedBitwiseCast(loc, op, ty);
}

RefToBridgeObjectInst *createRefToBridgeObject(SILLocation Loc, SILValue Ref,
SILValue Bits) {
return createRefToBridgeObject(Loc, Ref, Bits, Ref->getOwnershipKind());
Expand Down Expand Up @@ -2338,6 +2349,13 @@ class SILBuilder {
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));
Expand All @@ -2357,6 +2375,18 @@ class SILBuilder {
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,
Expand Down
11 changes: 11 additions & 0 deletions include/swift/SIL/SILType.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ class SILType {

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

bool isBuiltinImplicitIsolationActor() const {
return is<BuiltinImplicitIsolationActorType>();
}

SILType getBuiltinVectorElementType() const {
auto vector = castTo<BuiltinVectorType>();
return getPrimitiveObjectType(vector.getElementType());
Expand Down Expand Up @@ -1025,9 +1029,16 @@ class SILType {
/// Return '()'
static SILType getEmptyTupleType(const ASTContext &C);

/// Return (elementTypes).
static SILType getTupleType(const ASTContext &ctx,
ArrayRef<SILType> elementTypes);

/// Get the type for opaque actor isolation values.
static SILType getOpaqueIsolationType(const ASTContext &C);

/// Return Builtin.ImplicitIsolationActor.
static SILType getBuiltinImplicitIsolationActorType(const ASTContext &ctx);

//
// Utilities for treating SILType as a pointer-like type.
//
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ 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_IMPLICITISOLATIONACTOR = {
"Builtin.ImplicitIsolationActor"};
/// The name of the Builtin type for RawPointer
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_RAWPOINTER = {
"Builtin.RawPointer"};
Expand Down
2 changes: 2 additions & 0 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6109,6 +6109,8 @@ namespace {
TRIVIAL_TYPE_PRINTER(BuiltinRawUnsafeContinuation, builtin_raw_unsafe_continuation)
TRIVIAL_TYPE_PRINTER(BuiltinNativeObject, builtin_native_object)
TRIVIAL_TYPE_PRINTER(BuiltinBridgeObject, builtin_bridge_object)
TRIVIAL_TYPE_PRINTER(BuiltinImplicitIsolationActor,
builtin_implicit_isolated_actor)
TRIVIAL_TYPE_PRINTER(BuiltinUnsafeValueBuffer, builtin_unsafe_value_buffer)
TRIVIAL_TYPE_PRINTER(SILToken, sil_token)

Expand Down
2 changes: 2 additions & 0 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,8 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
auto loc = cast<LocatableType>(tybase);
return appendType(loc->getSinglyDesugaredType(), sig, forDecl);
}
case TypeKind::BuiltinImplicitIsolationActor:
return appendOperator("BA");
case TypeKind::BuiltinFixedArray: {
auto bfa = cast<BuiltinFixedArrayType>(tybase);
appendType(bfa->getSize(), sig, forDecl);
Expand Down
1 change: 1 addition & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6156,6 +6156,7 @@ class TypePrinter : public TypeVisitor<TypePrinter, void, NonRecursivePrintOptio
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinIntegerType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinFloatType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinUnboundGenericType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinImplicitIsolationActorType)
#undef ASTPRINTER_PRINT_BUILTINTYPE

void visitBuiltinFixedArrayType(BuiltinFixedArrayType *T,
Expand Down
Loading