@@ -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> }` 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 {}).
@@ -1511,9 +1519,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1511
1519
}
1512
1520
1513
1521
llvm::DIType *getOrCreateDesugaredType (Type Ty, DebugTypeInfo DbgTy) {
1514
- DebugTypeInfo BlandDbgTy (Ty, DbgTy. getAlignment (),
1515
- DbgTy.hasDefaultAlignment (),
1516
- DbgTy.isMetadataType (), DbgTy.isFixedBuffer ());
1522
+ DebugTypeInfo BlandDbgTy (
1523
+ Ty, DbgTy. getAlignment (), DbgTy.hasDefaultAlignment (), false ,
1524
+ DbgTy.isFixedBuffer (), DbgTy.getNumExtraInhabitants ());
1517
1525
return getOrCreateType (BlandDbgTy);
1518
1526
}
1519
1527
@@ -1525,8 +1533,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1525
1533
// / Collect the type parameters of a bound generic type. This is needed to
1526
1534
// / anchor any typedefs that may appear in parameters so they can be
1527
1535
// / resolved in the debugger without needing to query the Swift module.
1528
- llvm::DINodeArray
1529
- collectGenericParams (NominalOrBoundGenericNominalType *BGT, bool AsForwardDeclarations = false ) {
1536
+ llvm::DINodeArray collectGenericParams (NominalOrBoundGenericNominalType *BGT,
1537
+ bool AsForwardDeclarations = false ) {
1530
1538
1531
1539
// Collect the generic args from the type and its parent.
1532
1540
std::vector<Type> GenericArgs;
@@ -2164,7 +2172,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
2164
2172
unsigned FwdDeclLine = 0 ;
2165
2173
2166
2174
if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes) {
2167
- if (EnumTy->isSpecialized ())
2175
+ if (EnumTy->isSpecialized () && !EnumTy->hasTypeParameter () &&
2176
+ !EnumTy->hasPrimaryArchetype ())
2168
2177
return createSpecializedEnumType (EnumTy, Decl, MangledName,
2169
2178
SizeInBits, AlignInBits, Scope, File,
2170
2179
FwdDeclLine, Flags);
@@ -2561,7 +2570,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
2561
2570
if (DbgTy.getType ()->getKind () != swift::TypeKind::TypeAlias) {
2562
2571
// A type with the same canonical type already exists, emit a typedef.
2563
2572
// This extra step is necessary to break out of loops: We don't
2564
- // canoncialize types before mangling to preserver sugared types. But
2573
+ // canoncialize types before mangling to preserve sugared types. But
2565
2574
// some types can also have different equivalent non-canonical
2566
2575
// representations with no sugar involved, for example a type
2567
2576
// recursively that appears iniside itself. To deal with the latter we
@@ -2577,6 +2586,19 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
2577
2586
UID = llvm::MDString::get (IGM.getLLVMContext (), Mangled.Sugared );
2578
2587
}
2579
2588
// Fall through and create the sugared type.
2589
+ } else if (auto *AliasTy =
2590
+ llvm::dyn_cast<TypeAliasType>(DbgTy.getType ())) {
2591
+ // An alias type, but the mangler failed to produce a sugared type, just
2592
+ // return the desugared type.
2593
+ llvm::DIType *Desugared =
2594
+ getOrCreateDesugaredType (AliasTy->getSinglyDesugaredType (), DbgTy);
2595
+ StringRef Name;
2596
+ if (auto *AliasDecl = AliasTy->getDecl ())
2597
+ Name = AliasDecl->getName ().str ();
2598
+ if (!Name.empty ())
2599
+ return DBuilder.createTypedef (Desugared, Name, MainFile, 0 ,
2600
+ updateScope (Scope, DbgTy));
2601
+ return Desugared;
2580
2602
} else if (llvm::Metadata *CachedTy = DIRefMap.lookup (UID)) {
2581
2603
auto *DITy = cast<llvm::DIType>(CachedTy);
2582
2604
assert (sanityCheckCachedType (DbgTy, DITy));
@@ -2594,13 +2616,14 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
2594
2616
// If this is a forward decl, create one for this mangled name and don't
2595
2617
// cache it.
2596
2618
if (!isa<PrimaryArchetypeType>(DbgTy.getType ()) &&
2597
- (DbgTy.isFixedBuffer () || !completeType (DbgTy))) {
2619
+ !isa<TypeAliasType>(DbgTy.getType ()) &&
2620
+ (DbgTy.isForwardDecl () || DbgTy.isFixedBuffer () ||
2621
+ !completeType (DbgTy))) {
2598
2622
// In LTO type uniquing is performed based on the UID. Forward
2599
2623
// declarations may not have a unique ID to avoid a forward declaration
2600
2624
// winning over a full definition.
2601
2625
auto *FwdDecl = DBuilder.createReplaceableCompositeType (
2602
2626
llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, 0 , 0 ,
2603
-
2604
2627
llvm::dwarf::DW_LANG_Swift);
2605
2628
FwdDeclTypes.emplace_back (
2606
2629
std::piecewise_construct, std::make_tuple (MangledName),
0 commit comments