Skip to content

Commit c862253

Browse files
committed
IRGen: DebugTypeInfo doesn't need a DeclContext or GenericEnvironment
1 parent 2c01516 commit c862253

File tree

4 files changed

+42
-99
lines changed

4 files changed

+42
-99
lines changed

lib/IRGen/DebugTypeInfo.cpp

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
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,
27+
DebugTypeInfo::DebugTypeInfo(swift::Type Ty, llvm::Type *StorageTy, Size size,
2928
Alignment align, bool HasDefaultAlignment)
30-
: DeclCtx(DC), GenericEnv(GE), Type(Ty.getPointer()),
31-
StorageType(StorageTy), size(size), align(align),
29+
: Type(Ty.getPointer()), StorageType(StorageTy), size(size), align(align),
3230
DefaultAlignment(HasDefaultAlignment) {
3331
assert(StorageType && "StorageType is a nullptr");
3432
assert(align.getValue() != 0);
@@ -43,9 +41,7 @@ static bool hasDefaultAlignment(swift::Type Ty) {
4341
return true;
4442
}
4543

46-
DebugTypeInfo DebugTypeInfo::getFromTypeInfo(DeclContext *DC,
47-
GenericEnvironment *GE,
48-
swift::Type Ty,
44+
DebugTypeInfo DebugTypeInfo::getFromTypeInfo(swift::Type Ty,
4945
const TypeInfo &Info) {
5046
Size size;
5147
if (Info.isFixedSize()) {
@@ -56,13 +52,11 @@ DebugTypeInfo DebugTypeInfo::getFromTypeInfo(DeclContext *DC,
5652
// encounter one.
5753
size = Size(0);
5854
}
59-
return DebugTypeInfo(DC, GE, Ty.getPointer(), Info.getStorageType(), size,
55+
return DebugTypeInfo(Ty.getPointer(), Info.getStorageType(), size,
6056
Info.getBestKnownAlignment(), hasDefaultAlignment(Ty));
6157
}
6258

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

6862
auto DeclType = Decl->getInterfaceType();
@@ -77,12 +71,12 @@ DebugTypeInfo DebugTypeInfo::getLocalVariable(DeclContext *DC,
7771
// the type hasn't been mucked with by an optimization pass.
7872
auto *Type = Sugared->isEqual(RealType) ? DeclType.getPointer()
7973
: RealType.getPointer();
80-
return getFromTypeInfo(DC, GE, Type, Info);
74+
return getFromTypeInfo(Type, Info);
8175
}
8276

8377
DebugTypeInfo DebugTypeInfo::getMetadata(swift::Type Ty, llvm::Type *StorageTy,
8478
Size size, Alignment align) {
85-
DebugTypeInfo DbgTy(nullptr, nullptr, Ty.getPointer(), StorageTy, size,
79+
DebugTypeInfo DbgTy(Ty.getPointer(), StorageTy, size,
8680
align, true);
8781
assert(!DbgTy.isArchetype() && "type metadata cannot contain an archetype");
8882
return DbgTy;
@@ -93,18 +87,14 @@ DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
9387
Alignment align) {
9488
// Prefer the original, potentially sugared version of the type if
9589
// the type hasn't been mucked with by an optimization pass.
96-
DeclContext *DC = nullptr;
97-
GenericEnvironment *GE = nullptr;
9890
auto LowTy = GV->getLoweredType().getASTType();
9991
auto *Type = LowTy.getPointer();
10092
if (auto *Decl = GV->getDecl()) {
101-
DC = Decl->getDeclContext();
102-
GE = DC->getGenericEnvironmentOfContext();
10393
auto DeclType = Decl->getType();
10494
if (DeclType->isEqual(LowTy))
10595
Type = DeclType.getPointer();
10696
}
107-
DebugTypeInfo DbgTy(DC, GE, Type, StorageTy, size, align,
97+
DebugTypeInfo DbgTy(Type, StorageTy, size, align,
10898
hasDefaultAlignment(Type));
10999
assert(StorageTy && "StorageType is a nullptr");
110100
assert(!DbgTy.isArchetype() &&
@@ -116,8 +106,7 @@ DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
116106
DebugTypeInfo DebugTypeInfo::getObjCClass(ClassDecl *theClass,
117107
llvm::Type *StorageType, Size size,
118108
Alignment align) {
119-
DebugTypeInfo DbgTy(nullptr, nullptr,
120-
theClass->getInterfaceType().getPointer(), StorageType,
109+
DebugTypeInfo DbgTy(theClass->getInterfaceType().getPointer(), StorageType,
121110
size, align, true);
122111
assert(!DbgTy.isArchetype() && "type of objc class cannot be an archetype");
123112
return DbgTy;

lib/IRGen/DebugTypeInfo.h

Lines changed: 4 additions & 18 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;
@@ -56,19 +48,16 @@ class DebugTypeInfo {
5648
bool DefaultAlignment = true;
5749

5850
DebugTypeInfo() {}
59-
DebugTypeInfo(DeclContext *DC, GenericEnvironment *GE, swift::Type Ty,
60-
llvm::Type *StorageTy, Size SizeInBytes, Alignment AlignInBytes,
61-
bool HasDefaultAlignment);
51+
DebugTypeInfo(swift::Type Ty, llvm::Type *StorageTy, Size SizeInBytes,
52+
Alignment AlignInBytes, bool HasDefaultAlignment);
6253
/// Create type for a local variable.
63-
static DebugTypeInfo getLocalVariable(DeclContext *DeclCtx,
64-
GenericEnvironment *GE, VarDecl *Decl,
54+
static DebugTypeInfo getLocalVariable(VarDecl *Decl,
6555
swift::Type Ty, const TypeInfo &Info);
6656
/// Create type for an artificial metadata variable.
6757
static DebugTypeInfo getMetadata(swift::Type Ty, llvm::Type *StorageTy,
6858
Size size, Alignment align);
6959
/// Create a standalone type from a TypeInfo object.
70-
static DebugTypeInfo getFromTypeInfo(DeclContext *DC, GenericEnvironment *GE,
71-
swift::Type Ty, const TypeInfo &Info);
60+
static DebugTypeInfo getFromTypeInfo(swift::Type Ty, const TypeInfo &Info);
7261
/// Global variables.
7362
static DebugTypeInfo getGlobal(SILGlobalVariable *GV, llvm::Type *StorageType,
7463
Size size, Alignment align);
@@ -80,8 +69,6 @@ class DebugTypeInfo {
8069
TypeBase *getType() const { return Type; }
8170

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

8673
// Determine whether this type is an Archetype itself.
8774
bool isArchetype() const {
@@ -106,7 +93,6 @@ template <> struct DenseMapInfo<swift::irgen::DebugTypeInfo> {
10693
}
10794
static swift::irgen::DebugTypeInfo getTombstoneKey() {
10895
return swift::irgen::DebugTypeInfo(
109-
nullptr, nullptr,
11096
llvm::DenseMapInfo<swift::TypeBase *>::getTombstoneKey(), nullptr,
11197
swift::irgen::Size(0), swift::irgen::Alignment(0), false);
11298
}

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
149149
void emitImport(ImportDecl *D);
150150
llvm::DISubprogram *emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
151151
SILFunctionTypeRepresentation Rep,
152-
SILType Ty, DeclContext *DeclCtx = nullptr,
153-
GenericEnvironment *GE = nullptr);
152+
SILType Ty, DeclContext *DeclCtx = nullptr);
154153
llvm::DISubprogram *emitFunction(SILFunction &SILFn, llvm::Function *Fn);
155154
void emitArtificialFunction(IRBuilder &Builder, llvm::Function *Fn,
156155
SILType SILTy);
@@ -525,11 +524,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
525524
}
526525

527526
void createParameterType(llvm::SmallVectorImpl<llvm::Metadata *> &Parameters,
528-
SILType type, DeclContext *DeclCtx,
529-
GenericEnvironment *GE) {
527+
SILType type) {
530528
auto RealType = type.getASTType();
531-
auto DbgTy = DebugTypeInfo::getFromTypeInfo(DeclCtx, GE, RealType,
532-
IGM.getTypeInfo(type));
529+
auto DbgTy = DebugTypeInfo::getFromTypeInfo(RealType, IGM.getTypeInfo(type));
533530
Parameters.push_back(getOrCreateType(DbgTy));
534531
}
535532

@@ -550,30 +547,25 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
550547
}
551548
}
552549

553-
llvm::DITypeRefArray createParameterTypes(SILType SILTy, DeclContext *DeclCtx,
554-
GenericEnvironment *GE) {
550+
llvm::DITypeRefArray createParameterTypes(SILType SILTy) {
555551
if (!SILTy)
556552
return nullptr;
557-
return createParameterTypes(SILTy.castTo<SILFunctionType>(), DeclCtx, GE);
553+
return createParameterTypes(SILTy.castTo<SILFunctionType>());
558554
}
559555

560-
llvm::DITypeRefArray createParameterTypes(CanSILFunctionType FnTy,
561-
DeclContext *DeclCtx,
562-
GenericEnvironment *GE) {
556+
llvm::DITypeRefArray createParameterTypes(CanSILFunctionType FnTy) {
563557
SmallVector<llvm::Metadata *, 16> Parameters;
564558

565559
GenericContextScope scope(IGM, FnTy->getGenericSignature());
566560

567561
// The function return type is the first element in the list.
568-
createParameterType(Parameters, getResultTypeForDebugInfo(FnTy), DeclCtx,
569-
GE);
562+
createParameterType(Parameters, getResultTypeForDebugInfo(FnTy));
570563

571564
// Actually, the input type is either a single type or a tuple
572565
// type. We currently represent a function with one n-tuple argument
573566
// as an n-ary function.
574567
for (auto Param : FnTy->getParameters())
575-
createParameterType(Parameters, IGM.silConv.getSILType(Param), DeclCtx,
576-
GE);
568+
createParameterType(Parameters, IGM.silConv.getSILType(Param));
577569

578570
return DBuilder.getOrCreateTypeArray(Parameters);
579571
}
@@ -760,7 +752,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
760752

761753
Mangle::ASTMangler Mangler;
762754
std::string Result = Mangler.mangleTypeForDebugger(
763-
Ty, DbgTy.getDeclContext());
755+
Ty, nullptr);
764756

765757
if (!Opts.DisableRoundTripDebugTypes) {
766758
// Make sure we can reconstruct mangled types for the debugger.
@@ -806,16 +798,15 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
806798

807799
llvm::DINodeArray
808800
getTupleElements(TupleType *TupleTy, llvm::DIScope *Scope, llvm::DIFile *File,
809-
llvm::DINode::DIFlags Flags, DeclContext *DeclContext,
810-
GenericEnvironment *GE, unsigned &SizeInBits) {
801+
llvm::DINode::DIFlags Flags, unsigned &SizeInBits) {
811802
SmallVector<llvm::Metadata *, 16> Elements;
812803
unsigned OffsetInBits = 0;
813804
auto genericSig = IGM.getSILTypes().getCurGenericContext();
814805
for (auto ElemTy : TupleTy->getElementTypes()) {
815806
auto &elemTI = IGM.getTypeInfoForUnlowered(
816807
AbstractionPattern(genericSig, ElemTy->getCanonicalType()), ElemTy);
817808
auto DbgTy =
818-
DebugTypeInfo::getFromTypeInfo(DeclContext, GE, ElemTy, elemTI);
809+
DebugTypeInfo::getFromTypeInfo(ElemTy, elemTI);
819810
Elements.push_back(createMemberType(DbgTy, StringRef(), OffsetInBits,
820811
Scope, File, Flags));
821812
}
@@ -834,8 +825,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
834825
BaseTy->getTypeOfMember(IGM.getSwiftModule(), VD, nullptr);
835826

836827
auto DbgTy = DebugTypeInfo::getFromTypeInfo(
837-
VD->getDeclContext(),
838-
VD->getDeclContext()->getGenericEnvironmentOfContext(),
839828
VD->getInterfaceType(),
840829
IGM.getTypeInfoForUnlowered(
841830
IGM.getSILTypes().getAbstractionPattern(VD), memberTy));
@@ -899,25 +888,20 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
899888
// all enum values. Use the raw type for the debug type, but
900889
// the storage size from the enum.
901890
ElemDbgTy =
902-
DebugTypeInfo(ED, DbgTy.getGenericEnvironment(), ED->getRawType(),
891+
DebugTypeInfo(ED->getRawType(),
903892
DbgTy.StorageType, DbgTy.size, DbgTy.align, true);
904893
else if (auto ArgTy = ElemDecl->getArgumentInterfaceType()) {
905894
// A discriminated union. This should really be described as a
906895
// DW_TAG_variant_type. For now only describing the data.
907896
ArgTy = ElemDecl->getParentEnum()->mapTypeIntoContext(ArgTy);
908897
auto &TI = IGM.getTypeInfoForUnlowered(ArgTy);
909-
ElemDbgTy = DebugTypeInfo::getFromTypeInfo(
910-
ElemDecl->getDeclContext(),
911-
ElemDecl->getDeclContext()->getGenericEnvironmentOfContext(), ArgTy,
912-
TI);
898+
ElemDbgTy = DebugTypeInfo::getFromTypeInfo(ArgTy, TI);
913899
} else {
914900
// Discriminated union case without argument. Fallback to Int
915901
// as the element type; there is no storage here.
916902
Type IntTy = IGM.Context.getIntDecl()->getDeclaredType();
917903
ElemDbgTy = DebugTypeInfo(
918-
ElemDecl->getDeclContext(),
919-
ElemDecl->getDeclContext()->getGenericEnvironmentOfContext(), IntTy,
920-
DbgTy.StorageType, Size(0), Alignment(1), true);
904+
IntTy, DbgTy.StorageType, Size(0), Alignment(1), true);
921905
}
922906
unsigned Offset = 0;
923907
auto MTy = createMemberType(ElemDbgTy, ElemDecl->getName().str(), Offset,
@@ -958,8 +942,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
958942

959943
llvm::DIType *getOrCreateDesugaredType(Type Ty, DebugTypeInfo DbgTy) {
960944
DebugTypeInfo BlandDbgTy(
961-
DbgTy.getDeclContext(), DbgTy.getGenericEnvironment(), Ty,
962-
DbgTy.StorageType, DbgTy.size, DbgTy.align, DbgTy.DefaultAlignment);
945+
Ty, DbgTy.StorageType, DbgTy.size, DbgTy.align, DbgTy.DefaultAlignment);
963946
return getOrCreateType(BlandDbgTy);
964947
}
965948

@@ -1057,8 +1040,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
10571040
FunTy = IGM.getLoweredType(nongenericTy).castTo<SILFunctionType>();
10581041
} else
10591042
FunTy = IGM.getLoweredType(BaseTy).castTo<SILFunctionType>();
1060-
auto Params = createParameterTypes(FunTy, DbgTy.getDeclContext(),
1061-
DbgTy.getGenericEnvironment());
1043+
auto Params = createParameterTypes(FunTy);
10621044

10631045
auto FnTy = DBuilder.createSubroutineType(Params, Flags);
10641046
llvm::DIType *DITy;
@@ -1094,9 +1076,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
10941076
DITypeCache[DbgTy.getType()] = llvm::TrackingMDNodeRef(FwdDecl.get());
10951077

10961078
unsigned RealSize;
1097-
auto Elements = getTupleElements(TupleTy, Scope, MainFile, Flags,
1098-
DbgTy.getDeclContext(),
1099-
DbgTy.getGenericEnvironment(), RealSize);
1079+
auto Elements = getTupleElements(TupleTy, Scope, MainFile, Flags, RealSize);
11001080
// FIXME: Handle %swift.opaque members and make this into an assertion.
11011081
if (!RealSize)
11021082
RealSize = SizeInBits;
@@ -1337,7 +1317,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
13371317
auto PTy = IGM.getLoweredType(ProtocolDecl->getInterfaceType())
13381318
.getASTType();
13391319
auto PDbgTy = DebugTypeInfo::getFromTypeInfo(
1340-
DbgTy.getDeclContext(), DbgTy.getGenericEnvironment(),
13411320
ProtocolDecl->getInterfaceType(), IGM.getTypeInfoForLowered(PTy));
13421321
auto PDITy = getOrCreateType(PDbgTy);
13431322
Protocols.push_back(
@@ -1406,8 +1385,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
14061385
auto *BuiltinVectorTy = BaseTy->castTo<BuiltinVectorType>();
14071386
auto ElemTy = BuiltinVectorTy->getElementType();
14081387
auto ElemDbgTy = DebugTypeInfo::getFromTypeInfo(
1409-
DbgTy.getDeclContext(), DbgTy.getGenericEnvironment(), ElemTy,
1410-
IGM.getTypeInfoForUnlowered(ElemTy));
1388+
ElemTy, IGM.getTypeInfoForUnlowered(ElemTy));
14111389
unsigned Count = BuiltinVectorTy->getNumElements();
14121390
auto Subscript = DBuilder.getOrCreateSubrange(0, Count ? Count : -1);
14131391
return DBuilder.createVectorType(SizeInBits,
@@ -1439,7 +1417,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
14391417
// For TypeAlias types, the DeclContext for the aliased type is
14401418
// in the decl of the alias type.
14411419
DebugTypeInfo AliasedDbgTy(
1442-
DbgTy.getDeclContext(), DbgTy.getGenericEnvironment(), AliasedTy,
1420+
AliasedTy,
14431421
DbgTy.StorageType, DbgTy.size, DbgTy.align, DbgTy.DefaultAlignment);
14441422
return DBuilder.createTypedef(getOrCreateType(AliasedDbgTy), MangledName,
14451423
File, L.Line, Scope);
@@ -1915,15 +1893,13 @@ llvm::DISubprogram *IRGenDebugInfoImpl::emitFunction(SILFunction &SILFn,
19151893
assert(DS && "SIL function has no debug scope");
19161894
(void)DS;
19171895
return emitFunction(SILFn.getDebugScope(), Fn, SILFn.getRepresentation(),
1918-
SILFn.getLoweredType(), SILFn.getDeclContext(),
1919-
SILFn.getGenericEnvironment());
1896+
SILFn.getLoweredType(), SILFn.getDeclContext());
19201897
}
19211898

19221899
llvm::DISubprogram *
19231900
IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
19241901
SILFunctionTypeRepresentation Rep,
1925-
SILType SILTy, DeclContext *DeclCtx,
1926-
GenericEnvironment *GE) {
1902+
SILType SILTy, DeclContext *DeclCtx) {
19271903
auto Cached = ScopeCache.find(DS);
19281904
if (Cached != ScopeCache.end()) {
19291905
auto SP = cast<llvm::DISubprogram>(Cached->second);
@@ -1986,7 +1962,7 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
19861962

19871963
CanSILFunctionType FnTy = getFunctionType(SILTy);
19881964
auto Params = Opts.DebugInfoLevel > IRGenDebugInfoLevel::LineTables
1989-
? createParameterTypes(SILTy, DeclCtx, GE)
1965+
? createParameterTypes(SILTy)
19901966
: nullptr;
19911967
llvm::DISubroutineType *DIFnTy = DBuilder.createSubroutineType(Params);
19921968
llvm::DITemplateParameterArray TemplateParameters = nullptr;
@@ -2020,7 +1996,7 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
20201996
if (FnTy)
20211997
if (auto ErrorInfo = FnTy->getOptionalErrorResult()) {
20221998
auto DTI = DebugTypeInfo::getFromTypeInfo(
2023-
nullptr, nullptr, ErrorInfo->getType(),
1999+
ErrorInfo->getType(),
20242000
IGM.getTypeInfo(IGM.silConv.getSILType(*ErrorInfo)));
20252001
Error = DBuilder.getOrCreateArray({getOrCreateType(DTI)}).get();
20262002
}

0 commit comments

Comments
 (0)