IncludeGuardian created this revision.
IncludeGuardian added a reviewer: MaskRay.
Herald added a subscriber: hiraditya.
Herald added a project: All.
IncludeGuardian requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits.

**1st commit**
[lldb] Add missing StringExtras.h includes

In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.

This is fixing all files missed in b0abd4893fa1 
<https://reviews.llvm.org/rGb0abd4893fa1bfae7f71b6b6e98770c9b1c07620>, 
39d8e6e22cd1 
<https://reviews.llvm.org/rG39d8e6e22cd192db6ace37a4c842265058dcddb8>,
a11efd49266f 
<https://reviews.llvm.org/rGa11efd49266f6cf2a98bdf52428b0c9423158846>, 
5551657b310b 
<https://reviews.llvm.org/rG5551657b310b0f5f97b26288f87bc41a8050bf93>, and 
90bfe2df25e7 
<https://reviews.llvm.org/rG90bfe2df25e7eed4f3af33623ad26a028d94cef9>.

---

**2nd commit**
[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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155178

Files:
  lldb/unittests/Symbol/PostfixExpressionTest.cpp
  lldb/unittests/SymbolFile/NativePDB/UdtRecordCompleterTests.cpp
  llvm/include/llvm/Support/Error.h
  llvm/lib/Support/Error.cpp

Index: llvm/lib/Support/Error.cpp
===================================================================
--- llvm/lib/Support/Error.cpp
+++ llvm/lib/Support/Error.cpp
@@ -7,27 +7,29 @@
 //===----------------------------------------------------------------------===//

 #include "llvm/Support/Error.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/ErrorHandling.h"
 #include <system_error>

 using namespace llvm;

 namespace {

   enum class ErrorErrorCode : int {
     MultipleErrors = 1,
     FileError,
     InconvertibleError
   };

   // FIXME: This class is only here to support the transition to llvm::Error. It
   // will be removed once this transition is complete. Clients should prefer to
   // deal with the Error value directly, rather than converting to error_code.
   class ErrorErrorCategory : public std::error_category {
   public:
     const char *name() const noexcept override { return "Error"; }

     std::string message(int condition) const override {
       switch (static_cast<ErrorErrorCode>(condition)) {
       case ErrorErrorCode::MultipleErrors:
@@ -70,17 +72,26 @@
   });
 }

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

 std::error_code ErrorList::convertToErrorCode() const {
   return std::error_code(static_cast<int>(ErrorErrorCode::MultipleErrors),
                          getErrorErrorCat());
 }

 std::error_code inconvertibleErrorCode() {
   return std::error_code(static_cast<int>(ErrorErrorCode::InconvertibleError),
                          getErrorErrorCat());
 }

 std::error_code FileError::convertToErrorCode() const {
   std::error_code NestedEC = Err->convertToErrorCode();
   if (NestedEC == inconvertibleErrorCode())
Index: llvm/include/llvm/Support/Error.h
===================================================================
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -14,8 +14,6 @@
 #define LLVM_SUPPORT_ERROR_H

 #include "llvm-c/Error.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Config/abi-breaking.h"
 #include "llvm/Support/AlignOf.h"
@@ -1025,14 +1023,8 @@

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

 /// Consume a Error without doing anything. This method should be used
 /// only where an error can be considered a reasonable and expected return
 /// value.
Index: lldb/unittests/SymbolFile/NativePDB/UdtRecordCompleterTests.cpp
===================================================================
--- lldb/unittests/SymbolFile/NativePDB/UdtRecordCompleterTests.cpp
+++ lldb/unittests/SymbolFile/NativePDB/UdtRecordCompleterTests.cpp
@@ -7,24 +7,25 @@
 //===----------------------------------------------------------------------===//

 #include "Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h"
+#include "llvm/ADT/StringExtras.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"

 using namespace lldb_private::npdb;
 using namespace llvm;

 namespace {
 using Member = UdtRecordCompleter::Member;
 using MemberUP = std::unique_ptr<Member>;
 using Record = UdtRecordCompleter::Record;

 class WrappedMember {
 public:
   WrappedMember(const Member &obj) : m_obj(obj) {}

 private:
   const Member &m_obj;

   friend bool operator==(const WrappedMember &lhs, const WrappedMember &rhs) {
     return lhs.m_obj.kind == rhs.m_obj.kind &&
            lhs.m_obj.name == rhs.m_obj.name &&
Index: lldb/unittests/Symbol/PostfixExpressionTest.cpp
===================================================================
--- lldb/unittests/Symbol/PostfixExpressionTest.cpp
+++ lldb/unittests/Symbol/PostfixExpressionTest.cpp
@@ -9,16 +9,17 @@
 #include "lldb/Symbol/PostfixExpression.h"
 #include "lldb/Utility/DataExtractor.h"
 #include "lldb/Utility/StreamString.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/DebugInfo/DIContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/raw_ostream.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"

 using namespace lldb_private;
 using namespace lldb_private::postfix;

 static std::string ToString(BinaryOpNode::OpType type) {
   switch (type) {
   case BinaryOpNode::Align:
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits]... Elliot Goodrich via Phabricator via lldb-commits
    • [Lldb-com... Elliot Goodrich via Phabricator via lldb-commits
    • [Lldb-com... Felipe de Azevedo Piovezan via Phabricator via lldb-commits
    • [Lldb-com... Elliot Goodrich via Phabricator via lldb-commits
    • [Lldb-com... Elliot Goodrich via Phabricator via lldb-commits
    • [Lldb-com... Nico Weber via Phabricator via lldb-commits
    • [Lldb-com... Fangrui Song via Phabricator via lldb-commits
    • [Lldb-com... Fangrui Song via Phabricator via lldb-commits

Reply via email to