Skip to content

Commit bb55c6d

Browse files
committed
Clean up the constructors of DebugTypeInfo
and ensure that the DeclContext of the SILFunction is used when mangling substituted archetypes found in inlined variable declarations that have been reparented into the caller <rdar://problem/28859432>
1 parent d89f8f4 commit bb55c6d

File tree

7 files changed

+193
-174
lines changed

7 files changed

+193
-174
lines changed

lib/IRGen/DebugTypeInfo.cpp

Lines changed: 70 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,28 @@
1616
//===----------------------------------------------------------------------===//
1717

1818
#include "DebugTypeInfo.h"
19-
#include "IRGen.h"
2019
#include "FixedTypeInfo.h"
20+
#include "IRGen.h"
21+
#include "swift/SIL/SILGlobalVariable.h"
2122
#include "llvm/Support/Debug.h"
2223
#include "llvm/Support/raw_ostream.h"
2324

2425
using namespace swift;
2526
using namespace irgen;
2627

27-
DebugTypeInfo::DebugTypeInfo(swift::Type Ty, llvm::Type *StorageTy,
28-
uint64_t SizeInBytes, uint32_t AlignInBytes,
29-
DeclContext *DC)
30-
: DeclCtx(DC), Type(Ty.getPointer()), StorageType(StorageTy),
31-
size(SizeInBytes), align(AlignInBytes) {
32-
assert(StorageType && "StorageType is a nullptr");
33-
assert(align.getValue() != 0);
34-
}
35-
36-
DebugTypeInfo::DebugTypeInfo(swift::Type Ty, llvm::Type *StorageTy, Size size,
37-
Alignment align, DeclContext *DC)
38-
: DeclCtx(DC), Type(Ty.getPointer()), StorageType(StorageTy),
39-
size(size), align(align) {
28+
DebugTypeInfo::DebugTypeInfo(DeclContext *DC, swift::Type Ty,
29+
llvm::Type *StorageTy, Size size, Alignment align)
30+
: DeclCtx(DC), Type(Ty.getPointer()), StorageType(StorageTy), size(size),
31+
align(align) {
32+
assert((!isArchetype() || (isArchetype() && DC)) &&
33+
"archetype without a declcontext");
4034
assert(StorageType && "StorageType is a nullptr");
4135
assert(align.getValue() != 0);
4236
}
4337

44-
static void
45-
initFromTypeInfo(Size &size, Alignment &align, llvm::Type *&StorageType,
46-
const TypeInfo &Info) {
47-
StorageType = Info.getStorageType();
38+
DebugTypeInfo DebugTypeInfo::getFromTypeInfo(DeclContext *DC, swift::Type Ty,
39+
const TypeInfo &Info) {
40+
Size size;
4841
if (Info.isFixedSize()) {
4942
const FixedTypeInfo &FixTy = *cast<const FixedTypeInfo>(&Info);
5043
size = FixTy.getFixedSize();
@@ -53,50 +46,20 @@ initFromTypeInfo(Size &size, Alignment &align, llvm::Type *&StorageType,
5346
// encounter one.
5447
size = Size(0);
5548
}
56-
align = Info.getBestKnownAlignment();
57-
assert(align.getValue() != 0);
58-
assert(StorageType && "StorageType is a nullptr");
59-
}
60-
61-
DebugTypeInfo::DebugTypeInfo(swift::Type Ty, const TypeInfo &Info,
62-
DeclContext *DC)
63-
: DeclCtx(DC), Type(Ty.getPointer()) {
64-
initFromTypeInfo(size, align, StorageType, Info);
65-
}
66-
67-
DebugTypeInfo::DebugTypeInfo(TypeDecl *Decl, const TypeInfo &Info)
68-
: DeclCtx(Decl->getDeclContext()) {
69-
// Use the sugared version of the type, if there is one.
70-
if (auto AliasDecl = dyn_cast<TypeAliasDecl>(Decl))
71-
Type = AliasDecl->getDeclaredInterfaceType().getPointer();
72-
else
73-
Type = Decl->getInterfaceType().getPointer();
74-
75-
initFromTypeInfo(size, align, StorageType, Info);
49+
return DebugTypeInfo(DC, Ty.getPointer(), Info.getStorageType(), size,
50+
Info.getBestKnownAlignment());
7651
}
7752

78-
DebugTypeInfo::DebugTypeInfo(ValueDecl *Decl, llvm::Type *StorageTy, Size size,
79-
Alignment align)
80-
: DeclCtx(Decl->getDeclContext()), StorageType(StorageTy), size(size),
81-
align(align) {
82-
// Use the sugared version of the type, if there is one.
83-
if (auto AliasDecl = dyn_cast<TypeAliasDecl>(Decl))
84-
Type = AliasDecl->getDeclaredInterfaceType().getPointer();
85-
else
86-
Type = Decl->getInterfaceType().getPointer();
53+
DebugTypeInfo DebugTypeInfo::getLocalVariable(DeclContext *DeclCtx,
54+
VarDecl *Decl, swift::Type Ty,
55+
const TypeInfo &Info,
56+
bool Unwrap) {
8757

88-
assert(StorageType && "StorageType is a nullptr");
89-
assert(align.getValue() != 0);
90-
}
91-
92-
DebugTypeInfo::DebugTypeInfo(VarDecl *Decl, swift::Type Ty,
93-
const TypeInfo &Info, bool Unwrap)
94-
: DeclCtx(Decl->getDeclContext()) {
95-
// Prefer the original, potentially sugared version of the type if
96-
// the type hasn't been mucked with by an optimization pass.
97-
auto DeclType = (Decl->hasType()
98-
? Decl->getType()
99-
: DeclCtx->mapTypeIntoContext(Decl->getInterfaceType()));
58+
auto DeclType = Ty;
59+
if (DeclCtx)
60+
DeclType = (Decl->hasType()
61+
? Decl->getType()
62+
: DeclCtx->mapTypeIntoContext(Decl->getInterfaceType()));
10063
auto RealType = Ty;
10164
if (Unwrap) {
10265
DeclType = DeclType->getInOutObjectType();
@@ -108,27 +71,54 @@ DebugTypeInfo::DebugTypeInfo(VarDecl *Decl, swift::Type Ty,
10871
if (auto DynSelfTy = DeclType->getAs<DynamicSelfType>())
10972
DeclSelfType = DynSelfTy->getSelfType();
11073

111-
if (DeclSelfType->isEqual(RealType) || DeclType->getAs<FunctionType>())
74+
// Prefer the original, potentially sugared version of the type if
75+
// the type hasn't been mucked with by an optimization pass.
76+
auto *Type = DeclSelfType->isEqual(RealType) ? DeclType.getPointer()
77+
: RealType.getPointer();
78+
// FIXME: LLDB cannot deal with manglings that contain @owning annotations.
79+
if (DeclType->getAs<FunctionType>())
11280
Type = DeclType.getPointer();
113-
else
114-
Type = RealType.getPointer();
81+
return getFromTypeInfo(DeclCtx, Type, Info);
82+
}
11583

116-
initFromTypeInfo(size, align, StorageType, Info);
84+
DebugTypeInfo DebugTypeInfo::getMetadata(swift::Type Ty, llvm::Type *StorageTy,
85+
Size size, Alignment align) {
86+
DebugTypeInfo DbgTy = {nullptr, Ty.getPointer(), StorageTy, size, align};
87+
assert(!DbgTy.isArchetype() && "type metadata cannot contain an archetype");
88+
return DbgTy;
11789
}
11890

119-
DebugTypeInfo::DebugTypeInfo(VarDecl *Decl, swift::Type Ty,
120-
llvm::Type *StorageTy, Size size, Alignment align)
121-
: DeclCtx(Decl->getDeclContext()), StorageType(StorageTy), size(size),
122-
align(align) {
91+
DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
92+
llvm::Type *StorageTy, Size size,
93+
Alignment align) {
12394
// Prefer the original, potentially sugared version of the type if
12495
// the type hasn't been mucked with by an optimization pass.
125-
auto DeclType = (Decl->hasType()
126-
? Decl->getType()
127-
: DeclCtx->mapTypeIntoContext(Decl->getInterfaceType()));
128-
if (Ty && Decl->getInterfaceType()->isEqual(Ty))
129-
Type = DeclType.getPointer();
130-
else
131-
Type = Ty.getPointer();
96+
auto LowTy = GV->getLoweredType().getSwiftType();
97+
auto *Type = LowTy.getPointer();
98+
if (auto *Decl = GV->getDecl()) {
99+
auto DeclType =
100+
(Decl->hasType() ? Decl->getType()
101+
: Decl->getDeclContext()->mapTypeIntoContext(
102+
Decl->getInterfaceType()));
103+
if (DeclType->isEqual(LowTy))
104+
Type = DeclType.getPointer();
105+
}
106+
DebugTypeInfo DbgTy = {nullptr, Type, StorageTy, size, align};
107+
assert(StorageTy && "StorageType is a nullptr");
108+
assert(!DbgTy.isArchetype() &&
109+
"type of a global var cannot contain an archetype");
110+
assert(align.getValue() != 0);
111+
return DbgTy;
112+
}
113+
114+
DebugTypeInfo DebugTypeInfo::getObjCClass(ClassDecl *theClass,
115+
llvm::Type *StorageType, Size size,
116+
Alignment align) {
117+
DebugTypeInfo DbgTy(nullptr, theClass->getInterfaceType().getPointer(),
118+
StorageType, size, align);
119+
assert(!DbgTy.isArchetype() &&
120+
"type of an objc class cannot contain an archetype");
121+
return DbgTy;
132122
}
133123

134124
static bool typesEqual(Type A, Type B) {
@@ -141,7 +131,7 @@ static bool typesEqual(Type A, Type B) {
141131

142132
// Tombstone.
143133
auto Tombstone =
144-
llvm::DenseMapInfo<swift::Type>::getTombstoneKey().getPointer();
134+
llvm::DenseMapInfo<swift::Type>::getTombstoneKey().getPointer();
145135
if ((A.getPointer() == Tombstone) || (B.getPointer() == Tombstone))
146136
return false;
147137

@@ -150,14 +140,11 @@ static bool typesEqual(Type A, Type B) {
150140
}
151141

152142
bool DebugTypeInfo::operator==(DebugTypeInfo T) const {
153-
return typesEqual(getType(), T.getType())
154-
&& size == T.size
155-
&& align == T.align;
143+
return typesEqual(getType(), T.getType()) && size == T.size &&
144+
align == T.align;
156145
}
157146

158-
bool DebugTypeInfo::operator!=(DebugTypeInfo T) const {
159-
return !operator==(T);
160-
}
147+
bool DebugTypeInfo::operator!=(DebugTypeInfo T) const { return !operator==(T); }
161148

162149
TypeDecl *DebugTypeInfo::getDecl() const {
163150
if (auto *N = dyn_cast<NominalType>(Type))
@@ -172,8 +159,8 @@ TypeDecl *DebugTypeInfo::getDecl() const {
172159
}
173160

174161
void DebugTypeInfo::dump() const {
175-
llvm::errs() << "[Size " << size.getValue()
176-
<< " Alignment " << align.getValue()<<"] ";
162+
llvm::errs() << "[Size " << size.getValue() << " Alignment "
163+
<< align.getValue() << "] ";
177164

178165
getType()->dump();
179166
if (StorageType) {

lib/IRGen/DebugTypeInfo.h

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Type;
2828

2929
namespace swift {
3030
class SILDebugScope;
31+
class SILGlobalVariable;
3132

3233
namespace irgen {
3334
class TypeInfo;
@@ -47,51 +48,55 @@ class DebugTypeInfo {
4748
Size size;
4849
Alignment align;
4950

50-
// FIXME: feels like there might be too many constructors here
51-
5251
DebugTypeInfo()
5352
: DeclCtx(nullptr), Type(nullptr), StorageType(nullptr), size(0),
5453
align(1) {}
55-
DebugTypeInfo(swift::Type Ty, llvm::Type *StorageTy, uint64_t SizeInBytes,
56-
uint32_t AlignInBytes, DeclContext *DC);
57-
DebugTypeInfo(swift::Type Ty, llvm::Type *StorageTy, Size size,
58-
Alignment align, DeclContext *DC);
59-
DebugTypeInfo(swift::Type Ty, const TypeInfo &Info, DeclContext *DC);
60-
DebugTypeInfo(TypeDecl *Decl, const TypeInfo &Info);
61-
DebugTypeInfo(ValueDecl *Decl, llvm::Type *StorageType, Size size,
62-
Alignment align);
63-
DebugTypeInfo(VarDecl *Decl, swift::Type Ty, const TypeInfo &Info,
64-
bool Unwrap);
65-
DebugTypeInfo(VarDecl *Decl, swift::Type Ty,
66-
llvm::Type *StorageType, Size size,
67-
Alignment align);
54+
DebugTypeInfo(DeclContext *DC, swift::Type Ty, llvm::Type *StorageTy,
55+
Size SizeInBytes, Alignment AlignInBytes);
56+
/// Create type for a local variable.
57+
static DebugTypeInfo getLocalVariable(DeclContext *DeclCtx, VarDecl *Decl,
58+
swift::Type Ty, const TypeInfo &Info,
59+
bool Unwrap);
60+
/// Create type for an artificial metadata variable.
61+
static DebugTypeInfo getMetadata(swift::Type Ty, llvm::Type *StorageTy,
62+
Size size, Alignment align);
63+
/// Create a standalone type from a TypeInfo object.
64+
static DebugTypeInfo getFromTypeInfo(DeclContext *DC, swift::Type Ty,
65+
const TypeInfo &Info);
66+
/// Global variables.
67+
static DebugTypeInfo getGlobal(SILGlobalVariable *GV, llvm::Type *StorageType,
68+
Size size, Alignment align);
69+
/// ObjC classes.
70+
static DebugTypeInfo getObjCClass(ClassDecl *theClass,
71+
llvm::Type *StorageType, Size size,
72+
Alignment align);
73+
6874
TypeBase *getType() const { return Type; }
6975

7076
TypeDecl *getDecl() const;
7177
DeclContext *getDeclContext() const { return DeclCtx; }
7278

7379
void unwrapLValueOrInOutType() {
7480
Type = Type->getLValueOrInOutObjectType().getPointer();
75-
}
81+
}
7682

77-
// Determine whether this type is an Archetype itself.
78-
bool isArchetype() const {
79-
return Type->getLValueOrInOutObjectType()->getDesugaredType()->getKind() ==
80-
TypeKind::Archetype;
81-
}
83+
// Determine whether this type is an Archetype itself.
84+
bool isArchetype() const {
85+
return Type->getLValueOrInOutObjectType()->is<ArchetypeType>();
86+
}
8287

83-
/// LValues, inout args, and Archetypes are implicitly indirect by
84-
/// virtue of their DWARF type.
85-
bool isImplicitlyIndirect() const {
86-
return Type->isLValueType() || isArchetype() ||
87-
(Type->getKind() == TypeKind::InOut);
88-
}
88+
/// LValues, inout args, and Archetypes are implicitly indirect by
89+
/// virtue of their DWARF type.
90+
bool isImplicitlyIndirect() const {
91+
return Type->isLValueType() || isArchetype() ||
92+
(Type->getKind() == TypeKind::InOut);
93+
}
8994

90-
bool isNull() const { return Type == nullptr; }
91-
bool operator==(DebugTypeInfo T) const;
92-
bool operator!=(DebugTypeInfo T) const;
95+
bool isNull() const { return Type == nullptr; }
96+
bool operator==(DebugTypeInfo T) const;
97+
bool operator!=(DebugTypeInfo T) const;
9398

94-
void dump() const;
99+
void dump() const;
95100
};
96101
}
97102
}
@@ -101,12 +106,12 @@ namespace llvm {
101106
// Dense map specialization.
102107
template <> struct DenseMapInfo<swift::irgen::DebugTypeInfo> {
103108
static swift::irgen::DebugTypeInfo getEmptyKey() {
104-
return swift::irgen::DebugTypeInfo();
109+
return {};
105110
}
106111
static swift::irgen::DebugTypeInfo getTombstoneKey() {
107112
return swift::irgen::DebugTypeInfo(
108-
llvm::DenseMapInfo<swift::TypeBase *>::getTombstoneKey(), nullptr, 0, 0,
109-
0);
113+
nullptr, llvm::DenseMapInfo<swift::TypeBase *>::getTombstoneKey(),
114+
nullptr, swift::irgen::Size(0), swift::irgen::Alignment(0));
110115
}
111116
static unsigned getHashValue(swift::irgen::DebugTypeInfo Val) {
112117
return DenseMapInfo<swift::CanType>::getHashValue(Val.getType());

0 commit comments

Comments
 (0)