Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyailya committed May 3, 2024
1 parent a8c4de5 commit bf58f54
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 48 deletions.
7 changes: 7 additions & 0 deletions core/GlobalState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2584,4 +2584,11 @@ spdlog::logger &GlobalState::tracer() const {
return errorQueue->tracer;
}

void GlobalState::clearErrorCacheForFile(
core::FileRef fref, std::function<bool(const std::unique_ptr<core::ErrorQueueMessage> &)> predicate) {
auto &prevErrors = errors[fref];

prevErrors.erase(std::remove_if(prevErrors.begin(), prevErrors.end(), predicate), prevErrors.end());
}

} // namespace sorbet::core
2 changes: 2 additions & 0 deletions core/GlobalState.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ class GlobalState final {

bool shouldReportErrorOn(Loc loc, ErrorClass what) const;

void clearErrorCacheForFile(core::FileRef fref,
std::function<bool(const std::unique_ptr<core::ErrorQueueMessage> &)> predicate);
UnorderedMap<core::FileRef, std::vector<std::unique_ptr<core::ErrorQueueMessage>>> errors;

private:
Expand Down
10 changes: 9 additions & 1 deletion main/lsp/LSPTypechecker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ bool LSPTypechecker::copyIndexed(WorkerPool &workers, const UnorderedSet<int> &i
return epochManager.wasTypecheckingCanceled();
}

// TODO(iz) add extra flushes
bool LSPTypechecker::runSlowPath(LSPFileUpdates updates, WorkerPool &workers,
shared_ptr<core::ErrorFlusher> errorFlusher, bool cancelable) {
ENFORCE(this_thread::get_id() == typecheckerThreadId,
Expand Down Expand Up @@ -476,6 +475,15 @@ bool LSPTypechecker::runSlowPath(LSPFileUpdates updates, WorkerPool &workers,
auto foundHashes = nullptr;
auto canceled =
pipeline::name(*gs, absl::Span<ast::ParsedFile>(indexedCopies), config->opts, workers, foundHashes);

for (auto &file : indexedCopies) {
gs->clearErrorCacheForFile(file.file, [](const unique_ptr<core::ErrorQueueMessage> &err) {
// Namer errors codes are 40XX
return err->error->what.code < 5000;
});
gs->errorQueue->flushButRetainErrorsForFile(*gs, file.file);
}

if (canceled) {
ast::ParsedFilesOrCancelled::cancel(move(indexedCopies), workers);
return;
Expand Down
50 changes: 7 additions & 43 deletions main/pipeline/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ using namespace std;

namespace sorbet::realmain::pipeline {

void clearCacheForFileAndCode(core::GlobalState &gs, core::FileRef fref,
std::function<bool(const std::unique_ptr<core::ErrorQueueMessage> &)> filter) {
auto &prevErrors = gs.errors[fref];

prevErrors.erase(std::remove_if(prevErrors.begin(), prevErrors.end(), filter), prevErrors.end());
}

class CFGCollectorAndTyper {
const options::Options &opts;

Expand Down Expand Up @@ -282,9 +275,9 @@ incrementalResolve(core::GlobalState &gs, vector<ast::ParsedFile> what,
ENFORCE(!canceled);

for (auto &file : what) {
auto code = 5000; // namer errors are 40xx
clearCacheForFileAndCode(gs, file.file, [code](const unique_ptr<core::ErrorQueueMessage> &err) {
return err->error->what.code < code;
gs.clearErrorCacheForFile(file.file, [](const unique_ptr<core::ErrorQueueMessage> &err) {
// Namer errors codes are 40XX
return err->error->what.code < 5000;
});

gs.errorQueue->flushButRetainErrorsForFile(gs, file.file);
Expand All @@ -307,7 +300,8 @@ incrementalResolve(core::GlobalState &gs, vector<ast::ParsedFile> what,
what = move(result.result());

for (auto &file : what) {
clearCacheForFileAndCode(gs, file.file, [](const unique_ptr<core::ErrorQueueMessage> &err) {
// Resolver errors codes are 50XX
gs.clearErrorCacheForFile(file.file, [](const unique_ptr<core::ErrorQueueMessage> &err) {
return err->error->what.code > 4999 && err->error->what.code < 6000;
});
gs.errorQueue->flushButRetainErrorsForFile(gs, file.file);
Expand Down Expand Up @@ -928,34 +922,6 @@ ast::ParsedFilesOrCancelled nameAndResolve(unique_ptr<core::GlobalState> &gs, ve
ast::ParsedFilesOrCancelled resolve(unique_ptr<core::GlobalState> &gs, vector<ast::ParsedFile> what,
const options::Options &opts, WorkerPool &workers) {
try {
<<<<<<< HEAD
auto canceled = name(*gs, absl::Span<ast::ParsedFile>(what), opts, workers, foundHashes);
if (canceled) {
return ast::ParsedFilesOrCancelled::cancel(move(what), workers);
}

for (auto &file : what) {
// gs.clearCache

clearCacheForFileAndCode(*gs, file.file, [](const unique_ptr<core::ErrorQueueMessage> &err) {
return err->error->what.code < 5000;
});
gs->errorQueue->flushButRetainErrorsForFile(*gs, file.file);
}
// for (auto &file : what) {
// gs->errorQueue->flushButRetainErrorsForFile(*gs, file.file);
// }
for (auto &named : what) {
if (opts.print.NameTree.enabled) {
opts.print.NameTree.fmt("{}\n", named.tree.toStringWithTabs(*gs, 0));
}
if (opts.print.NameTreeRaw.enabled) {
opts.print.NameTreeRaw.fmt("{}\n", named.tree.showRaw(*gs));
}
}

=======
>>>>>>> master
if (opts.stopAfterPhase != options::Phase::NAMER) {
ProgressIndicator namingProgress(opts.showProgress, "Resolving", 1);
{
Expand All @@ -978,14 +944,12 @@ ast::ParsedFilesOrCancelled resolve(unique_ptr<core::GlobalState> &gs, vector<as


for (auto &file : what) {
clearCacheForFileAndCode(*gs, file.file, [](const unique_ptr<core::ErrorQueueMessage> &err) {
gs->clearErrorCacheForFile(file.file, [](const unique_ptr<core::ErrorQueueMessage> &err) {
// Resolver errors codes are 50XX
return err->error->what.code > 4999 && err->error->what.code < 6000;
});
gs->errorQueue->flushButRetainErrorsForFile(*gs, file.file);
}
// for (auto &file : what) {
// gs->errorQueue->flushButRetainErrorsForFile(*gs, file.file);
// }
if (opts.stressIncrementalResolver) {
auto symbolsBefore = gs->symbolsUsedTotal();
for (auto &f : what) {
Expand Down
8 changes: 8 additions & 0 deletions main/realmain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,14 @@ int realmain(int argc, char *argv[]) {
auto foundHashes = nullptr;
auto canceled =
pipeline::name(*gs, absl::Span<ast::ParsedFile>(nonPackageIndexed), opts, *workers, foundHashes);

for (auto &file : nonPackageIndexed) {
gs->clearErrorCacheForFile(file.file, [](const unique_ptr<core::ErrorQueueMessage> &err) {
// Namer errors codes are 40XX
return err->error->what.code < 5000;
});
gs->errorQueue->flushButRetainErrorsForFile(*gs, file.file);
}
ENFORCE(!canceled, "There's no cancellation in batch mode");

pipeline::unpartitionPackageFiles(indexed, move(nonPackageIndexed));
Expand Down
8 changes: 4 additions & 4 deletions test/pipeline_test_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class ExpectationHandler {
shared_ptr<core::ErrorCollector> &errorCollector)
: test(test), errorQueue(errorQueue), errorCollector(errorCollector){};

void addObserved(const core::GlobalState &gs, string_view expectationType, std::function<string()> mkExp,
void addObserved(core::GlobalState &gs, string_view expectationType, std::function<string()> mkExp,
bool addNewline = true) {
if (test.expectations.contains(expectationType)) {
got[expectationType].append(mkExp());
Expand Down Expand Up @@ -156,7 +156,7 @@ class ExpectationHandler {
}
}

void drainErrors(const core::GlobalState &gs) {
void drainErrors(core::GlobalState &gs) {
// Moves errors from being owned by GlobalState to having been flushed by the flusher
// In our case, errorCollector is our error flusher (accumulates a vector, instead of
// printing to stdout).
Expand All @@ -167,7 +167,7 @@ class ExpectationHandler {
errors.insert(errors.end(), make_move_iterator(newErrors.begin()), make_move_iterator(newErrors.end()));
}

void dropErrors(const core::GlobalState &gs) {
void dropErrors(core::GlobalState &gs) {
// Moves errors from being owned by GlobalState to having been flushed by the flusher
// In our case, errorCollector is our error flusher (accumulates a vector, instead of
// printing to stdout).
Expand All @@ -176,7 +176,7 @@ class ExpectationHandler {
auto _newErrors = errorCollector->drainErrors();
}

void clear(const core::GlobalState &gs) {
void clear(core::GlobalState &gs) {
got.clear();
errorQueue->flushAllErrors(gs);
auto _newErrors = errorCollector->drainErrors();
Expand Down

0 comments on commit bf58f54

Please sign in to comment.