Skip to content

Commit c6314a3

Browse files
authored
Merge pull request #84986 from gottesmm/release/6.2-rdar156525771
[6.2] Add support for TBI masking optimization for nonisolated(nonsending)
2 parents de48c2f + 8e3fa55 commit c6314a3

File tree

104 files changed

+2039
-866
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+2039
-866
lines changed

SwiftCompilerSources/Sources/SIL/ForwardingInstruction.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,12 @@ extension BorrowedFromInst: ForwardingInstruction {
462462
public var canForwardOwnedValues: Bool { false }
463463
}
464464

465+
extension ImplicitActorToOpaqueIsolationCastInst: ConversionInstruction {
466+
public var preservesRepresentation: Bool { true }
467+
public var canForwardGuaranteedValues: Bool { true }
468+
public var canForwardOwnedValues: Bool { false }
469+
}
470+
465471
// -----------------------------------------------------------------------------
466472
// ownership transition instructions
467473

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,3 +1892,6 @@ final public class MergeIsolationRegionInst : Instruction {
18921892

18931893
final public class IgnoredUseInst : Instruction, UnaryInstruction {
18941894
}
1895+
1896+
final public class ImplicitActorToOpaqueIsolationCastInst
1897+
: SingleValueInstruction, UnaryInstruction {}

SwiftCompilerSources/Sources/SIL/Registration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,5 @@ public func registerSILClasses() {
260260
register(ThunkInst.self)
261261
register(MergeIsolationRegionInst.self)
262262
register(IgnoredUseInst.self)
263+
register(ImplicitActorToOpaqueIsolationCastInst.self)
263264
}

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

docs/SIL/Instructions.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4535,6 +4535,9 @@ copy.
45354535
The resulting value must meet the usual ownership requirements; for
45364536
example, a trivial type must have '.none' ownership.
45374537

4538+
NOTE: A guaranteed result value is assumed to be a non-dependent guaranteed
4539+
value like a function argument.
4540+
45384541
### ref_to_raw_pointer
45394542

45404543
```
@@ -4851,6 +4854,27 @@ TODO
48514854

48524855
TODO
48534856

4857+
### cast_implicitactor_to_opaqueisolation
4858+
4859+
```
4860+
sil-instruction ::= 'cast_implicitactor_to_opaqueisolation' sil-operand
4861+
4862+
%1 = cast_implicitactor_to_opaqueisolation %0 : $Builtin.ImplicitActor
4863+
// %0 must have guaranteed ownership
4864+
// %1 must have guaranteed ownership
4865+
// %1 will have type $Optional<any Actor>
4866+
```
4867+
4868+
Convert a `$Builtin.ImplicitActor` to a `$Optional<any Actor>` masking out any
4869+
bits that we have stolen from the witness table pointer.
4870+
4871+
At IRGen time, we lower this to the relevant masking operations, allowing us to
4872+
avoid exposing these low level details to the SIL optimizer. On platforms where
4873+
we support TBI, IRGen uses a mask that is the bottom 2 bits of the top nibble of
4874+
the pointer. On 64 bit platforms this is bit 60,61. If the platform does not
4875+
support TBI, then IRGen uses the bottom two tagged pointer bits of the pointer
4876+
(bits 0,1).
4877+
48544878
## Checked Conversions
48554879

48564880
Some user-level cast operations can fail and thus require runtime

include/swift/AST/DiagnosticsParse.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,12 @@ ERROR(sil_operand_has_incorrect_moveonlywrapped,none,
614614
ERROR(sil_operand_not_ref_storage_address,none,
615615
"%0 operand of '%1' must have address of %2 type",
616616
(StringRef, StringRef, ReferenceOwnership))
617+
ERROR(sil_operand_has_wrong_ownership_kind,none,
618+
"operand has ownership kind %0 but ownership kind %1 was expected",
619+
(StringRef, StringRef))
620+
ERROR(sil_operand_has_incompatible_ownership_kind,none,
621+
"operand has ownership kind %0 but ownership kind compatible with %1 was expected",
622+
(StringRef, StringRef))
617623
ERROR(sil_integer_literal_not_integer_type,none,
618624
"integer_literal instruction requires a 'Builtin.Int<n>' type", ())
619625
ERROR(sil_integer_literal_not_well_formed,none,

include/swift/AST/IRGenOptions.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,9 @@ class IRGenOptions {
604604
/// Paths to the pass plugins registered via -load-pass-plugin.
605605
std::vector<std::string> LLVMPassPlugins;
606606

607+
/// Set to true if we support AArch64TBI.
608+
bool HasAArch64TBI = false;
609+
607610
IRGenOptions()
608611
: OutputKind(IRGenOutputKind::LLVMAssemblyAfterOptimization),
609612
Verify(true), VerifyEach(false), OptMode(OptimizationMode::NotSet),
@@ -649,13 +652,12 @@ class IRGenOptions {
649652
UseFragileResilientProtocolWitnesses(false), EnableHotColdSplit(false),
650653
EmitAsyncFramePushPopMetadata(true), EmitTypeMallocForCoroFrame(true),
651654
AsyncFramePointerAll(false), UseProfilingMarkerThunks(false),
652-
UseCoroCCX8664(false), UseCoroCCArm64(false),
653-
MergeableTraps(false),
655+
UseCoroCCX8664(false), UseCoroCCArm64(false), MergeableTraps(false),
654656
DebugInfoForProfiling(false), CmdArgs(),
655657
SanitizeCoverage(llvm::SanitizerCoverageOptions()),
656658
TypeInfoFilter(TypeInfoDumpFilter::All),
657659
PlatformCCallingConvention(llvm::CallingConv::C), UseCASBackend(false),
658-
CASObjMode(llvm::CASBackendMode::Native) {
660+
CASObjMode(llvm::CASBackendMode::Native), HasAArch64TBI(false) {
659661
DisableRoundTripDebugTypes = !CONDITIONAL_ASSERT_enabled();
660662
}
661663

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/Frontend/Frontend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ class CompilerInvocation {
274274
/// C++ stdlib is the default for the specified target.
275275
void computeCXXStdlibOptions();
276276

277+
/// Compute whether or not we support aarch64TBI
278+
void computeAArch64TBIOptions();
279+
277280
/// Computes the runtime resource path relative to the given Swift
278281
/// executable.
279282
static void computeRuntimeResourcePathFromExecutablePath(

0 commit comments

Comments
 (0)