Skip to content

[TBDGen] update usages of MachO::SymbolKind -> MachO::EncodeKind, NFC #71247

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
Jan 31, 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
42 changes: 21 additions & 21 deletions lib/IRGen/TBDGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ using namespace swift::irgen;
using namespace swift::tbdgen;
using namespace llvm::yaml;
using StringSet = llvm::StringSet<>;
using SymbolKind = llvm::MachO::SymbolKind;
using EncodeKind = llvm::MachO::EncodeKind;
using SymbolFlags = llvm::MachO::SymbolFlags;

TBDGenVisitor::TBDGenVisitor(const TBDGenDescriptor &desc,
APIRecorder &recorder)
: TBDGenVisitor(desc.getTarget(), desc.getDataLayoutString(),
desc.getParentModule(), desc.getOptions(), recorder) {}

void TBDGenVisitor::addSymbolInternal(StringRef name, SymbolKind kind,
void TBDGenVisitor::addSymbolInternal(StringRef name, EncodeKind kind,
SymbolSource source, SymbolFlags flags) {
if (!source.isLinkerDirective() && Opts.LinkerDirectivesOnly)
return;

#ifndef NDEBUG
if (kind == SymbolKind::GlobalSymbol) {
if (kind == EncodeKind::GlobalSymbol) {
if (!DuplicateSymbolChecker.insert(name).second) {
llvm::dbgs() << "TBDGen duplicate symbol: " << name << '\n';
assert(false && "TBDGen symbol appears twice");
Expand Down Expand Up @@ -291,9 +291,9 @@ static llvm::VersionTuple calculateLdPreviousVersionStart(ASTContext &ctx,
return introVer;
}

void TBDGenVisitor::addLinkerDirectiveSymbolsLdPrevious(StringRef name,
llvm::MachO::SymbolKind kind) {
if (kind != llvm::MachO::SymbolKind::GlobalSymbol)
void TBDGenVisitor::addLinkerDirectiveSymbolsLdPrevious(
StringRef name, llvm::MachO::EncodeKind kind) {
if (kind != llvm::MachO::EncodeKind::GlobalSymbol)
return;
if(DeclStack.empty())
return;
Expand Down Expand Up @@ -341,14 +341,14 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdPrevious(StringRef name,
OS << verStart.getMajor() << "." << getMinor(verStart.getMinor()) << "$";
OS << Ver.Version.getMajor() << "." << getMinor(Ver.Version.getMinor()) << "$";
OS << name << "$";
addSymbolInternal(OS.str(), SymbolKind::GlobalSymbol,
addSymbolInternal(OS.str(), EncodeKind::GlobalSymbol,
SymbolSource::forLinkerDirective(), SymbolFlags::Data);
}
}

void TBDGenVisitor::addLinkerDirectiveSymbolsLdHide(StringRef name,
llvm::MachO::SymbolKind kind) {
if (kind != llvm::MachO::SymbolKind::GlobalSymbol)
void TBDGenVisitor::addLinkerDirectiveSymbolsLdHide(
StringRef name, llvm::MachO::EncodeKind kind) {
if (kind != llvm::MachO::EncodeKind::GlobalSymbol)
return;
if (DeclStack.empty())
return;
Expand Down Expand Up @@ -387,19 +387,19 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdHide(StringRef name,
llvm::SmallString<64> Buffer;
llvm::raw_svector_ostream OS(Buffer);
OS << "$ld$hide$os" << CurMaj << "." << CurMin << "$" << name;
addSymbolInternal(OS.str(), SymbolKind::GlobalSymbol,
addSymbolInternal(OS.str(), EncodeKind::GlobalSymbol,
SymbolSource::forLinkerDirective(), SymbolFlags::Data);
}
}
}

void TBDGenVisitor::addSymbol(StringRef name, SymbolSource source,
SymbolFlags flags, SymbolKind kind) {
SymbolFlags flags, EncodeKind kind) {
// The linker expects to see mangled symbol names in TBD files,
// except when being passed objective c classes,
// so make sure to mangle before inserting the symbol.
SmallString<32> mangled;
if (kind == SymbolKind::ObjectiveCClass) {
if (kind == EncodeKind::ObjectiveCClass) {
mangled = name;
} else {
if (!DataLayout)
Expand Down Expand Up @@ -461,7 +461,7 @@ void TBDGenVisitor::addObjCInterface(ClassDecl *CD) {
// FIXME: We ought to have a symbol source for this.
SmallString<128> buffer;
addSymbol(CD->getObjCRuntimeName(buffer), SymbolSource::forUnknown(),
SymbolFlags::Data, SymbolKind::ObjectiveCClass);
SymbolFlags::Data, EncodeKind::ObjectiveCClass);
recorder.addObjCInterface(CD);
}

Expand Down Expand Up @@ -619,7 +619,7 @@ TBDFile GenerateTBDRequest::evaluate(Evaluator &evaluator,
targets.push_back(targetVar);
}

auto addSymbol = [&](StringRef symbol, SymbolKind kind, SymbolSource source,
auto addSymbol = [&](StringRef symbol, EncodeKind kind, SymbolSource source,
Decl *decl, SymbolFlags flags) {
file.addSymbol(kind, symbol, targets, flags);
};
Expand All @@ -633,12 +633,12 @@ std::vector<std::string>
PublicSymbolsRequest::evaluate(Evaluator &evaluator,
TBDGenDescriptor desc) const {
std::vector<std::string> symbols;
auto addSymbol = [&](StringRef symbol, SymbolKind kind, SymbolSource source,
auto addSymbol = [&](StringRef symbol, EncodeKind kind, SymbolSource source,
Decl *decl, SymbolFlags flags) {
if (kind == SymbolKind::GlobalSymbol)
if (kind == EncodeKind::GlobalSymbol)
symbols.push_back(symbol.str());
// TextAPI ObjC Class Kinds represents two symbols.
else if (kind == SymbolKind::ObjectiveCClass) {
else if (kind == EncodeKind::ObjectiveCClass) {
symbols.push_back((llvm::MachO::ObjC2ClassNamePrefix + symbol).str());
symbols.push_back((llvm::MachO::ObjC2MetaClassNamePrefix + symbol).str());
}
Expand Down Expand Up @@ -681,9 +681,9 @@ class APIGenRecorder final : public APIRecorder {
}
~APIGenRecorder() {}

void addSymbol(StringRef symbol, SymbolKind kind, SymbolSource source,
void addSymbol(StringRef symbol, EncodeKind kind, SymbolSource source,
Decl *decl, SymbolFlags flags) override {
if (kind != SymbolKind::GlobalSymbol)
if (kind != EncodeKind::GlobalSymbol)
return;

apigen::APIAvailability availability;
Expand Down Expand Up @@ -885,7 +885,7 @@ SymbolSourceMapRequest::evaluate(Evaluator &evaluator,
auto &Ctx = desc.getParentModule()->getASTContext();
auto *SymbolSources = Ctx.Allocate<SymbolSourceMap>();

auto addSymbol = [=](StringRef symbol, SymbolKind kind, SymbolSource source,
auto addSymbol = [=](StringRef symbol, EncodeKind kind, SymbolSource source,
Decl *decl, SymbolFlags flags) {
SymbolSources->insert({symbol, source});
};
Expand Down
16 changes: 8 additions & 8 deletions lib/IRGen/TBDGenVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class APIRecorder {
public:
virtual ~APIRecorder() {}

virtual void addSymbol(StringRef name, llvm::MachO::SymbolKind kind,
virtual void addSymbol(StringRef name, llvm::MachO::EncodeKind kind,
SymbolSource source, Decl *decl,
llvm::MachO::SymbolFlags flags) {}
virtual void addObjCInterface(const ClassDecl *decl) {}
Expand All @@ -72,12 +72,12 @@ class APIRecorder {
class SimpleAPIRecorder final : public APIRecorder {
public:
using SymbolCallbackFn =
llvm::function_ref<void(StringRef, llvm::MachO::SymbolKind, SymbolSource,
llvm::function_ref<void(StringRef, llvm::MachO::EncodeKind, SymbolSource,
Decl *, llvm::MachO::SymbolFlags)>;

SimpleAPIRecorder(SymbolCallbackFn func) : func(func) {}

void addSymbol(StringRef symbol, llvm::MachO::SymbolKind kind,
void addSymbol(StringRef symbol, llvm::MachO::EncodeKind kind,
SymbolSource source, Decl *decl,
llvm::MachO::SymbolFlags flags) override {
func(symbol, kind, source, decl, flags);
Expand All @@ -101,20 +101,20 @@ class TBDGenVisitor : public IRSymbolVisitor {
const TBDGenOptions &Opts;
APIRecorder &recorder;

using SymbolKind = llvm::MachO::SymbolKind;
using EncodeKind = llvm::MachO::EncodeKind;
using SymbolFlags = llvm::MachO::SymbolFlags;

std::vector<Decl*> DeclStack;
std::unique_ptr<std::map<std::string, InstallNameStore>>
previousInstallNameMap;
std::unique_ptr<std::map<std::string, InstallNameStore>>
parsePreviousModuleInstallNameMap();
void addSymbolInternal(StringRef name, SymbolKind kind, SymbolSource source,
void addSymbolInternal(StringRef name, EncodeKind kind, SymbolSource source,
SymbolFlags);
void addLinkerDirectiveSymbolsLdHide(StringRef name, SymbolKind kind);
void addLinkerDirectiveSymbolsLdPrevious(StringRef name, SymbolKind kind);
void addLinkerDirectiveSymbolsLdHide(StringRef name, EncodeKind kind);
void addLinkerDirectiveSymbolsLdPrevious(StringRef name, EncodeKind kind);
void addSymbol(StringRef name, SymbolSource source, SymbolFlags flags,
SymbolKind kind = SymbolKind::GlobalSymbol);
EncodeKind kind = EncodeKind::GlobalSymbol);

void addSymbol(LinkEntity entity);

Expand Down