8000 Delete a bunch of `std::` by jez · Pull Request #8849 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Delete a bunch of std:: #8849

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 19 commits into from
May 16, 2025
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
2 changes: 1 addition & 1 deletion ast/ArgParsing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ vector<core::ParsedArg> ArgParsing::parseArgs(const ast::MethodDef::ARGS_store &
}

// This has to match the implementation of Method::methodArityHash
core::ArityHash ArgParsing::hashArgs(core::Context ctx, const std::vector<core::ParsedArg> &args) {
core::ArityHash ArgParsing::hashArgs(core::Context ctx, const vector<core::ParsedArg> &args) {
uint32_t result = 0;
result = core::mix(result, args.size());
for (const auto &e : args) {
Expand Down
2 changes: 1 addition & 1 deletion ast/TreeCopying.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ ExpressionPtr deepCopy(const void *avoid, const Tag tag, const void *tree, bool

case Tag::ConstantLit: {
auto *exp = reinterpret_cast<const ConstantLit *>(tree);
std::unique_ptr<UnresolvedConstantLit> originalC;
unique_ptr<UnresolvedConstantLit> originalC;
if (auto *original = exp->original()) {
originalC =
make_unique<UnresolvedConstantLit>(original->loc, deepCopy(avoid, original->scope), original->cnst);
Expand Down
14 changes: 7 additions & 7 deletions ast/Trees.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ ConstantLit::ConstantLit(core::LocOffsets loc, core::SymbolRef symbol) : storage
_sanityCheck();
}

ConstantLit::ConstantLit(core::SymbolRef symbol, std::unique_ptr<UnresolvedConstantLit> original)
ConstantLit::ConstantLit(core::SymbolRef symbol, unique_ptr<UnresolvedConstantLit> original)
: storage(symbol, std::move(original)) {
categoryCounterInc("trees", "resolvedconstantlit");
_sanityCheck();
Expand Down Expand Up @@ -1010,20 +1010,20 @@ string Send::showRaw(const core::GlobalState &gs, int tabs) const {
return fmt::to_string(buf);
}

std::string RuntimeMethodDefinition::toStringWithTabs(const core::GlobalState &gs, int tabs) const {
string RuntimeMethodDefinition::toStringWithTabs(const core::GlobalState &gs, int tabs) const {
string prefix = this->isSelfMethod ? "self." : "";
return fmt::format("<runtime method definition of {}{}>", prefix, this->name.toString(gs));
}

std::string RuntimeMethodDefinition::showRaw(const core::GlobalState &gs, int tabs) const {
string RuntimeMethodDefinition::showRaw(const core::GlobalState &gs, int tabs) const {
return this->toStringWithTabs(gs, tabs);
}

std::string Self::toStringWithTabs(const core::GlobalState &gs, int tabs) const {
string Self::toStringWithTabs(const core::GlobalState &gs, int tabs) const {
return "<self>";
}

std::string Self::showRaw(const core::GlobalState &gs, int tabs) const {
string Self::showRaw(const core::GlobalState &gs, int tabs) const {
return "Self";
}

Expand Down Expand Up @@ -1497,9 +1497,9 @@ string Self::nodeName() const {
}

ParsedFilesOrCancelled::ParsedFilesOrCancelled() : trees(nullopt){};
ParsedFilesOrCancelled::ParsedFilesOrCancelled(std::vector<ParsedFile> &&trees) : trees(move(trees)) {}
ParsedFilesOrCancelled::ParsedFilesOrCancelled(vector<ParsedFile> &&trees) : trees(move(trees)) {}

ParsedFilesOrCancelled ParsedFilesOrCancelled::cancel(std::vector<ParsedFile> &&trees, WorkerPool &workers) {
ParsedFilesOrCancelled ParsedFilesOrCancelled::cancel(vector<ParsedFile> &&trees, WorkerPool &workers) {
if (!trees.empty()) {
auto fileq = make_shared<ConcurrentBoundedQueue<ast::ParsedFile>>(trees.size());
for (auto &tree : trees) {
Expand Down
6 changes: 3 additions & 3 deletions ast/desugar/Desugar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ ExpressionPtr node2TreeImplBody(DesugarContext dctx, parser::Node *what) {
argnodes.erase(fwdRestIt);
}

std::unique_ptr<parser::Node> array = make_unique<parser::Array>(locZeroLen, std::move(argnodes));
unique_ptr<parser::Node> array = make_unique<parser::Array>(locZeroLen, std::move(argnodes));
auto args = node2TreeImpl(dctx, array);

if (hasFwdArgs) {
Expand Down Expand Up @@ -1506,7 +1506,7 @@ ExpressionPtr node2TreeImplBody(DesugarContext dctx, parser::Node *what) {
// Replace the original method name with a new special one that conveys that this is a CSend, so
// that a&.foo is treated as different from a.foo when checking for structural equality.
auto newFun = dctx.ctx.state.freshNameUnique(core::UniqueNameKind::DesugarCsend, csend->method, 1);
std::unique_ptr<parser::Node> sendNode = make_unique<parser::Send>(
unique_ptr<parser::Node> sendNode = make_unique<parser::Send>(
loc, std::move(csend->receiver), newFun, csend->methodLoc, std::move(csend->args));
auto send = node2TreeImpl(dctx, sendNode);
result = std::move(send);
Expand Down Expand Up @@ -1765,7 +1765,7 @@ ExpressionPtr node2TreeImplBody(DesugarContext dctx, parser::Node *what) {
// Do this by synthesizing a `Send` parse node and letting our
// Send desugar handle it.
auto method = maybeTypedSuper(dctx);
std::unique_ptr<parser::Node> send =
unique_ptr<parser::Node> send =
make_unique<parser::Send>(super->loc, nullptr, method, super->loc, std::move(super->args));
auto res = node2TreeImpl(dctx, send);
result = std::move(res);
Expand Down
4 changes: 2 additions & 2 deletions cfg/Instructions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ string spacesForTabLevel(int tabs) {
CASE_STATEMENT(body, KeepAlive) \
}

std::string InstructionPtr::toString(const core::GlobalState &gs, const CFG &cfg) const {
string InstructionPtr::toString(const core::GlobalState &gs, const CFG &cfg) const {
auto *ptr = get();

#define TO_STRING(name) return static_cast<const name *>(ptr)->toString(gs, cfg);
GENERATE_TAG_SWITCH(tag(), TO_STRING)
#undef TO_STRING
}

std::string InstructionPtr::showRaw(const core::GlobalState &gs, const CFG &cfg, int tabs) const {
string InstructionPtr::showRaw(const core::GlobalState &gs, const CFG &cfg, int tabs) const {
auto *ptr = get();

#define SHOW_RAW(name) return static_cast<const name *>(ptr)->showRaw(gs, cfg, tabs);
Expand Down
6 changes: 3 additions & 3 deletions cfg/builder/builder_finalize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,13 @@ struct WorkItem {

} // namespace

std::vector<int> CFGBuilder::topoSortFwd(vector<BasicBlock *> &target, int numBlocks, BasicBlock *entryBB) {
vector<int> CFGBuilder::topoSortFwd(vector<BasicBlock *> &target, int numBlocks, BasicBlock *entryBB) {
ENFORCE(target.empty(), "The output vector must be empty to start with");

target.reserve(numBlocks);

std::vector<int> forwardIndex(numBlocks, UNVISITED);
std::vector<WorkItem> work;
vector<int> forwardIndex(numBlocks, UNVISITED);
vector<WorkItem> work;

// Arbitrary, could use tuning
work.reserve(10);
Expand Down
12 changes: 6 additions & 6 deletions common/FileSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ void OSFileSystem::writeFile(const string &filename, string_view text) {
return FileOps::write(filename, text);
}

vector<string> FileSystem::listFilesInDir(std::string_view path, const UnorderedSet<std::string> &extensions,
bool recursive, const std::vector<std::string> &absoluteIgnorePatterns,
const std::vector<std::string> &relativeIgnorePatterns) const {
vector<string> FileSystem::listFilesInDir(string_view path, const UnorderedSet<string> &extensions, bool recursive,
const vector<string> &absoluteIgnorePatterns,
const vector<string> &relativeIgnorePatterns) const {
unique_ptr<WorkerPool> workerPool = WorkerPool::create(0, *spdlog::default_logger());

return this->listFilesInDir(path, extensions, *workerPool, recursive, absoluteIgnorePatterns,
relativeIgnorePatterns);
}

vector<string> OSFileSystem::listFilesInDir(string_view path, const UnorderedSet<std::string> &extensions,
vector<string> OSFileSystem::listFilesInDir(string_view path, const UnorderedSet<string> &extensions,
WorkerPool &workerPool, bool recursive,
const std::vector<std::string> &absoluteIgnorePatterns,
const std::vector<std::string> &relativeIgnorePatterns) const {
const vector<string> &absoluteIgnorePatterns,
const vector<string> &relativeIgnorePatterns) const {
return FileOps::listFilesInDir(path, extensions, workerPool, recursive, absoluteIgnorePatterns,
relativeIgnorePatterns);
}
Expand Down
13 changes: 6 additions & 7 deletions common/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ string_view sorbet::FileOps::getExtension(string_view path) {
return path.substr(found + 1);
}

bool sorbet::FileOps::hasAllowedExtension(std::string_view path, const UnorderedSet<std::string> &extensions) {
bool sorbet::FileOps::hasAllowedExtension(string_view path, const UnorderedSet<string> &extensions) {
auto dotLocation = path.rfind('.');
if (dotLocation == string_view::npos) {
return false;
Expand Down Expand Up @@ -301,8 +301,7 @@ using JobOutput = variant<std::monostate, sorbet::FileNotFoundException, sorbet:

void appendFilesInDir(string_view basePath, const string &path, const sorbet::UnorderedSet<string> &extensions,
sorbet::WorkerPool &workers, bool recursive, vector<string> &allPaths,
const std::vector<std::string> &absoluteIgnorePatterns,
const std::vector<std::string> &relativeIgnorePatterns) {
const vector<string> &absoluteIgnorePatterns, const vector<string> &relativeIgnorePatterns) {
auto numWorkers = max(workers.size(), 1);
auto jobq = make_shared<ConcurrentUnBoundedQueue<Job>>();
auto resultq = make_shared<BlockingBoundedQueue<JobOutput>>(numWorkers);
Expand Down Expand Up @@ -459,8 +458,8 @@ void appendFilesInDir(string_view basePath, const string &path, const sorbet::Un

vector<string> sorbet::FileOps::listFilesInDir(string_view path, const UnorderedSet<string> &extensions,
WorkerPool &workerPool, bool recursive,
const std::vector<std::string> &absoluteIgnorePatterns,
const std::vector<std::string> &relativeIgnorePatterns) {
const vector<string> &absoluteIgnorePatterns,
const vector<string> &relativeIgnorePatterns) {
vector<string> result;
// Mini-optimization: appendFilesInDir needs to grab a c_str from path, so we pass in a string reference to avoid
// copying.
Expand Down Expand Up @@ -516,8 +515,8 @@ class SetTerminateHandler {
} catch (const std::exception &e) {
sorbet::fatalLogger->error("Sorbet raised uncaught exception type=\"{}\" what=\"{}\"",
demangle(typeid(e).name()), absl::CEscape(e.what()));
} catch (const std::string &s) {
sorbet::fatalLogger->error("Sorbet raised uncaught exception type=std::string what=\"{}\"",
} catch (const string &s) {
sorbet::fatalLogger->error("Sorbet raised uncaught exception type=string what=\"{}\"",
absl::CEscape(s));
} catch (const char *s) {
sorbet::fatalLogger->error("Sorbet raised uncaught exception type=\"char *\" what=\"{}\"",
Expand Down
8 changes: 4 additions & 4 deletions common/kvstore/KeyValueStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ int OwnedKeyValueStore::commit() {
return rc;
}

std::string_view OwnedKeyValueStore::kvstorePath() const {
string_view OwnedKeyValueStore::kvstorePath() const {
ENFORCE(kvstore != nullptr);
// This is used in error handling code, so we want to degrade gracefully if the ENFORCE is broken.
if (kvstore == nullptr) {
Expand All @@ -217,7 +217,7 @@ OwnedKeyValueStore::~OwnedKeyValueStore() {
abort();
}

void OwnedKeyValueStore::writeInternal(std::string_view key, void *value, size_t len) {
void OwnedKeyValueStore::writeInternal(string_view key, void *value, size_t len) {
if (writerId != this_thread::get_id()) {
throw_mdb_error("KeyValueStore can only write from thread that created it"sv, 0, kvstorePath());
}
Expand Down Expand Up @@ -482,15 +482,15 @@ unique_ptr<KeyValueStore> OwnedKeyValueStore::bestEffortCommit(spdlog::logger &l
return move(ownedKvstore->kvstore);
}

void OwnedKeyValueStore::copyTo(const std::string &path) const {
void OwnedKeyValueStore::copyTo(const string &path) const {
this->abort();

auto rc = mdb_env_copy(this->kvstore->dbState->env, path.c_str());
if (rc != 0) {
if (rc == ENOENT) {
}
try {
filesystem::create_directories(std::string_view(path));
filesystem::create_directories(string_view(path));
} catch (filesystem::filesystem_error &e) {
fmt::print(stderr,
"'{}' does not exist and could not be created. "
Expand Down
16 changes: 9 additions & 7 deletions common/web_tracer_framework/test/tracing_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#include "common/sort/sort.h"
#include "common/web_tracer_framework/tracing.h"

using namespace std;

namespace sorbet::web_tracer_framework {

class TracingTestHelper {
public:
static std::unique_ptr<CounterImpl> generateCounterStateImpl() {
auto impl = std::make_unique<CounterImpl>();
static unique_ptr<CounterImpl> generateCounterStateImpl() {
auto impl = make_unique<CounterImpl>();

// Deliberately output these in non-alphabetical order to maybe encourage the
// linker to output the strings in such a way as to motivate the sorting below.
Expand All @@ -34,10 +36,10 @@ class TracingTestHelper {
return CounterState{generateCounterStateImpl()};
}

static std::string generateJSON(pid_t pid, microseconds now, bool strict) {
static string generateJSON(pid_t pid, microseconds now, bool strict) {
CounterState state(TracingTestHelper::generateCounterState());

std::string jsonl = Tracing::stateToJSONL(state, pid, now);
string jsonl = Tracing::stateToJSONL(state, pid, now);

// The first line of `jsonl` is going to contain information about the Sorbet
// version. We don't really care about that, and handling that would make the
Expand All @@ -55,7 +57,7 @@ class TracingTestHelper {
// stores them based on the hashes of the string pointers, and that in turn depends
// on the vagaries of where the linker decided to put the string constants for the
// counter names.
std::vector<std::string> lines = absl::StrSplit(jsonl, '\n');
vector<string> lines = absl::StrSplit(jsonl, '\n');
{
// Don't sort empty lines.
auto it = absl::c_find_if(lines, [](const auto &line) { return line.empty(); });
Expand All @@ -76,7 +78,7 @@ TEST_SUITE("Tracing") {
microseconds now{20200928};

const bool strict = false;
std::string json = TracingTestHelper::generateJSON(pid, now, strict);
string json = TracingTestHelper::generateJSON(pid, now, strict);

// clang-format off
CHECK_EQ("[\n"
Expand All @@ -92,7 +94,7 @@ TEST_SUITE("Tracing") {
microseconds now{20200928};

const bool strict = true;
std::string json = TracingTestHelper::generateJSON(pid, now, strict);
string json = TracingTestHelper::generateJSON(pid, now, strict);

// clang-format off
CHECK_EQ("[\n"
Expand Down
10 changes: 5 additions & 5 deletions core/Error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ void ErrorSection::Collector::addErrorDetails(ErrorSection::Collector &&e) {

void toErrorSectionHelper(const ErrorSection::Collector &e, vector<ErrorLine> &result, int indentLevel) {
ENFORCE(e.message.length() > 0);
std::string message = fmt::format("{}{}", string(indentLevel * 2, ' '), e.message);
string message = fmt::format("{}{}", string(indentLevel * 2, ' '), e.message);
result.push_back(ErrorLine(core::Loc::none(), move(message), ErrorLine::LocDisplay::Hidden));
for (auto &c : e.children) {
toErrorSectionHelper(c, result, indentLevel + 1);
}
}

std::optional<ErrorSection> ErrorSection::Collector::toErrorSection() const {
optional<ErrorSection> ErrorSection::Collector::toErrorSection() const {
if (children.size() == 0) {
return nullopt;
}
Expand Down Expand Up @@ -213,7 +213,7 @@ void ErrorBuilder::addAutocorrect(AutocorrectSuggestion &&autocorrect) {
sectionTitle = "Autocorrect:";
}

std::vector<ErrorLine> messages;
vector<ErrorLine> messages;
for (auto &edit : autocorrect.edits) {
auto isInsert = edit.replacement == "";
uint32_t n = edit.loc.endPos() - edit.loc.beginPos();
Expand All @@ -238,12 +238,12 @@ void ErrorBuilder::addAutocorrect(AutocorrectSuggestion &&autocorrect) {
this->autocorrects.emplace_back(move(autocorrect));
}

void ErrorBuilder::didYouMean(const std::string &replacement, Loc loc) {
void ErrorBuilder::didYouMean(const string &replacement, Loc loc) {
if (!gs.didYouMean) {
return;
}

std::string formatted = fmt::format("Replace with `{}`", replacement);
string formatted = fmt::format("Replace with `{}`", replacement);
auto isDidYouMean = true;
addAutocorrect(
AutocorrectSuggestion{move(formatted), {AutocorrectSuggestion::Edit{loc, replacement}}, isDidYouMean});
Expand Down
2 changes: 1 addition & 1 deletion core/ErrorCollector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace std;
namespace sorbet::core {

void ErrorCollector::flushErrors(spdlog::logger &logger, const core::GlobalState &gs, core::FileRef file,
std::vector<std::unique_ptr<core::ErrorQueueMessage>> errors) {
vector<unique_ptr<core::ErrorQueueMessage>> errors) {
for (auto &error : errors) {
if (error->kind == core::ErrorQueueMessage::Kind::Error) {
if (error->error->isSilenced) {
Expand Down
4 changes: 2 additions & 2 deletions core/FileHash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ uint32_t hashFullNameRef(const GlobalState &gs, NameRef nm) {
WithoutUniqueNameHash::WithoutUniqueNameHash(const GlobalState &gs, NameRef nm)
: _hashValue(incZero(hashNameRefWithoutUniques(gs, nm))){};

void WithoutUniqueNameHash::sortAndDedupe(std::vector<core::WithoutUniqueNameHash> &hashes) {
void WithoutUniqueNameHash::sortAndDedupe(vector<core::WithoutUniqueNameHash> &hashes) {
fast_sort(hashes);
hashes.resize(std::distance(hashes.begin(), std::unique(hashes.begin(), hashes.end())));
hashes.shrink_to_fit();
}

FullNameHash::FullNameHash(const GlobalState &gs, NameRef nm) : _hashValue(incZero(hashFullNameRef(gs, nm))) {}

void FullNameHash::sortAndDedupe(std::vector<core::FullNameHash> &hashes) {
void FullNameHash::sortAndDedupe(vector<core::FullNameHash> &hashes) {
fast_sort(hashes);
hashes.resize(std::distance(hashes.begin(), std::unique(hashes.begin(), hashes.end())));
hashes.shrink_to_fit();
Expand Down
2 changes: 1 addition & 1 deletion core/FoundDefinitions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ string FoundTypeMember::toString(const core::GlobalState &gs, const FoundDefinit
return fmt::format("{{ id = {}, owner = {}, name = {} }}", id, owner.idx(), name.toString(gs));
}

std::string FoundMethod::toString(const core::GlobalState &gs, const FoundDefinitions &foundDefs, uint32_t id) const {
string FoundMethod::toString(const core::GlobalState &gs, const FoundDefinitions &foundDefs, uint32_t id) const {
return fmt::format("{{ id = {}, owner = {}, name = {} }}", id, owner.idx(), name.toString(gs));
}

Expand Down
Loading
0