Skip to content

[ASTMangler] Drop the legacy ASTManger constructor, always require ASTContext& #77922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions include/swift/AST/ASTMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ enum class DestructorKind {
/// The mangler for AST declarations.
class ASTMangler : public Mangler {
protected:
#if 0 // STAGING
const ASTContext &Context;
#endif
ModuleDecl *Mod = nullptr;

/// Optimize out protocol names if a type only conforms to one protocol.
Expand Down Expand Up @@ -189,19 +187,6 @@ class ASTMangler : public Mangler {
HasSymbolQuery,
};

// STAGING: legacy constructor for LLDB
/// lldb overrides the defaulted argument to 'true'.
ASTMangler(bool DWARFMangling = false) {
if (DWARFMangling) {
DWARFMangling = true;
RespectOriginallyDefinedIn = false;
}
}

/// lldb overrides the defaulted argument to 'true'.
ASTMangler(const ASTContext &Ctx, bool DWARFMangling = false) : ASTMangler(DWARFMangling) {}

#if 0
/// lldb overrides the defaulted argument to 'true'.
ASTMangler(const ASTContext &Ctx, bool DWARFMangling = false) : Context(Ctx) {
if (DWARFMangling) {
Expand All @@ -214,7 +199,6 @@ class ASTMangler : public Mangler {
}

const ASTContext &getASTContext() { return Context; }
#endif

void addTypeSubstitution(Type type, GenericSignature sig) {
type = dropProtocolsFromAssociatedTypes(type, sig);
Expand Down
47 changes: 1 addition & 46 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,7 @@ static NodePointer mangleSILDifferentiabilityWitnessAsNode(
Node::Kind::IndexSubset, config.resultIndices->getString()),
demangler);
if (auto genSig = config.derivativeGenericSignature) {
#if 0 // STAGING
ASTMangler genSigMangler(mangler->getASTContext());
#else
ASTMangler genSigMangler;
#endif
auto genSigSymbol = genSigMangler.mangleGenericSignature(genSig);
auto demangledGenSig = demangler.demangleSymbol(genSigSymbol);
assert(demangledGenSig);
Expand Down Expand Up @@ -717,13 +713,8 @@ static Type getTypeForDWARFMangling(Type t) {
}

std::string ASTMangler::mangleTypeForDebugger(Type Ty, GenericSignature sig) {
#if 0 // STAGING
PrettyStackTraceType prettyStackTrace(Context, "mangling type for debugger",
Ty);
#else
PrettyStackTraceType prettyStackTrace(Ty->getASTContext(), "mangling type for debugger",
Ty);
#endif

DWARFMangling = true;
RespectOriginallyDefinedIn = false;
Expand Down Expand Up @@ -1332,11 +1323,7 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
// unless the type alias references a builtin type.
auto underlyingType = aliasTy->getSinglyDesugaredType();
TypeAliasDecl *decl = aliasTy->getDecl();
#if 0 // STAGING
if (decl->getModuleContext() == Context.TheBuiltinModule) {
#else
if (decl->getModuleContext() == decl->getASTContext().TheBuiltinModule) {
#endif
return appendType(underlyingType, sig, forDecl);
}

Expand Down Expand Up @@ -2137,13 +2124,8 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
OpArgs.push_back('t');
}

#if 0 // STAGING
bool mangleClangType =
Context.LangOpts.UseClangFunctionTypes && fn->hasNonDerivableClangType();
#else
bool mangleClangType = fn->getASTContext().LangOpts.UseClangFunctionTypes &&
fn->hasNonDerivableClangType();
#endif

auto appendClangTypeToVec = [this, fn](auto &Vec) {
llvm::raw_svector_ostream OpArgsOS(Vec);
Expand Down Expand Up @@ -3053,13 +3035,8 @@ void ASTMangler::appendFunctionType(AnyFunctionType *fn, GenericSignature sig,

appendFunctionSignature(fn, sig, forDecl, NoFunctionMangling, isRecursedInto);

#if 0 // STAGING
bool mangleClangType =
Context.LangOpts.UseClangFunctionTypes && fn->hasNonDerivableClangType();
#else
bool mangleClangType = fn->getASTContext().LangOpts.UseClangFunctionTypes &&
fn->hasNonDerivableClangType();
#endif

// Note that we do not currently use thin representations in the AST
// for the types of function decls. This may need to change at some
Expand Down Expand Up @@ -3109,13 +3086,8 @@ void ASTMangler::appendClangType(FnType *fn, llvm::raw_svector_ostream &out) {
auto clangType = fn->getClangTypeInfo().getType();
SmallString<64> scratch;
llvm::raw_svector_ostream scratchOS(scratch);
#if 0 // STAGING
clang::ASTContext &clangCtx =
Context.getClangModuleLoader()->getClangASTContext();
#else
clang::ASTContext &clangCtx =
fn->getASTContext().getClangModuleLoader()->getClangASTContext();
#endif
std::unique_ptr<clang::ItaniumMangleContext> mangler{
clang::ItaniumMangleContext::create(clangCtx, clangCtx.getDiagnostics())};
mangler->mangleCanonicalTypeName(clang::QualType(clangType, 0), scratchOS);
Expand All @@ -3141,11 +3113,7 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
if (fn->isSendable())
appendOperator("Yb");
if (auto thrownError = fn->getEffectiveThrownErrorType()) {
#if 0 // STAGING
if ((*thrownError)->isEqual(Context.getErrorExistentialType())
#else
if ((*thrownError)->isEqual(fn->getASTContext().getErrorExistentialType())
#endif
|| !AllowTypedThrows) {
appendOperator("K");
} else {
Expand Down Expand Up @@ -3844,11 +3812,7 @@ void ASTMangler::appendClosureEntity(const AbstractClosureExpr *closure) {
// code; the type-checker currently isn't strict about producing typed
// expression nodes when it fails. Once we enforce that, we can remove this.
if (!type)
#if 0 // STAGING
type = CanType(ErrorType::get(Context));
#else
type = CanType(ErrorType::get(closure->getASTContext()));
#endif

auto canType = type->getCanonicalType();
if (canType->hasLocalArchetype())
Expand Down Expand Up @@ -3919,11 +3883,7 @@ CanType ASTMangler::getDeclTypeForMangling(
genericSig = GenericSignature();
parentGenericSig = GenericSignature();

#if 0 // STAGING
auto &C = Context;
#else
auto &C = decl->getASTContext();
#endif

auto ty = decl->getInterfaceType()->getReferenceStorageReferent();
if (ty->hasError()) {
Expand Down Expand Up @@ -4544,12 +4504,7 @@ void ASTMangler::appendMacroExpansionContext(
if (loc.isInvalid())
return appendContext(origDC, nullBase, StringRef());

#if 0 // STAGING
SourceManager &sourceMgr = Context.SourceMgr;
#else
ASTContext &ctx = origDC->getASTContext();
SourceManager &sourceMgr = ctx.SourceMgr;
#endif

auto appendMacroExpansionLoc = [&]() {
appendIdentifier(origDC->getParentModule()->getName().str());
Expand Down Expand Up @@ -4627,7 +4582,7 @@ void ASTMangler::appendMacroExpansionContext(
if (auto *macroDecl = decl->getResolvedMacro(attr))
baseName = macroDecl->getBaseName();
else
baseName = ctx.getIdentifier("__unknown_macro__");
baseName = Context.getIdentifier("__unknown_macro__");

discriminator = decl->getAttachedMacroDiscriminator(baseName, role, attr);
break;
Expand Down