Skip to content

Commit e932580

Browse files
committed
Emit debug info for generic type aliases.
Before comparing the potential sugared type for equality is needs to be mapped into the context to resolve generic type parameters to primary archetypes. <rdar://problem/59238327>
1 parent 2113df4 commit e932580

File tree

4 files changed

+67
-15
lines changed

4 files changed

+67
-15
lines changed

lib/IRGen/DebugTypeInfo.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,25 @@ DebugTypeInfo DebugTypeInfo::getFromTypeInfo(swift::Type Ty,
6060

6161
DebugTypeInfo DebugTypeInfo::getLocalVariable(VarDecl *Decl, swift::Type Ty,
6262
const TypeInfo &Info) {
63-
64-
auto DeclType = Decl->getInterfaceType();
65-
auto RealType = Ty;
66-
67-
// DynamicSelfType is also sugar as far as debug info is concerned.
68-
auto Sugared = DeclType;
69-
if (auto DynSelfTy = DeclType->getAs<DynamicSelfType>())
70-
Sugared = DynSelfTy->getSelfType();
71-
7263
// Prefer the original, potentially sugared version of the type if
7364
// the type hasn't been mucked with by an optimization pass.
74-
auto *Type = Sugared->isEqual(RealType) ? DeclType.getPointer()
75-
: RealType.getPointer();
76-
return getFromTypeInfo(Type, Info);
65+
swift::Type DeclType = Decl->getInterfaceType();
66+
swift::Type RealType = Ty;
67+
68+
swift::Type DebugType;
69+
if (auto DynSelfTy = DeclType->getAs<DynamicSelfType>()) {
70+
// DynamicSelfType is also sugar as far as debug info is concerned.
71+
auto DesugaredSelf = DynSelfTy->getSelfType();
72+
DebugType = DesugaredSelf->isEqual(RealType) ? DynSelfTy : RealType;
73+
} else {
74+
// Map the sugared type into the context to resolve bound generics and
75+
// generic type aliases.
76+
DeclContext *DeclCtx = Decl->getDeclContext();
77+
swift::Type Sugared =
78+
DeclCtx ? DeclCtx->mapTypeIntoContext(DeclType) : DeclType;
79+
DebugType = Sugared->isEqual(RealType) ? Sugared : RealType;
80+
}
81+
return getFromTypeInfo(DebugType, Info);
7782
}
7883

7984
DebugTypeInfo DebugTypeInfo::getMetadata(swift::Type Ty, llvm::Type *StorageTy,

lib/IRGen/IRGenSIL.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,7 +3660,7 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
36603660
llvm::SmallVector<llvm::Value *, 8> Copy;
36613661
emitShadowCopyIfNeeded(SILVal, i->getDebugScope(), *VarInfo, IsAnonymous,
36623662
Copy);
3663-
bindArchetypes(DbgTy.getType());
3663+
bindArchetypes(RealTy);
36643664
if (!IGM.DebugInfo)
36653665
return;
36663666

@@ -3691,7 +3691,7 @@ void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) {
36913691

36923692
auto DbgTy = DebugTypeInfo::getLocalVariable(
36933693
Decl, RealType, getTypeInfo(SILVal->getType()));
3694-
bindArchetypes(DbgTy.getType());
3694+
bindArchetypes(RealType);
36953695
if (!IGM.DebugInfo)
36963696
return;
36973697

@@ -3991,7 +3991,7 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
39913991
auto RealType = SILTy.getASTType();
39923992
auto DbgTy = DebugTypeInfo::getLocalVariable(Decl, RealType, type);
39933993

3994-
bindArchetypes(DbgTy.getType());
3994+
bindArchetypes(RealType);
39953995
if (IGM.DebugInfo)
39963996
emitDebugVariableDeclaration(addr, DbgTy, SILTy, DS, Decl, *VarInfo,
39973997
Indirection);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
2+
3+
// Test that a bound generic type is fully resolved in the debug info.
4+
5+
public protocol P {}
6+
7+
public struct S : P {
8+
var x: Int
9+
}
10+
// This is significant, it must be bound to S: main.BoundGeneric<main.S>
11+
// CHECK-DAG: ![[S:[0-9]+]] = !DICompositeType({{.*}}identifier: "$s4main12BoundGenericVyAA1SVGD")
12+
13+
public extension BoundGeneric where T == S {
14+
func f() {
15+
// CHECK-DAG: !DILocalVariable(name: "self", arg: 1,{{.*}} line: [[@LINE-1]],{{.*}} type: ![[C_BGS:[0-9]+]],
16+
// CHECK-DAG: ![[C_BGS]] = !DIDerivedType(tag: DW_TAG_const_type,{{.*}} baseType: ![[BGS:[0-9]+]])
17+
// CHECK-DAG: ![[BGS]] = !DICompositeType(tag: DW_TAG_structure_type,{{.*}} elements: ![[ELTS:[0-9]+]],
18+
// CHECK-DAG: ![[ELTS]] = !{![[MEMBER:[0-9]+]]}
19+
// CHECK-DAG: ![[MEMBER]] = !DIDerivedType(tag: DW_TAG_member,{{.*}} baseType: ![[S]],
20+
}
21+
}
22+
23+
public struct BoundGeneric<T> where T : P {
24+
let x : T
25+
}
26+
27+
public let pat = BoundGeneric<S>(x: S(x: 23))
28+
pat.f()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
2+
3+
// Test that a generic type alias is represented in the debug info.
4+
5+
public struct S<T> {
6+
public typealias Alias = (T, T)
7+
// CHECK: ![[T_T:[0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$sx_xtD"
8+
public let member : Alias
9+
public func f(t : Alias) -> Alias { return t }
10+
// CHECK: !DILocalVariable(name: "t", arg: 1,{{.*}} line: [[@LINE-1]],
11+
// CHECK-SAME: type: ![[C_ALIAS:[0-9]+]])
12+
// CHECK: ![[C_ALIAS]] = !DIDerivedType(tag: DW_TAG_const_type,
13+
// CHECK-SAME: baseType: ![[ALIAS:[0-9]+]])
14+
// CHECK: ![[ALIAS]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$
15+
// CHECK-SAME: baseType: ![[T_T]])
16+
17+
}
18+
19+
public let s = S<Int>(member: (4, 2))

0 commit comments

Comments
 (0)