Skip to content

Commit 77d0110

Browse files
committed
filter LLVM diagnostics before crossing the rust bridge
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.
1 parent 598acff commit 77d0110

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -1905,12 +1905,19 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler(
19051905
LlvmRemarkStreamer(std::move(LlvmRemarkStreamer)) {}
19061906

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

0 commit comments

Comments
 (0)