Skip to content

Commit

Permalink
filter LLVM diagnostics before crossing the rust bridge
Browse files Browse the repository at this point in the history
this will eliminate many short-lived allocations (e.g. 20% of the memory used
building cargo) when unpacking the diagnostic and converting its various
C++ strings into rust strings, just to be filtered out most of the time.
  • Loading branch information
lqd committed Aug 1, 2023
1 parent 598acff commit 77d0110
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1905,12 +1905,19 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler(
LlvmRemarkStreamer(std::move(LlvmRemarkStreamer)) {}

virtual bool handleDiagnostics(const DiagnosticInfo &DI) override {
if (this->LlvmRemarkStreamer) {
if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) {
if (OptDiagBase->isEnabled()) {
// If this diagnostic is one of the optimization remark kinds, we can check if it's enabled
// before emitting it. This can avoid many short-lived allocations when unpacking the
// diagnostic and converting its various C++ strings into rust strings.
// FIXME: some diagnostic infos still allocate before we get here, and avoiding that would be
// good in the future. That will require changing a few call sites in LLVM.
if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) {
if (OptDiagBase->isEnabled()) {
if (this->LlvmRemarkStreamer) {
this->LlvmRemarkStreamer->emit(*OptDiagBase);
return true;
}
} else {
return true;
}
}
if (DiagnosticHandlerCallback) {
Expand Down

0 comments on commit 77d0110

Please sign in to comment.