Skip to content

Commit d68d406

Browse files
authored
Merge pull request swiftlang#35094 from rjmccall/actor-dynamic-layout
Do dynamic layout of generic/resilient default actors properly
2 parents b7be6ce + bad16fd commit d68d406

29 files changed

+511
-115
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ Types
493493
type ::= 'Bb' // Builtin.BridgeObject
494494
type ::= 'BB' // Builtin.UnsafeValueBuffer
495495
type ::= 'Bc' // Builtin.RawUnsafeContinuation
496+
type ::= 'BD' // Builtin.DefaultActorStorage
496497
type ::= 'Bf' NATURAL '_' // Builtin.Float<n>
497498
type ::= 'Bi' NATURAL '_' // Builtin.Int<n>
498499
type ::= 'BI' // Builtin.IntLiteral

include/swift/AST/TypeNodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ ABSTRACT_TYPE(Builtin, Type)
110110
BUILTIN_TYPE(BuiltinNativeObject, BuiltinType)
111111
BUILTIN_TYPE(BuiltinBridgeObject, BuiltinType)
112112
BUILTIN_TYPE(BuiltinUnsafeValueBuffer, BuiltinType)
113+
BUILTIN_TYPE(BuiltinDefaultActorStorage, BuiltinType)
113114
BUILTIN_TYPE(BuiltinVector, BuiltinType)
114115
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinVector)
115116
TYPE(Tuple, Type)
@@ -185,6 +186,7 @@ SINGLETON_TYPE(RawUnsafeContinuation, BuiltinRawUnsafeContinuation)
185186
SINGLETON_TYPE(NativeObject, BuiltinNativeObject)
186187
SINGLETON_TYPE(BridgeObject, BuiltinBridgeObject)
187188
SINGLETON_TYPE(UnsafeValueBuffer, BuiltinUnsafeValueBuffer)
189+
SINGLETON_TYPE(DefaultActorStorage, BuiltinDefaultActorStorage)
188190
SINGLETON_TYPE(SILToken, SILToken)
189191
#undef SINGLETON_TYPE
190192
#endif

include/swift/AST/Types.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,22 @@ class BuiltinJobType : public BuiltinType {
14201420
};
14211421
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinJobType, BuiltinType);
14221422

1423+
/// BuiltinDefaultActorStorageType - The type of the stored property
1424+
/// that's added implicitly to default actors. No C equivalent because
1425+
/// the C types all include a heap-object header. Similarly, this type
1426+
/// generally does not appear in the AST/SIL around default actors;
1427+
/// it's purely a convenience in IRGen.
1428+
class BuiltinDefaultActorStorageType : public BuiltinType {
1429+
friend class ASTContext;
1430+
BuiltinDefaultActorStorageType(const ASTContext &C)
1431+
: BuiltinType(TypeKind::BuiltinDefaultActorStorage, C) {}
1432+
public:
1433+
static bool classof(const TypeBase *T) {
1434+
return T->getKind() == TypeKind::BuiltinDefaultActorStorage;
1435+
}
1436+
};
1437+
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinDefaultActorStorageType, BuiltinType);
1438+
14231439
/// BuiltinNativeObjectType - The builtin opaque object-pointer type.
14241440
/// Useful for keeping an object alive when it is otherwise being
14251441
/// manipulated via an unsafe pointer type.

include/swift/Reflection/Records.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class FieldRecordFlags {
3737

3838
// Is this a mutable `var` property?
3939
IsVar = 0x2,
40+
41+
// Is this an artificial field?
42+
IsArtificial = 0x4,
4043
};
4144
int_type Data = 0;
4245

@@ -49,6 +52,10 @@ class FieldRecordFlags {
4952
return (Data & IsVar) == IsVar;
5053
}
5154

