Skip to content

Commit 6f4ae28

Browse files
committed
[ASTMangler] Pass ASTContext to all instantiations of ASTMangler
1 parent 30cf647 commit 6f4ae28

File tree

88 files changed

+335
-315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+335
-315
lines changed

include/swift/AST/ASTMangler.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_AST_ASTMANGLER_H
1414
#define SWIFT_AST_ASTMANGLER_H
1515

16+
#include "swift/AST/ASTContext.h"
1617
#include "swift/AST/Decl.h"
1718
#include "swift/AST/FreestandingMacroExpansion.h"
1819
#include "swift/AST/SILThunkKind.h"
@@ -44,6 +45,7 @@ enum class DestructorKind {
4445
/// The mangler for AST declarations.
4546
class ASTMangler : public Mangler {
4647
protected:
48+
const ASTContext &Context;
4749
ModuleDecl *Mod = nullptr;
4850

4951
/// Optimize out protocol names if a type only conforms to one protocol.
@@ -186,13 +188,15 @@ class ASTMangler : public Mangler {
186188
};
187189

188190
/// lldb overrides the defaulted argument to 'true'.
189-
ASTMangler(bool DWARFMangling = false) {
191+
ASTMangler(const ASTContext &Ctx, bool DWARFMangling = false) : Context(Ctx) {
190192
if (DWARFMangling) {
191193
DWARFMangling = true;
192194
RespectOriginallyDefinedIn = false;
193195
}
194196
}
195197

198+
const ASTContext &getASTContext() { return Context; }
199+
196200
void addTypeSubstitution(Type type, GenericSignature sig) {
197201
type = dropProtocolsFromAssociatedTypes(type, sig);
198202
addSubstitution(type.getPointer());

include/swift/IRGen/Linking.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1452,9 +1452,9 @@ class LinkEntity {
14521452
return entity;
14531453
}
14541454

1455-
void mangle(llvm::raw_ostream &out) const;
1456-
void mangle(SmallVectorImpl<char> &buffer) const;
1457-
std::string mangleAsString() const;
1455+
void mangle(ASTContext &Ctx, llvm::raw_ostream &out) const;
1456+
void mangle(ASTContext &Ctx, SmallVectorImpl<char> &buffer) const;
1457+
std::string mangleAsString(ASTContext &Ctx) const;
14581458

14591459
SILDeclRef getSILDeclRef() const;
14601460
SILLinkage getLinkage(ForDefinition_t isDefinition) const;

include/swift/SIL/GenericSpecializationMangler.h

+10-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_SIL_UTILS_GENERICSPECIALIZATIONMANGLER_H
1414
#define SWIFT_SIL_UTILS_GENERICSPECIALIZATIONMANGLER_H
1515

16+
#include "swift/AST/ASTContext.h"
1617
#include "swift/AST/ASTMangler.h"
1718
#include "swift/AST/Effects.h"
1819
#include "swift/Basic/NullablePtr.h"
@@ -50,14 +51,14 @@ class SpecializationMangler : public Mangle::ASTMangler {
5051
PossibleEffects RemovedEffects;
5152

5253
protected:
53-
SpecializationMangler(SpecializationPass P, swift::SerializedKind_t Serialized,
54+
SpecializationMangler(ASTContext &Ctx, SpecializationPass P, swift::SerializedKind_t Serialized,
5455
SILFunction *F)
55-
: Pass(P), Serialized(Serialized), Function(F),
56+
: ASTMangler(Ctx), Pass(P), Serialized(Serialized), Function(F),
5657
ArgOpBuffer(ArgOpStorage) {}
5758

58-
SpecializationMangler(SpecializationPass P, swift::SerializedKind_t Serialized,
59+
SpecializationMangler(ASTContext &Ctx, SpecializationPass P, swift::SerializedKind_t Serialized,
5960
std::string functionName)
60-
: Pass(P), Serialized(Serialized), Function(nullptr),
61+
: ASTMangler(Ctx), Pass(P), Serialized(Serialized), Function(nullptr),
6162
FunctionName(functionName), ArgOpBuffer(ArgOpStorage) {}
6263

6364
void beginMangling();
@@ -73,8 +74,8 @@ class SpecializationMangler : public Mangle::ASTMangler {
7374
// The mangler for specialized generic functions.
7475
class GenericSpecializationMangler : public SpecializationMangler {
7576

76-
GenericSpecializationMangler(std::string origFuncName)
77-
: SpecializationMangler(SpecializationPass::GenericSpecializer,
77+
GenericSpecializationMangler(ASTContext &Ctx, std::string origFuncName)
78+
: SpecializationMangler(Ctx, SpecializationPass::GenericSpecializer,
7879
IsNotSerialized, origFuncName) {}
7980

8081
GenericSignature getGenericSignature() {
@@ -90,8 +91,8 @@ class GenericSpecializationMangler : public SpecializationMangler {
9091
void appendRemovedParams(const SmallBitVector &paramsRemoved);
9192

9293
public:
93-
GenericSpecializationMangler(SILFunction *F, swift::SerializedKind_t Serialized)
94-
: SpecializationMangler(SpecializationPass::GenericSpecializer,
94+
GenericSpecializationMangler(ASTContext &Ctx, SILFunction *F, swift::SerializedKind_t Serialized)
95+
: SpecializationMangler(Ctx, SpecializationPass::GenericSpecializer,
9596
Serialized, F) {}
9697

9798
std::string mangleNotReabstracted(SubstitutionMap subs,
@@ -118,7 +119,7 @@ class GenericSpecializationMangler : public SpecializationMangler {
118119
return manglePrespecialized(getGenericSignature(), subs);
119120
}
120121

121-
static std::string manglePrespecialization(std::string unspecializedName,
122+
static std::string manglePrespecialization(ASTContext &Ctx, std::string unspecializedName,
122123
GenericSignature genericSig,
123124
GenericSignature specializedSig);
124125
};

include/swift/SIL/TypeSubstCloner.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
383383
return ParentFunction;
384384

385385
// Clone the function with the substituted type for the debug info.
386-
Mangle::GenericSpecializationMangler Mangler(ParentFunction,
386+
Mangle::GenericSpecializationMangler Mangler(M.getASTContext(), ParentFunction,
387387
IsNotSerialized);
388388
std::string MangledName =
389389
Mangler.mangleForDebugInfo(RemappedSig, SubsMap, ForInlining);

include/swift/SILOptimizer/Utils/DifferentiationMangler.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_SIL_UTILS_DIFFERENTIATIONMANGLER_H
1414
#define SWIFT_SIL_UTILS_DIFFERENTIATIONMANGLER_H
1515

16+
#include "swift/AST/ASTContext.h"
1617
#include "swift/AST/ASTMangler.h"
1718
#include "swift/AST/AutoDiff.h"
1819
#include "swift/Basic/NullablePtr.h"
@@ -25,7 +26,7 @@ namespace Mangle {
2526
/// A mangler for generated differentiation functions.
2627
class DifferentiationMangler : public ASTMangler {
2728
public:
28-
DifferentiationMangler() {}
29+
DifferentiationMangler(const ASTContext &Ctx) : ASTMangler(Ctx) {}
2930
/// Returns the mangled name for a differentiation function of the given kind.
3031
std::string mangleAutoDiffFunction(StringRef originalName,
3132
Demangle::AutoDiffFunctionKind kind,

include/swift/SILOptimizer/Utils/SpecializationMangler.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class PartialSpecializationMangler : public SpecializationMangler {
3232
bool isReAbstracted;
3333

3434
public:
35-
PartialSpecializationMangler(SILFunction *F,
35+
PartialSpecializationMangler(ASTContext &Ctx, SILFunction *F,
3636
CanSILFunctionType SpecializedFnTy,
3737
swift::SerializedKind_t Serialized, bool isReAbstracted)
38-
: SpecializationMangler(SpecializationPass::GenericSpecializer,
38+
: SpecializationMangler(Ctx, SpecializationPass::GenericSpecializer,
3939
Serialized, F),
4040
SpecializedFnTy(SpecializedFnTy), isReAbstracted(isReAbstracted) {}
4141

@@ -92,7 +92,7 @@ class FunctionSignatureSpecializationMangler : public SpecializationMangler {
9292
ReturnValueModifierIntBase ReturnValue;
9393

9494
public:
95-
FunctionSignatureSpecializationMangler(SpecializationPass Pass,
95+
FunctionSignatureSpecializationMangler(ASTContext &Ctx, SpecializationPass Pass,
9696
swift::SerializedKind_t Serialized,
9797
SILFunction *F);
9898
// For arguments / return values

include/swift/Serialization/SerializedSILLoader.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class SILDifferentiabilityWitness;
4242
/// on each SILDeserializer.
4343
class SerializedSILLoader {
4444
private:
45+
ASTContext &Context;
4546
std::vector<std::unique_ptr<SILDeserializer>> LoadedSILSections;
4647

4748
explicit SerializedSILLoader(

lib/APIDigester/ModuleAnalyzerNodes.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ static StringRef calculateMangledName(SDKContext &Ctx, ValueDecl *VD) {
11161116
if (auto *attr = VD->getAttrs().getAttribute<SILGenNameAttr>()) {
11171117
return Ctx.buffer(attr->Name);
11181118
}
1119-
Mangle::ASTMangler NewMangler;
1119+
Mangle::ASTMangler NewMangler(VD->getASTContext());
11201120
return Ctx.buffer(NewMangler.mangleAnyDecl(VD, true,
11211121
/*bool respectOriginallyDefinedIn*/true));
11221122
}

lib/AST/ASTMangler.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ void ASTMangler::appendIndexSubset(IndexSubset *indices) {
579579

580580
static NodePointer mangleSILDifferentiabilityWitnessAsNode(
581581
StringRef originalName, DifferentiabilityKind kind,
582-
const AutoDiffConfig &config, Demangler &demangler) {
582+
const AutoDiffConfig &config, Demangler &demangler, ASTMangler *mangler) {
583583
auto *diffWitnessNode = demangler.createNode(
584584
Node::Kind::DifferentiabilityWitness);
585585
auto origNode = demangler.demangleSymbol(originalName);
@@ -600,7 +600,7 @@ static NodePointer mangleSILDifferentiabilityWitnessAsNode(
600600
Node::Kind::IndexSubset, config.resultIndices->getString()),
601601
demangler);
602602
if (auto genSig = config.derivativeGenericSignature) {
603-
ASTMangler genSigMangler;
603+
ASTMangler genSigMangler(mangler->getASTContext());
604604
auto genSigSymbol = genSigMangler.mangleGenericSignature(genSig);
605605
auto demangledGenSig = demangler.demangleSymbol(genSigSymbol);
606606
assert(demangledGenSig);
@@ -620,7 +620,7 @@ std::string ASTMangler::mangleSILDifferentiabilityWitness(StringRef originalName
620620
if (isMangledName(originalName)) {
621621
Demangler demangler;
622622
auto *node = mangleSILDifferentiabilityWitnessAsNode(
623-
originalName, kind, config, demangler);
623+
originalName, kind, config, demangler, this);
624624
auto mangling = mangleNode(node);
625625
if (!mangling.isSuccess()) {
626626
llvm_unreachable("unexpected mangling failure");

lib/AST/Decl.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
//===--- Decl.cpp - Swift Language Decl ASTs ------------------------------===//
23
//
34
// This source file is part of the Swift.org open source project
@@ -6199,7 +6200,7 @@ ClassDecl::MetaclassKind ClassDecl::getMetaclassKind() const {
61996200
static StringRef mangleObjCRuntimeName(const NominalTypeDecl *nominal,
62006201
llvm::SmallVectorImpl<char> &buffer) {
62016202
{
6202-
Mangle::ASTMangler Mangler;
6203+
Mangle::ASTMangler Mangler(nominal->getASTContext());
62036204
std::string MangledName = Mangler.mangleObjCRuntimeName(nominal);
62046205

62056206
buffer.clear();
@@ -10067,7 +10068,7 @@ Identifier OpaqueTypeDecl::getOpaqueReturnTypeIdentifier() const {
1006710068
SmallString<64> mangleBuf;
1006810069
{
1006910070
llvm::raw_svector_ostream os(mangleBuf);
10070-
Mangle::ASTMangler mangler;
10071+
Mangle::ASTMangler mangler(getASTContext());
1007110072
os << mangler.mangleOpaqueTypeDecl(this);
1007210073
}
1007310074

lib/AST/FrontendSourceFileDepGraphFactory.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ using namespace fine_grained_dependencies;
6161
static std::string identifierForContext(const DeclContext *DC) {
6262
if (!DC) return "";
6363

64-
Mangle::ASTMangler Mangler;
64+
Mangle::ASTMangler Mangler(DC->getASTContext());
6565
if (const auto *context = dyn_cast<NominalTypeDecl>(DC)) {
6666
return Mangler.mangleTypeAsContextUSR(context);
6767
}

lib/AST/USRGeneration.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ static inline StringRef getUSRSpacePrefix() {
3939

4040
bool ide::printTypeUSR(Type Ty, raw_ostream &OS) {
4141
assert(!Ty->hasArchetype() && "cannot have contextless archetypes mangled.");
42-
Mangle::ASTMangler Mangler;
42+
Mangle::ASTMangler Mangler(Ty->getASTContext());
4343
OS << Mangler.mangleTypeAsUSR(Ty->getRValueType());
4444
return false;
4545
}
4646

4747
bool ide::printDeclTypeUSR(const ValueDecl *D, raw_ostream &OS) {
48-
Mangle::ASTMangler Mangler;
48+
Mangle::ASTMangler Mangler(D->getASTContext());
4949
std::string MangledName = Mangler.mangleDeclType(D);
5050
OS << MangledName;
5151
return false;
@@ -254,7 +254,7 @@ swift::USRGenerationRequest::evaluate(Evaluator &evaluator,
254254
}))
255255
return std::string();
256256

257-
Mangle::ASTMangler NewMangler;
257+
Mangle::ASTMangler NewMangler(D->getASTContext());
258258
return NewMangler.mangleDeclAsUSR(D, getUSRSpacePrefix());
259259
}
260260

@@ -276,7 +276,7 @@ swift::MangleLocalTypeDeclRequest::evaluate(Evaluator &evaluator,
276276
if (isa<ModuleDecl>(D))
277277
return std::string(); // Ignore.
278278

279-
Mangle::ASTMangler NewMangler;
279+
Mangle::ASTMangler NewMangler(D->getASTContext());
280280
return NewMangler.mangleLocalTypeDecl(D);
281281
}
282282

@@ -320,7 +320,7 @@ bool ide::printAccessorUSR(const AbstractStorageDecl *D, AccessorKind AccKind,
320320
return printObjCUSRForAccessor(SD, AccKind, OS);
321321
}
322322

323-
Mangle::ASTMangler NewMangler;
323+
Mangle::ASTMangler NewMangler(D->getASTContext());
324324
std::string Mangled = NewMangler.mangleAccessorEntityAsUSR(AccKind,
325325
SD, getUSRSpacePrefix(), SD->isStatic());
326326

lib/ClangImporter/SwiftDeclSynthesizer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ getAccessorDeclarationName(clang::ASTContext &Ctx, NominalTypeDecl *structDecl,
954954
VarDecl *fieldDecl, const char *suffix) {
955955
std::string id;
956956
llvm::raw_string_ostream IdStream(id);
957-
Mangle::ASTMangler mangler;
957+
Mangle::ASTMangler mangler(structDecl->getASTContext());
958958
IdStream << "$" << mangler.mangleDeclAsUSR(structDecl, "") << "$"
959959
<< fieldDecl->getName() << "$" << suffix;
960960

lib/ConstExtract/ConstExtract.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ std::string toMangledTypeNameString(const swift::Type &Type) {
111111
auto PrintingType = Type;
112112
if (Type->hasArchetype())
113113
PrintingType = Type->mapTypeOutOfContext();
114-
return Mangle::ASTMangler().mangleTypeWithoutPrefix(PrintingType->getCanonicalType());
114+
return Mangle::ASTMangler(Type->getASTContext()).mangleTypeWithoutPrefix(PrintingType->getCanonicalType());
115115
}
116116

117117
} // namespace

lib/IRGen/GenCall.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3462,7 +3462,7 @@ static FunctionPointer getProfilingFuncFor(IRGenFunction &IGF,
34623462
os << replacementTypes.size();
34633463
os << "__";
34643464
for (auto replTy : replacementTypes) {
3465-
IRGenMangler mangler;
3465+
IRGenMangler mangler(IGF.IGM.Context);
34663466
os << mangler.mangleTypeMetadataFull(replTy->getCanonicalType());
34673467
os << "___";
34683468
}

lib/IRGen/GenClass.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ irgen::getPhysicalClassMemberAccessStrategy(IRGenModule &IGM,
711711

712712
case FieldAccess::NonConstantDirect: {
713713
std::string symbol =
714-
LinkEntity::forFieldOffset(field).mangleAsString();
714+
LinkEntity::forFieldOffset(field).mangleAsString(IGM.Context);
715715
return MemberAccessStrategy::getDirectGlobal(std::move(symbol),
716716
MemberAccessStrategy::OffsetKind::Bytes_Word);
717717
}
@@ -2336,7 +2336,7 @@ namespace {
23362336
llvm::raw_svector_ostream os(buffer);
23372337
os << LinkEntity::forTypeMetadata(*prespecialization,
23382338
TypeMetadataAddress::FullMetadata)
2339-
.mangleAsString();
2339+
.mangleAsString(IGM.Context);
23402340
return os.str();
23412341
}
23422342

@@ -3052,7 +3052,7 @@ llvm::MDString *irgen::typeIdForMethod(IRGenModule &IGM, SILDeclRef method) {
30523052
assert(!method.getOverridden() && "must always be base method");
30533053

30543054
auto entity = LinkEntity::forMethodDescriptor(method);
3055-
auto mangled = entity.mangleAsString();
3055+
auto mangled = entity.mangleAsString(IGM.Context);
30563056
auto typeId = llvm::MDString::get(*IGM.LLVMContext, mangled);
30573057
return typeId;
30583058
}

0 commit comments

Comments
 (0)