Skip to content

Commit 4cc52aa

Browse files
Merge pull request #22810 from adrian-prantl/47798056-5.1
[5.1] Replace mapIntoContext with DWARF Archetype name lookup.
2 parents 1d952f4 + ac78469 commit 4cc52aa

File tree

8 files changed

+139
-154
lines changed

8 files changed

+139
-154
lines changed

lib/IRGen/DebugTypeInfo.cpp

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
using namespace swift;
2525
using namespace irgen;
2626

27-
DebugTypeInfo::DebugTypeInfo(DeclContext *DC, GenericEnvironment *GE,
28-
swift::Type Ty, llvm::Type *StorageTy, Size size,
29-
Alignment align, bool HasDefaultAlignment)
30-
: DeclCtx(DC), GenericEnv(GE), Type(Ty.getPointer()),
31-
StorageType(StorageTy), size(size), align(align),
32-
DefaultAlignment(HasDefaultAlignment) {
27+
DebugTypeInfo::DebugTypeInfo(swift::Type Ty, llvm::Type *StorageTy, Size size,
28+
Alignment align, bool HasDefaultAlignment,
29+
bool IsMetadata)
30+
: Type(Ty.getPointer()), StorageType(StorageTy), size(size), align(align),
31+
DefaultAlignment(HasDefaultAlignment), IsMetadataType(IsMetadata) {
3332
assert(StorageType && "StorageType is a nullptr");
3433
assert(align.getValue() != 0);
3534
}
@@ -43,9 +42,7 @@ static bool hasDefaultAlignment(swift::Type Ty) {
4342
return true;
4443
}
4544

46-
DebugTypeInfo DebugTypeInfo::getFromTypeInfo(DeclContext *DC,
47-
GenericEnvironment *GE,
48-
swift::Type Ty,
45+
DebugTypeInfo DebugTypeInfo::getFromTypeInfo(swift::Type Ty,
4946
const TypeInfo &Info) {
5047
Size size;
5148
if (Info.isFixedSize()) {
@@ -56,13 +53,12 @@ DebugTypeInfo DebugTypeInfo::getFromTypeInfo(DeclContext *DC,
5653
// encounter one.
5754
size = Size(0);
5855
}
59-
return DebugTypeInfo(DC, GE, Ty.getPointer(), Info.getStorageType(), size,
60-
Info.getBestKnownAlignment(), hasDefaultAlignment(Ty));
56+
return DebugTypeInfo(Ty.getPointer(), Info.getStorageType(), size,
57+
Info.getBestKnownAlignment(), hasDefaultAlignment(Ty),
58+
false);
6159
}
6260

63-
DebugTypeInfo DebugTypeInfo::getLocalVariable(DeclContext *DC,
64-
GenericEnvironment *GE,
65-
VarDecl *Decl, swift::Type Ty,
61+
DebugTypeInfo DebugTypeInfo::getLocalVariable(VarDecl *Decl, swift::Type Ty,
6662
const TypeInfo &Info) {
6763

6864
auto DeclType = Decl->getInterfaceType();
@@ -77,13 +73,21 @@ DebugTypeInfo DebugTypeInfo::getLocalVariable(DeclContext *DC,
7773
// the type hasn't been mucked with by an optimization pass.
7874
auto *Type = Sugared->isEqual(RealType) ? DeclType.getPointer()
7975
: RealType.getPointer();
80-
return getFromTypeInfo(DC, GE, Type, Info);
76+
return getFromTypeInfo(Type, Info);
8177
}
8278

8379
DebugTypeInfo DebugTypeInfo::getMetadata(swift::Type Ty, llvm::Type *StorageTy,
8480
Size size, Alignment align) {
85-
DebugTypeInfo DbgTy(nullptr, nullptr, Ty.getPointer(), StorageTy, size,
86-
align, true);
81+
DebugTypeInfo DbgTy(Ty.getPointer(), StorageTy, size,
82+
align, true, false);
83+
assert(!DbgTy.isArchetype() && "type metadata cannot contain an archetype");
84+
return DbgTy;
85+
}
86+
87+
DebugTypeInfo DebugTypeInfo::getArchetype(swift::Type Ty, llvm::Type *StorageTy,
88+
Size size, Alignment align) {
89+
DebugTypeInfo DbgTy(Ty.getPointer(), StorageTy, size,
90+
align, true, true);
8791
assert(!DbgTy.isArchetype() && "type metadata cannot contain an archetype");
8892
return DbgTy;
8993
}
@@ -93,19 +97,15 @@ DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
9397
Alignment align) {
9498
// Prefer the original, potentially sugared version of the type if
9599
// the type hasn't been mucked with by an optimization pass.
96-
DeclContext *DC = nullptr;
97-
GenericEnvironment *GE = nullptr;
98100
auto LowTy = GV->getLoweredType().getASTType();
99101
auto *Type = LowTy.getPointer();
100102
if (auto *Decl = GV->getDecl()) {
101-
DC = Decl->getDeclContext();
102-
GE = DC->getGenericEnvironmentOfContext();
103103
auto DeclType = Decl->getType();
104104
if (DeclType->isEqual(LowTy))
105105
Type = DeclType.getPointer();
106106
}
107-
DebugTypeInfo DbgTy(DC, GE, Type, StorageTy, size, align,
108-
hasDefaultAlignment(Type));
107+
DebugTypeInfo DbgTy(Type, StorageTy, size, align, hasDefaultAlignment(Type),
108+
false);
109109
assert(StorageTy && "StorageType is a nullptr");
110110
assert(!DbgTy.isArchetype() &&
111111
"type of global variable cannot be an archetype");
@@ -116,13 +116,19 @@ DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
116116
DebugTypeInfo DebugTypeInfo::getObjCClass(ClassDecl *theClass,
117117
llvm::Type *StorageType, Size size,
118118
Alignment align) {
119-
DebugTypeInfo DbgTy(nullptr, nullptr,
120-
theClass->getInterfaceType().getPointer(), StorageType,
121-
size, align, true);
119+
DebugTypeInfo DbgTy(theClass->getInterfaceType().getPointer(), StorageType,
120+
size, align, true, false);
122121
assert(!DbgTy.isArchetype() && "type of objc class cannot be an archetype");
123122
return DbgTy;
124123
}
125124

125+
DebugTypeInfo DebugTypeInfo::getErrorResult(swift::Type Ty,
126+
llvm::Type *StorageType, Size size,
127+
Alignment align) {
128+
assert(StorageType && "StorageType is a nullptr");
129+
return {Ty, StorageType, size, align, true, false};
130+
}
131+
126132
bool DebugTypeInfo::operator==(DebugTypeInfo T) const {
127133
return (getType() == T.getType() &&
128134
size == T.size &&

lib/IRGen/DebugTypeInfo.h

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ class TypeInfo;
3737
/// for a type.
3838
class DebugTypeInfo {
3939
public:
40-
/// The DeclContext of the function. This might not be the DeclContext of
41-
/// the variable if inlining took place.
42-
DeclContext *DeclCtx = nullptr;
43-
44-
/// The generic environment of the type. Ideally we should need only this and
45-
/// retire the DeclCtxt.
46-
GenericEnvironment *GenericEnv = nullptr;
47-
4840
/// The type we need to emit may be different from the type
4941
/// mentioned in the Decl, for example, stripped of qualifiers.
5042
TypeBase *Type = nullptr;
@@ -54,34 +46,39 @@ class DebugTypeInfo {
5446
Size size = Size(0);
5547
Alignment align = Alignment(0);
5648
bool DefaultAlignment = true;
49+
bool IsMetadataType = false;
5750

5851
DebugTypeInfo() {}
59-
DebugTypeInfo(DeclContext *DC, GenericEnvironment *GE, swift::Type Ty,
60-
llvm::Type *StorageTy, Size SizeInBytes, Alignment AlignInBytes,
61-
bool HasDefaultAlignment);
52+
DebugTypeInfo(swift::Type Ty, llvm::Type *StorageTy, Size SizeInBytes,
53+
Alignment AlignInBytes, bool HasDefaultAlignment,
54+
bool IsMetadataType);
55+
6256
/// Create type for a local variable.
63-
static DebugTypeInfo getLocalVariable(DeclContext *DeclCtx,
64-
GenericEnvironment *GE, VarDecl *Decl,
57+
static DebugTypeInfo getLocalVariable(VarDecl *Decl,
6558
swift::Type Ty, const TypeInfo &Info);
66-
/// Create type for an artificial metadata variable.
59+
/// Create type for global type metadata.
6760
static DebugTypeInfo getMetadata(swift::Type Ty, llvm::Type *StorageTy,
6861
Size size, Alignment align);
62+
/// Create type for an artificial metadata variable.
63+
static DebugTypeInfo getArchetype(swift::Type Ty, llvm::Type *StorageTy,
64+
Size size, Alignment align);
65+
6966
/// Create a standalone type from a TypeInfo object.
70-
static DebugTypeInfo getFromTypeInfo(DeclContext *DC, GenericEnvironment *GE,
71-
swift::Type Ty, const TypeInfo &Info);
67+
static DebugTypeInfo getFromTypeInfo(swift::Type Ty, const TypeInfo &Info);
7268
/// Global variables.
7369
static DebugTypeInfo getGlobal(SILGlobalVariable *GV, llvm::Type *StorageType,
7470
Size size, Alignment align);
7571
/// ObjC classes.
7672
static DebugTypeInfo getObjCClass(ClassDecl *theClass,
7773
llvm::Type *StorageType, Size size,
7874
Alignment align);
75+
/// Error type.
76+
static DebugTypeInfo getErrorResult(swift::Type Ty, llvm::Type *StorageType,
77+
Size size, Alignment align);
7978

8079
TypeBase *getType() const { return Type; }
8180

8281
TypeDecl *getDecl() const;
83-
DeclContext *getDeclContext() const { return DeclCtx; }
84-
GenericEnvironment *getGenericEnvironment() const { return GenericEnv; }
8582

8683
// Determine whether this type is an Archetype itself.
8784
bool isArchetype() const {
@@ -106,9 +103,8 @@ template <> struct DenseMapInfo<swift::irgen::DebugTypeInfo> {
106103
}
107104
static swift::irgen::DebugTypeInfo getTombstoneKey() {
108105
return swift::irgen::DebugTypeInfo(
109-
nullptr, nullptr,
110106
llvm::DenseMapInfo<swift::TypeBase *>::getTombstoneKey(), nullptr,
111-
swift::irgen::Size(0), swift::irgen::Alignment(0), false);
107+
swift::irgen::Size(0), swift::irgen::Alignment(0), false, false);
112108
}
113109
static unsigned getHashValue(swift::irgen::DebugTypeInfo Val) {
114110
return DenseMapInfo<swift::CanType>::getHashValue(Val.getType());

0 commit comments

Comments
 (0)