Skip to content

Commit 903de11

Browse files
authored
Merge pull request #35494 from slavapestov/debug-info-mangling-generic-signature-5.4
IRGen: Plumb through a GenericSignature when mangling types for debug info [5.4]
2 parents c61896f + 0e57647 commit 903de11

File tree

5 files changed

+45
-24
lines changed

5 files changed

+45
-24
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class ASTMangler : public Mangler {
222222
GenericSignature signature,
223223
ResilienceExpansion expansion);
224224

225-
std::string mangleTypeForDebugger(Type decl, const DeclContext *DC);
225+
std::string mangleTypeForDebugger(Type decl, GenericSignature sig);
226226

227227
/// Create a mangled name to be used for _typeName constant propagation.
228228
std::string mangleTypeForTypeName(Type type);
@@ -280,9 +280,7 @@ class ASTMangler : public Mangler {
280280
void appendOpWithGenericParamIndex(StringRef,
281281
const GenericTypeParamType *paramTy);
282282

283-
void bindGenericParameters(const DeclContext *DC);
284-
285-
void bindGenericParameters(CanGenericSignature sig);
283+
void bindGenericParameters(GenericSignature sig);
286284

287285
/// Mangles a sugared type iff we are mangling for the debugger.
288286
template <class T> void appendSugaredType(Type type,

lib/AST/ASTMangler.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ static Type getTypeForDWARFMangling(Type t) {
538538
SubstFlags::AllowLoweredTypes);
539539
}
540540

541-
std::string ASTMangler::mangleTypeForDebugger(Type Ty, const DeclContext *DC) {
541+
std::string ASTMangler::mangleTypeForDebugger(Type Ty, GenericSignature sig) {
542542
PrettyStackTraceType prettyStackTrace(Ty->getASTContext(),
543543
"mangling type for debugger", Ty);
544544

@@ -548,9 +548,7 @@ std::string ASTMangler::mangleTypeForDebugger(Type Ty, const DeclContext *DC) {
548548

549549
Ty = getTypeForDWARFMangling(Ty);
550550

551-
if (DC)
552-
bindGenericParameters(DC);
553-
551+
bindGenericParameters(sig);
554552
appendType(Ty);
555553
appendOperator("D");
556554
return finalize();
@@ -676,7 +674,9 @@ std::string ASTMangler::mangleDeclAsUSR(const ValueDecl *Decl,
676674
beginManglingWithoutPrefix();
677675
llvm::SaveAndRestore<bool> allowUnnamedRAII(AllowNamelessEntities, true);
678676
Buffer << USRPrefix;
679-
bindGenericParameters(Decl->getDeclContext());
677+
678+
auto Sig = Decl->getInnermostDeclContext()->getGenericSignatureOfContext();
679+
bindGenericParameters(Sig);
680680

681681
if (auto Ctor = dyn_cast<ConstructorDecl>(Decl)) {
682682
appendConstructorEntity(Ctor, /*isAllocating=*/false);
@@ -1369,15 +1369,9 @@ void ASTMangler::appendOpWithGenericParamIndex(StringRef Op,
13691369

13701370

13711371
/// Bind the generic parameters from the given signature.
1372-
void ASTMangler::bindGenericParameters(CanGenericSignature sig) {
1372+
void ASTMangler::bindGenericParameters(GenericSignature sig) {
13731373
if (sig)
1374-
CurGenericSignature = sig;
1375-
}
1376-
1377-
/// Bind the generic parameters from the given context and its parents.
1378-
void ASTMangler::bindGenericParameters(const DeclContext *DC) {
1379-
if (auto sig = DC->getGenericSignatureOfContext())
1380-
bindGenericParameters(sig.getCanonicalSignature());
1374+
CurGenericSignature = sig.getCanonicalSignature();
13811375
}
13821376

13831377
void ASTMangler::appendFlatGenericArgs(SubstitutionMap subs) {
@@ -2853,12 +2847,13 @@ void ASTMangler::appendAccessorEntity(StringRef accessorKindCode,
28532847
const AbstractStorageDecl *decl,
28542848
bool isStatic) {
28552849
appendContextOf(decl);
2856-
bindGenericParameters(decl->getDeclContext());
2857-
if (isa<VarDecl>(decl)) {
2850+
if (auto *varDecl = dyn_cast<VarDecl>(decl)) {
2851+
bindGenericParameters(varDecl->getDeclContext()->getGenericSignatureOfContext());
28582852
appendDeclName(decl);
28592853
appendDeclType(decl);
28602854
appendOperator("v", accessorKindCode);
2861-
} else if (isa<SubscriptDecl>(decl)) {
2855+
} else if (auto *subscriptDecl = dyn_cast<SubscriptDecl>(decl)) {
2856+
bindGenericParameters(subscriptDecl->getGenericSignature());
28622857
appendDeclType(decl);
28632858

28642859
StringRef privateDiscriminator = getPrivateDiscriminatorIfNecessary(decl);

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
816816
->getKey();
817817

818818
Type Ty = DbgTy.getType();
819-
if (!Ty->hasTypeParameter())
819+
if (Ty->hasArchetype())
820820
Ty = Ty->mapTypeOutOfContext();
821821

822822
// Strip off top level of type sugar (except for type aliases).
@@ -842,7 +842,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
842842
IGM.getSILModule());
843843

844844
Mangle::ASTMangler Mangler;
845-
std::string Result = Mangler.mangleTypeForDebugger(Ty, nullptr);
845+
GenericSignature Sig = IGM.getCurGenericContext();
846+
std::string Result = Mangler.mangleTypeForDebugger(Ty, Sig);
846847

847848
if (!Opts.DisableRoundTripDebugTypes) {
848849
// Make sure we can reconstruct mangled types for the debugger.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swift-frontend -emit-ir -g -primary-file %s
2+
3+
// https://bugs.swift.org/browse/SR-14016
4+
5+
public struct PowerCollection<C : Collection> : Collection {
6+
public typealias Index = [C.Index]
7+
public typealias Element = [C.Element]
8+
9+
public var startIndex, endIndex: Index
10+
11+
public subscript(position: Index) -> [C.Element] {
12+
return []
13+
}
14+
15+
public func index(after i: Index) -> Index {
16+
return i
17+
}
18+
19+
}
20+
21+
extension Array : Comparable where Element : Comparable {
22+
public static func < (lhs: [Element], rhs: [Element]) -> Bool {
23+
return false
24+
}
25+
}

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,8 @@ static int doPrintLocalTypes(const CompilerInvocation &InitInvok,
22982298
for (auto LTD : LocalTypeDecls) {
22992299
Mangle::ASTMangler Mangler;
23002300
std::string MangledName = Mangler.mangleTypeForDebugger(
2301-
LTD->getDeclaredInterfaceType(), LTD->getDeclContext());
2301+
LTD->getDeclaredInterfaceType(),
2302+
LTD->getInnermostDeclContext()->getGenericSignatureOfContext());
23022303
MangledNames.push_back(MangledName);
23032304
}
23042305

@@ -3410,7 +3411,8 @@ class TypeReconstructWalker : public SourceEntityWalker {
34103411
private:
34113412
void tryDemangleType(Type T, const DeclContext *DC, CharSourceRange range) {
34123413
Mangle::ASTMangler Mangler;
3413-
std::string mangledName(Mangler.mangleTypeForDebugger(T, DC));
3414+
auto sig = DC->getGenericSignatureOfContext();
3415+
std::string mangledName(Mangler.mangleTypeForDebugger(T, sig));
34143416
Type ReconstructedType = DC->mapTypeIntoContext(
34153417
Demangle::getTypeForMangling(Ctx, mangledName));
34163418
Stream << "type: ";

0 commit comments

Comments
 (0)