Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyailya committed May 2, 2024
1 parent aae8d77 commit 28009e2
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 75 deletions.
46 changes: 19 additions & 27 deletions core/ErrorQueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,18 @@ void ErrorQueue::flushAllErrors(GlobalState &gs) {
auto collectedErrors = drainAll();

for (auto &[file, errors] : gs.errors) {
move(errors.begin(), errors.end(), std::back_inserter(collected[file]));
move(errors.begin(), errors.end(), std::back_inserter(collectedErrors[file]));
errors.clear();
}
gs.errors.clear();

for (auto &it : collectedErrors) {
gs.tracer().debug("\n\n*** ErrorQueue::flushAllErrors:");
for (const auto &e : it.second) {
gs.tracer().debug("\n\t*** code: {} text: {}",
e->error != nullptr ? to_string(e->error->what.code) : "no error code",
e->text.value_or("empty text"));
}
errorFlusher->flushErrors(logger, gs, it.first, move(it.second));
}
}
Expand All @@ -61,27 +68,19 @@ void ErrorQueue::flushErrorsForFile(const GlobalState &gs, FileRef file) {
auto prevErrorsIt = gs.errors.find(file);
if (prevErrorsIt != gs.errors.end()) {
auto &prevErrors = (*prevErrorsIt).second;
for (auto &e: prevErrors) {
for (auto &e : prevErrors) {
auto cloned = make_unique<ErrorQueueMessage>(e->clone());
collected[file].emplace_back(move(cloned));
}
}

errorFlusher->flushErrors(logger, gs, file, move(collected[file]));
}

std::vector<std::unique_ptr<ErrorQueueMessage>> ErrorQueue::getErrorsForFile(const GlobalState &gs,
core::FileRef file) {
checkOwned();

Timer timeit(tracer, "ErrorQueue::getErrorsForFile");

core::ErrorQueueMessage msg;
for (auto result = queue.try_pop(msg); result.gotItem(); result = queue.try_pop(msg)) {
collected[msg.whatFile].emplace_back(make_unique<ErrorQueueMessage>(move(msg)));
gs.tracer().debug("\n\n*** ErrorQueue::flushErrorsForFile:");
for (const auto &e : collected[file]) {
gs.tracer().debug("\n\t*** code: {} text: {}",
e->error != nullptr ? to_string(e->error->what.code) : "no error code",
e->text.value_or("empty text"));
}

return move(collected[file]);
errorFlusher->flushErrors(logger, gs, file, move(collected[file]));
}

void ErrorQueue::flushButRetainErrorsForFile(GlobalState &gs, FileRef file) {
Expand All @@ -94,11 +93,6 @@ void ErrorQueue::flushButRetainErrorsForFile(GlobalState &gs, FileRef file) {
if (!result.gotItem()) {
continue;
}
// gs->tracer->error
const auto &[s, e] = msg.error->loc.position(gs);
gs.tracer().error("\n***\tcode: {} whatFile: {} header: {} kind: {} loc: {}:{} {}:{}", msg.error->what.code,
msg.whatFile.data(gs).path(), msg.error->header, msg.kind, s.line, s.column, e.line,
e.column);

collected[msg.whatFile].emplace_back(make_unique<ErrorQueueMessage>(move(msg)));
}
Expand All @@ -116,13 +110,11 @@ void ErrorQueue::flushButRetainErrorsForFile(GlobalState &gs, FileRef file) {
errorsToFlush.emplace_back(move(cloned));
}

gs.tracer().error("\n\n*** ErrorQueue::flushButRetainErrorsForFile:");
gs.tracer().debug("\n\n*** ErrorQueue::flushButRetainErrorsForFile:");
for (const auto &e : errorsToFlush) {
if (e == nullptr) {
stopInDebugger();
continue;
}
gs.tracer().error("\n\t*** {}", e->text.value_or("empty text"));
gs.tracer().debug("\n\t*** code: {} text: {}",
e->error != nullptr ? to_string(e->error->what.code) : "no error code",
e->text.value_or("empty text"));
}
errorFlusher->flushErrors(logger, gs, file, move(errorsToFlush));
};
Expand Down
1 change: 0 additions & 1 deletion core/ErrorQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class ErrorQueue {

/** Checks if the queue is empty. Is approximate if there are any concurrent dequeue/enqueue operations */
bool queueIsEmptyApprox() const;
std::vector<std::unique_ptr<ErrorQueueMessage>> getErrorsForFile(const GlobalState &gs, core::FileRef file);
};

} // namespace core
Expand Down
2 changes: 1 addition & 1 deletion main/lsp/ErrorReporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void ErrorReporter::pushDiagnostics(uint32_t epoch, core::FileRef file, const ve
fileErrorStatus.lastReportedEpoch = epoch;

auto it = epochTimers.find(epoch);
if (!it->second.hasFirstDiagnosticEndTimes && it != epochTimers.end()) {
if (it != epochTimers.end() && !it->second.hasFirstDiagnosticEndTimes) {
it->second.hasFirstDiagnosticEndTimes = true;
for (auto &timer : it->second.firstDiagnosticLatencyTimers) {
timer.setEndTime();
Expand Down
93 changes: 47 additions & 46 deletions main/pipeline/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ 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];

gs.tracer().debug("\n\n*** clearing cache\n***before:");
for (auto &msg : prevErrors) {
const auto &[s, e] = msg->error->loc.position(gs);
gs.tracer().debug("\n***\tcode: {} whatFile: {} header: {} kind: {} loc: {}:{} {}:{}", msg->error->what.code,
msg->whatFile.data(gs).path(), msg->error->header, msg->kind, s.line, s.column, e.line,
e.column);
}
prevErrors.erase(std::remove_if(prevErrors.begin(), prevErrors.end(), filter), prevErrors.end());
gs.tracer().debug("\n\n*** clearing cache\n***after:");
for (auto &msg : prevErrors) {
const auto &[s, e] = msg->error->loc.position(gs);
gs.tracer().debug("\n***\tcode: {} whatFile: {} header: {} kind: {} loc: {}:{} {}:{}", msg->error->what.code,
msg->whatFile.data(gs).path(), msg->error->header, msg->kind, s.line, s.column, e.line,
e.column);
}
}

class CFGCollectorAndTyper {
const options::Options &opts;

Expand Down Expand Up @@ -274,37 +295,13 @@ incrementalResolve(core::GlobalState &gs, vector<ast::ParsedFile> what,
// Cancellation cannot occur during incremental namer.
ENFORCE(!canceled);

gs.tracer().error("\n\n*** after {}namer:", runIncrementalNamer ? "incremental " : "");
gs.tracer().debug("\n\n*** after {}namer:", runIncrementalNamer ? "incremental " : "");
for (auto &file : what) {
// gs.clearCache

auto fref = file.file;
auto &prevErrors = gs.errors[fref];
auto code = 5000; // namer errors are 40xx
//

gs.tracer().error("\n\n*** clearing cache\n***before:");
for (auto &msg : prevErrors) {
const auto &[s, e] = msg->error->loc.position(gs);
gs.tracer().error("\n***\tcode: {} whatFile: {} header: {} kind: {} loc: {}:{} {}:{}",
msg->error->what.code, msg->whatFile.data(gs).path(), msg->error->header, msg->kind,
s.line, s.column, e.line, e.column);
}
prevErrors.erase(std::remove_if(prevErrors.begin(), prevErrors.end(),
[code](const unique_ptr<core::ErrorQueueMessage> &err) {
return err->error->what.code < code;
}),
prevErrors.end());
gs.tracer().error("\n\n*** clearing cache\n***after:");
for (auto &msg : prevErrors) {
const auto &[s, e] = msg->error->loc.position(gs);
gs.tracer().error("\n***\tcode: {} whatFile: {} header: {} kind: {} loc: {}:{} {}:{}",
msg->error->what.code, msg->whatFile.data(gs).path(), msg->error->header, msg->kind,
s.line, s.column, e.line, e.column);
}
// gs.reportErrorsForFile()
// gs.pullErrorsFromTheQueue
// gs.mixErrors
clearCacheForFileAndCode(gs, file.file, [code](const unique_ptr<core::ErrorQueueMessage> &err) {
return err->error->what.code < code;
});

gs.errorQueue->flushButRetainErrorsForFile(gs, file.file);
}
// Required for autogen tests, which need to control which phase to stop after.
Expand All @@ -324,10 +321,13 @@ incrementalResolve(core::GlobalState &gs, vector<ast::ParsedFile> what,
ENFORCE(result.hasResult());
what = move(result.result());

gs.tracer().error("\n\n*** after incremental resolver:");
// for (auto &file : what) {
// gs.errorQueue->flushButRetainErrorsForFile(gs, file.file);
// }
gs.tracer().debug("\n\n*** after incremental resolver:");
for (auto &file : what) {
clearCacheForFileAndCode(gs, 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);
}
// Required for autogen tests, which need to control which phase to stop after.
if (opts.stopAfterPhase == options::Phase::RESOLVER) {
return what;
Expand Down Expand Up @@ -904,20 +904,13 @@ ast::ParsedFilesOrCancelled resolve(unique_ptr<core::GlobalState> &gs, vector<as
return ast::ParsedFilesOrCancelled::cancel(move(what), workers);
}

// gs->tracer().error("\n\n*** after namer:");
gs->tracer().debug("\n\n*** after full namer:");
for (auto &file : what) {
// gs.clearCache

auto fref = file.file;
auto code = 5000; // namer errors are 40xx
gs->errors[fref].erase(std::remove_if(gs->errors[fref].begin(), gs->errors[fref].end(),
[code](const unique_ptr<core::ErrorQueueMessage> &err) {
return err->error->what.code < code;
}),
gs->errors[fref].end());
// gs.reportErrorsForFile()
// gs.pullErrorsFromTheQueue
// gs.mixErrors
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) {
Expand Down Expand Up @@ -952,7 +945,14 @@ ast::ParsedFilesOrCancelled resolve(unique_ptr<core::GlobalState> &gs, vector<as
}
#endif

gs->tracer().error("\n\n*** after resolver:");
gs->tracer().debug("\n\n*** after resolver:");

for (auto &file : what) {
clearCacheForFileAndCode(*gs, 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);
}
// for (auto &file : what) {
// gs->errorQueue->flushButRetainErrorsForFile(*gs, file.file);
// }
Expand Down Expand Up @@ -1167,7 +1167,7 @@ void typecheck(const core::GlobalState &gs, vector<ast::ParsedFile> what, const
typecheckOne(ctx, move(job), opts, intentionallyLeakASTs);
} catch (SorbetException &) {
Exception::failInFuzzer();
gs.tracer().error("Exception typing file: {} (backtrace is above)",
gs.tracer().debug("Exception typing file: {} (backtrace is above)",
file.data(gs).path());
}
// Stream out errors
Expand Down Expand Up @@ -1448,3 +1448,4 @@ void printUntypedBlames(const core::GlobalState &gs, const UnorderedMap<long, lo
}

} // namespace sorbet::realmain::pipeline
// #611F69,#243806,#729C1A,#C474D

0 comments on commit 28009e2

Please sign in to comment.