Skip to content

Commit

Permalink
Split package db loading up from namespace generation (sorbet#5311)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottt authored Feb 15, 2022
1 parent 20f6782 commit fb29d1f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
4 changes: 2 additions & 2 deletions main/realmain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,6 @@ int realmain(int argc, char *argv[]) {
gs->errorUrlBase = opts.errorUrlBase;
gs->semanticExtensions = move(extensions);
vector<ast::ParsedFile> indexed;
UnorderedSet<core::ClassOrModuleRef> packageNamespaces;

gs->requiresAncestorEnabled = opts.requiresAncestorEnabled;

Expand Down Expand Up @@ -585,7 +584,7 @@ int realmain(int argc, char *argv[]) {

auto packageFileRefs = pipeline::reserveFiles(gs, packageFiles);
auto packages = pipeline::index(*gs, packageFileRefs, opts, *workers, nullptr);
packageNamespaces = packager::RBIGenerator::buildPackageNamespace(*gs, packages, *workers);
packages = packager::Packager::findPackages(*gs, *workers, move(packages));
#endif
}

Expand Down Expand Up @@ -737,6 +736,7 @@ int realmain(int argc, char *argv[]) {
logger->warn("Package rbi generation is disabled in sorbet-orig for faster builds");
return 1;
#else
auto packageNamespaces = packager::RBIGenerator::buildPackageNamespace(*gs, *workers);
packager::RBIGenerator::run(*gs, packageNamespaces, opts.packageRBIOutput, *workers);
#endif
}
Expand Down
6 changes: 1 addition & 5 deletions packager/rbi_gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1215,11 +1215,7 @@ class RBIExporter final {
};
} // namespace

UnorderedSet<core::ClassOrModuleRef>
RBIGenerator::buildPackageNamespace(core::GlobalState &gs, vector<ast::ParsedFile> &packageFiles, WorkerPool &workers) {
// Populate package database.
packageFiles = Packager::findPackages(gs, workers, move(packageFiles));

UnorderedSet<core::ClassOrModuleRef> RBIGenerator::buildPackageNamespace(core::GlobalState &gs, WorkerPool &workers) {
const auto &packageDB = gs.packageDB();

auto &packages = packageDB.packages();
Expand Down
3 changes: 1 addition & 2 deletions packager/rbi_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class RBIGenerator final {
};

// Exposed for testing.
static UnorderedSet<core::ClassOrModuleRef>
buildPackageNamespace(core::GlobalState &gs, std::vector<ast::ParsedFile> &packageFiles, WorkerPool &workers);
static UnorderedSet<core::ClassOrModuleRef> buildPackageNamespace(core::GlobalState &gs, WorkerPool &workers);
static RBIOutput runOnce(const core::GlobalState &gs, core::NameRef pkg,
const UnorderedSet<core::ClassOrModuleRef> &packageNamespaces);

Expand Down
6 changes: 3 additions & 3 deletions test/pipeline_test_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ TEST_CASE("PerPhaseTest") { // NOLINT
tree = ast::ParsedFile{rewriter::Rewriter::run(ctx, move(tree.tree)), tree.file};
tree = testSerialize(*gs, local_vars::LocalVars::run(ctx, move(tree)));

if (FileOps::getFileName(tree.file.data(*rbiGenGs).path()) == packageFileName) {
if (tree.file.data(*rbiGenGs).isPackage()) {
packageTrees.emplace_back(move(tree));
} else {
trees.emplace_back(move(tree));
Expand All @@ -373,8 +373,8 @@ TEST_CASE("PerPhaseTest") { // NOLINT

// RBI generation
{
auto packageNamespaces =
packager::RBIGenerator::buildPackageNamespace(*rbiGenGs, packageTrees, *workers);
packageTrees = packager::Packager::findPackages(*rbiGenGs, *workers, move(packageTrees));
auto packageNamespaces = packager::RBIGenerator::buildPackageNamespace(*rbiGenGs, *workers);
for (auto &package : rbiGenGs->packageDB().packages()) {
auto output = packager::RBIGenerator::runOnce(*rbiGenGs, package, packageNamespaces);
if (!output.rbi.empty()) {
Expand Down

0 comments on commit fb29d1f

Please sign in to comment.