Skip to content

Commit 38699bd

Browse files
committed
[RemoteInspection] Hardcode DefaultActorStorage's type info
No metadata is emitted for the builtin DefaultActorStorage type. Since its layout is fixed, hardcode its definition in Remote Mirrors. rdar://128032250 (cherry picked from commit 4417786)
1 parent 9fda132 commit 38699bd

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

include/swift/RemoteInspection/TypeLowering.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ class BuiltinTypeInfo : public TypeInfo {
184184
explicit BuiltinTypeInfo(TypeRefBuilder &builder,
185185
BuiltinTypeDescriptorBase &descriptor);
186186

187+
explicit BuiltinTypeInfo(unsigned Size, unsigned Alignment, unsigned Stride,
188+
unsigned NumExtraInhabitants, bool BitwiseTakable);
187189
/// Construct an empty builtin type info.
188190
BuiltinTypeInfo()
189191
: TypeInfo(TypeInfoKind::Builtin,
@@ -367,6 +369,7 @@ class TypeConverter {
367369
const TypeInfo *ThinFunctionTI = nullptr;
368370
const TypeInfo *ThickFunctionTI = nullptr;
369371
const TypeInfo *AnyMetatypeTI = nullptr;
372+
const TypeInfo *DefaultActorStorageTI = nullptr;
370373
const TypeInfo *EmptyTI = nullptr;
371374

372375
public:
@@ -424,6 +427,7 @@ class TypeConverter {
424427
const TypeInfo *getThinFunctionTypeInfo();
425428
const TypeInfo *getThickFunctionTypeInfo();
426429
const TypeInfo *getAnyMetatypeTypeInfo();
430+
const TypeInfo *getDefaultActorStorageTypeInfo();
427431
const TypeInfo *getEmptyTypeInfo();
428432

429433
template <typename TypeInfoTy, typename... Args>

stdlib/public/RemoteInspection/TypeLowering.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ BuiltinTypeInfo::BuiltinTypeInfo(TypeRefBuilder &builder,
243243
descriptor.IsBitwiseTakable),
244244
Name(descriptor.getMangledTypeName()) {}
245245

246+
BuiltinTypeInfo::BuiltinTypeInfo(unsigned Size, unsigned Alignment,
247+
unsigned Stride, unsigned NumExtraInhabitants,
248+
bool BitwiseTakable)
249+
: TypeInfo(TypeInfoKind::Builtin, Size, Alignment, Stride,
250+
NumExtraInhabitants, BitwiseTakable) {}
251+
246252
// Builtin.Int<N> is mangled as 'Bi' N '_'
247253
// Returns 0 if this isn't an Int
248254
static unsigned isIntType(std::string name) {
@@ -258,6 +264,7 @@ static unsigned isIntType(std::string name) {
258264
return 0;
259265
}
260266

267+
261268
bool BuiltinTypeInfo::readExtraInhabitantIndex(
262269
remote::MemoryReader &reader, remote::RemoteAddress address,
263270
int *extraInhabitantIndex) const {
@@ -1532,6 +1539,30 @@ TypeConverter::getAnyMetatypeTypeInfo() {
15321539
return AnyMetatypeTI;
15331540
}
15341541

1542+
const TypeInfo *TypeConverter::getDefaultActorStorageTypeInfo() {
1543+
if (DefaultActorStorageTI != nullptr)
1544+
return DefaultActorStorageTI;
1545+
1546+
// The default actor storage is an opaque fixed-size buffer. Use the raw
1547+
// pointer descriptor to find the word size and pointer alignment in the
1548+
// current platform.
1549+
auto descriptor =
1550+
getBuilder().getBuiltinTypeDescriptor(getRawPointerTypeRef());
1551+
if (descriptor == nullptr) {
1552+
DEBUG_LOG(fprintf(stderr, "No TypeInfo for default actor storage type\n"));
1553+
return nullptr;
1554+
}
1555+
1556+
auto size = descriptor->Size * NumWords_DefaultActor;
1557+
auto alignment = 2 * descriptor->Alignment;
1558+
1559+
DefaultActorStorageTI = makeTypeInfo<BuiltinTypeInfo>(
1560+
/*Size=*/size, /*Alignment*/ alignment, /*Stride=*/size,
1561+
/*NumExtraInhabitants*/ 0, /*BitwiseTakable*/ true);
1562+
1563+
return DefaultActorStorageTI;
1564+
}
1565+
15351566
const TypeInfo *TypeConverter::getEmptyTypeInfo() {
15361567
if (EmptyTI != nullptr)
15371568
return EmptyTI;
@@ -2156,6 +2187,8 @@ class LowerType
21562187
} else if (B->getMangledName() == "BO") {
21572188
return TC.getReferenceTypeInfo(ReferenceKind::Strong,
21582189
ReferenceCounting::Unknown);
2190+
} else if (B->getMangledName() == "BD") {
2191+
return TC.getDefaultActorStorageTypeInfo();
21592192
}
21602193

21612194
/// Otherwise, get the fixed layout information from reflection

test/Reflection/typeref_lowering.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,3 +1262,10 @@ BO
12621262
// CHECK-32-NEXT: (struct size=4 alignment=4 stride=4 num_extra_inhabitants=0 bitwise_takable=1
12631263
// CHECK-32-NEXT: (field name=_value offset=0
12641264
// CHECK-32-NEXT: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=0 bitwise_takable=1)))))
1265+
1266+
BD
1267+
// CHECK-64: (builtin Builtin.DefaultActorStorage)
1268+
// CHECK-64-NEXT: (builtin size=96 alignment=16 stride=96 num_extra_inhabitants=0 bitwise_takable=1)
1269+
1270+
// CHECK-32: (builtin Builtin.DefaultActorStorage)
1271+
// CHECK-32-NEXT: (builtin size=48 alignment=8 stride=48 num_extra_inhabitants=0 bitwise_takable=1)

0 commit comments

Comments
 (0)