@@ -107,7 +107,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
107
107
llvm::DIModule *MainModule = nullptr ; // / The current module.
108
108
llvm::DIScope *EntryPointFn =
109
109
nullptr ; // / Scope of SWIFT_ENTRY_POINT_FUNCTION.
110
- TypeAliasDecl *MetadataTypeDecl; // / The type decl for swift.type.
110
+ // / The artificial type decls for named archetypes.
111
+ llvm::StringMap<TypeAliasDecl *> MetadataTypeDeclCache;
111
112
llvm::DIType *InternalType; // / Catch-all type for opaque internal types.
112
113
113
114
SILLocation::DebugLoc LastDebugLoc; // / The last location that was emitted.
@@ -170,7 +171,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
170
171
bool IsLocalToUnit, bool InFixedBuffer,
171
172
Optional<SILLocation> Loc);
172
173
void emitTypeMetadata (IRGenFunction &IGF, llvm::Value *Metadata,
173
- unsigned Depth, unsigned Index, StringRef AssocType);
174
+ unsigned Depth, unsigned Index, StringRef ArchetypeName,
175
+ StringRef AssocType);
174
176
175
177
// / Return the DIBuilder.
176
178
llvm::DIBuilder &getBuilder () { return DBuilder; }
@@ -704,15 +706,17 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
704
706
return getOrCreateModule (M, TheCU, Name, Path);
705
707
}
706
708
707
- TypeAliasDecl *getMetadataType () {
708
- if (!MetadataTypeDecl) {
709
- MetadataTypeDecl = new (IGM.Context ) TypeAliasDecl (
710
- SourceLoc (), SourceLoc (), IGM.Context .getIdentifier (" $swift.type" ),
711
- SourceLoc (),
712
- /* genericparams*/ nullptr , IGM.Context .TheBuiltinModule );
713
- MetadataTypeDecl->setUnderlyingType (IGM.Context .TheRawPointerType );
714
- }
715
- return MetadataTypeDecl;
709
+ TypeAliasDecl *getMetadataType (StringRef ArchetypeName) {
710
+ TypeAliasDecl *&Entry = MetadataTypeDeclCache[ArchetypeName];
711
+ if (Entry)
712
+ return Entry;
713
+
714
+ SourceLoc NoLoc;
715
+ Entry = new (IGM.Context ) TypeAliasDecl (
716
+ NoLoc, NoLoc, IGM.Context .getIdentifier (ArchetypeName), NoLoc,
717
+ /* genericparams*/ nullptr , IGM.Context .TheBuiltinModule );
718
+ Entry->setUnderlyingType (IGM.Context .TheRawPointerType );
719
+ return Entry;
716
720
}
717
721
718
722
// / Return the DIFile that is the ancestor of Scope.
@@ -765,8 +769,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
765
769
#endif
766
770
767
771
StringRef getMangledName (DebugTypeInfo DbgTy) {
768
- if (MetadataTypeDecl && DbgTy.getDecl () == MetadataTypeDecl)
769
- return BumpAllocatedString (DbgTy.getDecl ()->getName ().str ());
772
+ if (DbgTy.IsMetadataType )
773
+ return MetadataTypeDeclCache.find (DbgTy.getDecl ()->getName ().str ())
774
+ ->getKey ();
770
775
771
776
Type Ty = DbgTy.getType ();
772
777
if (!Ty->hasTypeParameter ())
@@ -925,9 +930,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
925
930
// one of the raw type as long as it is large enough to hold
926
931
// all enum values. Use the raw type for the debug type, but
927
932
// the storage size from the enum.
928
- ElemDbgTy =
929
- DebugTypeInfo (ED->getRawType (),
930
- DbgTy.StorageType , DbgTy.size , DbgTy.align , true );
933
+ ElemDbgTy = DebugTypeInfo (ED->getRawType (), DbgTy.StorageType ,
934
+ DbgTy.size , DbgTy.align , true , false );
931
935
else if (auto ArgTy = ElemDecl->getArgumentInterfaceType ()) {
932
936
// A discriminated union. This should really be described as a
933
937
// DW_TAG_variant_type. For now only describing the data.
@@ -938,8 +942,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
938
942
// Discriminated union case without argument. Fallback to Int
939
943
// as the element type; there is no storage here.
940
944
Type IntTy = IGM.Context .getIntDecl ()->getDeclaredType ();
941
- ElemDbgTy = DebugTypeInfo (
942
- IntTy, DbgTy. StorageType , Size ( 0 ), Alignment (1 ), true );
945
+ ElemDbgTy = DebugTypeInfo (IntTy, DbgTy. StorageType , Size ( 0 ),
946
+ Alignment (1 ), true , false );
943
947
}
944
948
unsigned Offset = 0 ;
945
949
auto MTy = createMemberType (ElemDbgTy, ElemDecl->getName ().str (), Offset,
@@ -979,8 +983,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
979
983
}
980
984
981
985
llvm::DIType *getOrCreateDesugaredType (Type Ty, DebugTypeInfo DbgTy) {
982
- DebugTypeInfo BlandDbgTy (
983
- Ty, DbgTy. StorageType , DbgTy. size , DbgTy.align , DbgTy.DefaultAlignment );
986
+ DebugTypeInfo BlandDbgTy (Ty, DbgTy. StorageType , DbgTy. size , DbgTy. align ,
987
+ DbgTy.DefaultAlignment , DbgTy.IsMetadataType );
984
988
return getOrCreateType (BlandDbgTy);
985
989
}
986
990
@@ -1454,9 +1458,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1454
1458
auto File = getOrCreateFile (L.Filename );
1455
1459
// For TypeAlias types, the DeclContext for the aliased type is
1456
1460
// in the decl of the alias type.
1457
- DebugTypeInfo AliasedDbgTy (
1458
- AliasedTy ,
1459
- DbgTy. StorageType , DbgTy. size , DbgTy. align , DbgTy. DefaultAlignment );
1461
+ DebugTypeInfo AliasedDbgTy (AliasedTy, DbgTy. StorageType , DbgTy. size ,
1462
+ DbgTy. align , DbgTy. DefaultAlignment ,
1463
+ false );
1460
1464
return DBuilder.createTypedef (getOrCreateType (AliasedDbgTy), MangledName,
1461
1465
File, L.Line , Scope);
1462
1466
}
@@ -1637,7 +1641,7 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
1637
1641
llvm::Module &M,
1638
1642
StringRef MainOutputFilenameForDebugInfo)
1639
1643
: Opts(Opts), CI(CI), SM(IGM.Context.SourceMgr), M(M), DBuilder(M),
1640
- IGM (IGM), DebugPrefixMap(Opts.DebugPrefixMap), MetadataTypeDecl( nullptr ),
1644
+ IGM (IGM), DebugPrefixMap(Opts.DebugPrefixMap),
1641
1645
InternalType(nullptr ), LastDebugLoc({}), LastScope(nullptr ) {
1642
1646
assert (Opts.DebugInfoLevel > IRGenDebugInfoLevel::None &&
1643
1647
" no debug info should be generated" );
@@ -2244,7 +2248,9 @@ void IRGenDebugInfoImpl::emitGlobalVariableDeclaration(
2244
2248
2245
2249
void IRGenDebugInfoImpl::emitTypeMetadata (IRGenFunction &IGF,
2246
2250
llvm::Value *Metadata, unsigned Depth,
2247
- unsigned Index, StringRef AssocType) {
2251
+ unsigned Index,
2252
+ StringRef ArchetypeName,
2253
+ StringRef AssocType) {
2248
2254
if (Opts.DebugInfoLevel <= IRGenDebugInfoLevel::LineTables)
2249
2255
return ;
2250
2256
@@ -2254,11 +2260,11 @@ void IRGenDebugInfoImpl::emitTypeMetadata(IRGenFunction &IGF,
2254
2260
return ;
2255
2261
2256
2262
llvm::SmallString<8 > Buf;
2257
- static const char *Tau = u8" \u03C4 _ " ;
2263
+ static const char *Tau = u8" \u03C4 " ;
2258
2264
llvm::raw_svector_ostream OS (Buf);
2259
- OS << ' $' << Tau << Depth << ' _' << Index << AssocType;
2260
- auto DbgTy = DebugTypeInfo::getMetadata (
2261
- getMetadataType ()->getDeclaredInterfaceType ().getPointer (),
2265
+ OS << ' $' << Tau << ' _ ' << Depth << ' _' << Index << AssocType;
2266
+ auto DbgTy = DebugTypeInfo::getArchetype (
2267
+ getMetadataType (ArchetypeName )->getDeclaredInterfaceType ().getPointer (),
2262
2268
Metadata->getType (), Size (CI.getTargetInfo ().getPointerWidth (0 )),
2263
2269
Alignment (CI.getTargetInfo ().getPointerAlign (0 )));
2264
2270
emitVariableDeclaration (IGF.Builder , Metadata, DbgTy, IGF.getDebugScope (),
@@ -2381,9 +2387,10 @@ void IRGenDebugInfo::emitGlobalVariableDeclaration(
2381
2387
2382
2388
void IRGenDebugInfo::emitTypeMetadata (IRGenFunction &IGF, llvm::Value *Metadata,
2383
2389
unsigned Depth, unsigned Index,
2390
+ StringRef ArchetypeName,
2384
2391
StringRef AssocType) {
2385
2392
static_cast <IRGenDebugInfoImpl *>(this )->emitTypeMetadata (
2386
- IGF, Metadata, Depth, Index, AssocType);
2393
+ IGF, Metadata, Depth, Index, ArchetypeName , AssocType);
2387
2394
}
2388
2395
2389
2396
llvm::DIBuilder &IRGenDebugInfo::getBuilder () {
0 commit comments