Skip to content

Commit 5be8c89

Browse files
[Support] Move StringExtras.h include from Error.h to Error.cpp
Move the implementation of the `toString` function from `llvm/Support/Error.h` to the source file, which allows us to move `#include "llvm/ADT/StringExtras.h"` to the source file as well. As `Error.h` is present in a large number of translation units this means we are unnecessarily bringing in the contents of `StringExtras.h` - itself a large file with lots of includes - and slowing down compilation. Also move the `#include "llvm/ADT/SmallVector.h"` directive to the source file as it's no longer needed, but this does not give as much of a benefit. This reduces the total number of preprocessing tokens across the LLVM source files in lib from (roughly) 1,920,413,050 to 1,903,629,230 - a reduction of ~0.87%. This should result in a small improvement in compilation time. Differential Revision: https://reviews.llvm.org/D155018
1 parent 90bfe2d commit 5be8c89

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

llvm/include/llvm/Support/Error.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#define LLVM_SUPPORT_ERROR_H
1515

1616
#include "llvm-c/Error.h"
17-
#include "llvm/ADT/SmallVector.h"
18-
#include "llvm/ADT/StringExtras.h"
1917
#include "llvm/ADT/Twine.h"
2018
#include "llvm/Config/abi-breaking.h"
2119
#include "llvm/Support/AlignOf.h"
@@ -1025,13 +1023,7 @@ void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner = {});
10251023

10261024
/// Write all error messages (if any) in E to a string. The newline character
10271025
/// is used to separate error messages.
1028-
inline std::string toString(Error E) {
1029-
SmallVector<std::string, 2> Errors;
1030-
handleAllErrors(std::move(E), [&Errors](const ErrorInfoBase &EI) {
1031-
Errors.push_back(EI.message());
1032-
});
1033-
return join(Errors.begin(), Errors.end(), "\n");
1034-
}
1026+
std::string toString(Error E);
10351027

10361028
/// Consume a Error without doing anything. This method should be used
10371029
/// only where an error can be considered a reasonable and expected return

llvm/lib/Support/Error.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/Support/Error.h"
10+
#include "llvm/ADT/SmallVector.h"
11+
#include "llvm/ADT/StringExtras.h"
1012
#include "llvm/ADT/Twine.h"
1113
#include "llvm/Support/ErrorHandling.h"
1214
#include <system_error>
@@ -70,6 +72,15 @@ void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner) {
7072
});
7173
}
7274

75+
/// Write all error messages (if any) in E to a string. The newline character
76+
/// is used to separate error messages.
77+
std::string toString(Error E) {
78+
SmallVector<std::string, 2> Errors;
79+
handleAllErrors(std::move(E), [&Errors](const ErrorInfoBase &EI) {
80+
Errors.push_back(EI.message());
81+
});
82+
return join(Errors.begin(), Errors.end(), "\n");
83+
}
7384

7485
std::error_code ErrorList::convertToErrorCode() const {
7586
return std::error_code(static_cast<int>(ErrorErrorCode::MultipleErrors),

0 commit comments

Comments
 (0)