Skip to content

Commit 4417786

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
1 parent 8c9d545 commit 4417786

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 {
@@ -1520,6 +1527,30 @@ TypeConverter::getAnyMetatypeTypeInfo() {
15201527
return AnyMetatypeTI;
15211528
}
15221529

1530+
const TypeInfo *TypeConverter::getDefaultActorStorageTypeInfo() {
1531+
if (DefaultActorStorageTI != nullptr)
1532+
return DefaultActorStorageTI;
1533+
1534+
// The default actor storage is an opaque fixed-size buffer. Use the raw
1535+
// pointer descriptor to find the word size and pointer alignment in the
1536+
// current platform.
1537+
auto descriptor =
1538+
getBuilder().getBuiltinTypeDescriptor(getRawPointerTypeRef());
1539+
if (descriptor == nullptr) {
1540+
DEBUG_LOG(fprintf(stderr, "No TypeInfo for default actor storage type\n"));
1541+
return nullptr;
1542+
}
1543+
1544+
auto size = descriptor->Size * NumWords_DefaultActor;
1545+
auto alignment = 2 * descriptor->Alignment;
1546+
1547+
DefaultActorStorageTI = makeTypeInfo<BuiltinTypeInfo>(
1548+
/*Size=*/size, /*Alignment*/ alignment, /*Stride=*/size,
1549+
/*NumExtraInhabitants*/ 0, /*BitwiseTakable*/ true);
1550+
1551+
return DefaultActorStorageTI;
1552+
}
1553+
15231554
const TypeInfo *TypeConverter::getEmptyTypeInfo() {
15241555
if (EmptyTI != nullptr)
15251556
return EmptyTI;
@@ -2144,6 +2175,8 @@ class LowerType
21442175
} else if (B->getMangledName() == "BO") {
21452176
return TC.getReferenceTypeInfo(ReferenceKind::Strong,
21462177
ReferenceCounting::Unknown);
2178+
} else if (B->getMangledName() == "BD") {
2179+
return TC.getDefaultActorStorageTypeInfo();
21472180
}
21482181

21492182
/// 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)