24
24
25
25
#include < iostream>
26
26
27
+ #ifdef DEBUG_TYPE_LOWERING
28
+ #define DEBUG (expr ) expr;
29
+ #else
30
+ #define DEBUG (expr )
31
+ #endif
32
+
27
33
[[noreturn]]
28
34
static void unreachable (const char *Message) {
29
35
std::cerr << " fatal error: " << Message << " \n " ;
@@ -239,6 +245,7 @@ class ExistentialTypeInfoBuilder {
239
245
240
246
const FieldDescriptor *FD = TC.getBuilder ().getFieldTypeInfo (P);
241
247
if (FD == nullptr ) {
248
+ DEBUG (std::cerr << " No field descriptor: " ; P->dump ())
242
249
Invalid = true ;
243
250
continue ;
244
251
}
@@ -275,6 +282,7 @@ class ExistentialTypeInfoBuilder {
275
282
if (auto *P = dyn_cast<const ProtocolTypeRef>(TR)) {
276
283
Protocols.push_back (P);
277
284
} else {
285
+ DEBUG (std::cerr << " Not a protocol: " ; TR->dump ())
278
286
Invalid = true ;
279
287
}
280
288
}
@@ -286,8 +294,10 @@ class ExistentialTypeInfoBuilder {
286
294
return nullptr ;
287
295
288
296
if (ObjC) {
289
- if (WitnessTableCount > 0 )
297
+ if (WitnessTableCount > 0 ) {
298
+ DEBUG (std::cerr << " @objc existential with witness tables\n " );
290
299
return nullptr ;
300
+ }
291
301
292
302
return TC.getReferenceTypeInfo (ReferenceKind::Strong,
293
303
ReferenceCounting::Unknown);
@@ -316,8 +326,10 @@ class ExistentialTypeInfoBuilder {
316
326
break ;
317
327
case ExistentialTypeRepresentation::Opaque: {
318
328
auto *TI = TC.getTypeInfo (TC.getRawPointerTypeRef ());
319
- if (TI == nullptr )
329
+ if (TI == nullptr ) {
330
+ DEBUG (std::cerr << " No TypeInfo for RawPointer\n " );
320
331
return nullptr ;
332
+ }
321
333
322
334
// Non-class existentials consist of a three-word buffer,
323
335
// value metadata, and finally zero or more witness tables.
@@ -345,8 +357,10 @@ class ExistentialTypeInfoBuilder {
345
357
return nullptr ;
346
358
347
359
if (ObjC) {
348
- if (WitnessTableCount > 0 )
360
+ if (WitnessTableCount > 0 ) {
361
+ DEBUG (std::cerr << " @objc existential with witness tables\n " );
349
362
return nullptr ;
363
+ }
350
364
351
365
return TC.getAnyMetatypeTypeInfo ();
352
366
}
@@ -390,6 +404,7 @@ void RecordTypeInfoBuilder::addField(const std::string &Name,
390
404
const TypeRef *TR) {
391
405
const TypeInfo *TI = TC.getTypeInfo (TR);
392
406
if (TI == nullptr ) {
407
+ DEBUG (std::cerr << " No TypeInfo for field type: " ; TR->dump ());
393
408
Invalid = true ;
394
409
return ;
395
410
}
@@ -436,8 +451,10 @@ TypeConverter::getReferenceTypeInfo(ReferenceKind Kind,
436
451
// Weak references do not have any extra inhabitants.
437
452
438
453
auto *BuiltinTI = Builder.getBuiltinTypeInfo (TR);
439
- if (BuiltinTI == nullptr )
454
+ if (BuiltinTI == nullptr ) {
455
+ DEBUG (std::cerr << " No TypeInfo for reference type: " ; TR->dump ());
440
456
return nullptr ;
457
+ }
441
458
442
459
unsigned numExtraInhabitants = BuiltinTI->NumExtraInhabitants ;
443
460
if (Kind == ReferenceKind::Weak)
@@ -461,8 +478,10 @@ TypeConverter::getThinFunctionTypeInfo() {
461
478
462
479
auto *descriptor = getBuilder ().getBuiltinTypeInfo (
463
480
getThinFunctionTypeRef ());
464
- if (descriptor == nullptr )
481
+ if (descriptor == nullptr ) {
482
+ DEBUG (std::cerr << " No TypeInfo for function type\n " );
465
483
return nullptr ;
484
+ }
466
485
467
486
ThinFunctionTI = makeTypeInfo<BuiltinTypeInfo>(descriptor);
468
487
@@ -495,8 +514,10 @@ TypeConverter::getAnyMetatypeTypeInfo() {
495
514
496
515
auto *descriptor = getBuilder ().getBuiltinTypeInfo (
497
516
getAnyMetatypeTypeRef ());
498
- if (descriptor == nullptr )
517
+ if (descriptor == nullptr ) {
518
+ DEBUG (std::cerr << " No TypeInfo for metatype type\n " );
499
519
return nullptr ;
520
+ }
500
521
501
522
AnyMetatypeTI = makeTypeInfo<BuiltinTypeInfo>(descriptor);
502
523
@@ -837,6 +858,7 @@ class EnumTypeInfoBuilder {
837
858
void addCase (const std::string &Name, const TypeRef *TR,
838
859
const TypeInfo *TI) {
839
860
if (TI == nullptr ) {
861
+ DEBUG (std::cerr << " No TypeInfo for case type: " ; TR->dump ());
840
862
Invalid = true ;
841
863
return ;
842
864
}
@@ -967,8 +989,10 @@ class LowerType
967
989
// / Otherwise, get the fixed layout information from reflection
968
990
// / metadata.
969
991
auto *descriptor = TC.getBuilder ().getBuiltinTypeInfo (B);
970
- if (descriptor == nullptr )
992
+ if (descriptor == nullptr ) {
993
+ DEBUG (std::cerr << " No TypeInfo for builtin type: " ; B->dump ());
971
994
return nullptr ;
995
+ }
972
996
return TC.makeTypeInfo <BuiltinTypeInfo>(descriptor);
973
997
}
974
998
@@ -982,6 +1006,7 @@ class LowerType
982
1006
return TC.makeTypeInfo <BuiltinTypeInfo>(ImportedTypeDescriptor);
983
1007
984
1008
// Otherwise, we're out of luck.
1009
+ DEBUG (std::cerr << " No TypeInfo for nominal type: " ; TR->dump ());
985
1010
return nullptr ;
986
1011
}
987
1012
@@ -1009,7 +1034,7 @@ class LowerType
1009
1034
case FieldDescriptorKind::ObjCProtocol:
1010
1035
case FieldDescriptorKind::ClassProtocol:
1011
1036
case FieldDescriptorKind::Protocol:
1012
- // Invalid field descriptor
1037
+ DEBUG (std::cerr << " Invalid field descriptor: " ; TR-> dump ());
1013
1038
return nullptr ;
1014
1039
}
1015
1040
}
@@ -1060,6 +1085,7 @@ class LowerType
1060
1085
const TypeInfo *visitMetatypeTypeRef (const MetatypeTypeRef *M) {
1061
1086
switch (HasSingletonMetatype ().visit (M)) {
1062
1087
case MetatypeRepresentation::Unknown:
1088
+ DEBUG (std::cerr << " Unknown metatype representation: " ; M->dump ());
1063
1089
return nullptr ;
1064
1090
case MetatypeRepresentation::Thin:
1065
1091
return TC.getEmptyTypeInfo ();
@@ -1079,7 +1105,7 @@ class LowerType
1079
1105
for (auto *P : PC->getProtocols ())
1080
1106
builder.addProtocol (P);
1081
1107
} else {
1082
- // Invalid TypeRef
1108
+ DEBUG (std::cerr << " Invalid existential metatype: " ; EM-> dump ());
1083
1109
return nullptr ;
1084
1110
}
1085
1111
@@ -1114,8 +1140,10 @@ class LowerType
1114
1140
const TypeInfo *
1115
1141
rebuildStorageTypeInfo (const TypeInfo *TI, ReferenceKind Kind) {
1116
1142
// If we can't lower the original storage type, give up.
1117
- if (TI == nullptr )
1143
+ if (TI == nullptr ) {
1144
+ DEBUG (std::cerr << " Invalid reference type" );
1118
1145
return nullptr ;
1146
+ }
1119
1147
1120
1148
// Simple case: Just change the reference kind
1121
1149
if (auto *ReferenceTI = dyn_cast<ReferenceTypeInfo>(TI))
@@ -1156,6 +1184,7 @@ class LowerType
1156
1184
}
1157
1185
1158
1186
// Anything else -- give up
1187
+ DEBUG (std::cerr << " Invalid reference type" );
1159
1188
return nullptr ;
1160
1189
}
1161
1190
@@ -1213,8 +1242,10 @@ const TypeInfo *TypeConverter::getClassInstanceTypeInfo(const TypeRef *TR,
1213
1242
unsigned start,
1214
1243
unsigned align) {
1215
1244
const FieldDescriptor *FD = getBuilder ().getFieldTypeInfo (TR);
1216
- if (FD == nullptr )
1245
+ if (FD == nullptr ) {
1246
+ DEBUG (std::cerr << " No field descriptor: " ; TR->dump ());
1217
1247
return nullptr ;
1248
+ }
1218
1249
1219
1250
switch (FD->Kind ) {
1220
1251
case FieldDescriptorKind::Class:
@@ -1238,6 +1269,7 @@ const TypeInfo *TypeConverter::getClassInstanceTypeInfo(const TypeRef *TR,
1238
1269
case FieldDescriptorKind::ClassProtocol:
1239
1270
case FieldDescriptorKind::Protocol:
1240
1271
// Invalid field descriptor.
1272
+ DEBUG (std::cerr << " Invalid field descriptor: " ; TR->dump ());
1241
1273
return nullptr ;
1242
1274
}
1243
1275
}
0 commit comments