Skip to content

Commit 6c566eb

Browse files
varungandhi-srcreese-stripefroydnjthomasmarshallaadi-stripe
authored
chore: Merge upstream master into scip-ruby/master (#168)
Co-authored-by: Reese Williams <[email protected]> Co-authored-by: Nathan Froyd <[email protected]> Co-authored-by: Thomas Marshall <[email protected]> Co-authored-by: aadi-stripe <[email protected]> Co-authored-by: Mariano Simone <[email protected]> Co-authored-by: Jake Zimmerman <[email protected]> Co-authored-by: Reese Williams <[email protected]>
2 parents c7266c3 + 3e3abe6 commit 6c566eb

File tree

352 files changed

+3270
-1599
lines changed

Some content is hidden

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

352 files changed

+3270
-1599
lines changed

ast/Trees.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,15 @@ template <class T> void printArgs(const core::GlobalState &gs, fmt::memory_buffe
421421

422422
} // namespace
423423

424+
core::FoundClass::Kind ClassDef::kindToFoundClassKind(Kind kind) {
425+
switch (kind) {
426+
case Kind::Module:
427+
return core::FoundClass::Kind::Module;
428+
case Kind::Class:
429+
return core::FoundClass::Kind::Class;
430+
}
431+
}
432+
424433
string ClassDef::toStringWithTabs(const core::GlobalState &gs, int tabs) const {
425434
fmt::memory_buffer buf;
426435
if (kind == ClassDef::Kind::Module) {

ast/Trees.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,13 @@ EXPRESSION(ClassDef) {
352352
core::LocOffsets declLoc;
353353
core::ClassOrModuleRef symbol;
354354

355-
using Kind = core::FoundClass::Kind;
355+
enum class Kind : uint8_t {
356+
Module,
357+
Class,
358+
};
356359
Kind kind;
360+
361+
static core::FoundClass::Kind kindToFoundClassKind(Kind kind);
357362
static constexpr int EXPECTED_RHS_COUNT = 4;
358363
using RHS_store = InlinedVector<ExpressionPtr, EXPECTED_RHS_COUNT>;
359364

common/BUILD

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
cc_library(
22
name = "common",
3-
srcs = [
4-
"os/os.h",
5-
"os/os.cc",
6-
] + glob(
3+
srcs = glob(
74
[
85
"*.cc",
96
"*.h",
107
],
118
# workaround https://github.com/flycheck/flycheck/issues/248 in emacs
129
exclude = ["flycheck_*"],
13-
) + select({
14-
"//tools/config:darwin": ["os/mac.cc"],
15-
"//tools/config:webasm": ["os/emscripten.cc"],
16-
"//conditions:default": ["os/linux.cc"],
17-
}),
10+
),
1811
hdrs = [
1912
"FileOps.h",
2013
"FileSystem.h",
@@ -35,6 +28,10 @@ cc_library(
3528
}),
3629
visibility = ["//visibility:public"],
3730
deps = [
31+
"//common/concurrency",
32+
"//common/enforce_no_timer",
33+
"//common/exception",
34+
"//common/os",
3835
"//sorbet_version",
3936
"//third_party/progressbar",
4037
"@com_google_absl//absl/algorithm:container",

common/EarlyReturnWithCode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef SORBET_COMMON_EARLYRETURNWITHCODE_H
22
#define SORBET_COMMON_EARLYRETURNWITHCODE_H
33

4-
#include "Exception.h"
4+
#include "exception/Exception.h"
55

66
namespace sorbet {
77

common/FileOps.h

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <vector>
88

99
namespace sorbet {
10+
class WorkerPool;
1011

1112
class FileOps final {
1213
public:
@@ -16,36 +17,42 @@ class FileOps final {
1617
std::optional<std::string> output = std::nullopt;
1718
};
1819

19-
static bool exists(std::string_view filename);
20+
static bool exists(const std::string &filename);
2021
static bool isFile(std::string_view path, std::string_view ignorePattern, const int pos);
2122
static bool isFolder(std::string_view path, std::string_view ignorePattern, const int pos);
22-
static std::string read(std::string_view filename);
23-
static void write(std::string_view filename, const std::vector<uint8_t> &data);
24-
static void append(std::string_view filename, std::string_view text);
25-
static void write(std::string_view filename, std::string_view text);
26-
static bool writeIfDifferent(std::string_view filename, std::string_view text);
27-
static bool dirExists(std::string_view path);
28-
static void createDir(std::string_view path);
23+
static std::string read(const std::string &filename);
24+
static void write(const std::string &filename, const std::vector<uint8_t> &data);
25+
static void append(const std::string &filename, std::string_view text);
26+
static void write(const std::string &filename, std::string_view text);
27+
static bool writeIfDifferent(const std::string &filename, std::string_view text);
28+
static bool dirExists(const std::string &path);
29+
static void createDir(const std::string &path);
2930

3031
// This differs from createDir, as it will not raise an exception if the directory already exists. Returns true when
3132
// the directory was created, and false if it already existed.
3233
//
3334
// NOTE: This does not create parent directories if they exist.
34-
static bool ensureDir(std::string_view path);
35+
static bool ensureDir(const std::string &path);
3536

3637
static std::string getCurrentDir();
3738

3839
// NOTE: this is a minimal wrapper around rmdir, and as such will raise an exception if the directory is not empty
3940
// when it's removed.
40-
static void removeDir(std::string_view path);
41+
static void removeDir(const std::string &path);
42+
43+
// NOTE: this is a minimal wrapper around rmdir, and will return false if the directory is not empty
44+
// when it's removed. For any other errno, it will throw an exception. This exists as an convenience function to
45+
// prevent the caller from needing to try/catch removeDir.
46+
static bool removeEmptyDir(const std::string &path);
47+
48+
static void removeFile(const std::string &path);
4149

42-
static void removeFile(std::string_view path);
4350
/**
4451
* Returns a list of all files in the given directory. Returns paths that include the path to directory.
4552
* Throws FileNotFoundException if path does not exist, and FileNotDirException if path is not a directory.
4653
*/
4754
static std::vector<std::string> listFilesInDir(std::string_view path, const UnorderedSet<std::string> &extensions,
48-
bool recursive,
55+
WorkerPool &workers, bool recursive,
4956
const std::vector<std::string> &absoluteIgnorePatterns,
5057
const std::vector<std::string> &relativeIgnorePatterns);
5158
/**

common/FileSystem.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
#include "common/FileSystem.h"
22
#include "common/FileOps.h"
3+
#include "common/concurrency/WorkerPool.h"
34

45
namespace sorbet {
56
using namespace std;
67

7-
string OSFileSystem::readFile(string_view path) const {
8+
string OSFileSystem::readFile(const string &path) const {
89
return FileOps::read(path);
910
}
1011

11-
void OSFileSystem::writeFile(string_view filename, string_view text) {
12+
void OSFileSystem::writeFile(const string &filename, string_view text) {
1213
return FileOps::write(filename, text);
1314
}
1415

1516
std::string OSFileSystem::getCurrentDir() const {
1617
return FileOps::getCurrentDir();
1718
}
1819

20+
vector<string> FileSystem::listFilesInDir(std::string_view path, const UnorderedSet<std::string> &extensions,
21+
bool recursive, const std::vector<std::string> &absoluteIgnorePatterns,
22+
const std::vector<std::string> &relativeIgnorePatterns) const {
23+
unique_ptr<WorkerPool> workerPool = WorkerPool::create(0, *spdlog::default_logger());
24+
25+
return this->listFilesInDir(path, extensions, *workerPool, recursive, absoluteIgnorePatterns,
26+
relativeIgnorePatterns);
27+
}
28+
1929
vector<string> OSFileSystem::listFilesInDir(string_view path, const UnorderedSet<std::string> &extensions,
20-
bool recursive, const std::vector<std::string> &absoluteIgnorePatterns,
30+
WorkerPool &workerPool, bool recursive,
31+
const std::vector<std::string> &absoluteIgnorePatterns,
2132
const std::vector<std::string> &relativeIgnorePatterns) const {
22-
return FileOps::listFilesInDir(path, extensions, recursive, absoluteIgnorePatterns, relativeIgnorePatterns);
33+
return FileOps::listFilesInDir(path, extensions, workerPool, recursive, absoluteIgnorePatterns,
34+
relativeIgnorePatterns);
2335
}
2436

2537
} // namespace sorbet

common/FileSystem.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define COMMON_FILESYSTEM_H
33

44
#include "common/common.h"
5+
#include "common/concurrency/WorkerPool.h"
6+
#include <memory>
57
#include <string>
68
#include <vector>
79

@@ -16,10 +18,10 @@ class FileSystem {
1618
virtual ~FileSystem() = default;
1719

1820
/** Read the file at the given path. Throws a `FileNotFoundException` if not found. */
19-
virtual std::string readFile(std::string_view path) const = 0;
21+
virtual std::string readFile(const std::string &path) const = 0;
2022

2123
/** Writes the specified data to the given file. */
22-
virtual void writeFile(std::string_view filename, std::string_view text) = 0;
24+
virtual void writeFile(const std::string &filename, std::string_view text) = 0;
2325

2426
/** Gets the path for the current directory. */
2527
virtual std::string getCurrentDir() const = 0;
@@ -34,9 +36,14 @@ class FileSystem {
3436
* Throws FileNotFoundException if path does not exist, and FileNotDirException if path is not a directory.
3537
*/
3638
virtual std::vector<std::string> listFilesInDir(std::string_view path, const UnorderedSet<std::string> &extensions,
37-
bool recursive,
39+
WorkerPool &workerPool, bool recursive,
3840
const std::vector<std::string> &absoluteIgnorePatterns,
3941
const std::vector<std::string> &relativeIgnorePatterns) const = 0;
42+
43+
virtual std::vector<std::string> listFilesInDir(std::string_view path, const UnorderedSet<std::string> &extensions,
44+
bool recursive,
45+
const std::vector<std::string> &absoluteIgnorePatterns,
46+
const std::vector<std::string> &relativeIgnorePatterns) const;
4047
};
4148

4249
/**
@@ -46,14 +53,15 @@ class OSFileSystem final : public FileSystem {
4653
public:
4754
OSFileSystem() = default;
4855

49-
std::string readFile(std::string_view path) const override;
50-
void writeFile(std::string_view filename, std::string_view text) override;
56+
std::string readFile(const std::string &path) const override;
57+
void writeFile(const std::string &filename, std::string_view text) override;
5158
std::string getCurrentDir() const override;
5259
std::vector<std::string> listFilesInDir(std::string_view path, const UnorderedSet<std::string> &extensions,
53-
bool recursive, const std::vector<std::string> &absoluteIgnorePatterns,
60+
WorkerPool &workerPool, bool recursive,
61+
const std::vector<std::string> &absoluteIgnorePatterns,
5462
const std::vector<std::string> &relativeIgnorePatterns) const override;
5563
};
5664

5765
} // namespace sorbet
5866

59-
#endif // COMMON_FILESYSTEM_H
67+
#endif // COMMON_FILESYSTEM_H

0 commit comments

Comments
 (0)