[llvm] e9211e0 - Remove dependency from raw_ostream on <chrono>
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 21 06:17:57 PST 2022
Author: serge-sans-paille
Date: 2022-01-21T15:17:39+01:00
New Revision: e9211e03937751ab75bbb34e38acc330b85fb0d8
URL: https://github.com/llvm/llvm-project/commit/e9211e03937751ab75bbb34e38acc330b85fb0d8
DIFF: https://github.com/llvm/llvm-project/commit/e9211e03937751ab75bbb34e38acc330b85fb0d8.diff
LOG: Remove dependency from raw_ostream on <chrono>
The tryLockFor method from raw_fd_sotreamis the sole user of that
header, and it's not referenced in the mono repo. I still chose to keep
it (may be useful for downstream user) but added a transient type that's
forward declared to hold the duration parameter.
Notable changes:
- "llvm/Support/Duration.h" must be included in order to use tryLockFor.
- "llvm/Support/raw_ostream.h" no longer includes <chrono>
This sole change has an interesting impact on the number of processed
line, as measured by:
clang++ -E -Iinclude -I../llvm/include ../llvm/lib/Support/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l
before: 7917500
after: 7835142
Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
Added:
llvm/include/llvm/Support/Duration.h
Modified:
lldb/tools/lldb-vscode/FifoFiles.h
llvm/include/llvm/Debuginfod/Debuginfod.h
llvm/include/llvm/Debuginfod/HTTPClient.h
llvm/include/llvm/Support/raw_ostream.h
llvm/lib/Support/raw_ostream.cpp
llvm/unittests/Support/Path.cpp
Removed:
################################################################################
diff --git a/lldb/tools/lldb-vscode/FifoFiles.h b/lldb/tools/lldb-vscode/FifoFiles.h
index f186f65e86c43..a0c4562b5a6b7 100644
--- a/lldb/tools/lldb-vscode/FifoFiles.h
+++ b/lldb/tools/lldb-vscode/FifoFiles.h
@@ -14,6 +14,8 @@
#include "JSONUtils.h"
+#include <chrono>
+
namespace lldb_vscode {
/// Struct that controls the life of a fifo file in the filesystem.
diff --git a/llvm/include/llvm/Debuginfod/Debuginfod.h b/llvm/include/llvm/Debuginfod/Debuginfod.h
index fcb8ed3a9222b..064cfa75b1a1b 100644
--- a/llvm/include/llvm/Debuginfod/Debuginfod.h
+++ b/llvm/include/llvm/Debuginfod/Debuginfod.h
@@ -23,6 +23,8 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
+#include <chrono>
+
namespace llvm {
typedef ArrayRef<uint8_t> BuildIDRef;
diff --git a/llvm/include/llvm/Debuginfod/HTTPClient.h b/llvm/include/llvm/Debuginfod/HTTPClient.h
index e8f0e7ef8f786..ca3b76ca9f3f4 100644
--- a/llvm/include/llvm/Debuginfod/HTTPClient.h
+++ b/llvm/include/llvm/Debuginfod/HTTPClient.h
@@ -19,6 +19,8 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
+#include <chrono>
+
namespace llvm {
enum class HTTPMethod { GET };
diff --git a/llvm/include/llvm/Support/Duration.h b/llvm/include/llvm/Support/Duration.h
new file mode 100644
index 0000000000000..a5a0e2a3357aa
--- /dev/null
+++ b/llvm/include/llvm/Support/Duration.h
@@ -0,0 +1,28 @@
+//===--- Duration.h - wrapper around std::chrono::Duration ------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// The sole purpose of this file is to avoid the dependency on <chrono> in
+// raw_ostream.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_DURATION_H
+#define LLVM_SUPPORT_DURATION_H
+
+#include <chrono>
+
+namespace llvm {
+class Duration {
+ std::chrono::milliseconds Value;
+ public:
+ Duration(std::chrono::milliseconds Value) : Value(Value) {}
+ std::chrono::milliseconds getDuration() const { return Value; }
+};
+}
+
+#endif
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index fc46ec0d74564..e288ac27e804d 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -17,7 +17,6 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/DataTypes.h"
#include <cassert>
-#include <chrono>
#include <cstddef>
#include <cstdint>
#include <cstring>
@@ -30,6 +29,7 @@
namespace llvm {
+class Duration;
class formatv_object_base;
class format_object_base;
class FormattedString;
@@ -574,7 +574,7 @@ class raw_fd_ostream : public raw_pwrite_stream {
///
/// It is used as @ref lock.
LLVM_NODISCARD
- Expected<sys::fs::FileLocker> tryLockFor(std::chrono::milliseconds Timeout);
+ Expected<sys::fs::FileLocker> tryLockFor(Duration const& Timeout);
};
/// This returns a reference to a raw_fd_ostream for standard output. Use it
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 1b1b0af79ae8d..e4b747b68beaa 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -15,6 +15,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Duration.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
@@ -868,8 +869,8 @@ Expected<sys::fs::FileLocker> raw_fd_ostream::lock() {
}
Expected<sys::fs::FileLocker>
-raw_fd_ostream::tryLockFor(std::chrono::milliseconds Timeout) {
- std::error_code EC = sys::fs::tryLockFile(FD, Timeout);
+raw_fd_ostream::tryLockFor(Duration const& Timeout) {
+ std::error_code EC = sys::fs::tryLockFile(FD, Timeout.getDuration());
if (!EC)
return sys::fs::FileLocker(FD);
return errorCodeToError(EC);
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp
index b749448141f79..c3ba0b51f06f7 100644
--- a/llvm/unittests/Support/Path.cpp
+++ b/llvm/unittests/Support/Path.cpp
@@ -15,6 +15,7 @@
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/Duration.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
More information about the llvm-commits
mailing list