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
This commit is contained in:
serge-sans-paille 2022-01-20 12:04:42 +01:00
parent d5ae039ed7
commit e9211e0393
7 changed files with 40 additions and 4 deletions

View File

@ -14,6 +14,8 @@
#include "JSONUtils.h"
#include <chrono>
namespace lldb_vscode {
/// Struct that controls the life of a fifo file in the filesystem.

View File

@ -23,6 +23,8 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
#include <chrono>
namespace llvm {
typedef ArrayRef<uint8_t> BuildIDRef;

View File

@ -19,6 +19,8 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
#include <chrono>
namespace llvm {
enum class HTTPMethod { GET };

View File

@ -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

View File

@ -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 @@ public:
///
/// 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

View File

@ -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);

View File

@ -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"