Skip to content

Commit 305f0ed

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

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 19 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;

test/DebugInfo/Errors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ public enum E : Error { case Err }
33

44
// Function throws.
55
public func throwError() throws { throw E.Err }
6-
// CHECK: !DISubprogram(name: "throwError", {{.*}}thrownTypes: ![[THROWN:.*]])
6+
// CHECK-DAG: !DISubprogram(name: "throwError", {{.*}}thrownTypes: ![[THROWN:.*]])
77
// CHECK-DAG: ![[THROWN]] = !{![[ERROR:[0-9]+]]}
88
// CHECK-DAG: ![[ERROR]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Error"
99

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+

test/DebugInfo/typealias.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ public protocol Down {
120120
}
121121

122122
public typealias DependentAlias<T : Up> = T.A.A
123+
// CHECK-DAG: ![[DEPENDENTALIAS:.*]] = !DIDerivedType(tag: DW_TAG_typedef, name: "DependentAlias", {{.*}} baseType: ![[INTTYPE]])
123124

124125
extension Up where A.A == Int {
125126
public func foo() {
126-
// CHECK-DAG: !DILocalVariable(name: "gg",{{.*}} type: ![[INTTYPE]]
127+
// CHECK-DAG: !DILocalVariable(name: "gg",{{.*}} type: ![[DEPENDENTALIAS]]
127128
var gg: DependentAlias<Self> = 123
128129
}
129130
}

0 commit comments

Comments
 (0)