Skip to content

Commit 3d33b49

Browse files
committed
[DebugInfo] Properly nest types declared in extensions in the debug info
rdar://161923580
1 parent 25a1e42 commit 3d33b49

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,16 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
729729
if (!DC)
730730
return TheCU;
731731

732+
auto createContext = [&](NominalTypeDecl &NTD) {
733+
GenericContextScope scope(
734+
IGM, NTD.getGenericSignature().getCanonicalSignature());
735+
736+
auto Ty = NTD.getDeclaredInterfaceType();
737+
// Create a Forward-declared type.
738+
auto DbgTy = DebugTypeInfo::getForwardDecl(Ty);
739+
return getOrCreateType(DbgTy);
740+
};
741+
732742
if (isa<FuncDecl>(DC))
733743
if (auto *Decl = IGM.getSILModule().lookUpFunction(SILDeclRef(
734744
cast<AbstractFunctionDecl>(DC), SILDeclRef::Kind::Func)))
@@ -742,7 +752,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
742752

743753
// We don't model these in DWARF.
744754
case DeclContextKind::Initializer:
745-
case DeclContextKind::ExtensionDecl:
746755
case DeclContextKind::SubscriptDecl:
747756
case DeclContextKind::EnumElementDecl:
748757
case DeclContextKind::TopLevelCodeDecl:
@@ -761,16 +770,17 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
761770
return getOrCreateContext(DC->getParent());
762771
case DeclContextKind::MacroDecl:
763772
return getOrCreateContext(DC->getParent());
773+
case DeclContextKind::ExtensionDecl: {
774+
auto *ED = cast<ExtensionDecl>(DC);
775+
if (auto *NTD = ED->getExtendedNominal())
776+
return createContext(*NTD);
777+
return getOrCreateContext(DC->getParent());
778+
}
764779
case DeclContextKind::GenericTypeDecl: {
765-
// The generic signature of this nominal type has no relation to the current
766-
// function's generic signature.
780+
// The generic signature of this nominal type has no relation to the
781+
// current function's generic signature.
767782
auto *NTD = cast<NominalTypeDecl>(DC);
768-
GenericContextScope scope(IGM, NTD->getGenericSignature().getCanonicalSignature());
769-
770-
auto Ty = NTD->getDeclaredInterfaceType();
771-
// Create a Forward-declared type.
772-
auto DbgTy = DebugTypeInfo::getForwardDecl(Ty);
773-
return getOrCreateType(DbgTy);
783+
return createContext(*NTD);
774784
}
775785
}
776786
return TheCU;
@@ -2618,6 +2628,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
26182628
llvm::MDString *UID = nullptr;
26192629
if (canMangle(DbgTy.getType())) {
26202630
Mangled = getMangledName(DbgTy);
2631+
if (Mangled.Canonical=="$s11NestedTypes1DV1VVyx_GD")
2632+
llvm::errs();
26212633
if (!Mangled.Sugared.empty()) {
26222634
UID = llvm::MDString::get(IGM.getLLVMContext(), Mangled.Sugared);
26232635
if (llvm::Metadata *CachedTy = DIRefMap.lookup(UID))

test/DebugInfo/NestedTypes.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,19 @@ public let e : Enum = .WithClass(C())
1616
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "WithStruct",
1717
// CHECK-SAME: size: 128)
1818

19+
public struct D<U> {
20+
var v : V
21+
let u: U
22+
}
23+
24+
extension D {
25+
struct V {
26+
internal var obj: Int
27+
}
28+
}
29+
30+
public let d = D<Int>(v: D.V(obj: 1), u: 2)
31+
32+
// CHECK: ![[D:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "D"
33+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "V", scope: ![[D]],
34+

0 commit comments

Comments
 (0)