@@ -1326,11 +1326,19 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
13261326 }
13271327 }
13281328
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+
13291339 // 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);
13341342 }
13351343
13361344 // / Create debug information for an enum with a raw type (enum E : Int {}).
@@ -1411,6 +1419,11 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
14111419 PayloadTy = ElemDecl->getParentEnum ()->mapTypeIntoContext (PayloadTy);
14121420 auto &TI = IGM.getTypeInfoForUnlowered (PayloadTy);
14131421 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 );
14141427 if (!ElemDbgTy) {
14151428 // Without complete type info we can only create a forward decl.
14161429 return DBuilder.createForwardDecl (
@@ -1511,9 +1524,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
15111524 }
15121525
15131526 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 ());
15171530 return getOrCreateType (BlandDbgTy);
15181531 }
15191532
@@ -1525,8 +1538,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
15251538 // / Collect the type parameters of a bound generic type. This is needed to
15261539 // / anchor any typedefs that may appear in parameters so they can be
15271540 // / 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 ) {
15301543
15311544 // Collect the generic args from the type and its parent.
15321545 std::vector<Type> GenericArgs;
@@ -2164,7 +2177,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
21642177 unsigned FwdDeclLine = 0 ;
21652178
21662179 if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes) {
2167- if (EnumTy->isSpecialized ())
2180+ if (EnumTy->isSpecialized () && !EnumTy->hasTypeParameter () &&
2181+ !EnumTy->hasPrimaryArchetype ())
21682182 return createSpecializedEnumType (EnumTy, Decl, MangledName,
21692183 SizeInBits, AlignInBits, Scope, File,
21702184 FwdDeclLine, Flags);
@@ -2561,7 +2575,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
25612575 if (DbgTy.getType ()->getKind () != swift::TypeKind::TypeAlias) {
25622576 // A type with the same canonical type already exists, emit a typedef.
25632577 // 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
25652579 // some types can also have different equivalent non-canonical
25662580 // representations with no sugar involved, for example a type
25672581 // recursively that appears iniside itself. To deal with the latter we
@@ -2577,6 +2591,19 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
25772591 UID = llvm::MDString::get (IGM.getLLVMContext (), Mangled.Sugared );
25782592 }
25792593 // 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;
25802607 } else if (llvm::Metadata *CachedTy = DIRefMap.lookup (UID)) {
25812608 auto *DITy = cast<llvm::DIType>(CachedTy);
25822609 assert (sanityCheckCachedType (DbgTy, DITy));
@@ -2594,13 +2621,14 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
25942621 // If this is a forward decl, create one for this mangled name and don't
25952622 // cache it.
25962623 if (!isa<PrimaryArchetypeType>(DbgTy.getType ()) &&
2597- (DbgTy.isFixedBuffer () || !completeType (DbgTy))) {
2624+ !isa<TypeAliasType>(DbgTy.getType ()) &&
2625+ (DbgTy.isForwardDecl () || DbgTy.isFixedBuffer () ||
2626+ !completeType (DbgTy))) {
25982627 // In LTO type uniquing is performed based on the UID. Forward
25992628 // declarations may not have a unique ID to avoid a forward declaration
26002629 // winning over a full definition.
26012630 auto *FwdDecl = DBuilder.createReplaceableCompositeType (
26022631 llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, 0 , 0 ,
2603-
26042632 llvm::dwarf::DW_LANG_Swift);
26052633 FwdDeclTypes.emplace_back (
26062634 std::piecewise_construct, std::make_tuple (MangledName),
@@ -3434,9 +3462,6 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
34343462 if (!DInstLine || (ArgNo > 0 && VarInfo.Name == IGM.Context .Id_self .str ()))
34353463 Artificial = ArtificialValue;
34363464
3437- if (VarInfo.Name == " index" )
3438- llvm::errs ();
3439-
34403465 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
34413466 if (Artificial || DITy->isArtificial () || DITy == InternalType)
34423467 Flags |= llvm::DINode::FlagArtificial;
0 commit comments