Skip to content

Commit f49e0ba

Browse files
committed
AST: Remove unused DeclContext and GenericEnvironment from mangling
1 parent 50f6883 commit f49e0ba

File tree

5 files changed

+15
-30
lines changed

5 files changed

+15
-30
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ class ASTMangler : public Mangler {
3333
protected:
3434
CanGenericSignature CurGenericSignature;
3535
ModuleDecl *Mod = nullptr;
36-
const DeclContext *DeclCtx = nullptr;
37-
GenericEnvironment *GenericEnv = nullptr;
3836

3937
/// Optimize out protocol names if a type only conforms to one protocol.
4038
bool OptimizeProtocolNames = true;
4139

42-
/// If enabled, Arche- and Alias types are mangled with context.
40+
/// If enabled, non-canonical types are allowed and type alias types get a
41+
/// special mangling.
4342
bool DWARFMangling;
4443

4544
/// If enabled, entities that ought to have names but don't get a placeholder.
@@ -148,8 +147,7 @@ class ASTMangler : public Mangler {
148147
std::string mangleKeyPathHashHelper(ArrayRef<CanType> indices,
149148
GenericSignature *signature);
150149

151-
std::string mangleTypeForDebugger(Type decl, const DeclContext *DC,
152-
GenericEnvironment *GE);
150+
std::string mangleTypeForDebugger(Type decl, const DeclContext *DC);
153151

154152
std::string mangleDeclType(const ValueDecl *decl);
155153

@@ -269,8 +267,7 @@ class ASTMangler : public Mangler {
269267
void appendClosureEntity(const AbstractClosureExpr *closure);
270268

271269
void appendClosureComponents(Type Ty, unsigned discriminator, bool isImplicit,
272-
const DeclContext *parentContext,
273-
const DeclContext *localContext);
270+
const DeclContext *parentContext);
274271

275272
void appendDefaultArgumentEntity(const DeclContext *ctx, unsigned index);
276273

lib/AST/ASTMangler.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "swift/AST/ASTContext.h"
1919
#include "swift/AST/ASTVisitor.h"
2020
#include "swift/AST/ExistentialLayout.h"
21-
#include "swift/AST/GenericEnvironment.h"
21+
#include "swift/AST/GenericSignature.h"
2222
#include "swift/AST/Initializer.h"
2323
#include "swift/AST/Module.h"
2424
#include "swift/AST/Ownership.h"
@@ -378,18 +378,15 @@ std::string ASTMangler::mangleReabstractionThunkHelper(
378378
return finalize();
379379
}
380380

381-
std::string ASTMangler::mangleTypeForDebugger(Type Ty, const DeclContext *DC,
382-
GenericEnvironment *GE) {
381+
std::string ASTMangler::mangleTypeForDebugger(Type Ty, const DeclContext *DC) {
383382
PrettyStackTraceType prettyStackTrace(Ty->getASTContext(),
384383
"mangling type for debugger", Ty);
385384

386-
GenericEnv = GE;
387385
DWARFMangling = true;
388386
beginMangling();
389387

390388
if (DC)
391389
bindGenericParameters(DC);
392-
DeclCtx = DC;
393390

394391
if (auto *fnType = Ty->getAs<AnyFunctionType>()) {
395392
appendFunction(fnType, false);
@@ -2060,29 +2057,24 @@ void ASTMangler::appendAssociatedTypeName(DependentMemberType *dmt) {
20602057
void ASTMangler::appendClosureEntity(
20612058
const SerializedAbstractClosureExpr *closure) {
20622059
appendClosureComponents(closure->getType(), closure->getDiscriminator(),
2063-
closure->isImplicit(), closure->getParent(),
2064-
closure->getLocalContext());
2060+
closure->isImplicit(), closure->getParent());
20652061
}
20662062

20672063
void ASTMangler::appendClosureEntity(const AbstractClosureExpr *closure) {
20682064
appendClosureComponents(closure->getType(), closure->getDiscriminator(),
2069-
isa<AutoClosureExpr>(closure), closure->getParent(),
2070-
closure->getLocalContext());
2065+
isa<AutoClosureExpr>(closure), closure->getParent());
20712066
}
20722067

20732068
void ASTMangler::appendClosureComponents(Type Ty, unsigned discriminator,
2074-
bool isImplicit,
2075-
const DeclContext *parentContext,
2076-
const DeclContext *localContext) {
2077-
if (!DeclCtx) DeclCtx = localContext;
2078-
2069+
bool isImplicit,
2070+
const DeclContext *parentContext) {
20792071
assert(discriminator != AbstractClosureExpr::InvalidDiscriminator
20802072
&& "closure must be marked correctly with discriminator");
20812073

20822074
appendContext(parentContext);
20832075

20842076
if (!Ty)
2085-
Ty = ErrorType::get(localContext->getASTContext());
2077+
Ty = ErrorType::get(parentContext->getASTContext());
20862078

20872079
Ty = Ty->mapTypeOutOfContext();
20882080
appendType(Ty->getCanonicalType());
@@ -2226,7 +2218,6 @@ void ASTMangler::appendAccessorEntity(StringRef accessorKindCode,
22262218

22272219
void ASTMangler::appendEntity(const ValueDecl *decl, StringRef EntityOp,
22282220
bool isStatic) {
2229-
if (!DeclCtx) DeclCtx = decl->getInnermostDeclContext();
22302221
appendContextOf(decl);
22312222
appendDeclName(decl);
22322223
appendDeclType(decl);
@@ -2236,7 +2227,6 @@ void ASTMangler::appendEntity(const ValueDecl *decl, StringRef EntityOp,
22362227
}
22372228

22382229
void ASTMangler::appendEntity(const ValueDecl *decl) {
2239-
if (!DeclCtx) DeclCtx = decl->getInnermostDeclContext();
22402230
assert(!isa<ConstructorDecl>(decl));
22412231
assert(!isa<DestructorDecl>(decl));
22422232

lib/AST/USRGeneration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static inline StringRef getUSRSpacePrefix() {
3535
bool ide::printTypeUSR(Type Ty, raw_ostream &OS) {
3636
assert(!Ty->hasArchetype() && "cannot have contextless archetypes mangled.");
3737
Mangle::ASTMangler Mangler;
38-
OS << Mangler.mangleTypeForDebugger(Ty->getRValueType(), nullptr, nullptr);
38+
OS << Mangler.mangleTypeForDebugger(Ty->getRValueType(), nullptr);
3939
return false;
4040
}
4141

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
651651

652652
Mangle::ASTMangler Mangler;
653653
std::string Name = Mangler.mangleTypeForDebugger(
654-
Ty, DbgTy.getDeclContext(), DbgTy.getGenericEnvironment());
654+
Ty, DbgTy.getDeclContext());
655655
return BumpAllocatedString(Name);
656656
}
657657

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,8 +1601,7 @@ static int doPrintLocalTypes(const CompilerInvocation &InitInvok,
16011601
for (auto LTD : LocalTypeDecls) {
16021602
Mangle::ASTMangler Mangler;
16031603
std::string MangledName = Mangler.mangleTypeForDebugger(
1604-
LTD->getDeclaredInterfaceType(), LTD->getDeclContext(),
1605-
LTD->getDeclContext()->getGenericEnvironmentOfContext());
1604+
LTD->getDeclaredInterfaceType(), LTD->getDeclContext());
16061605
MangledNames.push_back(MangledName);
16071606
}
16081607

@@ -2632,8 +2631,7 @@ class TypeReconstructWalker : public SourceEntityWalker {
26322631
void tryDemangleType(Type T, const DeclContext *DC, CharSourceRange range) {
26332632
Mangle::ASTMangler Mangler;
26342633
std::string mangledName(Mangler.mangleTypeForDebugger(
2635-
T->mapTypeOutOfContext(), DC,
2636-
DC->getGenericEnvironmentOfContext()));
2634+
T->mapTypeOutOfContext(), DC));
26372635
std::string Error;
26382636
Type ReconstructedType = DC->mapTypeIntoContext(
26392637
getTypeFromMangledSymbolname(Ctx, mangledName, Error));

0 commit comments

Comments
 (0)