@@ -1326,11 +1326,19 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1326
1326
}
1327
1327
}
1328
1328
1329
+ // Recursive types such as `class A<B> { let a : A<A<B>> }` would produce an
1330
+ // infinite chain of expansions for the type of `a`. Break these cycles by
1331
+ // emitting any bound generics that still have type parameters as forward
1332
+ // declarations.
1333
+ if (Type->hasTypeParameter () || Type->hasPrimaryArchetype ())
1334
+ return createOpaqueStructWithSizedContainer (
1335
+ Scope, Decl ? Decl->getNameStr () : " " , File, Line, SizeInBits,
1336
+ AlignInBits, Flags, MangledName, collectGenericParams (Type, true ),
1337
+ UnsubstitutedDITy);
1338
+
1329
1339
// Create the substituted type.
1330
- auto *OpaqueType =
1331
- createStructType (Type, Decl, Scope, File, Line, SizeInBits, AlignInBits,
1332
- Flags, MangledName, UnsubstitutedDITy);
1333
- return OpaqueType;
1340
+ return createStructType (Type, Decl, Scope, File, Line, SizeInBits,
1341
+ AlignInBits, Flags, MangledName, UnsubstitutedDITy);
1334
1342
}
1335
1343
1336
1344
// / Create debug information for an enum with a raw type (enum E : Int {}).
@@ -1411,6 +1419,11 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1411
1419
PayloadTy = ElemDecl->getParentEnum ()->mapTypeIntoContext (PayloadTy);
1412
1420
auto &TI = IGM.getTypeInfoForUnlowered (PayloadTy);
1413
1421
ElemDbgTy = CompletedDebugTypeInfo::getFromTypeInfo (PayloadTy, TI, IGM);
1422
+ // FIXME: This is not correct, but seems to be the only way to emit
1423
+ // children for opaque-sized payload-carrying enums.
1424
+ if (!ElemDbgTy)
1425
+ ElemDbgTy =
1426
+ CompletedDebugTypeInfo::getFromTypeInfo (PayloadTy, TI, IGM, 0 );
1414
1427
if (!ElemDbgTy) {
1415
1428
// Without complete type info we can only create a forward decl.
1416
1429
return DBuilder.createForwardDecl (
@@ -1511,9 +1524,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1511
1524
}
1512
1525
1513
1526
llvm::DIType *getOrCreateDesugaredType (Type Ty, DebugTypeInfo DbgTy) {
1514
- DebugTypeInfo BlandDbgTy (Ty, DbgTy. getAlignment (),
1515
- DbgTy.hasDefaultAlignment (),
1516
- DbgTy.isMetadataType (), DbgTy.isFixedBuffer ());
1527
+ DebugTypeInfo BlandDbgTy (
1528
+ Ty, DbgTy. getAlignment (), DbgTy.hasDefaultAlignment (), false ,
1529
+ DbgTy.isFixedBuffer (), DbgTy.getNumExtraInhabitants ());
1517
1530
return getOrCreateType (BlandDbgTy);
1518
1531
}
1519
1532
@@ -1525,8 +1538,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1525
1538
// / Collect the type parameters of a bound generic type. This is needed to
1526
1539
// / anchor any typedefs that may appear in parameters so they can be
1527
1540
// / resolved in the debugger without needing to query the Swift module.
1528
- llvm::DINodeArray
1529
- collectGenericParams (NominalOrBoundGenericNominalType *BGT, bool AsForwardDeclarations = false ) {
1541
+ llvm::DINodeArray collectGenericParams (NominalOrBoundGenericNominalType *BGT,
1542
+ bool AsForwardDeclarations = false ) {
1530
1543
1531
1544
// Collect the generic args from the type and its parent.
1532
1545
std::vector<Type> GenericArgs;
@@ -2164,7 +2177,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
2164
2177
unsigned FwdDeclLine = 0 ;
2165
2178
2166
2179
if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes) {
2167
- if (EnumTy->isSpecialized ())
2180
+ if (EnumTy->isSpecialized () && !EnumTy->hasTypeParameter () &&
2181
+ !EnumTy->hasPrimaryArchetype ())
2168
2182
return createSpecializedEnumType (EnumTy, Decl, MangledName,
2169
2183
SizeInBits, AlignInBits, Scope, File,
2170
2184
FwdDeclLine, Flags);
@@ -2561,7 +2575,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
2561
2575
if (DbgTy.getType ()->getKind () != swift::TypeKind::TypeAlias) {
2562
2576
// A type with the same canonical type already exists, emit a typedef.
2563
2577
// This extra step is necessary to break out of loops: We don't
2564
- // canoncialize types before mangling to preserver sugared types. But
2578
+ // canoncialize types before mangling to preserve sugared types. But
2565
2579
// some types can also have different equivalent non-canonical
2566
2580
// representations with no sugar involved, for example a type
2567
2581
// recursively that appears iniside itself. To deal with the latter we
@@ -2577,6 +2591,19 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
2577
2591
UID = llvm::MDString::get (IGM.getLLVMContext (), Mangled.Sugared );
2578
2592
}
2579
2593
// Fall through and create the sugared type.
2594
+ } else if (auto *AliasTy =
2595
+ llvm::dyn_cast<TypeAliasType>(DbgTy.getType ())) {
2596
+ // An alias type, but the mangler failed to produce a sugared type, just
2597
+ // return the desugared type.
2598
+ llvm::DIType *Desugared =
2599
+ getOrCreateDesugaredType (AliasTy->getSinglyDesugaredType (), DbgTy);
2600
+ StringRef Name;
2601
+ if (auto *AliasDecl = AliasTy->getDecl ())
2602
+ Name = AliasDecl->getName ().str ();
2603
+ if (!Name.empty ())
2604
+ return DBuilder.createTypedef (Desugared, Name, MainFile, 0 ,
2605
+ updateScope (Scope, DbgTy));
2606
+ return Desugared;
2580
2607
} else if (llvm::Metadata *CachedTy = DIRefMap.lookup (UID)) {
2581
2608
auto *DITy = cast<llvm::DIType>(CachedTy);
2582
2609
assert (sanityCheckCachedType (DbgTy, DITy));
@@ -2594,13 +2621,14 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
2594
2621
// If this is a forward decl, create one for this mangled name and don't
2595
2622
// cache it.
2596
2623
if (!isa<PrimaryArchetypeType>(DbgTy.getType ()) &&
2597
- (DbgTy.isFixedBuffer () || !completeType (DbgTy))) {
2624
+ !isa<TypeAliasType>(DbgTy.getType ()) &&
2625
+ (DbgTy.isForwardDecl () || DbgTy.isFixedBuffer () ||
2626
+ !completeType (DbgTy))) {
2598
2627
// In LTO type uniquing is performed based on the UID. Forward
2599
2628
// declarations may not have a unique ID to avoid a forward declaration
2600
2629
// winning over a full definition.
2601
2630
auto *FwdDecl = DBuilder.createReplaceableCompositeType (
2602
2631
llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, 0 , 0 ,
2603
-
2604
2632
llvm::dwarf::DW_LANG_Swift);
2605
2633
FwdDeclTypes.emplace_back (
2606
2634
std::piecewise_construct, std::make_tuple (MangledName),
0 commit comments