mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Semiwrap / meson / robotpy define `NDEBUG` when building their software in all modes, while `allwplib` only does it when building debug. This causes the size of `DenseMap` to differ between the shared libraries built here, and the extension modules built in `mostrobotpy`, causing segfaults when you try to execute code that uses `DenseMap`. This is not a problem with the robotpy code in `allwpilib`, because bazel uses the exact same compiler flags when building the shared libraries and pybind11 extensions.
244 lines
9.0 KiB
Diff
244 lines
9.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: PJ Reiniger <pj.reiniger@gmail.com>
|
|
Date: Sat, 7 May 2022 22:53:50 -0400
|
|
Subject: [PATCH 07/35] Remove format_provider
|
|
|
|
---
|
|
llvm/include/llvm/Support/Chrono.h | 114 ------------------------
|
|
llvm/include/llvm/Support/raw_ostream.h | 6 --
|
|
llvm/unittests/Support/Chrono.cpp | 67 --------------
|
|
3 files changed, 187 deletions(-)
|
|
|
|
diff --git a/llvm/include/llvm/Support/Chrono.h b/llvm/include/llvm/Support/Chrono.h
|
|
index 9c9ba7002310eba5113c14957f769702c61f4326..b269ff8bb5db7bb3c62c3a87daf255b18ece4cd7 100644
|
|
--- a/llvm/include/llvm/Support/Chrono.h
|
|
+++ b/llvm/include/llvm/Support/Chrono.h
|
|
@@ -10,7 +10,6 @@
|
|
#define LLVM_SUPPORT_CHRONO_H
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
-#include "llvm/Support/FormatProviders.h"
|
|
|
|
#include <chrono>
|
|
#include <ctime>
|
|
@@ -80,119 +79,6 @@ toTimePoint(std::time_t T, uint32_t nsec) {
|
|
raw_ostream &operator<<(raw_ostream &OS, sys::TimePoint<> TP);
|
|
raw_ostream &operator<<(raw_ostream &OS, sys::UtcTime<> TP);
|
|
|
|
-/// Format provider for TimePoint<>
|
|
-///
|
|
-/// The options string is a strftime format string, with extensions:
|
|
-/// - %L is millis: 000-999
|
|
-/// - %f is micros: 000000-999999
|
|
-/// - %N is nanos: 000000000 - 999999999
|
|
-///
|
|
-/// If no options are given, the default format is "%Y-%m-%d %H:%M:%S.%N".
|
|
-template <>
|
|
-struct format_provider<sys::TimePoint<>> {
|
|
- static void format(const sys::TimePoint<> &TP, llvm::raw_ostream &OS,
|
|
- std::string_view Style);
|
|
-};
|
|
-
|
|
-template <> struct format_provider<sys::UtcTime<std::chrono::seconds>> {
|
|
- static void format(const sys::UtcTime<std::chrono::seconds> &TP,
|
|
- llvm::raw_ostream &OS, StringRef Style);
|
|
-};
|
|
-
|
|
-namespace detail {
|
|
-template <typename Period> struct unit { static const char value[]; };
|
|
-template <typename Period> const char unit<Period>::value[] = "";
|
|
-
|
|
-template <> struct unit<std::ratio<3600>> { static const char value[]; };
|
|
-template <> struct unit<std::ratio<60>> { static const char value[]; };
|
|
-template <> struct unit<std::ratio<1>> { static const char value[]; };
|
|
-template <> struct unit<std::milli> { static const char value[]; };
|
|
-template <> struct unit<std::micro> { static const char value[]; };
|
|
-template <> struct unit<std::nano> { static const char value[]; };
|
|
-} // namespace detail
|
|
-
|
|
-/// Implementation of format_provider<T> for duration types.
|
|
-///
|
|
-/// The options string of a duration type has the grammar:
|
|
-///
|
|
-/// duration_options ::= [unit][show_unit [number_options]]
|
|
-/// unit ::= `h`|`m`|`s`|`ms|`us`|`ns`
|
|
-/// show_unit ::= `+` | `-`
|
|
-/// number_options ::= options string for a integral or floating point type
|
|
-///
|
|
-/// Examples
|
|
-/// =================================
|
|
-/// | options | Input | Output |
|
|
-/// =================================
|
|
-/// | "" | 1s | 1 s |
|
|
-/// | "ms" | 1s | 1000 ms |
|
|
-/// | "ms-" | 1s | 1000 |
|
|
-/// | "ms-n" | 1s | 1,000 |
|
|
-/// | "" | 1.0s | 1.00 s |
|
|
-/// =================================
|
|
-///
|
|
-/// If the unit of the duration type is not one of the units specified above,
|
|
-/// it is still possible to format it, provided you explicitly request a
|
|
-/// display unit or you request that the unit is not displayed.
|
|
-
|
|
-template <typename Rep, typename Period>
|
|
-struct format_provider<std::chrono::duration<Rep, Period>> {
|
|
-private:
|
|
- typedef std::chrono::duration<Rep, Period> Dur;
|
|
- typedef std::conditional_t<std::chrono::treat_as_floating_point<Rep>::value,
|
|
- double, intmax_t>
|
|
- InternalRep;
|
|
-
|
|
- template <typename AsPeriod> static InternalRep getAs(const Dur &D) {
|
|
- using namespace std::chrono;
|
|
- return duration_cast<duration<InternalRep, AsPeriod>>(D).count();
|
|
- }
|
|
-
|
|
- static std::pair<InternalRep, std::string_view> consumeUnit(std::string_view &Style,
|
|
- const Dur &D) {
|
|
- using namespace std::chrono;
|
|
- if (Style.consume_front("ns"))
|
|
- return {getAs<std::nano>(D), "ns"};
|
|
- if (Style.consume_front("us"))
|
|
- return {getAs<std::micro>(D), "us"};
|
|
- if (Style.consume_front("ms"))
|
|
- return {getAs<std::milli>(D), "ms"};
|
|
- if (Style.consume_front("s"))
|
|
- return {getAs<std::ratio<1>>(D), "s"};
|
|
- if (Style.consume_front("m"))
|
|
- return {getAs<std::ratio<60>>(D), "m"};
|
|
- if (Style.consume_front("h"))
|
|
- return {getAs<std::ratio<3600>>(D), "h"};
|
|
- return {D.count(), detail::unit<Period>::value};
|
|
- }
|
|
-
|
|
- static bool consumeShowUnit(std::string_view &Style) {
|
|
- if (Style.empty())
|
|
- return true;
|
|
- if (Style.consume_front("-"))
|
|
- return false;
|
|
- if (Style.consume_front("+"))
|
|
- return true;
|
|
- assert(0 && "Unrecognised duration format");
|
|
- return true;
|
|
- }
|
|
-
|
|
-public:
|
|
- static void format(const Dur &D, llvm::raw_ostream &Stream, std::string_view Style) {
|
|
- InternalRep count;
|
|
- std::string_view unit;
|
|
- std::tie(count, unit) = consumeUnit(Style, D);
|
|
- bool show_unit = consumeShowUnit(Style);
|
|
-
|
|
- format_provider<InternalRep>::format(count, Stream, Style);
|
|
-
|
|
- if (show_unit) {
|
|
- assert(!unit.empty());
|
|
- Stream << " " << unit;
|
|
- }
|
|
- }
|
|
-};
|
|
-
|
|
} // namespace llvm
|
|
|
|
#endif // LLVM_SUPPORT_CHRONO_H
|
|
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
|
|
index c43c68c9114d8cd564484b190456b0069818dc87..96b7a2463e2336a0f61a03ce11cf643bc253f422 100644
|
|
--- a/llvm/include/llvm/Support/raw_ostream.h
|
|
+++ b/llvm/include/llvm/Support/raw_ostream.h
|
|
@@ -27,12 +27,6 @@
|
|
|
|
namespace llvm {
|
|
|
|
-class Duration;
|
|
-class formatv_object_base;
|
|
-class format_object_base;
|
|
-class FormattedString;
|
|
-class FormattedNumber;
|
|
-class FormattedBytes;
|
|
template <class T> class [[nodiscard]] Expected;
|
|
|
|
namespace sys {
|
|
diff --git a/llvm/unittests/Support/Chrono.cpp b/llvm/unittests/Support/Chrono.cpp
|
|
index 3e3e5517a0aedbd72605adbdde932a5e5e92693b..a4d166d435d6d679f773dcf3eab985f0631e12d2 100644
|
|
--- a/llvm/unittests/Support/Chrono.cpp
|
|
+++ b/llvm/unittests/Support/Chrono.cpp
|
|
@@ -29,43 +29,6 @@ TEST(Chrono, TimeTConversion) {
|
|
EXPECT_EQ(TP, toTimePoint(toTimeT(TP)));
|
|
}
|
|
|
|
-TEST(Chrono, TimePointFormat) {
|
|
- using namespace std::chrono;
|
|
- struct tm TM {};
|
|
- TM.tm_year = 106;
|
|
- TM.tm_mon = 0;
|
|
- TM.tm_mday = 2;
|
|
- TM.tm_hour = 15;
|
|
- TM.tm_min = 4;
|
|
- TM.tm_sec = 5;
|
|
- TM.tm_isdst = -1;
|
|
- TimePoint<> T =
|
|
- system_clock::from_time_t(mktime(&TM)) + nanoseconds(123456789);
|
|
- TimePoint<> T2 =
|
|
- system_clock::from_time_t(mktime(&TM)) + nanoseconds(23456789);
|
|
-
|
|
- // operator<< uses the format YYYY-MM-DD HH:MM:SS.NNNNNNNNN
|
|
- std::string S;
|
|
- raw_string_ostream OS(S);
|
|
- OS << T;
|
|
- EXPECT_EQ("2006-01-02 15:04:05.123456789", S);
|
|
- S.clear();
|
|
- OS << T2;
|
|
- EXPECT_EQ("2006-01-02 15:04:05.023456789", S);
|
|
-
|
|
- // formatv default style matches operator<<.
|
|
- EXPECT_EQ("2006-01-02 15:04:05.123456789", formatv("{0}", T).str());
|
|
- EXPECT_EQ("2006-01-02 15:04:05.023456789", formatv("{0}", T2).str());
|
|
- // formatv supports strftime-style format strings.
|
|
- EXPECT_EQ("15:04:05", formatv("{0:%H:%M:%S}", T).str());
|
|
- // formatv supports our strftime extensions for sub-second precision.
|
|
- EXPECT_EQ("123", formatv("{0:%L}", T).str());
|
|
- EXPECT_EQ("123456", formatv("{0:%f}", T).str());
|
|
- EXPECT_EQ("123456789", formatv("{0:%N}", T).str());
|
|
- // our extensions don't interfere with %% escaping.
|
|
- EXPECT_EQ("%foo", formatv("{0:%%foo}", T).str());
|
|
-}
|
|
-
|
|
// Test that toTimePoint and toTimeT can be called with a arguments with varying
|
|
// precisions.
|
|
TEST(Chrono, ImplicitConversions) {
|
|
@@ -83,34 +46,4 @@ TEST(Chrono, ImplicitConversions) {
|
|
EXPECT_EQ(TimeT, toTimeT(Nano));
|
|
}
|
|
|
|
-TEST(Chrono, DurationFormat) {
|
|
- EXPECT_EQ("1 h", formatv("{0}", hours(1)).str());
|
|
- EXPECT_EQ("1 m", formatv("{0}", minutes(1)).str());
|
|
- EXPECT_EQ("1 s", formatv("{0}", seconds(1)).str());
|
|
- EXPECT_EQ("1 ms", formatv("{0}", milliseconds(1)).str());
|
|
- EXPECT_EQ("1 us", formatv("{0}", microseconds(1)).str());
|
|
- EXPECT_EQ("1 ns", formatv("{0}", nanoseconds(1)).str());
|
|
-
|
|
- EXPECT_EQ("1 s", formatv("{0:+}", seconds(1)).str());
|
|
- EXPECT_EQ("1", formatv("{0:-}", seconds(1)).str());
|
|
-
|
|
- EXPECT_EQ("1000 ms", formatv("{0:ms}", seconds(1)).str());
|
|
- EXPECT_EQ("1000000 us", formatv("{0:us}", seconds(1)).str());
|
|
- EXPECT_EQ("1000", formatv("{0:ms-}", seconds(1)).str());
|
|
-
|
|
- EXPECT_EQ("1,000 ms", formatv("{0:+n}", milliseconds(1000)).str());
|
|
- EXPECT_EQ("0x3e8", formatv("{0:-x}", milliseconds(1000)).str());
|
|
- EXPECT_EQ("010", formatv("{0:-3}", milliseconds(10)).str());
|
|
- EXPECT_EQ("10,000", formatv("{0:ms-n}", seconds(10)).str());
|
|
-
|
|
- EXPECT_EQ("1.00 s", formatv("{0}", duration<float>(1)).str());
|
|
- EXPECT_EQ("0.123 s", formatv("{0:+3}", duration<float>(0.123f)).str());
|
|
- EXPECT_EQ("1.230e-01 s", formatv("{0:+e3}", duration<float>(0.123f)).str());
|
|
-
|
|
- typedef duration<float, std::ratio<60 * 60 * 24 * 14, 1000000>>
|
|
- microfortnights;
|
|
- EXPECT_EQ("1.00", formatv("{0:-}", microfortnights(1)).str());
|
|
- EXPECT_EQ("1209.60 ms", formatv("{0:ms}", microfortnights(1)).str());
|
|
-}
|
|
-
|
|
} // anonymous namespace
|