55+
bool isArtificial() const {
56+
return (Data & IsArtificial) == IsArtificial;
57+
}
58+
5259
void setIsIndirectCase(bool IndirectCase=true) {
5360
if (IndirectCase)
5461
Data |= IsIndirectCase;
@@ -63,6 +70,13 @@ class FieldRecordFlags {
6370
Data &= ~IsVar;
6471
}
6572

73+
void setIsArtificial(bool artificial=true) {
74+
if (artificial)
75+
Data |= IsArtificial;
76+
else
77+
Data &= ~IsArtificial;
78+
}
79+
6680
int_type getRawValue() const {
6781
return Data;
6882
}

include/swift/Strings.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ constexpr static const StringLiteral CXX_TEMPLATE_INST_PREFIX =
4747
constexpr static const StringLiteral SEMANTICS_PROGRAMTERMINATION_POINT =
4848
"programtermination_point";
4949

50+
constexpr static const StringLiteral DEFAULT_ACTOR_STORAGE_FIELD_NAME =
51+
"$defaultActor";
52+
5053
/// The name of the Builtin type prefix
5154
constexpr static const StringLiteral BUILTIN_TYPE_NAME_PREFIX = "Builtin.";
5255

@@ -119,6 +122,9 @@ constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_UNSAFEVALUEBUFFER =
119122
/// The name of the Builtin type for Job
120123
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_JOB = {
121124
"Builtin.Job"};
125+
/// The name of the Builtin type for DefaultActorStorage
126+
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_DEFAULTACTORSTORAGE = {
127+
"Builtin.DefaultActorStorage"};
122128
/// The name of the Builtin type for UnknownObject
123129
///
124130
/// This no longer exists as an AST-accessible type, but it's still used for

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,6 +3561,7 @@ namespace {
35613561

35623562
TRIVIAL_TYPE_PRINTER(BuiltinIntegerLiteral, builtin_integer_literal)
35633563
TRIVIAL_TYPE_PRINTER(BuiltinJob, builtin_job)
3564+
TRIVIAL_TYPE_PRINTER(BuiltinDefaultActorStorage, builtin_default_actor_storage)
35643565
TRIVIAL_TYPE_PRINTER(BuiltinRawPointer, builtin_raw_pointer)
35653566
TRIVIAL_TYPE_PRINTER(BuiltinRawUnsafeContinuation, builtin_raw_unsafe_continuation)
35663567
TRIVIAL_TYPE_PRINTER(BuiltinNativeObject, builtin_native_object)

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,8 @@ void ASTMangler::appendType(Type type, const ValueDecl *forDecl) {
975975
return appendOperator("BI");
976976
case TypeKind::BuiltinJob:
977977
return appendOperator("Bj");
978+
case TypeKind::BuiltinDefaultActorStorage:
979+
return appendOperator("BD");
978980
case TypeKind::BuiltinRawPointer:
979981
return appendOperator("Bp");
980982
case TypeKind::BuiltinRawUnsafeContinuation:

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,6 +3946,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
39463946
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinRawPointerType)
39473947
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinRawUnsafeContinuationType)
39483948
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinJobType)
3949+
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinDefaultActorStorageType)
39493950
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinNativeObjectType)
39503951
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinBridgeObjectType)
39513952
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinUnsafeValueBufferType)

lib/AST/Builtins.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ Type swift::getBuiltinType(ASTContext &Context, StringRef Name) {
8383
return Context.TheRawUnsafeContinuationType;
8484
if (Name == "Job")
8585
return Context.TheJobType;
86+
if (Name == "DefaultActorStorage")
87+
return Context.TheDefaultActorStorageType;
8688
if (Name == "NativeObject")
8789
return Context.TheNativeObjectType;
8890
if (Name == "BridgeObject")
@@ -2733,6 +2735,9 @@ StringRef BuiltinType::getTypeName(SmallVectorImpl<char> &result,
27332735
case BuiltinTypeKind::BuiltinJob:
27342736
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_JOB);
27352737
break;
2738+
case BuiltinTypeKind::BuiltinDefaultActorStorage:
2739+
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_DEFAULTACTORSTORAGE);
2740+
break;
27362741
case BuiltinTypeKind::BuiltinNativeObject:
27372742
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_NATIVEOBJECT);
27382743
break;

lib/AST/Type.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ bool CanType::isReferenceTypeImpl(CanType type, const GenericSignatureImpl *sig,
210210
case TypeKind::BuiltinRawPointer:
211211
case TypeKind::BuiltinRawUnsafeContinuation:
212212
case TypeKind::BuiltinJob:
213+
case TypeKind::BuiltinDefaultActorStorage:
213214
case TypeKind::BuiltinUnsafeValueBuffer:
214215
case TypeKind::BuiltinVector:
215216
case TypeKind::Tuple:
@@ -5007,6 +5008,7 @@ ReferenceCounting TypeBase::getReferenceCounting() {
50075008
case TypeKind::BuiltinRawPointer:
50085009
case TypeKind::BuiltinRawUnsafeContinuation:
50095010
case TypeKind::BuiltinJob:
5011+
case TypeKind::BuiltinDefaultActorStorage:
50105012
case TypeKind::BuiltinUnsafeValueBuffer:
50115013
case TypeKind::BuiltinVector:
50125014
case TypeKind::Tuple:

0 commit comments

Comments
 (0)