From 3b2a2381b6efa17b756cf78c8ba853e59c91d8e0 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sun, 4 Feb 2024 10:38:23 -0800 Subject: [PATCH 01/10] [ci] Upgrade to new macOS runner (#6328) --- .github/workflows/cmake.yml | 12 ++++++------ .github/workflows/comment-command.yml | 4 ++-- .github/workflows/gradle.yml | 4 ++-- .github/workflows/lint-format.yml | 8 ++++---- cscore/src/main/native/objcpp/UsbCameraImpl.mm | 4 ++++ cscore/src/main/native/objcpp/UsbCameraListener.mm | 4 ++++ sysid/src/test/native/cpp/analysis/OLSTest.cpp | 8 ++++---- 7 files changed, 26 insertions(+), 18 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 6db3659e1a..9e9769e527 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -16,11 +16,11 @@ jobs: name: Linux container: wpilib/roborio-cross-ubuntu:2024-22.04 flags: "-DCMAKE_BUILD_TYPE=Release -DWITH_EXAMPLES=ON" - - os: macOS-12 + - os: macOS-14 name: macOS container: "" - env: "PATH=\"/usr/local/opt/protobuf@3/bin:$PATH\"" - flags: "-DCMAKE_BUILD_TYPE=Release -DWITH_JAVA=OFF -DWITH_EXAMPLES=ON -DCMAKE_LIBRARY_PATH=/usr/local/opt/protobuf@3/lib -DProtobuf_INCLUDE_DIR=/usr/local/opt/protobuf@3/include -DProtobuf_PROTOC_EXECUTABLE=/usr/local/opt/protobuf@3/bin/protoc" + env: "PATH=\"/opt/homebrew/opt/protobuf@3/bin:$PATH\"" + flags: "-DCMAKE_BUILD_TYPE=Release -DWITH_JAVA=OFF -DWITH_EXAMPLES=ON -DCMAKE_LIBRARY_PATH=/opt/homebrew/opt/protobuf@3/lib -DProtobuf_INCLUDE_DIR=/opt/homebrew/opt/protobuf@3/include -DProtobuf_PROTOC_EXECUTABLE=/opt/homebrew/opt/protobuf@3/bin/protoc" name: "Build - ${{ matrix.name }}" runs-on: ${{ matrix.os }} @@ -34,15 +34,15 @@ jobs: if: runner.os == 'Linux' run: wget https://github.com/HebiRobotics/QuickBuffers/releases/download/1.3.3/protoc-gen-quickbuf_1.3.3_amd64.deb && sudo apt install ./protoc-gen-quickbuf_1.3.3_amd64.deb - - name: Install opencv (macOS) + - name: Install dependencies (macOS) run: brew install opencv protobuf@3 ninja if: runner.os == 'macOS' - - name: Set up Python 3.8 (macOS) + - name: Set up Python 3.10 (macOS) if: runner.os == 'macOS' uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: '3.10' - name: Run sccache-cache uses: mozilla-actions/sccache-action@v0.0.3 diff --git a/.github/workflows/comment-command.yml b/.github/workflows/comment-command.yml index abb7acda92..0efdebb985 100644 --- a/.github/workflows/comment-command.yml +++ b/.github/workflows/comment-command.yml @@ -33,10 +33,10 @@ jobs: env: GITHUB_TOKEN: "${{ secrets.COMMENT_COMMAND_PAT_TOKEN }}" NUMBER: ${{ github.event.issue.number }} - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: '3.10' - name: Setup Java uses: actions/setup-java@v4 with: diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index fa17ad1391..6f6d1b7fca 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -94,9 +94,9 @@ jobs: task: "copyAllOutputs" outputs: "build/allOutputs" build-dir: "c:\\work" - - os: macOS-12 + - os: macOS-14 artifact-name: macOS - architecture: x64 + architecture: aarch64 task: "build" outputs: "build/allOutputs" build-dir: "." diff --git a/.github/workflows/lint-format.yml b/.github/workflows/lint-format.yml index 436f165076..afbcde895c 100644 --- a/.github/workflows/lint-format.yml +++ b/.github/workflows/lint-format.yml @@ -22,10 +22,10 @@ jobs: run: | git checkout -b pr git branch -f main origin/main - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: '3.10' - name: Install wpiformat run: pip3 install wpiformat==2023.36 - name: Run @@ -61,10 +61,10 @@ jobs: git config --global --add safe.directory /__w/allwpilib/allwpilib git checkout -b pr git branch -f main origin/main - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: '3.10' - name: Install wpiformat run: pip3 install wpiformat - name: Create compile_commands.json diff --git a/cscore/src/main/native/objcpp/UsbCameraImpl.mm b/cscore/src/main/native/objcpp/UsbCameraImpl.mm index 5607fbf30f..ce0744a45c 100644 --- a/cscore/src/main/native/objcpp/UsbCameraImpl.mm +++ b/cscore/src/main/native/objcpp/UsbCameraImpl.mm @@ -135,7 +135,11 @@ std::vector EnumerateUsbCameras(CS_Status* status) { std::vector retval; NSArray* deviceTypes = @[ AVCaptureDeviceTypeBuiltInWideAngleCamera, +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 140000 + AVCaptureDeviceTypeExternal +#else AVCaptureDeviceTypeExternalUnknown +#endif ]; AVCaptureDeviceDiscoverySession* session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:deviceTypes diff --git a/cscore/src/main/native/objcpp/UsbCameraListener.mm b/cscore/src/main/native/objcpp/UsbCameraListener.mm index b6b59d37df..049c781ac9 100644 --- a/cscore/src/main/native/objcpp/UsbCameraListener.mm +++ b/cscore/src/main/native/objcpp/UsbCameraListener.mm @@ -76,7 +76,11 @@ using namespace cs; if ([device.deviceType isEqualToString:AVCaptureDeviceTypeBuiltInWideAngleCamera] || [device.deviceType +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 140000 + isEqualToString:AVCaptureDeviceTypeExternal]) { +#else isEqualToString:AVCaptureDeviceTypeExternalUnknown]) { +#endif self.notifier->NotifyUsbCamerasChanged(); } }); diff --git a/sysid/src/test/native/cpp/analysis/OLSTest.cpp b/sysid/src/test/native/cpp/analysis/OLSTest.cpp index 00d14b983c..380a53d086 100644 --- a/sysid/src/test/native/cpp/analysis/OLSTest.cpp +++ b/sysid/src/test/native/cpp/analysis/OLSTest.cpp @@ -14,8 +14,8 @@ TEST(OLSTest, TwoVariablesTwoPoints) { auto [coeffs, rSquared, rmse] = sysid::OLS(X, y); EXPECT_EQ(coeffs.size(), 2u); - EXPECT_DOUBLE_EQ(coeffs[0], 1.0); - EXPECT_DOUBLE_EQ(coeffs[1], 2.0); + EXPECT_NEAR(coeffs[0], 1.0, 1e-12); + EXPECT_NEAR(coeffs[1], 2.0, 1e-12); EXPECT_DOUBLE_EQ(rSquared, 1.0); } @@ -28,8 +28,8 @@ TEST(OLSTest, TwoVariablesFivePoints) { auto [coeffs, rSquared, rmse] = sysid::OLS(X, y); EXPECT_EQ(coeffs.size(), 2u); - EXPECT_DOUBLE_EQ(coeffs[0], 0.30487804878048774); - EXPECT_DOUBLE_EQ(coeffs[1], 1.5182926829268293); + EXPECT_NEAR(coeffs[0], 0.30487804878048774, 1e-12); + EXPECT_NEAR(coeffs[1], 1.5182926829268293, 1e-12); EXPECT_DOUBLE_EQ(rSquared, 0.91906029466386019); } From 4f9d73783b000895a3499c96b6311c40019007dc Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Mon, 5 Feb 2024 22:43:12 -0800 Subject: [PATCH 02/10] [wpimath] Make units math functions constexpr (#6345) --- wpimath/src/main/native/include/units/base.h | 6 +- wpimath/src/main/native/include/units/math.h | 138 ++++++++++--------- 2 files changed, 75 insertions(+), 69 deletions(-) diff --git a/wpimath/src/main/native/include/units/base.h b/wpimath/src/main/native/include/units/base.h index bbb8a2bc4f..e7333a91ee 100644 --- a/wpimath/src/main/native/include/units/base.h +++ b/wpimath/src/main/native/include/units/base.h @@ -81,6 +81,8 @@ #include #endif +#include + //------------------------------ // STRING FORMATTER //------------------------------ @@ -2803,10 +2805,10 @@ namespace units * @returns new unit_t, raised to the given exponent */ template::value, int>> - inline auto pow(const UnitType& value) noexcept -> unit_t::unit_type>::type, typename units::traits::unit_t_traits::underlying_type, linear_scale> + inline constexpr auto pow(const UnitType& value) noexcept -> unit_t::unit_type>::type, typename units::traits::unit_t_traits::underlying_type, linear_scale> { return unit_t::unit_type>::type, typename units::traits::unit_t_traits::underlying_type, linear_scale> - (std::pow(value(), power)); + (gcem::pow(value(), power)); } /** diff --git a/wpimath/src/main/native/include/units/math.h b/wpimath/src/main/native/include/units/math.h index 995335bbb5..727aee62fb 100644 --- a/wpimath/src/main/native/include/units/math.h +++ b/wpimath/src/main/native/include/units/math.h @@ -28,6 +28,8 @@ #include +#include + #include "units/angle.h" #include "units/base.h" #include "units/dimensionless.h" @@ -58,12 +60,12 @@ namespace units::math { */ #if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) template -dimensionless::scalar_t cos(const AngleUnit angle) noexcept { +constexpr dimensionless::scalar_t cos(const AngleUnit angle) noexcept { static_assert( traits::is_angle_unit::value, "Type `AngleUnit` must be a unit of angle derived from `unit_t`."); return dimensionless::scalar_t( - std::cos(angle.template convert()())); + gcem::cos(angle.template convert()())); } #endif @@ -78,12 +80,12 @@ dimensionless::scalar_t cos(const AngleUnit angle) noexcept { */ #if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) template -dimensionless::scalar_t sin(const AngleUnit angle) noexcept { +constexpr dimensionless::scalar_t sin(const AngleUnit angle) noexcept { static_assert( traits::is_angle_unit::value, "Type `AngleUnit` must be a unit of angle derived from `unit_t`."); return dimensionless::scalar_t( - std::sin(angle.template convert()())); + gcem::sin(angle.template convert()())); } #endif /** @@ -97,12 +99,12 @@ dimensionless::scalar_t sin(const AngleUnit angle) noexcept { */ #if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) template -dimensionless::scalar_t tan(const AngleUnit angle) noexcept { +constexpr dimensionless::scalar_t tan(const AngleUnit angle) noexcept { static_assert( traits::is_angle_unit::value, "Type `AngleUnit` must be a unit of angle derived from `unit_t`."); return dimensionless::scalar_t( - std::tan(angle.template convert()())); + gcem::tan(angle.template convert()())); } #endif @@ -116,11 +118,11 @@ dimensionless::scalar_t tan(const AngleUnit angle) noexcept { */ #if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) template -angle::radian_t acos(const ScalarUnit x) noexcept { +constexpr angle::radian_t acos(const ScalarUnit x) noexcept { static_assert( traits::is_dimensionless_unit::value, "Type `ScalarUnit` must be a dimensionless unit derived from `unit_t`."); - return angle::radian_t(std::acos(x())); + return angle::radian_t(gcem::acos(x())); } #endif @@ -134,11 +136,11 @@ angle::radian_t acos(const ScalarUnit x) noexcept { */ #if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) template -angle::radian_t asin(const ScalarUnit x) noexcept { +constexpr angle::radian_t asin(const ScalarUnit x) noexcept { static_assert( traits::is_dimensionless_unit::value, "Type `ScalarUnit` must be a dimensionless unit derived from `unit_t`."); - return angle::radian_t(std::asin(x())); + return angle::radian_t(gcem::asin(x())); } #endif @@ -156,11 +158,11 @@ angle::radian_t asin(const ScalarUnit x) noexcept { */ #if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) template -angle::radian_t atan(const ScalarUnit x) noexcept { +constexpr angle::radian_t atan(const ScalarUnit x) noexcept { static_assert( traits::is_dimensionless_unit::value, "Type `ScalarUnit` must be a dimensionless unit derived from `unit_t`."); - return angle::radian_t(std::atan(x())); + return angle::radian_t(gcem::atan(x())); } #endif @@ -176,15 +178,15 @@ angle::radian_t atan(const ScalarUnit x) noexcept { */ #if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) template -angle::radian_t atan2(const Y y, const X x) noexcept { +constexpr angle::radian_t atan2(const Y y, const X x) noexcept { static_assert(traits::is_dimensionless_unit::value, "The quantity y/x must yield a dimensionless ratio."); // X and Y could be different length units, so normalize them return angle::radian_t( - std::atan2(y.template convert< - typename units::traits::unit_t_traits::unit_type>()(), - x())); + gcem::atan2(y.template convert< + typename units::traits::unit_t_traits::unit_type>()(), + x())); } #endif @@ -203,12 +205,12 @@ angle::radian_t atan2(const Y y, const X x) noexcept { */ #if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) template -dimensionless::scalar_t cosh(const AngleUnit angle) noexcept { +constexpr dimensionless::scalar_t cosh(const AngleUnit angle) noexcept { static_assert( traits::is_angle_unit::value, "Type `AngleUnit` must be a unit of angle derived from `unit_t`."); return dimensionless::scalar_t( - std::cosh(angle.template convert()())); + gcem::cosh(angle.template convert()())); } #endif @@ -223,12 +225,12 @@ dimensionless::scalar_t cosh(const AngleUnit angle) noexcept { */ #if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) template -dimensionless::scalar_t sinh(const AngleUnit angle) noexcept { +constexpr dimensionless::scalar_t sinh(const AngleUnit angle) noexcept { static_assert( traits::is_angle_unit::value, "Type `AngleUnit` must be a unit of angle derived from `unit_t`."); return dimensionless::scalar_t( - std::sinh(angle.template convert()())); + gcem::sinh(angle.template convert()())); } #endif @@ -243,12 +245,12 @@ dimensionless::scalar_t sinh(const AngleUnit angle) noexcept { */ #if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) template -dimensionless::scalar_t tanh(const AngleUnit angle) noexcept { +constexpr dimensionless::scalar_t tanh(const AngleUnit angle) noexcept { static_assert( traits::is_angle_unit::value, "Type `AngleUnit` must be a unit of angle derived from `unit_t`."); return dimensionless::scalar_t( - std::tanh(angle.template convert()())); + gcem::tanh(angle.template convert()())); } #endif @@ -264,11 +266,11 @@ dimensionless::scalar_t tanh(const AngleUnit angle) noexcept { */ #if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) template -angle::radian_t acosh(const ScalarUnit x) noexcept { +constexpr angle::radian_t acosh(const ScalarUnit x) noexcept { static_assert( traits::is_dimensionless_unit::value, "Type `ScalarUnit` must be a dimensionless unit derived from `unit_t`."); - return angle::radian_t(std::acosh(x())); + return angle::radian_t(gcem::acosh(x())); } #endif @@ -281,11 +283,11 @@ angle::radian_t acosh(const ScalarUnit x) noexcept { */ #if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) template -angle::radian_t asinh(const ScalarUnit x) noexcept { +constexpr angle::radian_t asinh(const ScalarUnit x) noexcept { static_assert( traits::is_dimensionless_unit::value, "Type `ScalarUnit` must be a dimensionless unit derived from `unit_t`."); - return angle::radian_t(std::asinh(x())); + return angle::radian_t(gcem::asinh(x())); } #endif @@ -300,11 +302,11 @@ angle::radian_t asinh(const ScalarUnit x) noexcept { */ #if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) template -angle::radian_t atanh(const ScalarUnit x) noexcept { +constexpr angle::radian_t atanh(const ScalarUnit x) noexcept { static_assert( traits::is_dimensionless_unit::value, "Type `ScalarUnit` must be a dimensionless unit derived from `unit_t`."); - return angle::radian_t(std::atanh(x())); + return angle::radian_t(gcem::atanh(x())); } #endif @@ -329,11 +331,11 @@ angle::radian_t atanh(const ScalarUnit x) noexcept { * error occurs. */ template -dimensionless::scalar_t exp(const ScalarUnit x) noexcept { +constexpr dimensionless::scalar_t exp(const ScalarUnit x) noexcept { static_assert( traits::is_dimensionless_unit::value, "Type `ScalarUnit` must be a dimensionless unit derived from `unit_t`."); - return dimensionless::scalar_t(std::exp(x())); + return dimensionless::scalar_t(gcem::exp(x())); } /** @@ -346,11 +348,11 @@ dimensionless::scalar_t exp(const ScalarUnit x) noexcept { * @returns Natural logarithm of x. */ template -dimensionless::scalar_t log(const ScalarUnit x) noexcept { +constexpr dimensionless::scalar_t log(const ScalarUnit x) noexcept { static_assert( traits::is_dimensionless_unit::value, "Type `ScalarUnit` must be a dimensionless unit derived from `unit_t`."); - return dimensionless::scalar_t(std::log(x())); + return dimensionless::scalar_t(gcem::log(x())); } /** @@ -362,11 +364,11 @@ dimensionless::scalar_t log(const ScalarUnit x) noexcept { * @returns Common logarithm of x. */ template -dimensionless::scalar_t log10(const ScalarUnit x) noexcept { +constexpr dimensionless::scalar_t log10(const ScalarUnit x) noexcept { static_assert( traits::is_dimensionless_unit::value, "Type `ScalarUnit` must be a dimensionless unit derived from `unit_t`."); - return dimensionless::scalar_t(std::log10(x())); + return dimensionless::scalar_t(gcem::log10(x())); } /** @@ -417,11 +419,11 @@ dimensionless::scalar_t exp2(const ScalarUnit x) noexcept { * @returns e raised to the power of x, minus one. */ template -dimensionless::scalar_t expm1(const ScalarUnit x) noexcept { +constexpr dimensionless::scalar_t expm1(const ScalarUnit x) noexcept { static_assert( traits::is_dimensionless_unit::value, "Type `ScalarUnit` must be a dimensionless unit derived from `unit_t`."); - return dimensionless::scalar_t(std::expm1(x())); + return dimensionless::scalar_t(gcem::expm1(x())); } /** @@ -434,11 +436,11 @@ dimensionless::scalar_t expm1(const ScalarUnit x) noexcept { * @returns The natural logarithm of (1+x). */ template -dimensionless::scalar_t log1p(const ScalarUnit x) noexcept { +constexpr dimensionless::scalar_t log1p(const ScalarUnit x) noexcept { static_assert( traits::is_dimensionless_unit::value, "Type `ScalarUnit` must be a dimensionless unit derived from `unit_t`."); - return dimensionless::scalar_t(std::log1p(x())); + return dimensionless::scalar_t(gcem::log1p(x())); } /** @@ -450,11 +452,11 @@ dimensionless::scalar_t log1p(const ScalarUnit x) noexcept { * @returns The binary logarithm of x: log2x. */ template -dimensionless::scalar_t log2(const ScalarUnit x) noexcept { +constexpr dimensionless::scalar_t log2(const ScalarUnit x) noexcept { static_assert( traits::is_dimensionless_unit::value, "Type `ScalarUnit` must be a dimensionless unit derived from `unit_t`."); - return dimensionless::scalar_t(std::log2(x())); + return dimensionless::scalar_t(gcem::log2(x())); } //---------------------------------- @@ -480,14 +482,14 @@ dimensionless::scalar_t log2(const ScalarUnit x) noexcept { template < class UnitType, std::enable_if_t::value, int> = 0> -inline auto sqrt(const UnitType& value) noexcept -> unit_t< +inline constexpr auto sqrt(const UnitType& value) noexcept -> unit_t< square_root::unit_type>, typename units::traits::unit_t_traits::underlying_type, linear_scale> { return unit_t< square_root::unit_type>, typename units::traits::unit_t_traits::underlying_type, - linear_scale>(std::sqrt(value())); + linear_scale>(gcem::sqrt(value())); } /** @@ -502,10 +504,10 @@ template ::value, int> = 0> -inline UnitTypeLhs hypot(const UnitTypeLhs& x, const UnitTypeRhs& y) { +inline constexpr UnitTypeLhs hypot(const UnitTypeLhs& x, const UnitTypeRhs& y) { static_assert(traits::is_convertible_unit_t::value, "Parameters of hypot() function are not compatible units."); - return UnitTypeLhs(std::hypot( + return UnitTypeLhs(gcem::hypot( x(), y.template convert< typename units::traits::unit_t_traits::unit_type>()())); @@ -525,8 +527,8 @@ inline UnitTypeLhs hypot(const UnitTypeLhs& x, const UnitTypeRhs& y) { */ template ::value>> -UnitType ceil(const UnitType x) noexcept { - return UnitType(std::ceil(x())); +constexpr UnitType ceil(const UnitType x) noexcept { + return UnitType(gcem::ceil(x())); } /** @@ -539,8 +541,8 @@ UnitType ceil(const UnitType x) noexcept { */ template ::value>> -UnitType floor(const UnitType x) noexcept { - return UnitType(std::floor(x())); +constexpr UnitType floor(const UnitType x) noexcept { + return UnitType(gcem::floor(x())); } /** @@ -555,10 +557,11 @@ UnitType floor(const UnitType x) noexcept { template ::value && traits::is_unit_t::value>> -UnitTypeLhs fmod(const UnitTypeLhs numer, const UnitTypeRhs denom) noexcept { +constexpr UnitTypeLhs fmod(const UnitTypeLhs numer, + const UnitTypeRhs denom) noexcept { static_assert(traits::is_convertible_unit_t::value, "Parameters of fmod() function are not compatible units."); - return UnitTypeLhs(std::fmod( + return UnitTypeLhs(gcem::fmod( numer(), denom.template convert< typename units::traits::unit_t_traits::unit_type>()())); @@ -574,8 +577,8 @@ UnitTypeLhs fmod(const UnitTypeLhs numer, const UnitTypeRhs denom) noexcept { */ template ::value>> -UnitType trunc(const UnitType x) noexcept { - return UnitType(std::trunc(x())); +constexpr UnitType trunc(const UnitType x) noexcept { + return UnitType(gcem::trunc(x())); } /** @@ -588,8 +591,8 @@ UnitType trunc(const UnitType x) noexcept { */ template ::value>> -UnitType round(const UnitType x) noexcept { - return UnitType(std::round(x())); +constexpr UnitType round(const UnitType x) noexcept { + return UnitType(gcem::round(x())); } //---------------------------------- @@ -608,17 +611,18 @@ UnitType round(const UnitType x) noexcept { template ::value && traits::is_unit_t::value>> -UnitTypeLhs copysign(const UnitTypeLhs x, const UnitTypeRhs y) noexcept { - return UnitTypeLhs(std::copysign( +constexpr UnitTypeLhs copysign(const UnitTypeLhs x, + const UnitTypeRhs y) noexcept { + return UnitTypeLhs(gcem::copysign( x(), y())); // no need for conversion to get the correct sign. } /// Overload to copy the sign from a raw double template ::value>> -UnitTypeLhs copysign(const UnitTypeLhs x, - const UNIT_LIB_DEFAULT_TYPE y) noexcept { - return UnitTypeLhs(std::copysign(x(), y)); +constexpr UnitTypeLhs copysign(const UnitTypeLhs x, + const UNIT_LIB_DEFAULT_TYPE y) noexcept { + return UnitTypeLhs(gcem::copysign(x(), y)); } //---------------------------------- @@ -660,10 +664,10 @@ UnitTypeLhs fdim(const UnitTypeLhs x, const UnitTypeRhs y) noexcept { template ::value && traits::is_unit_t::value>> -UnitTypeLhs fmax(const UnitTypeLhs x, const UnitTypeRhs y) noexcept { +constexpr UnitTypeLhs fmax(const UnitTypeLhs x, const UnitTypeRhs y) noexcept { static_assert(traits::is_convertible_unit_t::value, "Parameters of fmax() function are not compatible units."); - return UnitTypeLhs(std::fmax( + return UnitTypeLhs(gcem::max( x(), y.template convert< typename units::traits::unit_t_traits::unit_type>()())); @@ -683,10 +687,10 @@ UnitTypeLhs fmax(const UnitTypeLhs x, const UnitTypeRhs y) noexcept { template ::value && traits::is_unit_t::value>> -UnitTypeLhs fmin(const UnitTypeLhs x, const UnitTypeRhs y) noexcept { +constexpr UnitTypeLhs fmin(const UnitTypeLhs x, const UnitTypeRhs y) noexcept { static_assert(traits::is_convertible_unit_t::value, "Parameters of fmin() function are not compatible units."); - return UnitTypeLhs(std::fmin( + return UnitTypeLhs(gcem::min( x(), y.template convert< typename units::traits::unit_t_traits::unit_type>()())); @@ -705,8 +709,8 @@ UnitTypeLhs fmin(const UnitTypeLhs x, const UnitTypeRhs y) noexcept { */ template ::value>> -UnitType fabs(const UnitType x) noexcept { - return UnitType(std::fabs(x())); +constexpr UnitType fabs(const UnitType x) noexcept { + return UnitType(gcem::abs(x())); } /** @@ -718,8 +722,8 @@ UnitType fabs(const UnitType x) noexcept { */ template ::value>> -UnitType abs(const UnitType x) noexcept { - return UnitType(std::fabs(x())); +constexpr UnitType abs(const UnitType x) noexcept { + return UnitType(gcem::abs(x())); } /** From fb947fe9984ff3f52daa51402308a32f442547a4 Mon Sep 17 00:00:00 2001 From: Thad House Date: Mon, 12 Feb 2024 22:33:03 -0800 Subject: [PATCH 03/10] [cscore] Use Raw for CvSink and CvSource (#6364) Eventually we want to get to a point where we can remove OpenCV from the internals of cscore. The start to doing that is converting the existing CvSource and CvSink methods to RawFrame. For CvSource, this is 100% a free operation. We can do everything the existing code could have done (with one small exception we can fairly easily fix). For CvSink, by defaut this change would incur one extra copy, but no extra allocations. A set of direct methods were added to CvSink to add a method to avoid this extra copy. --- .../wpi/first/cameraserver/CameraServer.java | 2 + .../native/cpp/cameraserver/CameraServer.cpp | 2 + .../edu/wpi/first/cscore/CameraServerJNI.java | 6 +- .../java/edu/wpi/first/cscore/CvSink.java | 191 +++++++++++-- .../java/edu/wpi/first/cscore/CvSource.java | 47 ++- ...meraServerCvJNI.java => OpenCvLoader.java} | 81 ++---- .../java/edu/wpi/first/cscore/VideoSink.java | 2 + .../edu/wpi/first/cscore/VideoSource.java | 2 + .../edu/wpi/first/cscore/raw/RawSink.java | 2 +- .../edu/wpi/first/cscore/raw/RawSource.java | 4 +- .../native/cpp/ConfigurableSourceImpl.cpp | 137 +++++++++ .../main/native/cpp/ConfigurableSourceImpl.h | 2 +- cscore/src/main/native/cpp/CvSinkImpl.cpp | 270 ------------------ cscore/src/main/native/cpp/CvSinkImpl.h | 50 ---- cscore/src/main/native/cpp/CvSourceImpl.cpp | 232 --------------- cscore/src/main/native/cpp/CvSourceImpl.h | 37 --- cscore/src/main/native/cpp/RawSinkImpl.cpp | 29 +- cscore/src/main/native/cpp/RawSourceImpl.cpp | 25 +- cscore/src/main/native/cpp/SinkImpl.cpp | 66 +++++ cscore/src/main/native/cpp/cscore_c.cpp | 1 - .../main/native/cpp/jni/CameraServerJNI.cpp | 156 +--------- cscore/src/main/native/include/cscore_c.h | 4 +- cscore/src/main/native/include/cscore_cpp.h | 4 +- cscore/src/main/native/include/cscore_cv.h | 246 +++++++++------- cscore/src/main/native/include/cscore_oo.h | 8 +- cscore/src/main/native/include/cscore_raw.h | 26 +- .../src/main/native/include/cscore_raw_cv.h | 228 --------------- styleguide/spotbugs-exclude.xml | 9 + 28 files changed, 666 insertions(+), 1203 deletions(-) rename cscore/src/main/java/edu/wpi/first/cscore/{CameraServerCvJNI.java => OpenCvLoader.java} (51%) delete mode 100644 cscore/src/main/native/cpp/CvSinkImpl.cpp delete mode 100644 cscore/src/main/native/cpp/CvSinkImpl.h delete mode 100644 cscore/src/main/native/cpp/CvSourceImpl.cpp delete mode 100644 cscore/src/main/native/cpp/CvSourceImpl.h delete mode 100644 cscore/src/main/native/include/cscore_raw_cv.h diff --git a/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java b/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java index 5597f8002e..630943ec5d 100644 --- a/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java +++ b/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java @@ -366,6 +366,8 @@ public final class CameraServer { } case kCv: return "cv:"; + case kRaw: + return "raw:"; default: return "unknown:"; } diff --git a/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp b/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp index 97dba02dab..58394b465e 100644 --- a/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp +++ b/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp @@ -113,6 +113,8 @@ static std::string_view MakeSourceValue(CS_Source source, } case CS_SOURCE_CV: return "cv:"; + case CS_SOURCE_RAW: + return "raw:"; default: return "unknown:"; } diff --git a/cscore/src/main/java/edu/wpi/first/cscore/CameraServerJNI.java b/cscore/src/main/java/edu/wpi/first/cscore/CameraServerJNI.java index d3b28cfb29..0d874a7dd8 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/CameraServerJNI.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/CameraServerJNI.java @@ -212,6 +212,7 @@ public class CameraServerJNI { * Creates a raw source. * * @param name Source name. + * @param isCv true for a Cv source. * @param pixelFormat Pixel format. * @param width Image width. * @param height Image height. @@ -219,7 +220,7 @@ public class CameraServerJNI { * @return Raw source handle. */ public static native int createRawSource( - String name, int pixelFormat, int width, int height, int fps); + String name, boolean isCv, int pixelFormat, int width, int height, int fps); // // Source Functions @@ -630,9 +631,10 @@ public class CameraServerJNI { * Creates a raw sink. * * @param name Sink name. + * @param isCv true for a Cv source. * @return Raw sink handle. */ - public static native int createRawSink(String name); + public static native int createRawSink(String name, boolean isCv); // // Sink Functions diff --git a/cscore/src/main/java/edu/wpi/first/cscore/CvSink.java b/cscore/src/main/java/edu/wpi/first/cscore/CvSink.java index af390e5967..922bd38abb 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/CvSink.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/CvSink.java @@ -5,6 +5,9 @@ package edu.wpi.first.cscore; import edu.wpi.first.util.PixelFormat; +import edu.wpi.first.util.RawFrame; +import java.nio.ByteBuffer; +import org.opencv.core.CvType; import org.opencv.core.Mat; /** @@ -12,15 +15,52 @@ import org.opencv.core.Mat; * OpenCV builds. For an alternate OpenCV, see the documentation how to build your own with RawSink. */ public class CvSink extends ImageSink { + private final RawFrame m_frame = new RawFrame(); + private Mat m_tmpMat; + private ByteBuffer m_origByteBuffer; + private int m_width; + private int m_height; + private PixelFormat m_pixelFormat; + + @Override + public void close() { + if (m_tmpMat != null) { + m_tmpMat.release(); + } + m_frame.close(); + super.close(); + } + + private int getCVFormat(PixelFormat pixelFormat) { + int type = 0; + switch (pixelFormat) { + case kYUYV: + case kRGB565: + type = CvType.CV_8UC2; + break; + case kBGR: + type = CvType.CV_8UC3; + break; + case kGray: + case kMJPEG: + default: + type = CvType.CV_8UC1; + break; + } + return type; + } + /** - * Create a sink for accepting OpenCV images. WaitForFrame() must be called on the created sink to + * Create a sink for accepting OpenCV images. grabFrame() must be called on the created sink to * get each new image. * * @param name Source name (arbitrary unique identifier) * @param pixelFormat Source pixel format */ public CvSink(String name, PixelFormat pixelFormat) { - super(CameraServerCvJNI.createCvSink(name, pixelFormat.getValue())); + super(CameraServerJNI.createRawSink(name, true)); + m_pixelFormat = pixelFormat; + OpenCvLoader.forceStaticLoad(); } /** @@ -33,22 +73,9 @@ public class CvSink extends ImageSink { this(name, PixelFormat.kBGR); } - /// Create a sink for accepting OpenCV images in a separate thread. - /// A thread will be created that calls WaitForFrame() and calls the - /// processFrame() callback each time a new frame arrives. - /// @param name Source name (arbitrary unique identifier) - /// @param processFrame Frame processing function; will be called with a - /// time=0 if an error occurred. processFrame should call GetImage() - /// or GetError() as needed, but should not call (except in very - /// unusual circumstances) WaitForImage(). - // public CvSink(wpi::StringRef name, - // std::function processFrame) { - // super(CameraServerJNI.createCvSinkCallback(name, processFrame)); - // } - /** * Wait for the next frame and get the image. Times out (returning 0) after 0.225 seconds. The - * provided image will have three 3-bit channels stored in BGR order. + * provided image will have the pixelFormat this class was constructed with. * * @param image Where to store the image. * @return Frame time, or 0 on error (call GetError() to obtain the error message) @@ -59,7 +86,7 @@ public class CvSink extends ImageSink { /** * Wait for the next frame and get the image. Times out (returning 0) after timeout seconds. The - * provided image will have three 3-bit channels stored in BGR order. + * provided image will have the pixelFormat this class was constructed with. * * @param image Where to store the image. * @param timeout Retrieval timeout in seconds. @@ -67,18 +94,140 @@ public class CvSink extends ImageSink { * is in 1 us increments. */ public long grabFrame(Mat image, double timeout) { - return CameraServerCvJNI.grabSinkFrameTimeout(m_handle, image.nativeObj, timeout); + long rv = grabFrameDirect(timeout); + if (rv <= 0) { + return rv; + } + m_tmpMat.copyTo(image); + return rv; } /** - * Wait for the next frame and get the image. May block forever. The provided image will have - * three 3-bit channels stored in BGR order. + * Wait for the next frame and get the image. May block forever. The provided image will have the + * pixelFormat this class was constructed with. * * @param image Where to store the image. * @return Frame time, or 0 on error (call GetError() to obtain the error message); the frame time * is in 1 us increments. */ public long grabFrameNoTimeout(Mat image) { - return CameraServerCvJNI.grabSinkFrame(m_handle, image.nativeObj); + long rv = grabFrameNoTimeoutDirect(); + if (rv <= 0) { + return rv; + } + m_tmpMat.copyTo(image); + return rv; + } + + /** + * Get the direct backing mat for this sink. + * + *

This mat can be invalidated any time any of the grab* methods are called, or when the CvSink + * is closed. + * + * @return The backing mat. + */ + public Mat getDirectMat() { + return m_tmpMat; + } + + /** + * Wait for the next frame and store the image. Times out (returning 0) after 0.225 seconds. The + * provided image will have the pixelFormat this class was constructed with. Use getDirectMat() to + * grab the image. + * + * @return Frame time, or 0 on error (call GetError() to obtain the error message) + */ + public long grabFrameDirect() { + return grabFrameDirect(0.225); + } + + /** + * Wait for the next frame and store the image. Times out (returning 0) after timeout seconds. The + * provided image will have the pixelFormat this class was constructed with. Use getDirectMat() to + * grab the image. + * + * @param timeout Retrieval timeout in seconds. + * @return Frame time, or 0 on error (call GetError() to obtain the error message); the frame time + * is in 1 us increments. + */ + @SuppressWarnings("PMD.CompareObjectsWithEquals") + public long grabFrameDirect(double timeout) { + m_frame.setInfo(0, 0, 0, m_pixelFormat); + long rv = + CameraServerJNI.grabRawSinkFrameTimeout(m_handle, m_frame, m_frame.getNativeObj(), timeout); + if (rv <= 0) { + return rv; + } + + if (m_frame.getData() != m_origByteBuffer + || m_width != m_frame.getWidth() + || m_height != m_frame.getHeight() + || m_pixelFormat != m_frame.getPixelFormat()) { + m_origByteBuffer = m_frame.getData(); + m_height = m_frame.getHeight(); + m_width = m_frame.getWidth(); + m_pixelFormat = m_frame.getPixelFormat(); + if (m_frame.getStride() == 0) { + m_tmpMat = + new Mat( + m_frame.getHeight(), + m_frame.getWidth(), + getCVFormat(m_pixelFormat), + m_origByteBuffer); + } else { + m_tmpMat = + new Mat( + m_frame.getHeight(), + m_frame.getWidth(), + getCVFormat(m_pixelFormat), + m_origByteBuffer, + m_frame.getStride()); + } + } + return rv; + } + + /** + * Wait for the next frame and store the image. May block forever. The provided image will have + * the pixelFormat this class was constructed with. Use getDirectMat() to grab the image. + * + * @return Frame time, or 0 on error (call GetError() to obtain the error message); the frame time + * is in 1 us increments. + */ + @SuppressWarnings("PMD.CompareObjectsWithEquals") + public long grabFrameNoTimeoutDirect() { + m_frame.setInfo(0, 0, 0, m_pixelFormat); + long rv = CameraServerJNI.grabRawSinkFrame(m_handle, m_frame, m_frame.getNativeObj()); + if (rv <= 0) { + return rv; + } + + if (m_frame.getData() != m_origByteBuffer + || m_width != m_frame.getWidth() + || m_height != m_frame.getHeight() + || m_pixelFormat != m_frame.getPixelFormat()) { + m_origByteBuffer = m_frame.getData(); + m_height = m_frame.getHeight(); + m_width = m_frame.getWidth(); + m_pixelFormat = m_frame.getPixelFormat(); + if (m_frame.getStride() == 0) { + m_tmpMat = + new Mat( + m_frame.getHeight(), + m_frame.getWidth(), + getCVFormat(m_pixelFormat), + m_origByteBuffer); + } else { + m_tmpMat = + new Mat( + m_frame.getHeight(), + m_frame.getWidth(), + getCVFormat(m_pixelFormat), + m_origByteBuffer, + m_frame.getStride()); + } + } + return rv; } } diff --git a/cscore/src/main/java/edu/wpi/first/cscore/CvSource.java b/cscore/src/main/java/edu/wpi/first/cscore/CvSource.java index 4c29ffc482..1fcf5ab21f 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/CvSource.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/CvSource.java @@ -20,8 +20,9 @@ public class CvSource extends ImageSource { */ public CvSource(String name, VideoMode mode) { super( - CameraServerCvJNI.createCvSource( - name, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps)); + CameraServerJNI.createRawSource( + name, true, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps)); + OpenCvLoader.forceStaticLoad(); } /** @@ -34,7 +35,8 @@ public class CvSource extends ImageSource { * @param fps fps */ public CvSource(String name, PixelFormat pixelFormat, int width, int height, int fps) { - super(CameraServerCvJNI.createCvSource(name, pixelFormat.getValue(), width, height, fps)); + super(CameraServerJNI.createRawSource(name, true, pixelFormat.getValue(), width, height, fps)); + OpenCvLoader.forceStaticLoad(); } /** @@ -47,6 +49,43 @@ public class CvSource extends ImageSource { * @param image OpenCV image */ public void putFrame(Mat image) { - CameraServerCvJNI.putSourceFrame(m_handle, image.nativeObj); + // We only support 8-bit images, convert if necessary + boolean cleanupRequired = false; + Mat finalImage; + if (image.depth() == 0) { + finalImage = image; + } else { + finalImage = new Mat(); + image.convertTo(finalImage, 0); + cleanupRequired = true; + } + + try { + int channels = finalImage.channels(); + PixelFormat format; + if (channels == 1) { + format = PixelFormat.kGray; + } else if (channels == 3) { + format = PixelFormat.kBGR; + } else { + throw new VideoException("Unsupported image type"); + } + // TODO old code supported BGRA, but the only way I can support that is slow. + // Update cscore to support BGRA for raw frames + + CameraServerJNI.putRawSourceFrameData( + m_handle, + finalImage.dataAddr(), + (int) finalImage.total() * channels, + finalImage.width(), + finalImage.height(), + image.width(), + format.getValue()); + + } finally { + if (cleanupRequired) { + finalImage.release(); + } + } } } diff --git a/cscore/src/main/java/edu/wpi/first/cscore/CameraServerCvJNI.java b/cscore/src/main/java/edu/wpi/first/cscore/OpenCvLoader.java similarity index 51% rename from cscore/src/main/java/edu/wpi/first/cscore/CameraServerCvJNI.java rename to cscore/src/main/java/edu/wpi/first/cscore/OpenCvLoader.java index 26933d41bb..0ca098c282 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/CameraServerCvJNI.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/OpenCvLoader.java @@ -9,11 +9,13 @@ import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; import org.opencv.core.Core; -/** CameraServer CV JNI. */ -public class CameraServerCvJNI { - static boolean libraryLoaded = false; +/** OpenCV Native Loader. */ +public final class OpenCvLoader { + @SuppressWarnings("PMD.MutableStaticState") + static boolean libraryLoaded; - static RuntimeLoader loader = null; + @SuppressWarnings("PMD.MutableStaticState") + static RuntimeLoader loader; /** Sets whether JNI should be loaded in the static block. */ public static class Helper { @@ -45,7 +47,6 @@ public class CameraServerCvJNI { String opencvName = Core.NATIVE_LIBRARY_NAME; if (Helper.getExtractOnStaticLoad()) { try { - CameraServerJNI.forceLoad(); loader = new RuntimeLoader<>(opencvName, RuntimeLoader.getDefaultExtractionRoot(), Core.class); loader.loadLibraryHashed(); @@ -57,6 +58,15 @@ public class CameraServerCvJNI { } } + /** + * Forces a static load. + * + * @return a garbage value + */ + public static int forceStaticLoad() { + return libraryLoaded ? 1 : 0; + } + /** * Force load the library. * @@ -66,7 +76,6 @@ public class CameraServerCvJNI { if (libraryLoaded) { return; } - CameraServerJNI.forceLoad(); loader = new RuntimeLoader<>( Core.NATIVE_LIBRARY_NAME, RuntimeLoader.getDefaultExtractionRoot(), Core.class); @@ -74,64 +83,6 @@ public class CameraServerCvJNI { libraryLoaded = true; } - /** - * Creates a CV source. - * - * @param name Name. - * @param pixelFormat OpenCV pixel format. - * @param width Image width. - * @param height Image height. - * @param fps Frames per second. - * @return CV source. - */ - public static native int createCvSource( - String name, int pixelFormat, int width, int height, int fps); - - /** - * Put source frame. - * - * @param source Source handle. - * @param imageNativeObj Image native object handle. - */ - public static native void putSourceFrame(int source, long imageNativeObj); - - /** - * Creates a CV sink. - * - * @param name Name. - * @param pixelFormat OpenCV pixel format. - * @return CV sink handle. - */ - public static native int createCvSink(String name, int pixelFormat); - - // /** - // * Creates a CV sink callback. - // * - // * @param name Name. - // * @param processFrame Process frame callback. - // */ - // public static native int createCvSinkCallback(String name, - // void (*processFrame)(long time)); - - /** - * Returns sink frame handle. - * - * @param sink Sink handle. - * @param imageNativeObj Image native object handle. - * @return Sink frame handle. - */ - public static native long grabSinkFrame(int sink, long imageNativeObj); - - /** - * Returns sink frame timeout in microseconds. - * - * @param sink Sink handle. - * @param imageNativeObj Image native object handle. - * @param timeout Timeout in seconds. - * @return Sink frame timeout in microseconds. - */ - public static native long grabSinkFrameTimeout(int sink, long imageNativeObj, double timeout); - /** Utility class. */ - private CameraServerCvJNI() {} + private OpenCvLoader() {} } diff --git a/cscore/src/main/java/edu/wpi/first/cscore/VideoSink.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoSink.java index 661ae9adb3..5eced4c622 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/VideoSink.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoSink.java @@ -48,6 +48,8 @@ public class VideoSink implements AutoCloseable { return Kind.kMjpeg; case 4: return Kind.kCv; + case 8: + return Kind.kRaw; default: return Kind.kUnknown; } diff --git a/cscore/src/main/java/edu/wpi/first/cscore/VideoSource.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoSource.java index 2356940ef3..7657eafa56 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/VideoSource.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoSource.java @@ -86,6 +86,8 @@ public class VideoSource implements AutoCloseable { return Kind.kHttp; case 4: return Kind.kCv; + case 8: + return Kind.kRaw; default: return Kind.kUnknown; } diff --git a/cscore/src/main/java/edu/wpi/first/cscore/raw/RawSink.java b/cscore/src/main/java/edu/wpi/first/cscore/raw/RawSink.java index babb0fdede..ba567a98e3 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/raw/RawSink.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/raw/RawSink.java @@ -22,7 +22,7 @@ public class RawSink extends ImageSink { * @param name Source name (arbitrary unique identifier) */ public RawSink(String name) { - super(CameraServerJNI.createRawSink(name)); + super(CameraServerJNI.createRawSink(name, false)); } /** diff --git a/cscore/src/main/java/edu/wpi/first/cscore/raw/RawSource.java b/cscore/src/main/java/edu/wpi/first/cscore/raw/RawSource.java index 1c8bc23709..f1dafd9a01 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/raw/RawSource.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/raw/RawSource.java @@ -26,7 +26,7 @@ public class RawSource extends ImageSource { public RawSource(String name, VideoMode mode) { super( CameraServerJNI.createRawSource( - name, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps)); + name, false, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps)); } /** @@ -39,7 +39,7 @@ public class RawSource extends ImageSource { * @param fps fps */ public RawSource(String name, PixelFormat pixelFormat, int width, int height, int fps) { - super(CameraServerJNI.createRawSource(name, pixelFormat.getValue(), width, height, fps)); + super(CameraServerJNI.createRawSource(name, false, pixelFormat.getValue(), width, height, fps)); } /** diff --git a/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp b/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp index 48677a6319..9f09eff050 100644 --- a/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp +++ b/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp @@ -104,3 +104,140 @@ void ConfigurableSourceImpl::SetEnumPropertyChoices( prop->name, property, CS_PROP_ENUM, prop->value, {}); } + +namespace cs { +static constexpr unsigned SourceMask = CS_SOURCE_CV | CS_SOURCE_RAW; + +void NotifySourceError(CS_Source source, std::string_view msg, + CS_Status* status) { + auto data = Instance::GetInstance().GetSource(source); + if (!data || (data->kind & SourceMask) == 0) { + *status = CS_INVALID_HANDLE; + return; + } + static_cast(*data->source).NotifyError(msg); +} + +void SetSourceConnected(CS_Source source, bool connected, CS_Status* status) { + auto data = Instance::GetInstance().GetSource(source); + if (!data || (data->kind & SourceMask) == 0) { + *status = CS_INVALID_HANDLE; + return; + } + static_cast(*data->source).SetConnected(connected); +} + +void SetSourceDescription(CS_Source source, std::string_view description, + CS_Status* status) { + auto data = Instance::GetInstance().GetSource(source); + if (!data || (data->kind & SourceMask) == 0) { + *status = CS_INVALID_HANDLE; + return; + } + static_cast(*data->source) + .SetDescription(description); +} + +CS_Property CreateSourceProperty(CS_Source source, std::string_view name, + CS_PropertyKind kind, int minimum, int maximum, + int step, int defaultValue, int value, + CS_Status* status) { + auto data = Instance::GetInstance().GetSource(source); + if (!data || (data->kind & SourceMask) == 0) { + *status = CS_INVALID_HANDLE; + return -1; + } + int property = static_cast(*data->source) + .CreateProperty(name, kind, minimum, maximum, step, + defaultValue, value); + return Handle{source, property, Handle::kProperty}; +} + +CS_Property CreateSourcePropertyCallback( + CS_Source source, std::string_view name, CS_PropertyKind kind, int minimum, + int maximum, int step, int defaultValue, int value, + std::function onChange, CS_Status* status) { + auto data = Instance::GetInstance().GetSource(source); + if (!data || (data->kind & SourceMask) == 0) { + *status = CS_INVALID_HANDLE; + return -1; + } + int property = static_cast(*data->source) + .CreateProperty(name, kind, minimum, maximum, step, + defaultValue, value, onChange); + return Handle{source, property, Handle::kProperty}; +} + +void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property, + std::span choices, + CS_Status* status) { + auto data = Instance::GetInstance().GetSource(source); + if (!data || (data->kind & SourceMask) == 0) { + *status = CS_INVALID_HANDLE; + return; + } + + // Get property index; also validate the source owns this property + Handle handle{property}; + int i = handle.GetParentIndex(); + if (i < 0) { + *status = CS_INVALID_HANDLE; + return; + } + auto data2 = Instance::GetInstance().GetSource(Handle{i, Handle::kSource}); + if (!data2 || data->source.get() != data2->source.get()) { + *status = CS_INVALID_HANDLE; + return; + } + int propertyIndex = handle.GetIndex(); + static_cast(*data->source) + .SetEnumPropertyChoices(propertyIndex, choices, status); +} + +} // namespace cs + +extern "C" { +void CS_NotifySourceError(CS_Source source, const char* msg, + CS_Status* status) { + return cs::NotifySourceError(source, msg, status); +} + +void CS_SetSourceConnected(CS_Source source, CS_Bool connected, + CS_Status* status) { + return cs::SetSourceConnected(source, connected, status); +} + +void CS_SetSourceDescription(CS_Source source, const char* description, + CS_Status* status) { + return cs::SetSourceDescription(source, description, status); +} + +CS_Property CS_CreateSourceProperty(CS_Source source, const char* name, + enum CS_PropertyKind kind, int minimum, + int maximum, int step, int defaultValue, + int value, CS_Status* status) { + return cs::CreateSourceProperty(source, name, kind, minimum, maximum, step, + defaultValue, value, status); +} + +CS_Property CS_CreateSourcePropertyCallback( + CS_Source source, const char* name, enum CS_PropertyKind kind, int minimum, + int maximum, int step, int defaultValue, int value, void* data, + void (*onChange)(void* data, CS_Property property), CS_Status* status) { + return cs::CreateSourcePropertyCallback( + source, name, kind, minimum, maximum, step, defaultValue, value, + [=](CS_Property property) { onChange(data, property); }, status); +} + +void CS_SetSourceEnumPropertyChoices(CS_Source source, CS_Property property, + const char** choices, int count, + CS_Status* status) { + wpi::SmallVector vec; + vec.reserve(count); + for (int i = 0; i < count; ++i) { + vec.push_back(choices[i]); + } + return cs::SetSourceEnumPropertyChoices(source, property, vec, status); +} + +} // extern "C" diff --git a/cscore/src/main/native/cpp/ConfigurableSourceImpl.h b/cscore/src/main/native/cpp/ConfigurableSourceImpl.h index 31236f5317..570ab21ead 100644 --- a/cscore/src/main/native/cpp/ConfigurableSourceImpl.h +++ b/cscore/src/main/native/cpp/ConfigurableSourceImpl.h @@ -33,7 +33,7 @@ class ConfigurableSourceImpl : public SourceImpl { void NumSinksChanged() override; void NumSinksEnabledChanged() override; - // OpenCV-specific functions + // Frame based specific functions void NotifyError(std::string_view msg); int CreateProperty(std::string_view name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value); diff --git a/cscore/src/main/native/cpp/CvSinkImpl.cpp b/cscore/src/main/native/cpp/CvSinkImpl.cpp deleted file mode 100644 index a5447cccfe..0000000000 --- a/cscore/src/main/native/cpp/CvSinkImpl.cpp +++ /dev/null @@ -1,270 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include "CvSinkImpl.h" - -#include -#include -#include -#include - -#include "Handle.h" -#include "Instance.h" -#include "Log.h" -#include "Notifier.h" -#include "c_util.h" -#include "cscore_cpp.h" - -using namespace cs; - -CvSinkImpl::CvSinkImpl(std::string_view name, wpi::Logger& logger, - Notifier& notifier, Telemetry& telemetry, - VideoMode::PixelFormat pixelFormat) - : SinkImpl{name, logger, notifier, telemetry}, m_pixelFormat{pixelFormat} { - m_active = true; - // m_thread = std::thread(&CvSinkImpl::ThreadMain, this); -} - -CvSinkImpl::CvSinkImpl(std::string_view name, wpi::Logger& logger, - Notifier& notifier, Telemetry& telemetry, - VideoMode::PixelFormat pixelFormat, - std::function processFrame) - : SinkImpl{name, logger, notifier, telemetry}, m_pixelFormat{pixelFormat} {} - -CvSinkImpl::~CvSinkImpl() { - Stop(); -} - -void CvSinkImpl::Stop() { - m_active = false; - - // wake up any waiters by forcing an empty frame to be sent - if (auto source = GetSource()) { - source->Wakeup(); - } - - // join thread - if (m_thread.joinable()) { - m_thread.join(); - } -} - -uint64_t CvSinkImpl::GrabFrame(cv::Mat& image) { - SetEnabled(true); - - auto source = GetSource(); - if (!source) { - // Source disconnected; sleep for one second - std::this_thread::sleep_for(std::chrono::seconds(1)); - return 0; - } - - auto frame = source->GetNextFrame(); // blocks - if (!frame) { - // Bad frame; sleep for 20 ms so we don't consume all processor time. - std::this_thread::sleep_for(std::chrono::milliseconds(20)); - return 0; // signal error - } - - if (!frame.GetCv(image, m_pixelFormat)) { - // Shouldn't happen, but just in case... - std::this_thread::sleep_for(std::chrono::milliseconds(20)); - return 0; - } - - return frame.GetTime(); -} - -uint64_t CvSinkImpl::GrabFrame(cv::Mat& image, double timeout) { - SetEnabled(true); - - auto source = GetSource(); - if (!source) { - // Source disconnected; sleep for one second - std::this_thread::sleep_for(std::chrono::seconds(1)); - return 0; - } - - auto frame = source->GetNextFrame(timeout); // blocks - if (!frame) { - // Bad frame; sleep for 20 ms so we don't consume all processor time. - std::this_thread::sleep_for(std::chrono::milliseconds(20)); - return 0; // signal error - } - - if (!frame.GetCv(image, m_pixelFormat)) { - // Shouldn't happen, but just in case... - std::this_thread::sleep_for(std::chrono::milliseconds(20)); - return 0; - } - - return frame.GetTime(); -} - -// Send HTTP response and a stream of JPG-frames -void CvSinkImpl::ThreadMain() { - Enable(); - while (m_active) { - auto source = GetSource(); - if (!source) { - // Source disconnected; sleep for one second - std::this_thread::sleep_for(std::chrono::seconds(1)); - continue; - } - SDEBUG4("waiting for frame"); - Frame frame = source->GetNextFrame(); // blocks - if (!m_active) { - break; - } - if (!frame) { - // Bad frame; sleep for 10 ms so we don't consume all processor time. - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - continue; - } - // TODO m_processFrame(); - } - Disable(); -} - -namespace cs { - -CS_Sink CreateCvSink(std::string_view name, VideoMode::PixelFormat pixelFormat, - CS_Status* status) { - auto& inst = Instance::GetInstance(); - return inst.CreateSink( - CS_SINK_CV, std::make_shared(name, inst.logger, inst.notifier, - inst.telemetry, pixelFormat)); -} - -CS_Sink CreateCvSinkCallback(std::string_view name, - VideoMode::PixelFormat pixelFormat, - std::function processFrame, - CS_Status* status) { - auto& inst = Instance::GetInstance(); - return inst.CreateSink( - CS_SINK_CV, - std::make_shared(name, inst.logger, inst.notifier, - inst.telemetry, pixelFormat, processFrame)); -} - -static constexpr unsigned SinkMask = CS_SINK_CV | CS_SINK_RAW; - -void SetSinkDescription(CS_Sink sink, std::string_view description, - CS_Status* status) { - auto data = Instance::GetInstance().GetSink(sink); - if (!data || (data->kind & SinkMask) == 0) { - *status = CS_INVALID_HANDLE; - return; - } - static_cast(*data->sink).SetDescription(description); -} - -uint64_t GrabSinkFrame(CS_Sink sink, cv::Mat& image, CS_Status* status) { - auto data = Instance::GetInstance().GetSink(sink); - if (!data || data->kind != CS_SINK_CV) { - *status = CS_INVALID_HANDLE; - return 0; - } - return static_cast(*data->sink).GrabFrame(image); -} - -uint64_t GrabSinkFrameTimeout(CS_Sink sink, cv::Mat& image, double timeout, - CS_Status* status) { - auto data = Instance::GetInstance().GetSink(sink); - if (!data || data->kind != CS_SINK_CV) { - *status = CS_INVALID_HANDLE; - return 0; - } - return static_cast(*data->sink).GrabFrame(image, timeout); -} - -std::string GetSinkError(CS_Sink sink, CS_Status* status) { - auto data = Instance::GetInstance().GetSink(sink); - if (!data || (data->kind & SinkMask) == 0) { - *status = CS_INVALID_HANDLE; - return std::string{}; - } - return static_cast(*data->sink).GetError(); -} - -std::string_view GetSinkError(CS_Sink sink, wpi::SmallVectorImpl& buf, - CS_Status* status) { - auto data = Instance::GetInstance().GetSink(sink); - if (!data || (data->kind & SinkMask) == 0) { - *status = CS_INVALID_HANDLE; - return {}; - } - return static_cast(*data->sink).GetError(buf); -} - -void SetSinkEnabled(CS_Sink sink, bool enabled, CS_Status* status) { - auto data = Instance::GetInstance().GetSink(sink); - if (!data || (data->kind & SinkMask) == 0) { - *status = CS_INVALID_HANDLE; - return; - } - static_cast(*data->sink).SetEnabled(enabled); -} - -} // namespace cs - -extern "C" { - -CS_Sink CS_CreateCvSink(const char* name, enum WPI_PixelFormat pixelFormat, - CS_Status* status) { - return cs::CreateCvSink( - name, static_cast(pixelFormat), status); -} - -CS_Sink CS_CreateCvSinkCallback(const char* name, - enum WPI_PixelFormat pixelFormat, void* data, - void (*processFrame)(void* data, uint64_t time), - CS_Status* status) { - return cs::CreateCvSinkCallback( - name, static_cast(pixelFormat), - [=](uint64_t time) { processFrame(data, time); }, status); -} - -void CS_SetSinkDescription(CS_Sink sink, const char* description, - CS_Status* status) { - return cs::SetSinkDescription(sink, description, status); -} - -#if CV_VERSION_MAJOR < 4 -uint64_t CS_GrabSinkFrame(CS_Sink sink, struct CvMat* image, - CS_Status* status) { - auto mat = cv::cvarrToMat(image); - return cs::GrabSinkFrame(sink, mat, status); -} - -uint64_t CS_GrabSinkFrameTimeout(CS_Sink sink, struct CvMat* image, - double timeout, CS_Status* status) { - auto mat = cv::cvarrToMat(image); - return cs::GrabSinkFrameTimeout(sink, mat, timeout, status); -} -#endif // CV_VERSION_MAJOR < 4 - -uint64_t CS_GrabSinkFrameCpp(CS_Sink sink, cv::Mat* image, CS_Status* status) { - return cs::GrabSinkFrame(sink, *image, status); -} - -uint64_t CS_GrabSinkFrameTimeoutCpp(CS_Sink sink, cv::Mat* image, - double timeout, CS_Status* status) { - return cs::GrabSinkFrameTimeout(sink, *image, timeout, status); -} - -char* CS_GetSinkError(CS_Sink sink, CS_Status* status) { - wpi::SmallString<128> buf; - auto str = cs::GetSinkError(sink, buf, status); - if (*status != 0) { - return nullptr; - } - return cs::ConvertToC(str); -} - -void CS_SetSinkEnabled(CS_Sink sink, CS_Bool enabled, CS_Status* status) { - return cs::SetSinkEnabled(sink, enabled, status); -} - -} // extern "C" diff --git a/cscore/src/main/native/cpp/CvSinkImpl.h b/cscore/src/main/native/cpp/CvSinkImpl.h deleted file mode 100644 index da9392f39c..0000000000 --- a/cscore/src/main/native/cpp/CvSinkImpl.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#ifndef CSCORE_CVSINKIMPL_H_ -#define CSCORE_CVSINKIMPL_H_ - -#include - -#include -#include -#include -#include - -#include -#include - -#include "Frame.h" -#include "SinkImpl.h" - -namespace cs { - -class SourceImpl; - -class CvSinkImpl : public SinkImpl { - public: - CvSinkImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier, - Telemetry& telemetry, VideoMode::PixelFormat pixelFormat); - CvSinkImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier, - Telemetry& telemetry, VideoMode::PixelFormat pixelFormat, - std::function processFrame); - ~CvSinkImpl() override; - - void Stop(); - - uint64_t GrabFrame(cv::Mat& image); - uint64_t GrabFrame(cv::Mat& image, double timeout); - - private: - void ThreadMain(); - - std::atomic_bool m_active; // set to false to terminate threads - std::thread m_thread; - std::function m_processFrame; - VideoMode::PixelFormat m_pixelFormat; -}; - -} // namespace cs - -#endif // CSCORE_CVSINKIMPL_H_ diff --git a/cscore/src/main/native/cpp/CvSourceImpl.cpp b/cscore/src/main/native/cpp/CvSourceImpl.cpp deleted file mode 100644 index 511cf6ceb2..0000000000 --- a/cscore/src/main/native/cpp/CvSourceImpl.cpp +++ /dev/null @@ -1,232 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include "CvSourceImpl.h" - -#include -#include -#include -#include - -#include "Handle.h" -#include "Instance.h" -#include "Log.h" -#include "Notifier.h" -#include "c_util.h" -#include "cscore_cpp.h" - -using namespace cs; - -CvSourceImpl::CvSourceImpl(std::string_view name, wpi::Logger& logger, - Notifier& notifier, Telemetry& telemetry, - const VideoMode& mode) - : ConfigurableSourceImpl{name, logger, notifier, telemetry, mode} {} - -CvSourceImpl::~CvSourceImpl() = default; - -void CvSourceImpl::PutFrame(cv::Mat& image) { - // We only support 8-bit images; convert if necessary. - cv::Mat finalImage; - if (image.depth() == CV_8U) { - finalImage = image; - } else { - image.convertTo(finalImage, CV_8U); - } - - std::unique_ptr dest; - switch (image.channels()) { - case 1: - dest = - AllocImage(VideoMode::kGray, image.cols, image.rows, image.total()); - finalImage.copyTo(dest->AsMat()); - break; - case 3: - dest = AllocImage(VideoMode::kBGR, image.cols, image.rows, - image.total() * 3); - finalImage.copyTo(dest->AsMat()); - break; - case 4: - dest = AllocImage(VideoMode::kBGR, image.cols, image.rows, - image.total() * 3); - cv::cvtColor(finalImage, dest->AsMat(), cv::COLOR_BGRA2BGR); - break; - default: - SERROR("PutFrame: {}-channel images not supported", image.channels()); - return; - } - SourceImpl::PutFrame(std::move(dest), wpi::Now()); -} - -namespace cs { - -CS_Source CreateCvSource(std::string_view name, const VideoMode& mode, - CS_Status* status) { - auto& inst = Instance::GetInstance(); - return inst.CreateSource(CS_SOURCE_CV, std::make_shared( - name, inst.logger, inst.notifier, - inst.telemetry, mode)); -} - -void PutSourceFrame(CS_Source source, cv::Mat& image, CS_Status* status) { - auto data = Instance::GetInstance().GetSource(source); - if (!data || data->kind != CS_SOURCE_CV) { - *status = CS_INVALID_HANDLE; - return; - } - static_cast(*data->source).PutFrame(image); -} - -static constexpr unsigned SourceMask = CS_SINK_CV | CS_SINK_RAW; - -void NotifySourceError(CS_Source source, std::string_view msg, - CS_Status* status) { - auto data = Instance::GetInstance().GetSource(source); - if (!data || (data->kind & SourceMask) == 0) { - *status = CS_INVALID_HANDLE; - return; - } - static_cast(*data->source).NotifyError(msg); -} - -void SetSourceConnected(CS_Source source, bool connected, CS_Status* status) { - auto data = Instance::GetInstance().GetSource(source); - if (!data || (data->kind & SourceMask) == 0) { - *status = CS_INVALID_HANDLE; - return; - } - static_cast(*data->source).SetConnected(connected); -} - -void SetSourceDescription(CS_Source source, std::string_view description, - CS_Status* status) { - auto data = Instance::GetInstance().GetSource(source); - if (!data || (data->kind & SourceMask) == 0) { - *status = CS_INVALID_HANDLE; - return; - } - static_cast(*data->source).SetDescription(description); -} - -CS_Property CreateSourceProperty(CS_Source source, std::string_view name, - CS_PropertyKind kind, int minimum, int maximum, - int step, int defaultValue, int value, - CS_Status* status) { - auto data = Instance::GetInstance().GetSource(source); - if (!data || (data->kind & SourceMask) == 0) { - *status = CS_INVALID_HANDLE; - return -1; - } - int property = static_cast(*data->source) - .CreateProperty(name, kind, minimum, maximum, step, - defaultValue, value); - return Handle{source, property, Handle::kProperty}; -} - -CS_Property CreateSourcePropertyCallback( - CS_Source source, std::string_view name, CS_PropertyKind kind, int minimum, - int maximum, int step, int defaultValue, int value, - std::function onChange, CS_Status* status) { - auto data = Instance::GetInstance().GetSource(source); - if (!data || (data->kind & SourceMask) == 0) { - *status = CS_INVALID_HANDLE; - return -1; - } - int property = static_cast(*data->source) - .CreateProperty(name, kind, minimum, maximum, step, - defaultValue, value, onChange); - return Handle{source, property, Handle::kProperty}; -} - -void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property, - std::span choices, - CS_Status* status) { - auto data = Instance::GetInstance().GetSource(source); - if (!data || (data->kind & SourceMask) == 0) { - *status = CS_INVALID_HANDLE; - return; - } - - // Get property index; also validate the source owns this property - Handle handle{property}; - int i = handle.GetParentIndex(); - if (i < 0) { - *status = CS_INVALID_HANDLE; - return; - } - auto data2 = Instance::GetInstance().GetSource(Handle{i, Handle::kSource}); - if (!data2 || data->source.get() != data2->source.get()) { - *status = CS_INVALID_HANDLE; - return; - } - int propertyIndex = handle.GetIndex(); - static_cast(*data->source) - .SetEnumPropertyChoices(propertyIndex, choices, status); -} - -} // namespace cs - -extern "C" { - -CS_Source CS_CreateCvSource(const char* name, const CS_VideoMode* mode, - CS_Status* status) { - return cs::CreateCvSource(name, static_cast(*mode), - status); -} - -#if CV_VERSION_MAJOR < 4 -void CS_PutSourceFrame(CS_Source source, struct CvMat* image, - CS_Status* status) { - auto mat = cv::cvarrToMat(image); - return cs::PutSourceFrame(source, mat, status); -} -#endif // CV_VERSION_MAJOR < 4 - -void CS_PutSourceFrameCpp(CS_Source source, cv::Mat* image, CS_Status* status) { - return cs::PutSourceFrame(source, *image, status); -} - -void CS_NotifySourceError(CS_Source source, const char* msg, - CS_Status* status) { - return cs::NotifySourceError(source, msg, status); -} - -void CS_SetSourceConnected(CS_Source source, CS_Bool connected, - CS_Status* status) { - return cs::SetSourceConnected(source, connected, status); -} - -void CS_SetSourceDescription(CS_Source source, const char* description, - CS_Status* status) { - return cs::SetSourceDescription(source, description, status); -} - -CS_Property CS_CreateSourceProperty(CS_Source source, const char* name, - enum CS_PropertyKind kind, int minimum, - int maximum, int step, int defaultValue, - int value, CS_Status* status) { - return cs::CreateSourceProperty(source, name, kind, minimum, maximum, step, - defaultValue, value, status); -} - -CS_Property CS_CreateSourcePropertyCallback( - CS_Source source, const char* name, enum CS_PropertyKind kind, int minimum, - int maximum, int step, int defaultValue, int value, void* data, - void (*onChange)(void* data, CS_Property property), CS_Status* status) { - return cs::CreateSourcePropertyCallback( - source, name, kind, minimum, maximum, step, defaultValue, value, - [=](CS_Property property) { onChange(data, property); }, status); -} - -void CS_SetSourceEnumPropertyChoices(CS_Source source, CS_Property property, - const char** choices, int count, - CS_Status* status) { - wpi::SmallVector vec; - vec.reserve(count); - for (int i = 0; i < count; ++i) { - vec.push_back(choices[i]); - } - return cs::SetSourceEnumPropertyChoices(source, property, vec, status); -} - -} // extern "C" diff --git a/cscore/src/main/native/cpp/CvSourceImpl.h b/cscore/src/main/native/cpp/CvSourceImpl.h deleted file mode 100644 index fba7131b43..0000000000 --- a/cscore/src/main/native/cpp/CvSourceImpl.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#ifndef CSCORE_CVSOURCEIMPL_H_ -#define CSCORE_CVSOURCEIMPL_H_ - -#include -#include -#include -#include -#include -#include - -#include - -#include "ConfigurableSourceImpl.h" -#include "SourceImpl.h" - -namespace cs { - -class CvSourceImpl : public ConfigurableSourceImpl { - public: - CvSourceImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier, - Telemetry& telemetry, const VideoMode& mode); - ~CvSourceImpl() override; - - // OpenCV-specific functions - void PutFrame(cv::Mat& image); - - private: - std::atomic_bool m_connected{true}; -}; - -} // namespace cs - -#endif // CSCORE_CVSOURCEIMPL_H_ diff --git a/cscore/src/main/native/cpp/RawSinkImpl.cpp b/cscore/src/main/native/cpp/RawSinkImpl.cpp index 77116416d8..74e7359093 100644 --- a/cscore/src/main/native/cpp/RawSinkImpl.cpp +++ b/cscore/src/main/native/cpp/RawSinkImpl.cpp @@ -143,25 +143,28 @@ void RawSinkImpl::ThreadMain() { } namespace cs { -CS_Sink CreateRawSink(std::string_view name, CS_Status* status) { +static constexpr unsigned SinkMask = CS_SINK_CV | CS_SINK_RAW; + +CS_Sink CreateRawSink(std::string_view name, bool isCv, CS_Status* status) { auto& inst = Instance::GetInstance(); - return inst.CreateSink(CS_SINK_RAW, + return inst.CreateSink(isCv ? CS_SINK_CV : CS_SINK_RAW, std::make_shared( name, inst.logger, inst.notifier, inst.telemetry)); } -CS_Sink CreateRawSinkCallback(std::string_view name, +CS_Sink CreateRawSinkCallback(std::string_view name, bool isCv, std::function processFrame, CS_Status* status) { auto& inst = Instance::GetInstance(); - return inst.CreateSink(CS_SINK_RAW, std::make_shared( - name, inst.logger, inst.notifier, - inst.telemetry, processFrame)); + return inst.CreateSink( + isCv ? CS_SINK_CV : CS_SINK_RAW, + std::make_shared(name, inst.logger, inst.notifier, + inst.telemetry, processFrame)); } uint64_t GrabSinkFrame(CS_Sink sink, WPI_RawFrame& image, CS_Status* status) { auto data = Instance::GetInstance().GetSink(sink); - if (!data || data->kind != CS_SINK_RAW) { + if (!data || (data->kind & SinkMask) == 0) { *status = CS_INVALID_HANDLE; return 0; } @@ -171,25 +174,26 @@ uint64_t GrabSinkFrame(CS_Sink sink, WPI_RawFrame& image, CS_Status* status) { uint64_t GrabSinkFrameTimeout(CS_Sink sink, WPI_RawFrame& image, double timeout, CS_Status* status) { auto data = Instance::GetInstance().GetSink(sink); - if (!data || data->kind != CS_SINK_RAW) { + if (!data || (data->kind & SinkMask) == 0) { *status = CS_INVALID_HANDLE; return 0; } return static_cast(*data->sink).GrabFrame(image, timeout); } + } // namespace cs extern "C" { -CS_Sink CS_CreateRawSink(const char* name, CS_Status* status) { - return cs::CreateRawSink(name, status); +CS_Sink CS_CreateRawSink(const char* name, CS_Bool isCv, CS_Status* status) { + return cs::CreateRawSink(name, isCv, status); } -CS_Sink CS_CreateRawSinkCallback(const char* name, void* data, +CS_Sink CS_CreateRawSinkCallback(const char* name, CS_Bool isCv, void* data, void (*processFrame)(void* data, uint64_t time), CS_Status* status) { return cs::CreateRawSinkCallback( - name, [=](uint64_t time) { processFrame(data, time); }, status); + name, isCv, [=](uint64_t time) { processFrame(data, time); }, status); } uint64_t CS_GrabRawSinkFrame(CS_Sink sink, struct WPI_RawFrame* image, @@ -201,4 +205,5 @@ uint64_t CS_GrabRawSinkFrameTimeout(CS_Sink sink, struct WPI_RawFrame* image, double timeout, CS_Status* status) { return cs::GrabSinkFrameTimeout(sink, *image, timeout, status); } + } // extern "C" diff --git a/cscore/src/main/native/cpp/RawSourceImpl.cpp b/cscore/src/main/native/cpp/RawSourceImpl.cpp index 0d53f8993b..b5c27803fe 100644 --- a/cscore/src/main/native/cpp/RawSourceImpl.cpp +++ b/cscore/src/main/native/cpp/RawSourceImpl.cpp @@ -50,34 +50,39 @@ void RawSourceImpl::PutFrame(const WPI_RawFrame& image) { } namespace cs { -CS_Source CreateRawSource(std::string_view name, const VideoMode& mode, - CS_Status* status) { +static constexpr unsigned SourceMask = CS_SOURCE_CV | CS_SOURCE_RAW; + +CS_Source CreateRawSource(std::string_view name, bool isCv, + const VideoMode& mode, CS_Status* status) { auto& inst = Instance::GetInstance(); - return inst.CreateSource(CS_SOURCE_RAW, std::make_shared( - name, inst.logger, inst.notifier, - inst.telemetry, mode)); + return inst.CreateSource( + isCv ? CS_SOURCE_CV : CS_SOURCE_RAW, + std::make_shared(name, inst.logger, inst.notifier, + inst.telemetry, mode)); } void PutSourceFrame(CS_Source source, const WPI_RawFrame& image, CS_Status* status) { auto data = Instance::GetInstance().GetSource(source); - if (!data || data->kind != CS_SOURCE_RAW) { + if (!data || (data->kind & SourceMask) == 0) { *status = CS_INVALID_HANDLE; return; } static_cast(*data->source).PutFrame(image); } + } // namespace cs extern "C" { -CS_Source CS_CreateRawSource(const char* name, const CS_VideoMode* mode, - CS_Status* status) { - return cs::CreateRawSource(name, static_cast(*mode), - status); +CS_Source CS_CreateRawSource(const char* name, CS_Bool isCv, + const CS_VideoMode* mode, CS_Status* status) { + return cs::CreateRawSource(name, isCv, + static_cast(*mode), status); } void CS_PutRawSourceFrame(CS_Source source, const struct WPI_RawFrame* image, CS_Status* status) { return cs::PutSourceFrame(source, *image, status); } + } // extern "C" diff --git a/cscore/src/main/native/cpp/SinkImpl.cpp b/cscore/src/main/native/cpp/SinkImpl.cpp index 93a625f814..3d4e70cf9a 100644 --- a/cscore/src/main/native/cpp/SinkImpl.cpp +++ b/cscore/src/main/native/cpp/SinkImpl.cpp @@ -4,11 +4,13 @@ #include "SinkImpl.h" +#include #include #include "Instance.h" #include "Notifier.h" #include "SourceImpl.h" +#include "c_util.h" using namespace cs; @@ -195,3 +197,67 @@ void SinkImpl::UpdatePropertyValue(int property, bool setString, int value, } void SinkImpl::SetSourceImpl(std::shared_ptr source) {} + +namespace cs { +static constexpr unsigned SinkMask = CS_SINK_CV | CS_SINK_RAW; + +void SetSinkDescription(CS_Sink sink, std::string_view description, + CS_Status* status) { + auto data = Instance::GetInstance().GetSink(sink); + if (!data || (data->kind & SinkMask) == 0) { + *status = CS_INVALID_HANDLE; + return; + } + data->sink->SetDescription(description); +} + +std::string GetSinkError(CS_Sink sink, CS_Status* status) { + auto data = Instance::GetInstance().GetSink(sink); + if (!data || (data->kind & SinkMask) == 0) { + *status = CS_INVALID_HANDLE; + return std::string{}; + } + return data->sink->GetError(); +} + +std::string_view GetSinkError(CS_Sink sink, wpi::SmallVectorImpl& buf, + CS_Status* status) { + auto data = Instance::GetInstance().GetSink(sink); + if (!data || (data->kind & SinkMask) == 0) { + *status = CS_INVALID_HANDLE; + return {}; + } + return data->sink->GetError(buf); +} + +void SetSinkEnabled(CS_Sink sink, bool enabled, CS_Status* status) { + auto data = Instance::GetInstance().GetSink(sink); + if (!data || (data->kind & SinkMask) == 0) { + *status = CS_INVALID_HANDLE; + return; + } + data->sink->SetEnabled(enabled); +} + +} // namespace cs + +extern "C" { +void CS_SetSinkDescription(CS_Sink sink, const char* description, + CS_Status* status) { + return cs::SetSinkDescription(sink, description, status); +} + +char* CS_GetSinkError(CS_Sink sink, CS_Status* status) { + wpi::SmallString<128> buf; + auto str = cs::GetSinkError(sink, buf, status); + if (*status != 0) { + return nullptr; + } + return cs::ConvertToC(str); +} + +void CS_SetSinkEnabled(CS_Sink sink, CS_Bool enabled, CS_Status* status) { + return cs::SetSinkEnabled(sink, enabled, status); +} + +} // extern "C" diff --git a/cscore/src/main/native/cpp/cscore_c.cpp b/cscore/src/main/native/cpp/cscore_c.cpp index 45583acc57..4670dd4c8e 100644 --- a/cscore/src/main/native/cpp/cscore_c.cpp +++ b/cscore/src/main/native/cpp/cscore_c.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include diff --git a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp index d7a9b4537e..e65e9ac6b5 100644 --- a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp +++ b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp @@ -6,7 +6,6 @@ #include #include -#include #define WPI_RAWFRAME_JNI #include @@ -82,32 +81,6 @@ static void ListenerOnExit() { jvm->DetachCurrentThread(); } -/// throw java exception -static void ThrowJavaException(JNIEnv* env, const std::exception* e) { - wpi::SmallString<128> what; - jclass je = nullptr; - - if (e) { - const char* exception_type = "std::exception"; - - if (dynamic_cast(e)) { - exception_type = "cv::Exception"; - je = env->FindClass("org/opencv/core/CvException"); - } - - what = exception_type; - what += ": "; - what += e->what(); - } else { - what = "unknown exception"; - } - - if (!je) { - je = exceptionEx; - } - env->ThrowNew(je, what.c_str()); -} - extern "C" { JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { @@ -593,40 +566,15 @@ Java_edu_wpi_first_cscore_CameraServerJNI_createHttpCameraMulti return val; } -/* - * Class: edu_wpi_first_cscore_CameraServerCvJNI - * Method: createCvSource - * Signature: (Ljava/lang/String;IIII)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_cscore_CameraServerCvJNI_createCvSource - (JNIEnv* env, jclass, jstring name, jint pixelFormat, jint width, jint height, - jint fps) -{ - if (!name) { - nullPointerEx.Throw(env, "name cannot be null"); - return 0; - } - CS_Status status = 0; - auto val = cs::CreateCvSource( - JStringRef{env, name}.str(), - cs::VideoMode{static_cast(pixelFormat), - static_cast(width), static_cast(height), - static_cast(fps)}, - &status); - CheckStatus(env, status); - return val; -} - /* * Class: edu_wpi_first_cscore_CameraServerJNI * Method: createRawSource - * Signature: (Ljava/lang/String;IIII)I + * Signature: (Ljava/lang/String;ZIIII)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_cscore_CameraServerJNI_createRawSource - (JNIEnv* env, jclass, jstring name, jint pixelFormat, jint width, jint height, - jint fps) + (JNIEnv* env, jclass, jstring name, jboolean isCv, jint pixelFormat, + jint width, jint height, jint fps) { if (!name) { nullPointerEx.Throw(env, "name cannot be null"); @@ -634,7 +582,7 @@ Java_edu_wpi_first_cscore_CameraServerJNI_createRawSource } CS_Status status = 0; auto val = cs::CreateRawSource( - JStringRef{env, name}.str(), + JStringRef{env, name}.str(), isCv, cs::VideoMode{static_cast(pixelFormat), static_cast(width), static_cast(height), static_cast(fps)}, @@ -1202,27 +1150,6 @@ Java_edu_wpi_first_cscore_CameraServerJNI_getHttpCameraUrls return MakeJStringArray(env, arr); } -/* - * Class: edu_wpi_first_cscore_CameraServerCvJNI - * Method: putSourceFrame - * Signature: (IJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_cscore_CameraServerCvJNI_putSourceFrame - (JNIEnv* env, jclass, jint source, jlong imageNativeObj) -{ - try { - cv::Mat& image = *((cv::Mat*)imageNativeObj); - CS_Status status = 0; - cs::PutSourceFrame(source, image, &status); - CheckStatus(env, status); - } catch (const std::exception& e) { - ThrowJavaException(env, &e); - } catch (...) { - ThrowJavaException(env, nullptr); - } -} - /* * Class: edu_wpi_first_cscore_CameraServerJNI * Method: putRawSourceFrame @@ -1421,42 +1348,21 @@ Java_edu_wpi_first_cscore_CameraServerJNI_createMjpegServer return val; } -/* - * Class: edu_wpi_first_cscore_CameraServerCvJNI - * Method: createCvSink - * Signature: (Ljava/lang/String;I)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_cscore_CameraServerCvJNI_createCvSink - (JNIEnv* env, jclass, jstring name, jint pixelFormat) -{ - if (!name) { - nullPointerEx.Throw(env, "name cannot be null"); - return 0; - } - CS_Status status = 0; - auto val = cs::CreateCvSink( - JStringRef{env, name}.str(), - static_cast(pixelFormat), &status); - CheckStatus(env, status); - return val; -} - /* * Class: edu_wpi_first_cscore_CameraServerJNI * Method: createRawSink - * Signature: (Ljava/lang/String;)I + * Signature: (Ljava/lang/String;Z)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_cscore_CameraServerJNI_createRawSink - (JNIEnv* env, jclass, jstring name) + (JNIEnv* env, jclass, jstring name, jboolean isCv) { if (!name) { nullPointerEx.Throw(env, "name cannot be null"); return 0; } CS_Status status = 0; - auto val = cs::CreateRawSink(JStringRef{env, name}.str(), &status); + auto val = cs::CreateRawSink(JStringRef{env, name}.str(), isCv, &status); CheckStatus(env, status); return val; } @@ -1707,54 +1613,6 @@ Java_edu_wpi_first_cscore_CameraServerJNI_setSinkDescription CheckStatus(env, status); } -/* - * Class: edu_wpi_first_cscore_CameraServerCvJNI - * Method: grabSinkFrame - * Signature: (IJ)J - */ -JNIEXPORT jlong JNICALL -Java_edu_wpi_first_cscore_CameraServerCvJNI_grabSinkFrame - (JNIEnv* env, jclass, jint sink, jlong imageNativeObj) -{ - try { - cv::Mat& image = *((cv::Mat*)imageNativeObj); - CS_Status status = 0; - auto rv = cs::GrabSinkFrame(sink, image, &status); - CheckStatus(env, status); - return rv; - } catch (const std::exception& e) { - ThrowJavaException(env, &e); - return 0; - } catch (...) { - ThrowJavaException(env, nullptr); - return 0; - } -} - -/* - * Class: edu_wpi_first_cscore_CameraServerCvJNI - * Method: grabSinkFrameTimeout - * Signature: (IJD)J - */ -JNIEXPORT jlong JNICALL -Java_edu_wpi_first_cscore_CameraServerCvJNI_grabSinkFrameTimeout - (JNIEnv* env, jclass, jint sink, jlong imageNativeObj, jdouble timeout) -{ - try { - cv::Mat& image = *((cv::Mat*)imageNativeObj); - CS_Status status = 0; - auto rv = cs::GrabSinkFrameTimeout(sink, image, timeout, &status); - CheckStatus(env, status); - return rv; - } catch (const std::exception& e) { - ThrowJavaException(env, &e); - return 0; - } catch (...) { - ThrowJavaException(env, nullptr); - return 0; - } -} - /* * Class: edu_wpi_first_cscore_CameraServerJNI * Method: grabRawSinkFrame diff --git a/cscore/src/main/native/include/cscore_c.h b/cscore/src/main/native/include/cscore_c.h index 277d0ffc03..45a334269a 100644 --- a/cscore/src/main/native/include/cscore_c.h +++ b/cscore/src/main/native/include/cscore_c.h @@ -347,7 +347,7 @@ char** CS_GetHttpCameraUrls(CS_Source source, int* count, CS_Status* status); /** @} */ /** - * @defgroup cscore_opencv_source_cfunc OpenCV Source Functions + * @defgroup cscore_frame_source_cfunc Frame Source Functions * @{ */ void CS_NotifySourceError(CS_Source source, const char* msg, CS_Status* status); @@ -409,7 +409,7 @@ int CS_GetMjpegServerPort(CS_Sink sink, CS_Status* status); /** @} */ /** - * @defgroup cscore_opencv_sink_cfunc OpenCV Sink Functions + * @defgroup cscore_frame_sink_cfunc Frame Sink Functions * @{ */ void CS_SetSinkDescription(CS_Sink sink, const char* description, diff --git a/cscore/src/main/native/include/cscore_cpp.h b/cscore/src/main/native/include/cscore_cpp.h index 1d15039018..76c37fed91 100644 --- a/cscore/src/main/native/include/cscore_cpp.h +++ b/cscore/src/main/native/include/cscore_cpp.h @@ -294,7 +294,7 @@ std::vector GetHttpCameraUrls(CS_Source source, CS_Status* status); /** @} */ /** - * @defgroup cscore_opencv_source_func OpenCV Source Functions + * @defgroup cscore_frame_source_func Frame Source Functions * @{ */ void NotifySourceError(CS_Source source, std::string_view msg, @@ -365,7 +365,7 @@ int GetMjpegServerPort(CS_Sink sink, CS_Status* status); /** @} */ /** - * @defgroup cscore_opencv_sink_func OpenCV Sink Functions + * @defgroup cscore_frame_sink_func Frame Sink Functions * @{ */ void SetSinkDescription(CS_Sink sink, std::string_view description, diff --git a/cscore/src/main/native/include/cscore_cv.h b/cscore/src/main/native/include/cscore_cv.h index 6fdfdfb95d..e623f6aea3 100644 --- a/cscore/src/main/native/include/cscore_cv.h +++ b/cscore/src/main/native/include/cscore_cv.h @@ -7,72 +7,17 @@ #include -#include "cscore_c.h" - -#ifdef CSCORE_CSCORE_RAW_CV_H_ -#error "Cannot include both cscore_cv.h and cscore_raw_cv.h in the same file" -#endif - -#ifdef __cplusplus -#include "cscore_oo.h" // NOLINT(build/include_order) - -#endif - -#if CV_VERSION_MAJOR < 4 - -#ifdef __cplusplus -extern "C" { // NOLINT(build/include_order) -#endif - -struct CvMat; - -void CS_PutSourceFrame(CS_Source source, struct CvMat* image, - CS_Status* status); - -uint64_t CS_GrabSinkFrame(CS_Sink sink, struct CvMat* image, CS_Status* status); -uint64_t CS_GrabSinkFrameTimeout(CS_Sink sink, struct CvMat* image, - double timeout, CS_Status* status); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // CV_VERSION_MAJOR < 4 - -#ifdef __cplusplus +#include #include "cscore_oo.h" - -namespace cv { -class Mat; -} // namespace cv +#include "cscore_raw.h" namespace cs { - -/** - * @defgroup cscore_cpp_opencv_special cscore C functions taking a cv::Mat* - * - * These are needed for specific interop implementations. - * @{ - */ -extern "C" { -uint64_t CS_GrabSinkFrameCpp(CS_Sink sink, cv::Mat* image, CS_Status* status); -uint64_t CS_GrabSinkFrameTimeoutCpp(CS_Sink sink, cv::Mat* image, - double timeout, CS_Status* status); -void CS_PutSourceFrameCpp(CS_Source source, cv::Mat* image, CS_Status* status); -} // extern "C" -/** @} */ - -void PutSourceFrame(CS_Source source, cv::Mat& image, CS_Status* status); -uint64_t GrabSinkFrame(CS_Sink sink, cv::Mat& image, CS_Status* status); -uint64_t GrabSinkFrameTimeout(CS_Sink sink, cv::Mat& image, double timeout, - CS_Status* status); - /** * A source for user code to provide OpenCV images as video frames. - * These sources require the WPILib OpenCV builds. - * For an alternate OpenCV, include "cscore_raw_cv.h" instead, and - * include your Mat header before that header. + * + * This is not dependent on any opencv binary ABI, and can be used + * with versions of most versions of OpenCV. */ class CvSource : public ImageSource { public: @@ -87,7 +32,7 @@ class CvSource : public ImageSource { CvSource(std::string_view name, const VideoMode& mode); /** - * Create an OpenCV source. + * Create an OpenCV source. * * @param name Source name (arbitrary unique identifier) * @param pixelFormat Pixel format @@ -111,14 +56,15 @@ class CvSource : public ImageSource { }; /** - * A sink for user code to accept video frames as OpenCV images. - * These sinks require the WPILib OpenCV builds. - * For an alternate OpenCV, include "cscore_raw_cv.h" instead, and - * include your Mat header before that header. + * A source for user code to accept video frames as OpenCV images. + * + * This is not dependent on any opencv binary ABI, and can be used + * with versions of most versions of OpenCV. */ class CvSink : public ImageSink { public: CvSink() = default; + CvSink(const CvSink& sink); /** * Create a sink for accepting OpenCV images. @@ -127,89 +73,191 @@ class CvSink : public ImageSink { * image. * * @param name Source name (arbitrary unique identifier) - * @param pixelFormat Source pixel format + * @param pixelFormat The pixel format to read */ explicit CvSink(std::string_view name, VideoMode::PixelFormat pixelFormat = VideoMode::PixelFormat::kBGR); /** - * Create a sink for accepting OpenCV images in a separate thread. + * Wait for the next frame and get the image. + * Times out (returning 0) after timeout seconds. + * The provided image will have the pixelFormat this class was constructed + * with. * - *

A thread will be created that calls WaitForFrame() and calls the - * processFrame() callback each time a new frame arrives. - * - * @param name Source name (arbitrary unique identifier) - * @param processFrame Frame processing function; will be called with a - * time=0 if an error occurred. processFrame should call GetImage() - * or GetError() as needed, but should not call (except in very - * unusual circumstances) WaitForImage(). - * @param pixelFormat Source pixel format + * @return Frame time, or 0 on error (call GetError() to obtain the error + * message); the frame time is in the same time base as wpi::Now(), + * and is in 1 us increments. */ - CvSink(std::string_view name, std::function processFrame, - VideoMode::PixelFormat pixelFormat = VideoMode::PixelFormat::kBGR); + [[nodiscard]] + uint64_t GrabFrame(cv::Mat& image, double timeout = 0.225); + + /** + * Wait for the next frame and get the image. May block forever. + * The provided image will have the pixelFormat this class was constructed + * with. + * + * @return Frame time, or 0 on error (call GetError() to obtain the error + * message); the frame time is in the same time base as wpi::Now(), + * and is in 1 us increments. + */ + [[nodiscard]] + uint64_t GrabFrameNoTimeout(cv::Mat& image); /** * Wait for the next frame and get the image. * Times out (returning 0) after timeout seconds. - * The provided image will have three 8-bit channels stored in BGR order. + * The provided image will have the pixelFormat this class was constructed + * with. The data is backed by data in the CvSink. It will be invalidated by + * any grabFrame*() call on the sink. * * @return Frame time, or 0 on error (call GetError() to obtain the error * message); the frame time is in the same time base as wpi::Now(), * and is in 1 us increments. */ [[nodiscard]] - uint64_t GrabFrame(cv::Mat& image, double timeout = 0.225) const; + uint64_t GrabFrameDirect(cv::Mat& image, double timeout = 0.225); /** * Wait for the next frame and get the image. May block forever. - * The provided image will have three 8-bit channels stored in BGR order. + * The provided image will have the pixelFormat this class was constructed + * with. The data is backed by data in the CvSink. It will be invalidated by + * any grabFrame*() call on the sink. * * @return Frame time, or 0 on error (call GetError() to obtain the error * message); the frame time is in the same time base as wpi::Now(), * and is in 1 us increments. */ [[nodiscard]] - uint64_t GrabFrameNoTimeout(cv::Mat& image) const; + uint64_t GrabFrameNoTimeoutDirect(cv::Mat& image); + + private: + wpi::RawFrame rawFrame; + VideoMode::PixelFormat pixelFormat; }; inline CvSource::CvSource(std::string_view name, const VideoMode& mode) { - m_handle = CreateCvSource(name, mode, &m_status); + m_handle = CreateRawSource(name, true, mode, &m_status); } inline CvSource::CvSource(std::string_view name, VideoMode::PixelFormat format, int width, int height, int fps) { - m_handle = - CreateCvSource(name, VideoMode{format, width, height, fps}, &m_status); + m_handle = CreateRawSource(name, true, VideoMode{format, width, height, fps}, + &m_status); } inline void CvSource::PutFrame(cv::Mat& image) { + // We only support 8-bit images; convert if necessary. + cv::Mat finalImage; + if (image.depth() == CV_8U) { + finalImage = image; + } else { + image.convertTo(finalImage, CV_8U); + } + + int channels = finalImage.channels(); + WPI_PixelFormat format; + if (channels == 1) { + format = WPI_PIXFMT_GRAY; + } else if (channels == 3) { + format = WPI_PIXFMT_BGR; + } else { + // TODO Error + return; + } + // TODO old code supported BGRA, but the only way I can support that is slow. + // Update cscore to support BGRA for raw frames + + WPI_RawFrame frame; // use WPI_Frame because we don't want the destructor + frame.data = finalImage.data; + frame.freeFunc = nullptr; + frame.freeCbData = nullptr; + frame.size = finalImage.total() * channels; + frame.width = finalImage.cols; + frame.height = finalImage.rows; + frame.stride = finalImage.cols; + frame.pixelFormat = format; m_status = 0; - PutSourceFrame(m_handle, image, &m_status); + PutSourceFrame(m_handle, frame, &m_status); } inline CvSink::CvSink(std::string_view name, VideoMode::PixelFormat pixelFormat) { - m_handle = CreateCvSink(name, pixelFormat, &m_status); + m_handle = CreateRawSink(name, true, &m_status); + this->pixelFormat = pixelFormat; } -inline CvSink::CvSink(std::string_view name, - std::function processFrame, - VideoMode::PixelFormat pixelFormat) { - m_handle = CreateCvSinkCallback(name, pixelFormat, processFrame, &m_status); +inline CvSink::CvSink(const CvSink& sink) + : ImageSink{sink}, pixelFormat{sink.pixelFormat} {} + +inline uint64_t CvSink::GrabFrame(cv::Mat& image, double timeout) { + cv::Mat tmpnam; + auto retVal = GrabFrameDirect(tmpnam); + if (retVal <= 0) { + return retVal; + } + tmpnam.copyTo(image); + return retVal; } -inline uint64_t CvSink::GrabFrame(cv::Mat& image, double timeout) const { - m_status = 0; - return GrabSinkFrameTimeout(m_handle, image, timeout, &m_status); +inline uint64_t CvSink::GrabFrameNoTimeout(cv::Mat& image) { + cv::Mat tmpnam; + auto retVal = GrabFrameNoTimeoutDirect(tmpnam); + if (retVal <= 0) { + return retVal; + } + tmpnam.copyTo(image); + return retVal; } -inline uint64_t CvSink::GrabFrameNoTimeout(cv::Mat& image) const { - m_status = 0; - return GrabSinkFrame(m_handle, image, &m_status); +inline constexpr int GetCvFormat(WPI_PixelFormat pixelFormat) { + int type = 0; + switch (pixelFormat) { + case WPI_PIXFMT_YUYV: + case WPI_PIXFMT_RGB565: + type = CV_8UC2; + break; + case WPI_PIXFMT_BGR: + type = CV_8UC3; + break; + case WPI_PIXFMT_GRAY: + case WPI_PIXFMT_MJPEG: + default: + type = CV_8UC1; + break; + } + return type; +} + +inline uint64_t CvSink::GrabFrameDirect(cv::Mat& image, double timeout) { + rawFrame.height = 0; + rawFrame.width = 0; + rawFrame.pixelFormat = pixelFormat; + m_status = GrabSinkFrameTimeout(m_handle, rawFrame, timeout, &m_status); + if (m_status <= 0) { + return m_status; + } + image = + cv::Mat{rawFrame.height, rawFrame.width, + GetCvFormat(static_cast(rawFrame.pixelFormat)), + rawFrame.data}; + return m_status; +} + +inline uint64_t CvSink::GrabFrameNoTimeoutDirect(cv::Mat& image) { + rawFrame.height = 0; + rawFrame.width = 0; + rawFrame.pixelFormat = pixelFormat; + m_status = GrabSinkFrame(m_handle, rawFrame, &m_status); + if (m_status <= 0) { + return m_status; + } + image = + cv::Mat{rawFrame.height, rawFrame.width, + GetCvFormat(static_cast(rawFrame.pixelFormat)), + rawFrame.data}; + return m_status; } } // namespace cs -#endif - #endif // CSCORE_CSCORE_CV_H_ diff --git a/cscore/src/main/native/include/cscore_oo.h b/cscore/src/main/native/include/cscore_oo.h index 3a55d86376..1f96476742 100644 --- a/cscore/src/main/native/include/cscore_oo.h +++ b/cscore/src/main/native/include/cscore_oo.h @@ -221,7 +221,9 @@ class VideoSource { /// HTTP video source. kHttp = CS_SOURCE_HTTP, /// CV video source. - kCv = CS_SOURCE_CV + kCv = CS_SOURCE_CV, + /// Raw video source. + kRaw = CS_SOURCE_RAW, }; /** Connection strategy. Used for SetConnectionStrategy(). */ @@ -856,7 +858,9 @@ class VideoSink { /// MJPEG video sink. kMjpeg = CS_SINK_MJPEG, /// CV video sink. - kCv = CS_SINK_CV + kCv = CS_SINK_CV, + /// Raw video sink. + kRaw = CS_SINK_RAW, }; VideoSink() noexcept = default; diff --git a/cscore/src/main/native/include/cscore_raw.h b/cscore/src/main/native/include/cscore_raw.h index 6d49612218..9367c26c6b 100644 --- a/cscore/src/main/native/include/cscore_raw.h +++ b/cscore/src/main/native/include/cscore_raw.h @@ -28,9 +28,9 @@ uint64_t CS_GrabRawSinkFrame(CS_Sink sink, struct WPI_RawFrame* rawImage, uint64_t CS_GrabRawSinkFrameTimeout(CS_Sink sink, struct WPI_RawFrame* rawImage, double timeout, CS_Status* status); -CS_Sink CS_CreateRawSink(const char* name, CS_Status* status); +CS_Sink CS_CreateRawSink(const char* name, CS_Bool isCv, CS_Status* status); -CS_Sink CS_CreateRawSinkCallback(const char* name, void* data, +CS_Sink CS_CreateRawSinkCallback(const char* name, CS_Bool isCv, void* data, void (*processFrame)(void* data, uint64_t time), CS_Status* status); @@ -38,8 +38,8 @@ CS_Sink CS_CreateRawSinkCallback(const char* name, void* data, void CS_PutRawSourceFrame(CS_Source source, const struct WPI_RawFrame* image, CS_Status* status); -CS_Source CS_CreateRawSource(const char* name, const CS_VideoMode* mode, - CS_Status* status); +CS_Source CS_CreateRawSource(const char* name, CS_Bool isCv, + const CS_VideoMode* mode, CS_Status* status); /** @} */ #ifdef __cplusplus @@ -54,11 +54,11 @@ namespace cs { * @{ */ -CS_Source CreateRawSource(std::string_view name, const VideoMode& mode, - CS_Status* status); +CS_Source CreateRawSource(std::string_view name, bool isCv, + const VideoMode& mode, CS_Status* status); -CS_Sink CreateRawSink(std::string_view name, CS_Status* status); -CS_Sink CreateRawSinkCallback(std::string_view name, +CS_Sink CreateRawSink(std::string_view name, bool isCv, CS_Status* status); +CS_Sink CreateRawSinkCallback(std::string_view name, bool isCv, std::function processFrame, CS_Status* status); @@ -166,14 +166,14 @@ class RawSink : public ImageSink { }; inline RawSource::RawSource(std::string_view name, const VideoMode& mode) { - m_handle = CreateRawSource(name, mode, &m_status); + m_handle = CreateRawSource(name, false, mode, &m_status); } inline RawSource::RawSource(std::string_view name, VideoMode::PixelFormat format, int width, int height, int fps) { - m_handle = - CreateRawSource(name, VideoMode{format, width, height, fps}, &m_status); + m_handle = CreateRawSource(name, false, VideoMode{format, width, height, fps}, + &m_status); } inline void RawSource::PutFrame(wpi::RawFrame& image) { @@ -182,12 +182,12 @@ inline void RawSource::PutFrame(wpi::RawFrame& image) { } inline RawSink::RawSink(std::string_view name) { - m_handle = CreateRawSink(name, &m_status); + m_handle = CreateRawSink(name, false, &m_status); } inline RawSink::RawSink(std::string_view name, std::function processFrame) { - m_handle = CreateRawSinkCallback(name, processFrame, &m_status); + m_handle = CreateRawSinkCallback(name, false, processFrame, &m_status); } inline uint64_t RawSink::GrabFrame(wpi::RawFrame& image, double timeout) const { diff --git a/cscore/src/main/native/include/cscore_raw_cv.h b/cscore/src/main/native/include/cscore_raw_cv.h deleted file mode 100644 index 7b687f8f90..0000000000 --- a/cscore/src/main/native/include/cscore_raw_cv.h +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#ifndef CSCORE_CSCORE_RAW_CV_H_ -#define CSCORE_CSCORE_RAW_CV_H_ - -#ifdef CSCORE_CSCORE_CV_H_ -#error "Cannot include both cscore_cv.h and cscore_raw_cv.h in the same file" -#endif - -#include - -#include - -#include "cscore_raw.h" - -namespace cs { -/** - * A source for using the raw frame API to provide opencv images. - * - * If you are using the WPILib OpenCV builds, do not use this, and - * instead include "cscore_cv.h" to get a more performant version. - * - * This is not dependent on any opencv binary ABI, and can be used - * with versions of OpenCV that are not 3. If using OpenCV 3, use - * CvSource. - */ -class RawCvSource : public RawSource { - public: - RawCvSource() = default; - - /** - * Create a Raw OpenCV source. - * - * @param name Source name (arbitrary unique identifier) - * @param mode Video mode being generated - */ - RawCvSource(std::string_view name, const VideoMode& mode); - - /** - * Create a Raw OpenCV source. - * - * @param name Source name (arbitrary unique identifier) - * @param pixelFormat Pixel format - * @param width width - * @param height height - * @param fps fps - */ - RawCvSource(std::string_view name, VideoMode::PixelFormat pixelFormat, - int width, int height, int fps); - - /** - * Put an OpenCV image and notify sinks. - * - *

Only 8-bit single-channel or 3-channel (with BGR channel order) images - * are supported. If the format, depth or channel order is different, use - * cv::Mat::convertTo() and/or cv::cvtColor() to convert it first. - * - * @param image OpenCV image - */ - void PutFrame(cv::Mat& image); - - private: - wpi::RawFrame rawFrame; -}; - -/** - * A sink for user code to accept raw video frames as OpenCV images. - * - * If you are using the WPILib OpenCV builds, do not use this, and - * instead include "cscore_cv.h" to get a more performant version. - * - * This is not dependent on any opencv binary ABI, and can be used - * with versions of OpenCV that are not 3. If using OpenCV 3, use - * CvSink. - */ -class RawCvSink : public RawSink { - public: - RawCvSink() = default; - - /** - * Create a sink for accepting OpenCV images. - * - *

WaitForFrame() must be called on the created sink to get each new - * image. - * - * @param name Source name (arbitrary unique identifier) - */ - explicit RawCvSink(std::string_view name); - - /** - * Create a sink for accepting OpenCV images in a separate thread. - * - *

A thread will be created that calls WaitForFrame() and calls the - * processFrame() callback each time a new frame arrives. - * - * @param name Source name (arbitrary unique identifier) - * @param processFrame Frame processing function; will be called with a - * time=0 if an error occurred. processFrame should call GetImage() - * or GetError() as needed, but should not call (except in very - * unusual circumstances) WaitForImage(). - */ - RawCvSink(std::string_view name, - std::function processFrame); - - /** - * Wait for the next frame and get the image. - * Times out (returning 0) after timeout seconds. - * The provided image will have three 8-bit channels stored in BGR order. - * - * @return Frame time, or 0 on error (call GetError() to obtain the error - * message); the frame time is in the same time base as wpi::Now(), - * and is in 1 us increments. - */ - [[nodiscard]] - uint64_t GrabFrame(cv::Mat& image, double timeout = 0.225); - - /** - * Wait for the next frame and get the image. May block forever. - * The provided image will have three 8-bit channels stored in BGR order. - * - * @return Frame time, or 0 on error (call GetError() to obtain the error - * message); the frame time is in the same time base as wpi::Now(), - * and is in 1 us increments. - */ - [[nodiscard]] - uint64_t GrabFrameNoTimeout(cv::Mat& image); - - /** - * Wait for the next frame and get the image. - * Times out (returning 0) after timeout seconds. - * The provided image will have three 8-bit channels stored in BGR order. - * - * @return Frame time, or 0 on error (call GetError() to obtain the error - * message); the frame time is in the same time base as wpi::Now(), - * and is in 1 us increments. - */ - [[nodiscard]] - uint64_t GrabFrameDirect(cv::Mat& image, double timeout = 0.225); - - /** - * Wait for the next frame and get the image. May block forever. - * The provided image will have three 8-bit channels stored in BGR order. - * - * @return Frame time, or 0 on error (call GetError() to obtain the error - * message); the frame time is in the same time base as wpi::Now(), - * and is in 1 us increments. - */ - [[nodiscard]] - uint64_t GrabFrameNoTimeoutDirect(cv::Mat& image); - - private: - wpi::RawFrame rawFrame; -}; - -inline RawCvSource::RawCvSource(std::string_view name, const VideoMode& mode) - : RawSource{name, mode} {} - -inline RawCvSource::RawCvSource(std::string_view name, - VideoMode::PixelFormat format, int width, - int height, int fps) - : RawSource{name, format, width, height, fps} {} - -inline void RawCvSource::PutFrame(cv::Mat& image) { - m_status = 0; - rawFrame.data = reinterpret_cast(image.data); - rawFrame.width = image.cols; - rawFrame.height = image.rows; - rawFrame.totalData = image.total() * image.channels(); - rawFrame.pixelFormat = - image.channels() == 3 ? WPI_PIXFMT_BGR : WPI_PIXFMT_GRAY; - PutSourceFrame(m_handle, rawFrame, &m_status); -} - -inline RawCvSink::RawCvSink(std::string_view name) : RawSink{name} {} - -inline RawCvSink::RawCvSink(std::string_view name, - std::function processFrame) - : RawSink{name, processFrame} {} - -inline uint64_t RawCvSink::GrabFrame(cv::Mat& image, double timeout) { - cv::Mat tmpnam; - auto retVal = GrabFrameDirect(tmpnam); - if (retVal <= 0) { - return retVal; - } - tmpnam.copyTo(image); - return retVal; -} - -inline uint64_t RawCvSink::GrabFrameNoTimeout(cv::Mat& image) { - cv::Mat tmpnam; - auto retVal = GrabFrameNoTimeoutDirect(tmpnam); - if (retVal <= 0) { - return retVal; - } - tmpnam.copyTo(image); - return retVal; -} - -inline uint64_t RawCvSink::GrabFrameDirect(cv::Mat& image, double timeout) { - rawFrame.height = 0; - rawFrame.width = 0; - rawFrame.pixelFormat = WPI_PixelFormat::WPI_PIXFMT_BGR; - m_status = RawSink::GrabFrame(rawFrame, timeout); - if (m_status <= 0) { - return m_status; - } - image = cv::Mat{rawFrame.height, rawFrame.width, CV_8UC3, rawFrame.data}; - return m_status; -} - -inline uint64_t RawCvSink::GrabFrameNoTimeoutDirect(cv::Mat& image) { - rawFrame.height = 0; - rawFrame.width = 0; - rawFrame.pixelFormat = WPI_PixelFormat::WPI_PIXFMT_BGR; - m_status = RawSink::GrabFrameNoTimeout(rawFrame); - if (m_status <= 0) { - return m_status; - } - image = cv::Mat{rawFrame.height, rawFrame.width, CV_8UC3, rawFrame.data}; - return m_status; -} - -} // namespace cs - -#endif // CSCORE_CSCORE_RAW_CV_H_ diff --git a/styleguide/spotbugs-exclude.xml b/styleguide/spotbugs-exclude.xml index ba4feb2ffd..e015399a7f 100644 --- a/styleguide/spotbugs-exclude.xml +++ b/styleguide/spotbugs-exclude.xml @@ -155,4 +155,13 @@ + + + + From 9ed0631ec962f5ab56541f2a1aebfef6fe107ec3 Mon Sep 17 00:00:00 2001 From: Thad House Date: Mon, 12 Feb 2024 23:42:17 -0800 Subject: [PATCH 04/10] [cscore] Add BGRA support (#6365) --- .../java/edu/wpi/first/cscore/CvSink.java | 5 + .../java/edu/wpi/first/cscore/CvSource.java | 112 +++++++++++-- cscore/src/main/native/cpp/Frame.cpp | 83 ++++++++++ cscore/src/main/native/cpp/Frame.h | 5 + cscore/src/main/native/cpp/Image.h | 5 + .../src/main/native/cpp/MjpegServerImpl.cpp | 3 + cscore/src/main/native/cpp/RawSourceImpl.cpp | 29 +--- cscore/src/main/native/cpp/SourceImpl.cpp | 14 ++ .../main/native/cpp/jni/CameraServerJNI.cpp | 1 - cscore/src/main/native/include/cscore_cpp.h | 3 +- cscore/src/main/native/include/cscore_cv.h | 155 +++++++++++++++--- .../src/main/native/linux/UsbCameraImpl.cpp | 4 + .../main/native/objcpp/UsbCameraDelegate.mm | 15 +- .../src/main/native/objcpp/UsbCameraImpl.mm | 1 - .../src/main/native/windows/UsbCameraImpl.cpp | 60 +------ .../java/edu/wpi/first/util/PixelFormat.java | 4 +- .../src/main/native/include/wpi/RawFrame.h | 1 + 17 files changed, 371 insertions(+), 129 deletions(-) diff --git a/cscore/src/main/java/edu/wpi/first/cscore/CvSink.java b/cscore/src/main/java/edu/wpi/first/cscore/CvSink.java index 922bd38abb..a6db5978da 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/CvSink.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/CvSink.java @@ -36,11 +36,16 @@ public class CvSink extends ImageSink { switch (pixelFormat) { case kYUYV: case kRGB565: + case kY16: + case kUYVY: type = CvType.CV_8UC2; break; case kBGR: type = CvType.CV_8UC3; break; + case kBGRA: + type = CvType.CV_8UC4; + break; case kGray: case kMJPEG: default: diff --git a/cscore/src/main/java/edu/wpi/first/cscore/CvSource.java b/cscore/src/main/java/edu/wpi/first/cscore/CvSource.java index 1fcf5ab21f..f3bd147274 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/CvSource.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/CvSource.java @@ -40,16 +40,16 @@ public class CvSource extends ImageSource { } /** - * Put an OpenCV image and notify sinks. + * Put an OpenCV image and notify sinks * - *

Only 8-bit single-channel or 3-channel (with BGR channel order) images are supported. If the - * format, depth or channel order is different, use Mat.convertTo() and/or cvtColor() to convert - * it first. + *

The image format is guessed from the number of channels. The channel mapping is as follows. + * 1: kGray 2: kYUYV 3: BGR 4: BGRA Any other channel numbers will throw an error. If your image + * is an in alternate format, use the overload that takes a PixelFormat. * - * @param image OpenCV image + * @param image OpenCV Image */ public void putFrame(Mat image) { - // We only support 8-bit images, convert if necessary + // We only support 8 bit channels boolean cleanupRequired = false; Mat finalImage; if (image.depth() == 0) { @@ -64,22 +64,64 @@ public class CvSource extends ImageSource { int channels = finalImage.channels(); PixelFormat format; if (channels == 1) { + // 1 channel is assumed Graysacle format = PixelFormat.kGray; + } else if (channels == 2) { + // 2 channels is assumed YUYV + format = PixelFormat.kYUYV; } else if (channels == 3) { + // 3 channels is assumed BGR format = PixelFormat.kBGR; + } else if (channels == 4) { + // 4 channels is assumed BGRA + format = PixelFormat.kBGRA; } else { - throw new VideoException("Unsupported image type"); + throw new VideoException("Unable to get pixel format for " + channels + " channels"); } - // TODO old code supported BGRA, but the only way I can support that is slow. - // Update cscore to support BGRA for raw frames + putFrame(finalImage, format, true); + } finally { + if (cleanupRequired) { + finalImage.release(); + } + } + } + + /** + * Put an OpenCV image and notify sinks. + * + *

The format of the Mat must match the PixelFormat. You will corrupt memory if they dont. With + * skipVerification false, we will verify the number of channels matches the pixel format. If + * skipVerification is true, this step is skipped and is passed straight through. + * + * @param image OpenCV image + * @param format The pixel format of the image + * @param skipVerification skip verifying pixel format + */ + public void putFrame(Mat image, PixelFormat format, boolean skipVerification) { + // We only support 8-bit images, convert if necessary + boolean cleanupRequired = false; + Mat finalImage; + if (image.depth() == 0) { + finalImage = image; + } else { + finalImage = new Mat(); + image.convertTo(finalImage, 0); + cleanupRequired = true; + } + + try { + if (!skipVerification) { + verifyFormat(finalImage, format); + } + long step = image.step1() * image.elemSize1(); CameraServerJNI.putRawSourceFrameData( m_handle, finalImage.dataAddr(), - (int) finalImage.total() * channels, + (int) finalImage.total() * finalImage.channels(), finalImage.width(), finalImage.height(), - image.width(), + (int) step, format.getValue()); } finally { @@ -88,4 +130,52 @@ public class CvSource extends ImageSource { } } } + + private void verifyFormat(Mat image, PixelFormat pixelFormat) { + int channels = image.channels(); + switch (pixelFormat) { + case kBGR: + if (channels == 3) { + return; + } + break; + case kBGRA: + if (channels == 4) { + return; + } + break; + case kGray: + if (channels == 1) { + return; + } + break; + case kRGB565: + if (channels == 2) { + return; + } + break; + case kUYVY: + if (channels == 2) { + return; + } + break; + case kY16: + if (channels == 2) { + return; + } + break; + case kYUYV: + if (channels == 2) { + return; + } + break; + case kMJPEG: + if (channels == 1) { + return; + } + break; + default: + break; + } + } } diff --git a/cscore/src/main/native/cpp/Frame.cpp b/cscore/src/main/native/cpp/Frame.cpp index 1a30393e59..af108f46a7 100644 --- a/cscore/src/main/native/cpp/Frame.cpp +++ b/cscore/src/main/native/cpp/Frame.cpp @@ -314,6 +314,54 @@ Image* Frame::ConvertImpl(Image* image, VideoMode::PixelFormat pixelFormat, } } break; + case VideoMode::kBGRA: + // If source is RGB565, YUYV, UYVY, Gray or Y16, need to convert to BGR + // first + if (cur->pixelFormat == VideoMode::kRGB565) { + // Check to see if BGR version already exists... + if (Image* newImage = + GetExistingImage(cur->width, cur->height, VideoMode::kBGR)) { + cur = newImage; + } else { + cur = ConvertRGB565ToBGR(cur); + } + } else if (cur->pixelFormat == VideoMode::kYUYV) { + // Check to see if BGR version already exists... + if (Image* newImage = + GetExistingImage(cur->width, cur->height, VideoMode::kBGR)) { + cur = newImage; + } else { + cur = ConvertYUYVToBGR(cur); + } + } else if (cur->pixelFormat == VideoMode::kUYVY) { + // Check to see if BGR version already exists... + if (Image* newImage = + GetExistingImage(cur->width, cur->height, VideoMode::kBGR)) { + cur = newImage; + } else { + cur = ConvertUYVYToBGR(cur); + } + } else if (cur->pixelFormat == VideoMode::kGray) { + // Check to see if BGR version already exists... + if (Image* newImage = + GetExistingImage(cur->width, cur->height, VideoMode::kBGR)) { + cur = newImage; + } else { + cur = ConvertGrayToBGR(cur); + } + } else if (cur->pixelFormat == VideoMode::kY16) { + // Check to see if BGR version already exists... + if (Image* newImage = + GetExistingImage(cur->width, cur->height, VideoMode::kBGR)) { + cur = newImage; + } else if (Image* newImage = GetExistingImage(cur->width, cur->height, + VideoMode::kGray)) { + cur = ConvertGrayToBGR(newImage); + } else { + cur = ConvertGrayToBGR(ConvertY16ToGray(cur)); + } + } + return ConvertBGRToBGRA(cur); case VideoMode::kYUYV: case VideoMode::kUYVY: default: @@ -664,6 +712,28 @@ Image* Frame::ConvertY16ToGray(Image* image) { return rv; } +Image* Frame::ConvertBGRToBGRA(Image* image) { + if (!image || image->pixelFormat != VideoMode::kBGR) { + return nullptr; + } + + // Allocate a RGB565 image + auto newImage = + m_impl->source.AllocImage(VideoMode::kBGRA, image->width, image->height, + image->width * image->height * 4); + + // Convert + cv::cvtColor(image->AsMat(), newImage->AsMat(), cv::COLOR_BGR2BGRA); + + // Save the result + Image* rv = newImage.release(); + if (m_impl) { + std::scoped_lock lock(m_impl->mutex); + m_impl->images.push_back(rv); + } + return rv; +} + Image* Frame::GetImageImpl(int width, int height, VideoMode::PixelFormat pixelFormat, int requiredJpegQuality, int defaultJpegQuality) { @@ -727,3 +797,16 @@ void Frame::ReleaseFrame() { m_impl->source.ReleaseFrameImpl(std::unique_ptr(m_impl)); m_impl = nullptr; } + +namespace cs { +std::unique_ptr CreateImageFromBGRA(cs::SourceImpl* source, size_t width, + size_t height, size_t stride, + const uint8_t* data) { + cv::Mat finalImage{static_cast(height), static_cast(width), CV_8UC4, + const_cast(data), stride}; + std::unique_ptr dest = source->AllocImage( + VideoMode::PixelFormat::kBGR, width, height, width * height * 3); + cv::cvtColor(finalImage, dest->AsMat(), cv::COLOR_BGRA2BGR); + return dest; +} +} // namespace cs diff --git a/cscore/src/main/native/cpp/Frame.h b/cscore/src/main/native/cpp/Frame.h index 6132463680..d835de9efc 100644 --- a/cscore/src/main/native/cpp/Frame.h +++ b/cscore/src/main/native/cpp/Frame.h @@ -22,6 +22,10 @@ namespace cs { class SourceImpl; +std::unique_ptr CreateImageFromBGRA(cs::SourceImpl* source, size_t width, + size_t height, size_t stride, + const uint8_t* data); + class Frame { friend class SourceImpl; @@ -206,6 +210,7 @@ class Frame { Image* ConvertGrayToMJPEG(Image* image, int quality); Image* ConvertGrayToY16(Image* image); Image* ConvertY16ToGray(Image* image); + Image* ConvertBGRToBGRA(Image* image); Image* GetImage(int width, int height, VideoMode::PixelFormat pixelFormat) { if (pixelFormat == VideoMode::kMJPEG) { diff --git a/cscore/src/main/native/cpp/Image.h b/cscore/src/main/native/cpp/Image.h index b66a7f1742..27d34a7cf2 100644 --- a/cscore/src/main/native/cpp/Image.h +++ b/cscore/src/main/native/cpp/Image.h @@ -63,6 +63,9 @@ class Image { case VideoMode::kBGR: type = CV_8UC3; break; + case VideoMode::kBGRA: + type = CV_8UC4; + break; case VideoMode::kGray: case VideoMode::kMJPEG: default: @@ -81,6 +84,8 @@ class Image { return 2 * width; case VideoMode::kBGR: return 3 * width; + case VideoMode::kBGRA: + return 4 * width; case VideoMode::kGray: return width; case VideoMode::kMJPEG: diff --git a/cscore/src/main/native/cpp/MjpegServerImpl.cpp b/cscore/src/main/native/cpp/MjpegServerImpl.cpp index 82273e598d..c57dde57f9 100644 --- a/cscore/src/main/native/cpp/MjpegServerImpl.cpp +++ b/cscore/src/main/native/cpp/MjpegServerImpl.cpp @@ -457,6 +457,9 @@ void MjpegServerImpl::ConnThread::SendHTML(wpi::raw_ostream& os, case VideoMode::kBGR: os << "BGR"; break; + case VideoMode::kBGRA: + os << "BGRA"; + break; case VideoMode::kGray: os << "gray"; break; diff --git a/cscore/src/main/native/cpp/RawSourceImpl.cpp b/cscore/src/main/native/cpp/RawSourceImpl.cpp index b5c27803fe..94da6d06aa 100644 --- a/cscore/src/main/native/cpp/RawSourceImpl.cpp +++ b/cscore/src/main/native/cpp/RawSourceImpl.cpp @@ -22,31 +22,10 @@ RawSourceImpl::RawSourceImpl(std::string_view name, wpi::Logger& logger, RawSourceImpl::~RawSourceImpl() = default; void RawSourceImpl::PutFrame(const WPI_RawFrame& image) { - int type; - switch (image.pixelFormat) { - case VideoMode::kYUYV: - case VideoMode::kRGB565: - case VideoMode::kY16: - case VideoMode::kUYVY: - type = CV_8UC2; - break; - case VideoMode::kBGR: - type = CV_8UC3; - break; - case VideoMode::kGray: - case VideoMode::kMJPEG: - default: - type = CV_8UC1; - break; - } - cv::Mat finalImage{image.height, image.width, type, image.data, - static_cast(image.stride)}; - std::unique_ptr dest = - AllocImage(static_cast(image.pixelFormat), - image.width, image.height, image.size); - finalImage.copyTo(dest->AsMat()); - - SourceImpl::PutFrame(std::move(dest), wpi::Now()); + auto currentTime = wpi::Now(); + std::string_view data_view{reinterpret_cast(image.data), image.size}; + SourceImpl::PutFrame(static_cast(image.pixelFormat), + image.width, image.height, data_view, currentTime); } namespace cs { diff --git a/cscore/src/main/native/cpp/SourceImpl.cpp b/cscore/src/main/native/cpp/SourceImpl.cpp index 045bdd4692..e30821064a 100644 --- a/cscore/src/main/native/cpp/SourceImpl.cpp +++ b/cscore/src/main/native/cpp/SourceImpl.cpp @@ -196,6 +196,8 @@ bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) { mode.pixelFormat = cs::VideoMode::kRGB565; } else if (wpi::equals_lower(str, "bgr")) { mode.pixelFormat = cs::VideoMode::kBGR; + } else if (wpi::equals_lower(str, "bgra")) { + mode.pixelFormat = cs::VideoMode::kBGRA; } else if (wpi::equals_lower(str, "gray")) { mode.pixelFormat = cs::VideoMode::kGray; } else if (wpi::equals_lower(str, "y16")) { @@ -361,6 +363,9 @@ wpi::json SourceImpl::GetConfigJsonObject(CS_Status* status) { case VideoMode::kBGR: pixelFormat = "bgr"; break; + case VideoMode::kBGRA: + pixelFormat = "bgra"; + break; case VideoMode::kGray: pixelFormat = "gray"; break; @@ -450,6 +455,15 @@ std::unique_ptr SourceImpl::AllocImage( void SourceImpl::PutFrame(VideoMode::PixelFormat pixelFormat, int width, int height, std::string_view data, Frame::Time time) { + if (pixelFormat == VideoMode::PixelFormat::kBGRA) { + // Write BGRA as BGR to save a copy + auto image = + CreateImageFromBGRA(this, width, height, width * 4, + reinterpret_cast(data.data())); + PutFrame(std::move(image), time); + return; + } + auto image = AllocImage(pixelFormat, width, height, data.size()); // Copy in image data diff --git a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp index e65e9ac6b5..6c13376212 100644 --- a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp +++ b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp @@ -12,7 +12,6 @@ #include #include -#include "cscore_cv.h" #include "cscore_raw.h" #include "cscore_runloop.h" #include "edu_wpi_first_cscore_CameraServerJNI.h" diff --git a/cscore/src/main/native/include/cscore_cpp.h b/cscore/src/main/native/include/cscore_cpp.h index 76c37fed91..b57faee0ff 100644 --- a/cscore/src/main/native/include/cscore_cpp.h +++ b/cscore/src/main/native/include/cscore_cpp.h @@ -68,7 +68,8 @@ struct VideoMode : public CS_VideoMode { kBGR = WPI_PIXFMT_BGR, kGray = WPI_PIXFMT_GRAY, kY16 = WPI_PIXFMT_Y16, - kUYVY = WPI_PIXFMT_UYVY + kUYVY = WPI_PIXFMT_UYVY, + kBGRA = WPI_PIXFMT_BGRA, }; VideoMode() { pixelFormat = 0; diff --git a/cscore/src/main/native/include/cscore_cv.h b/cscore/src/main/native/include/cscore_cv.h index e623f6aea3..aec10d4a55 100644 --- a/cscore/src/main/native/include/cscore_cv.h +++ b/cscore/src/main/native/include/cscore_cv.h @@ -44,15 +44,36 @@ class CvSource : public ImageSource { int height, int fps); /** - * Put an OpenCV image and notify sinks. + * Put an OpenCV image and notify sinks * - *

Only 8-bit single-channel or 3-channel (with BGR channel order) images - * are supported. If the format, depth or channel order is different, use - * cv::Mat::convertTo() and/or cv::cvtColor() to convert it first. + *

+ * The image format is guessed from the number of channels. The channel + * mapping is as follows. 1: kGray 2: kYUYV 3: BGR 4: BGRA Any other channel + * numbers will throw an error. If your image is an in alternate format, use + * the overload that takes a PixelFormat. * - * @param image OpenCV image + * @param image OpenCV Image */ void PutFrame(cv::Mat& image); + + /** + * Put an OpenCV image and notify sinks. + * + *

+ * The format of the Mat must match the PixelFormat. You will corrupt memory + * if they dont. With skipVerification false, we will verify the number of + * channels matches the pixel format. If skipVerification is true, this step + * is skipped and is passed straight through. + * + * @param image OpenCV image + * @param pixelFormat The pixel format of the image + * @param skipVerification skip verifying pixel format + */ + void PutFrame(cv::Mat& image, VideoMode::PixelFormat pixelFormat, + bool skipVerification); + + private: + static bool VerifyFormat(cv::Mat& image, VideoMode::PixelFormat pixelFormat); }; /** @@ -131,6 +152,8 @@ class CvSink : public ImageSink { uint64_t GrabFrameNoTimeoutDirect(cv::Mat& image); private: + constexpr int GetCvFormat(WPI_PixelFormat pixelFormat); + wpi::RawFrame rawFrame; VideoMode::PixelFormat pixelFormat; }; @@ -145,6 +168,56 @@ inline CvSource::CvSource(std::string_view name, VideoMode::PixelFormat format, &m_status); } +inline bool CvSource::VerifyFormat(cv::Mat& image, + VideoMode::PixelFormat pixelFormat) { + int channels = image.channels(); + switch (pixelFormat) { + case VideoMode::PixelFormat::kBGR: + if (channels == 3) { + return true; + } + break; + case VideoMode::PixelFormat::kBGRA: + if (channels == 4) { + return true; + } + break; + case VideoMode::PixelFormat::kGray: + if (channels == 1) { + return true; + } + break; + case VideoMode::PixelFormat::kRGB565: + if (channels == 2) { + return true; + } + break; + case VideoMode::PixelFormat::kUYVY: + if (channels == 2) { + return true; + } + break; + case VideoMode::PixelFormat::kY16: + if (channels == 2) { + return true; + } + break; + case VideoMode::PixelFormat::kYUYV: + if (channels == 2) { + return true; + } + break; + case VideoMode::PixelFormat::kMJPEG: + if (channels == 1) { + return true; + } + break; + default: + break; + } + return false; +} + inline void CvSource::PutFrame(cv::Mat& image) { // We only support 8-bit images; convert if necessary. cv::Mat finalImage; @@ -155,27 +228,54 @@ inline void CvSource::PutFrame(cv::Mat& image) { } int channels = finalImage.channels(); - WPI_PixelFormat format; + VideoMode::PixelFormat format; if (channels == 1) { - format = WPI_PIXFMT_GRAY; + // 1 channel is assumed Graysacle + format = VideoMode::PixelFormat::kGray; + } else if (channels == 2) { + // 2 channels is assumed YUYV + format = VideoMode::PixelFormat::kYUYV; } else if (channels == 3) { - format = WPI_PIXFMT_BGR; + // 3 channels is assumed BGR + format = VideoMode::PixelFormat::kBGR; + } else if (channels == 4) { + // 4 channels is assumed BGRA + format = VideoMode::PixelFormat::kBGRA; } else { // TODO Error return; } - // TODO old code supported BGRA, but the only way I can support that is slow. - // Update cscore to support BGRA for raw frames + + PutFrame(finalImage, format, true); +} + +inline void CvSource::PutFrame(cv::Mat& image, + VideoMode::PixelFormat pixelFormat, + bool skipVerification) { + // We only support 8-bit images; convert if necessary. + cv::Mat finalImage; + if (image.depth() == CV_8U) { + finalImage = image; + } else { + image.convertTo(finalImage, CV_8U); + } + + if (!skipVerification) { + if (!VerifyFormat(finalImage, pixelFormat)) { + // TODO Error + return; + } + } WPI_RawFrame frame; // use WPI_Frame because we don't want the destructor frame.data = finalImage.data; frame.freeFunc = nullptr; frame.freeCbData = nullptr; - frame.size = finalImage.total() * channels; + frame.size = finalImage.total() * finalImage.channels(); frame.width = finalImage.cols; frame.height = finalImage.rows; - frame.stride = finalImage.cols; - frame.pixelFormat = format; + frame.stride = finalImage.step; + frame.pixelFormat = pixelFormat; m_status = 0; PutSourceFrame(m_handle, frame, &m_status); } @@ -209,16 +309,21 @@ inline uint64_t CvSink::GrabFrameNoTimeout(cv::Mat& image) { return retVal; } -inline constexpr int GetCvFormat(WPI_PixelFormat pixelFormat) { +inline constexpr int CvSink::GetCvFormat(WPI_PixelFormat pixelFormat) { int type = 0; switch (pixelFormat) { case WPI_PIXFMT_YUYV: case WPI_PIXFMT_RGB565: + case WPI_PIXFMT_Y16: + case WPI_PIXFMT_UYVY: type = CV_8UC2; break; case WPI_PIXFMT_BGR: type = CV_8UC3; break; + case WPI_PIXFMT_BGRA: + type = CV_8UC4; + break; case WPI_PIXFMT_GRAY: case WPI_PIXFMT_MJPEG: default: @@ -231,31 +336,33 @@ inline constexpr int GetCvFormat(WPI_PixelFormat pixelFormat) { inline uint64_t CvSink::GrabFrameDirect(cv::Mat& image, double timeout) { rawFrame.height = 0; rawFrame.width = 0; + rawFrame.stride = 0; rawFrame.pixelFormat = pixelFormat; - m_status = GrabSinkFrameTimeout(m_handle, rawFrame, timeout, &m_status); - if (m_status <= 0) { - return m_status; + auto timestamp = GrabSinkFrameTimeout(m_handle, rawFrame, timeout, &m_status); + if (m_status != CS_OK) { + return 0; } image = cv::Mat{rawFrame.height, rawFrame.width, GetCvFormat(static_cast(rawFrame.pixelFormat)), - rawFrame.data}; - return m_status; + rawFrame.data, static_cast(rawFrame.stride)}; + return timestamp; } inline uint64_t CvSink::GrabFrameNoTimeoutDirect(cv::Mat& image) { rawFrame.height = 0; rawFrame.width = 0; + rawFrame.stride = 0; rawFrame.pixelFormat = pixelFormat; - m_status = GrabSinkFrame(m_handle, rawFrame, &m_status); - if (m_status <= 0) { - return m_status; + auto timestamp = GrabSinkFrame(m_handle, rawFrame, &m_status); + if (m_status != CS_OK) { + return 0; } image = cv::Mat{rawFrame.height, rawFrame.width, GetCvFormat(static_cast(rawFrame.pixelFormat)), - rawFrame.data}; - return m_status; + rawFrame.data, static_cast(rawFrame.stride)}; + return timestamp; } } // namespace cs diff --git a/cscore/src/main/native/linux/UsbCameraImpl.cpp b/cscore/src/main/native/linux/UsbCameraImpl.cpp index b50b6d934b..eca6ab7797 100644 --- a/cscore/src/main/native/linux/UsbCameraImpl.cpp +++ b/cscore/src/main/native/linux/UsbCameraImpl.cpp @@ -80,6 +80,8 @@ static VideoMode::PixelFormat ToPixelFormat(__u32 pixelFormat) { return VideoMode::kRGB565; case V4L2_PIX_FMT_BGR24: return VideoMode::kBGR; + case V4L2_PIX_FMT_ABGR32: + return VideoMode::kBGRA; case V4L2_PIX_FMT_GREY: return VideoMode::kGray; case V4L2_PIX_FMT_Y16: @@ -102,6 +104,8 @@ static __u32 FromPixelFormat(VideoMode::PixelFormat pixelFormat) { return V4L2_PIX_FMT_RGB565; case VideoMode::kBGR: return V4L2_PIX_FMT_BGR24; + case VideoMode::kBGRA: + return V4L2_PIX_FMT_ABGR32; case VideoMode::kGray: return V4L2_PIX_FMT_GREY; case VideoMode::kY16: diff --git a/cscore/src/main/native/objcpp/UsbCameraDelegate.mm b/cscore/src/main/native/objcpp/UsbCameraDelegate.mm index efa0fbf602..e3a2bfdf60 100644 --- a/cscore/src/main/native/objcpp/UsbCameraDelegate.mm +++ b/cscore/src/main/native/objcpp/UsbCameraDelegate.mm @@ -7,9 +7,6 @@ #include -#include -#include - @implementation UsbCameraDelegate - (id)init { @@ -24,6 +21,8 @@ (void)sampleBuffer; (void)connection; + auto currentTime = wpi::Now(); + auto sharedThis = self.cppImpl.lock(); if (!sharedThis) { return; @@ -52,16 +51,12 @@ return; } - size_t currSize = width * 3 * height; - - auto tmpMat = cv::Mat(height, width, CV_8UC4, baseaddress, rowBytes); - auto image = sharedThis->AllocImage(cs::VideoMode::PixelFormat::kBGR, width, - height, currSize); - cv::cvtColor(tmpMat, image->AsMat(), cv::COLOR_BGRA2BGR); + std::unique_ptr image = cs::CreateImageFromBGRA( + sharedThis.get(), width, height, rowBytes, reinterpret_cast(baseaddress)); CVPixelBufferUnlockBaseAddress(imageBuffer, 0); - sharedThis->objcPutFrame(std::move(image), wpi::Now()); + sharedThis->objcPutFrame(std::move(image), currentTime); } @end diff --git a/cscore/src/main/native/objcpp/UsbCameraImpl.mm b/cscore/src/main/native/objcpp/UsbCameraImpl.mm index ce0744a45c..b0dfc330a0 100644 --- a/cscore/src/main/native/objcpp/UsbCameraImpl.mm +++ b/cscore/src/main/native/objcpp/UsbCameraImpl.mm @@ -18,7 +18,6 @@ #include "Instance.h" #include "c_util.h" #include "cscore_cpp.h" -#include "opencv2/imgproc.hpp" #include "UsbCameraImpl.h" namespace cs { diff --git a/cscore/src/main/native/windows/UsbCameraImpl.cpp b/cscore/src/main/native/windows/UsbCameraImpl.cpp index cde8c2556b..606ceb2145 100644 --- a/cscore/src/main/native/windows/UsbCameraImpl.cpp +++ b/cscore/src/main/native/windows/UsbCameraImpl.cpp @@ -21,9 +21,6 @@ #include #include #include -#include -#include -#include #include #include #include @@ -284,6 +281,8 @@ void UsbCameraImpl::ProcessFrame(IMFSample* videoSample, return; } + auto currentTime = wpi::Now(); + ComPtr buf; if (!SUCCEEDED(videoSample->ConvertToContiguousBuffer(buf.GetAddressOf()))) { @@ -339,56 +338,9 @@ void UsbCameraImpl::ProcessFrame(IMFSample* videoSample, } } - cv::Mat tmpMat; - std::unique_ptr dest; - bool doFinalSet = true; - - switch (mode.pixelFormat) { - case cs::VideoMode::PixelFormat::kMJPEG: { - // Special case - PutFrame(VideoMode::kMJPEG, mode.width, mode.height, - {reinterpret_cast(ptr), length}, wpi::Now()); - doFinalSet = false; - break; - } - case cs::VideoMode::PixelFormat::kGray: - tmpMat = cv::Mat(mode.height, mode.width, CV_8UC1, ptr, pitch); - dest = AllocImage(VideoMode::kGray, tmpMat.cols, tmpMat.rows, - tmpMat.total()); - tmpMat.copyTo(dest->AsMat()); - break; - case cs::VideoMode::PixelFormat::kY16: - tmpMat = cv::Mat(mode.height, mode.width, CV_8UC2, ptr, pitch); - dest = - AllocImage(VideoMode::kY16, tmpMat.cols, tmpMat.rows, tmpMat.total()); - tmpMat.copyTo(dest->AsMat()); - break; - case cs::VideoMode::PixelFormat::kBGR: - tmpMat = cv::Mat(mode.height, mode.width, CV_8UC3, ptr, pitch); - dest = AllocImage(VideoMode::kBGR, tmpMat.cols, tmpMat.rows, - tmpMat.total() * 3); - tmpMat.copyTo(dest->AsMat()); - break; - case cs::VideoMode::PixelFormat::kYUYV: - tmpMat = cv::Mat(mode.height, mode.width, CV_8UC2, ptr, pitch); - dest = AllocImage(VideoMode::kYUYV, tmpMat.cols, tmpMat.rows, - tmpMat.total() * 2); - tmpMat.copyTo(dest->AsMat()); - break; - case cs::VideoMode::PixelFormat::kUYVY: - tmpMat = cv::Mat(mode.height, mode.width, CV_8UC2, ptr, pitch); - dest = AllocImage(VideoMode::kUYVY, tmpMat.cols, tmpMat.rows, - tmpMat.total() * 2); - tmpMat.copyTo(dest->AsMat()); - break; - default: - doFinalSet = false; - break; - } - - if (doFinalSet) { - PutFrame(std::move(dest), wpi::Now()); - } + std::string_view data_view{reinterpret_cast(ptr), length}; + SourceImpl::PutFrame(static_cast(mode.pixelFormat), + mode.width, mode.height, data_view, currentTime); if (buffer2d) { buffer2d->Unlock2D(); @@ -480,8 +432,6 @@ static cs::VideoMode::PixelFormat GetFromGUID(const GUID& guid) { return cs::VideoMode::PixelFormat::kY16; } else if (IsEqualGUID(guid, MFVideoFormat_YUY2)) { return cs::VideoMode::PixelFormat::kYUYV; - } else if (IsEqualGUID(guid, MFVideoFormat_RGB24)) { - return cs::VideoMode::PixelFormat::kBGR; } else if (IsEqualGUID(guid, MFVideoFormat_MJPG)) { return cs::VideoMode::PixelFormat::kMJPEG; } else if (IsEqualGUID(guid, MFVideoFormat_RGB565)) { diff --git a/wpiutil/src/main/java/edu/wpi/first/util/PixelFormat.java b/wpiutil/src/main/java/edu/wpi/first/util/PixelFormat.java index 809bfd0361..9951f8683a 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/PixelFormat.java +++ b/wpiutil/src/main/java/edu/wpi/first/util/PixelFormat.java @@ -21,7 +21,9 @@ public enum PixelFormat { /** Grayscale, 16 bpp. */ kY16(6), /** YUV 4:2:2, 16 bpp. */ - kUYVY(7); + kUYVY(7), + /** BGRA 8-8-8-8. 32 bpp. */ + kBGRA(8); private final int value; diff --git a/wpiutil/src/main/native/include/wpi/RawFrame.h b/wpiutil/src/main/native/include/wpi/RawFrame.h index 1345ff134e..2e925b1e0b 100644 --- a/wpiutil/src/main/native/include/wpi/RawFrame.h +++ b/wpiutil/src/main/native/include/wpi/RawFrame.h @@ -55,6 +55,7 @@ enum WPI_PixelFormat { WPI_PIXFMT_GRAY, // Grayscale, 8 bpp WPI_PIXFMT_Y16, // Grayscale, 16 bpp WPI_PIXFMT_UYVY, // YUV 4:2:2, 16 bpp + WPI_PIXFMT_BGRA, // BGRA 8-8-8-8-, 32 bpp }; // Returns nonzero if the frame data was allocated/reallocated From b4674bacb94f67486b98f30ba0a027b44c80196b Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sun, 17 Mar 2024 18:39:03 -0700 Subject: [PATCH 05/10] [wpiutil] Upgrade to LLVM 18.1.1 (#6405) --- .../native/cpp/net/WebSocketConnection.cpp | 2 +- ...move-StringRef-ArrayRef-and-Optional.patch | 273 ++++++++++-------- ...-calls-in-parens-for-Windows-warning.patch | 48 +-- ...-Change-unique_function-storage-size.patch | 8 +- .../llvm_patches/0004-Threading-updates.patch | 8 +- .../0005-ifdef-guard-safety.patch | 46 +-- .../0006-Explicitly-use-std.patch | 2 +- .../0007-Remove-format_provider.patch | 27 +- .../0008-Add-compiler-warning-pragmas.patch | 24 +- .../0009-Remove-unused-functions.patch | 86 +++--- .../0010-Detemplatize-SmallVectorBase.patch | 49 +++- .../0011-Add-vectors-to-raw_ostream.patch | 6 +- .../0012-Extra-collections-features.patch | 6 +- .../0013-EpochTracker-ABI-macro.patch | 2 +- .../0014-Delete-numbers-from-MathExtras.patch | 4 +- .../llvm_patches/0015-Add-lerp-and-sgn.patch | 6 +- .../llvm_patches/0016-Fixup-includes.patch | 10 +- ...-std-is_trivially_copy_constructible.patch | 2 +- ...-std-is_trivially_copy_constructible.patch | 60 ---- .../llvm_patches/0018-Windows-support.patch | 6 +- .../llvm_patches/0019-Prefer-fmtlib.patch | 2 +- .../llvm_patches/0020-Prefer-wpi-s-fs.h.patch | 2 +- .../0021-Remove-unused-functions.patch | 16 +- .../0022-OS-specific-changes.patch | 2 +- ...3-Use-SmallVector-for-UTF-conversion.patch | 2 +- ...o-use-static-pointers-in-raw_ostream.patch | 17 +- .../0025-constexpr-endian-byte-swap.patch | 14 +- ...-from-STLExtras.h-into-PointerUnion..patch | 2 +- ...-Remove-StringMap-test-for-llvm-sort.patch | 2 +- ...0028-Unused-variable-in-release-mode.patch | 2 +- .../0029-Use-C-20-bit-header.patch | 44 ++- ...0-Remove-DenseMap-GTest-printer-test.patch | 2 +- ...ace-deprecated-std-aligned_storage_t.patch | 10 +- ...-of-MathExtras.h-on-Windows-with-sdl.patch | 26 -- ...raw_ostream-Add-SetNumBytesInBuffer.patch} | 2 +- ...0033-type_traits.h-Add-is_constexpr.patch} | 2 +- ...emoved-raw_string_ostream-write_impl.patch | 28 ++ ...ove-auto-conversion-from-raw_ostream.patch | 43 +++ upstream_utils/update_llvm.py | 9 +- wpiutil/src/main/native/cpp/DataLog.cpp | 16 +- .../thirdparty/llvm/cpp/llvm/SmallVector.cpp | 3 +- .../thirdparty/llvm/cpp/llvm/raw_ostream.cpp | 5 +- .../thirdparty/llvm/include/wpi/Casting.h | 11 +- .../thirdparty/llvm/include/wpi/Chrono.h | 21 ++ .../thirdparty/llvm/include/wpi/Compiler.h | 33 +++ .../thirdparty/llvm/include/wpi/Endian.h | 212 ++++++++------ .../llvm/include/wpi/FunctionExtras.h | 7 +- .../thirdparty/llvm/include/wpi/Hashing.h | 16 +- .../thirdparty/llvm/include/wpi/MapVector.h | 57 ++-- .../thirdparty/llvm/include/wpi/MathExtras.h | 4 +- .../thirdparty/llvm/include/wpi/MemAlloc.h | 2 +- .../llvm/include/wpi/STLForwardCompat.h | 7 + .../thirdparty/llvm/include/wpi/SmallString.h | 35 ++- .../thirdparty/llvm/include/wpi/SmallVector.h | 23 +- .../llvm/include/wpi/SwapByteOrder.h | 53 +--- .../llvm/include/wpi/VersionTuple.h | 4 +- .../native/thirdparty/llvm/include/wpi/bit.h | 10 + .../llvm/include/wpi/iterator_range.h | 7 +- wpiutil/src/test/native/cpp/llvm/Chrono.cpp | 1 - .../src/test/native/cpp/llvm/EndianTest.cpp | 72 +++-- .../test/native/cpp/llvm/MapVectorTest.cpp | 110 +++++++ .../native/cpp/llvm/STLForwardCompatTest.cpp | 17 ++ 62 files changed, 964 insertions(+), 664 deletions(-) delete mode 100644 upstream_utils/llvm_patches/0018-Use-std-is_trivially_copy_constructible.patch delete mode 100644 upstream_utils/llvm_patches/0032-Fix-compilation-of-MathExtras.h-on-Windows-with-sdl.patch rename upstream_utils/llvm_patches/{0033-raw_ostream-Add-SetNumBytesInBuffer.patch => 0032-raw_ostream-Add-SetNumBytesInBuffer.patch} (93%) rename upstream_utils/llvm_patches/{0034-type_traits.h-Add-is_constexpr.patch => 0033-type_traits.h-Add-is_constexpr.patch} (94%) create mode 100644 upstream_utils/llvm_patches/0034-Add-back-removed-raw_string_ostream-write_impl.patch create mode 100644 upstream_utils/llvm_patches/0035-Remove-auto-conversion-from-raw_ostream.patch diff --git a/ntcore/src/main/native/cpp/net/WebSocketConnection.cpp b/ntcore/src/main/native/cpp/net/WebSocketConnection.cpp index 1312af2eb2..595e724e0a 100644 --- a/ntcore/src/main/native/cpp/net/WebSocketConnection.cpp +++ b/ntcore/src/main/native/cpp/net/WebSocketConnection.cpp @@ -124,7 +124,7 @@ void WebSocketConnection::SendPing(uint64_t time) { WPI_DEBUG4(m_logger, "conn: sending ping {}", time); auto buf = AllocBuf(); buf.len = 8; - wpi::support::endian::write64(buf.base, time); + wpi::support::endian::write64(buf.base, time); m_ws.SendPing({buf}, [selfweak = weak_from_this()](auto bufs, auto err) { if (auto self = selfweak.lock()) { self->m_err = err; diff --git a/upstream_utils/llvm_patches/0001-Remove-StringRef-ArrayRef-and-Optional.patch b/upstream_utils/llvm_patches/0001-Remove-StringRef-ArrayRef-and-Optional.patch index 20b83645e2..229cc473b6 100644 --- a/upstream_utils/llvm_patches/0001-Remove-StringRef-ArrayRef-and-Optional.patch +++ b/upstream_utils/llvm_patches/0001-Remove-StringRef-ArrayRef-and-Optional.patch @@ -1,40 +1,40 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sat, 7 May 2022 22:09:18 -0400 -Subject: [PATCH 01/34] Remove StringRef, ArrayRef, and Optional +Subject: [PATCH 01/35] Remove StringRef, ArrayRef, and Optional --- - llvm/include/llvm/ADT/PointerUnion.h | 1 - - llvm/include/llvm/ADT/SmallSet.h | 2 +- - llvm/include/llvm/ADT/SmallString.h | 77 ++++++++++--------- - llvm/include/llvm/ADT/SmallVector.h | 7 +- - llvm/include/llvm/ADT/StringMap.h | 38 ++++----- - llvm/include/llvm/ADT/StringMapEntry.h | 20 ++--- - llvm/include/llvm/Support/Chrono.h | 10 +-- - llvm/include/llvm/Support/Compiler.h | 2 +- - llvm/include/llvm/Support/ConvertUTF.h | 31 ++++---- - llvm/include/llvm/Support/ErrorHandling.h | 9 +-- - .../llvm/Support/SmallVectorMemoryBuffer.h | 6 +- - llvm/include/llvm/Support/VersionTuple.h | 6 -- - .../llvm/Support/Windows/WindowsSupport.h | 4 +- - llvm/include/llvm/Support/raw_ostream.h | 46 ++++++----- - llvm/include/llvm/Support/xxhash.h | 16 ++-- - llvm/lib/Support/ConvertUTFWrapper.cpp | 38 ++++----- - llvm/lib/Support/ErrorHandling.cpp | 13 ++-- - llvm/lib/Support/SmallVector.cpp | 5 +- - llvm/lib/Support/StringMap.cpp | 12 +-- - llvm/lib/Support/raw_ostream.cpp | 25 +++--- - llvm/lib/Support/xxhash.cpp | 10 +-- - llvm/unittests/ADT/DenseMapTest.cpp | 29 +------ - llvm/unittests/ADT/FunctionExtrasTest.cpp | 12 +-- - llvm/unittests/ADT/HashingTest.cpp | 2 +- - llvm/unittests/ADT/SmallPtrSetTest.cpp | 1 - - llvm/unittests/ADT/SmallStringTest.cpp | 50 ++++++------ - llvm/unittests/ADT/SmallVectorTest.cpp | 30 ++------ - llvm/unittests/ADT/StringMapTest.cpp | 32 ++++---- - llvm/unittests/Support/ConvertUTFTest.cpp | 41 +++++----- - llvm/unittests/Support/xxhashTest.cpp | 4 +- - 30 files changed, 264 insertions(+), 315 deletions(-) + llvm/include/llvm/ADT/PointerUnion.h | 1 - + llvm/include/llvm/ADT/SmallSet.h | 2 +- + llvm/include/llvm/ADT/SmallString.h | 103 ++++++++++-------- + llvm/include/llvm/ADT/SmallVector.h | 7 +- + llvm/include/llvm/ADT/StringMap.h | 38 +++---- + llvm/include/llvm/ADT/StringMapEntry.h | 20 ++-- + llvm/include/llvm/Support/Chrono.h | 10 +- + llvm/include/llvm/Support/Compiler.h | 2 +- + llvm/include/llvm/Support/ConvertUTF.h | 31 +++--- + llvm/include/llvm/Support/ErrorHandling.h | 9 +- + .../llvm/Support/SmallVectorMemoryBuffer.h | 6 +- + llvm/include/llvm/Support/VersionTuple.h | 6 - + .../llvm/Support/Windows/WindowsSupport.h | 4 +- + llvm/include/llvm/Support/raw_ostream.h | 46 +++++--- + llvm/include/llvm/Support/xxhash.h | 16 +-- + llvm/lib/Support/ConvertUTFWrapper.cpp | 38 +++---- + llvm/lib/Support/ErrorHandling.cpp | 13 +-- + llvm/lib/Support/SmallVector.cpp | 5 +- + llvm/lib/Support/StringMap.cpp | 12 +- + llvm/lib/Support/raw_ostream.cpp | 25 ++--- + llvm/lib/Support/xxhash.cpp | 10 +- + llvm/unittests/ADT/DenseMapTest.cpp | 29 +---- + llvm/unittests/ADT/FunctionExtrasTest.cpp | 12 +- + llvm/unittests/ADT/HashingTest.cpp | 2 +- + llvm/unittests/ADT/SmallPtrSetTest.cpp | 1 - + llvm/unittests/ADT/SmallStringTest.cpp | 50 ++++----- + llvm/unittests/ADT/SmallVectorTest.cpp | 30 +---- + llvm/unittests/ADT/StringMapTest.cpp | 32 +++--- + llvm/unittests/Support/ConvertUTFTest.cpp | 41 ++++--- + llvm/unittests/Support/xxhashTest.cpp | 4 +- + 30 files changed, 282 insertions(+), 323 deletions(-) diff --git a/llvm/include/llvm/ADT/PointerUnion.h b/llvm/include/llvm/ADT/PointerUnion.h index 7d4ed02b622626bb8043acb57b8ce7ed97a5f949..8ac68dbc0a791b8ac0e0ca865e69024cb642aa70 100644 @@ -67,7 +67,7 @@ index a16e8ac6f07552d98250e808190b00ee270f12b3..aeee5f97799aea7e7588d7afba1e47b4 #include #include diff --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h -index 0052c86fb37b82dcdf577a7acf06e3a47f54da61..4d673cc8b1c49cf8a3f19653de53881cd12662ee 100644 +index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413b0e36e0f 100644 --- a/llvm/include/llvm/ADT/SmallString.h +++ b/llvm/include/llvm/ADT/SmallString.h @@ -15,8 +15,9 @@ @@ -141,155 +141,176 @@ index 0052c86fb37b82dcdf577a7acf06e3a47f54da61..4d673cc8b1c49cf8a3f19653de53881c std::copy(Ref.begin(), Ref.end(), this->begin() + CurrentSize); CurrentSize += Ref.size(); } -@@ -89,30 +90,30 @@ public: +@@ -89,26 +90,30 @@ public: /// Check for string equality. This is more efficient than compare() when /// the relative ordering of inequal strings isn't needed. -- bool equals(StringRef RHS) const { -+ bool equals(std::string_view RHS) const { - return str().equals(RHS); - } +- [[nodiscard]] bool equals(StringRef RHS) const { return str().equals(RHS); } ++ [[nodiscard]] bool equals(std::string_view RHS) const { ++ return str().equals(RHS); ++ } /// Check for string equality, ignoring case. -- bool equals_insensitive(StringRef RHS) const { -+ bool equals_insensitive(std::string_view RHS) const { +- [[nodiscard]] bool equals_insensitive(StringRef RHS) const { ++ [[nodiscard]] bool equals_insensitive(std::string_view RHS) const { return str().equals_insensitive(RHS); } /// compare - Compare two strings; the result is negative, zero, or positive /// if this string is lexicographically less than, equal to, or greater than /// the \p RHS. -- int compare(StringRef RHS) const { -+ int compare(std::string_view RHS) const { - return str().compare(RHS); - } +- [[nodiscard]] int compare(StringRef RHS) const { return str().compare(RHS); } ++ [[nodiscard]] int compare(std::string_view RHS) const { ++ return str().compare(RHS); ++ } /// compare_insensitive - Compare two strings, ignoring case. -- int compare_insensitive(StringRef RHS) const { -+ int compare_insensitive(std::string_view RHS) const { +- [[nodiscard]] int compare_insensitive(StringRef RHS) const { ++ [[nodiscard]] int compare_insensitive(std::string_view RHS) const { return str().compare_insensitive(RHS); } /// compare_numeric - Compare two strings, treating sequences of digits as /// numbers. -- int compare_numeric(StringRef RHS) const { -+ int compare_numeric(std::string_view RHS) const { +- [[nodiscard]] int compare_numeric(StringRef RHS) const { ++ [[nodiscard]] int compare_numeric(std::string_view RHS) const { return str().compare_numeric(RHS); } -@@ -121,12 +122,12 @@ public: +@@ -116,14 +121,14 @@ public: + /// @name String Predicates /// @{ - /// startswith - Check if this string starts with the given \p Prefix. -- bool startswith(StringRef Prefix) const { -+ bool startswith(std::string_view Prefix) const { - return str().startswith(Prefix); +- /// starts_with - Check if this string starts with the given \p Prefix. +- [[nodiscard]] bool starts_with(StringRef Prefix) const { +- return str().starts_with(Prefix); ++ /// startswith - Check if this string starts with the given \p Prefix. ++ [[nodiscard]] bool startswith(std::string_view Prefix) const { ++ return str().startswith(Prefix); } - /// endswith - Check if this string ends with the given \p Suffix. -- bool endswith(StringRef Suffix) const { -+ bool endswith(std::string_view Suffix) const { - return str().endswith(Suffix); +- /// ends_with - Check if this string ends with the given \p Suffix. +- [[nodiscard]] bool ends_with(StringRef Suffix) const { +- return str().ends_with(Suffix); ++ /// endswith - Check if this string ends with the given \p Suffix. ++ [[nodiscard]] bool endswith(std::string_view Suffix) const { ++ return str().endswith(Suffix); } -@@ -146,7 +147,7 @@ public: + /// @} +@@ -142,7 +147,7 @@ public: /// /// \returns The index of the first occurrence of \p Str, or npos if not /// found. -- size_t find(StringRef Str, size_t From = 0) const { -+ size_t find(std::string_view Str, size_t From = 0) const { +- [[nodiscard]] size_t find(StringRef Str, size_t From = 0) const { ++ [[nodiscard]] size_t find(std::string_view Str, size_t From = 0) const { return str().find(Str, From); } -@@ -154,7 +155,7 @@ public: +@@ -150,7 +155,8 @@ public: /// /// \returns The index of the last occurrence of \p C, or npos if not /// found. -- size_t rfind(char C, size_t From = StringRef::npos) const { -+ size_t rfind(char C, size_t From = std::string_view::npos) const { +- [[nodiscard]] size_t rfind(char C, size_t From = StringRef::npos) const { ++ [[nodiscard]] size_t rfind(char C, ++ size_t From = std::string_view::npos) const { return str().rfind(C, From); } -@@ -162,7 +163,7 @@ public: +@@ -158,7 +164,9 @@ public: /// /// \returns The index of the last occurrence of \p Str, or npos if not /// found. -- size_t rfind(StringRef Str) const { -+ size_t rfind(std::string_view Str) const { - return str().rfind(Str); - } +- [[nodiscard]] size_t rfind(StringRef Str) const { return str().rfind(Str); } ++ [[nodiscard]] size_t rfind(std::string_view Str) const { ++ return str().rfind(Str); ++ } -@@ -176,7 +177,7 @@ public: + /// Find the first character in the string that is \p C, or npos if not + /// found. Same as find. +@@ -170,7 +178,8 @@ public: /// not found. /// /// Complexity: O(size() + Chars.size()) -- size_t find_first_of(StringRef Chars, size_t From = 0) const { -+ size_t find_first_of(std::string_view Chars, size_t From = 0) const { +- [[nodiscard]] size_t find_first_of(StringRef Chars, size_t From = 0) const { ++ [[nodiscard]] size_t find_first_of(std::string_view Chars, ++ size_t From = 0) const { return str().find_first_of(Chars, From); } -@@ -190,13 +191,13 @@ public: +@@ -184,15 +193,15 @@ public: /// \p Chars, or npos if not found. /// /// Complexity: O(size() + Chars.size()) -- size_t find_first_not_of(StringRef Chars, size_t From = 0) const { -+ size_t find_first_not_of(std::string_view Chars, size_t From = 0) const { +- [[nodiscard]] size_t find_first_not_of(StringRef Chars, ++ [[nodiscard]] size_t find_first_not_of(std::string_view Chars, + size_t From = 0) const { return str().find_first_not_of(Chars, From); } /// Find the last character in the string that is \p C, or npos if not /// found. -- size_t find_last_of(char C, size_t From = StringRef::npos) const { -+ size_t find_last_of(char C, size_t From = std::string_view::npos) const { +- [[nodiscard]] size_t find_last_of(char C, +- size_t From = StringRef::npos) const { ++ [[nodiscard]] size_t find_last_of( ++ char C, size_t From = std::string_view::npos) const { return str().find_last_of(C, From); } -@@ -205,7 +206,7 @@ public: +@@ -200,8 +209,8 @@ public: + /// found. /// /// Complexity: O(size() + Chars.size()) - size_t find_last_of( -- StringRef Chars, size_t From = StringRef::npos) const { +- [[nodiscard]] size_t find_last_of(StringRef Chars, +- size_t From = StringRef::npos) const { ++ [[nodiscard]] size_t find_last_of( + std::string_view Chars, size_t From = std::string_view::npos) const { return str().find_last_of(Chars, From); } -@@ -220,7 +221,7 @@ public: +@@ -214,7 +223,9 @@ public: /// Return the number of non-overlapped occurrences of \p Str in the /// string. -- size_t count(StringRef Str) const { -+ size_t count(std::string_view Str) const { - return str().count(Str); - } +- [[nodiscard]] size_t count(StringRef Str) const { return str().count(Str); } ++ [[nodiscard]] size_t count(std::string_view Str) const { ++ return str().count(Str); ++ } -@@ -237,7 +238,7 @@ public: + /// @} + /// @name Substring Operations +@@ -229,8 +240,8 @@ public: /// \param N The number of characters to included in the substring. If \p N /// exceeds the number of characters remaining in the string, the string /// suffix (starting with \p Start) will be returned. -- StringRef substr(size_t Start, size_t N = StringRef::npos) const { -+ std::string_view substr(size_t Start, size_t N = std::string_view::npos) const { +- [[nodiscard]] StringRef substr(size_t Start, +- size_t N = StringRef::npos) const { ++ [[nodiscard]] std::string_view substr( ++ size_t Start, size_t N = std::string_view::npos) const { return str().substr(Start, N); } -@@ -251,14 +252,14 @@ public: +@@ -244,15 +255,15 @@ public: /// substring. If this is npos, or less than \p Start, or exceeds the /// number of characters remaining in the string, the string suffix /// (starting with \p Start) will be returned. -- StringRef slice(size_t Start, size_t End) const { -+ std::string_view slice(size_t Start, size_t End) const { +- [[nodiscard]] StringRef slice(size_t Start, size_t End) const { ++ [[nodiscard]] std::string_view slice(size_t Start, size_t End) const { return str().slice(Start, End); } // Extra methods. - /// Explicit conversion to StringRef. -- StringRef str() const { return StringRef(this->data(), this->size()); } +- [[nodiscard]] StringRef str() const { +- return StringRef(this->data(), this->size()); + /// Explicit conversion to std::string_view. -+ std::string_view str() const { return std::string_view(this->begin(), this->size()); } ++ [[nodiscard]] std::string_view str() const { ++ return std::string_view(this->begin(), this->size()); + } // TODO: Make this const, if it's safe... - const char* c_str() { -@@ -267,20 +268,20 @@ public: +@@ -262,20 +273,20 @@ public: return this->data(); } @@ -315,7 +336,7 @@ index 0052c86fb37b82dcdf577a7acf06e3a47f54da61..4d673cc8b1c49cf8a3f19653de53881c return *this; } diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h -index 53a107b1574c6a35c66c7fe3c61deb2ffc84b991..4559864ed231206b098936dae4fc378bfa986371 100644 +index 09676d792dfebd88e5c8eace666b3ab0044a962e..c96fd0e4956ee6d586f85dc79623de137e781ce0 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -27,13 +27,12 @@ @@ -333,7 +354,7 @@ index 53a107b1574c6a35c66c7fe3c61deb2ffc84b991..4559864ed231206b098936dae4fc378b template class iterator_range; template -@@ -117,7 +116,7 @@ template struct SmallVectorAlignmentAndSize { +@@ -127,7 +126,7 @@ template struct SmallVectorAlignmentAndSize { }; /// This is the part of SmallVectorTemplateBase which does not depend on whether @@ -342,7 +363,7 @@ index 53a107b1574c6a35c66c7fe3c61deb2ffc84b991..4559864ed231206b098936dae4fc378b /// to avoid unnecessarily requiring T to be complete. template class SmallVectorTemplateCommon -@@ -1233,7 +1232,7 @@ public: +@@ -1242,7 +1241,7 @@ public: template ::value>> @@ -576,10 +597,10 @@ index 98b51cc1aebd59eba20076e6d8a4eebc0eebb982..388e81c361642113937f7d5680de73a5 #endif // LLVM_ADT_STRINGMAPENTRY_H diff --git a/llvm/include/llvm/Support/Chrono.h b/llvm/include/llvm/Support/Chrono.h -index 9c2bd45d2803e56ed316d8552d899d87f2fbbb07..a7dea19d9193bcff4bc6b553b80a10b2bc7b64af 100644 +index 71859af7c7e4a595140475daf356744f52d14d24..9c9ba7002310eba5113c14957f769702c61f4326 100644 --- a/llvm/include/llvm/Support/Chrono.h +++ b/llvm/include/llvm/Support/Chrono.h -@@ -70,7 +70,7 @@ raw_ostream &operator<<(raw_ostream &OS, sys::TimePoint<> TP); +@@ -91,7 +91,7 @@ raw_ostream &operator<<(raw_ostream &OS, sys::UtcTime<> TP); template <> struct format_provider> { static void format(const sys::TimePoint<> &TP, llvm::raw_ostream &OS, @@ -587,8 +608,8 @@ index 9c2bd45d2803e56ed316d8552d899d87f2fbbb07..a7dea19d9193bcff4bc6b553b80a10b2 + std::string_view Style); }; - namespace detail { -@@ -122,7 +122,7 @@ private: + template <> struct format_provider> { +@@ -148,7 +148,7 @@ private: return duration_cast>(D).count(); } @@ -597,7 +618,7 @@ index 9c2bd45d2803e56ed316d8552d899d87f2fbbb07..a7dea19d9193bcff4bc6b553b80a10b2 const Dur &D) { using namespace std::chrono; if (Style.consume_front("ns")) -@@ -140,7 +140,7 @@ private: +@@ -166,7 +166,7 @@ private: return {D.count(), detail::unit::value}; } @@ -606,7 +627,7 @@ index 9c2bd45d2803e56ed316d8552d899d87f2fbbb07..a7dea19d9193bcff4bc6b553b80a10b2 if (Style.empty()) return true; if (Style.consume_front("-")) -@@ -152,9 +152,9 @@ private: +@@ -178,9 +178,9 @@ private: } public: @@ -619,10 +640,10 @@ index 9c2bd45d2803e56ed316d8552d899d87f2fbbb07..a7dea19d9193bcff4bc6b553b80a10b2 bool show_unit = consumeShowUnit(Style); diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h -index 10d5cec231a523c943c37a5464cb3943627239a9..92376629c607461061bc60597a47aed1e535af52 100644 +index 8c315d255bb772d9e3c100adbd2c07b61283219b..6789f0413d8dc94cb465b6e66506b036449ee186 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h -@@ -300,7 +300,7 @@ +@@ -319,7 +319,7 @@ #endif /// LLVM_GSL_POINTER - Apply this to non-owning classes like @@ -800,18 +821,18 @@ index f7f2d4e54e705d6f29812dc93d1fb0a3ca2dee12..b5e321b5f74ce35940649b9d1342b3cd BufferKind getBufferKind() const override { return MemoryBuffer_Malloc; } diff --git a/llvm/include/llvm/Support/VersionTuple.h b/llvm/include/llvm/Support/VersionTuple.h -index 828a6db54708dfa9a1a4b4456a92945a92ad80cb..953b40701dc934c1a356b5413c9c6c692d5f5679 100644 +index 0a4623f049d28825530bf50c8acfe85deaed96ba..e1cdce77ce8659305c99a21e01f9b3cc3481a5fd 100644 --- a/llvm/include/llvm/Support/VersionTuple.h +++ b/llvm/include/llvm/Support/VersionTuple.h -@@ -25,7 +25,6 @@ namespace llvm { - template - class HashBuilderImpl; +@@ -23,7 +23,6 @@ + namespace llvm { + template class HashBuilder; class raw_ostream; -class StringRef; /// Represents a version number in the form major[.minor[.subminor[.build]]]. class VersionTuple { -@@ -182,11 +181,6 @@ public: +@@ -180,11 +179,6 @@ public: /// Retrieve a string representation of the version number. std::string getAsString() const; @@ -846,7 +867,7 @@ index d3aacd14b2097b1e7e13c1003987c1fd52e0cf76..aabdb2f14668a990329b57f5454a0d7d template diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h -index 1e01eb9ea19c4187302a91457b6d34fbe5b67584..2463f1af612a78cafafe3c0e16d496e607cdc322 100644 +index 42663a9adf2e51ae36209faf7d465094adbf0943..9345348d9ba555022b31f94299684316ffa15939 100644 --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -14,13 +14,12 @@ @@ -944,9 +965,9 @@ index 1e01eb9ea19c4187302a91457b6d34fbe5b67584..2463f1af612a78cafafe3c0e16d496e6 - raw_fd_stream(StringRef Filename, std::error_code &EC); + raw_fd_stream(std::string_view Filename, std::error_code &EC); - /// This reads the \p Size bytes into a buffer pointed by \p Ptr. - /// -@@ -693,8 +703,8 @@ public: + raw_fd_stream(int fd, bool shouldClose); + +@@ -695,8 +705,8 @@ public: void flush() = delete; @@ -957,7 +978,7 @@ index 1e01eb9ea19c4187302a91457b6d34fbe5b67584..2463f1af612a78cafafe3c0e16d496e6 void reserveExtraSpace(uint64_t ExtraSize) override { OS.reserve(tell() + ExtraSize); -@@ -751,7 +761,7 @@ class Error; +@@ -753,7 +763,7 @@ class Error; /// for other names. For raw_fd_ostream instances, the stream writes to /// a temporary file. The final output file is atomically replaced with the /// temporary file after the \p Write function is finished. @@ -1178,7 +1199,7 @@ index b8b3b7424ac6b1de782e739782f9671194ce77a1..0aa13a0f78eb370b2a673ca4a773f268 (void)written; // If something went wrong, we deliberately just give up. } diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp -index f7e7e80332cc337f6dfa388d1e218e6f3ec95cf2..6cefdff7c28060ca18b522acf5279af3a206e23a 100644 +index b6ce37842040b36fc79770ca0296255f2bb42a1a..4f6fee18b659adcbfd79822832f914170cbb1635 100644 --- a/llvm/lib/Support/SmallVector.cpp +++ b/llvm/lib/Support/SmallVector.cpp @@ -11,7 +11,6 @@ @@ -1265,10 +1286,10 @@ index 67c05a87959cf0c243d17646ae2f28f6c9f0d708..7be219323f6d76f32a9a841115f2f146 if (Bucket == -1) return nullptr; diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d83ac20248 100644 +index 3d3a564af51d120786b358b96a3c90e2b7fbf9f3..220d850b9bc69f8fc2fba7cd23629eca487cde23 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp -@@ -166,7 +166,7 @@ raw_ostream &raw_ostream::write_uuid(const uuid_t UUID) { +@@ -167,7 +167,7 @@ raw_ostream &raw_ostream::write_uuid(const uuid_t UUID) { } @@ -1277,7 +1298,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8 bool UseHexEscapes) { for (unsigned char c : Str) { switch (c) { -@@ -569,7 +569,7 @@ void format_object_base::home() { +@@ -570,7 +570,7 @@ void format_object_base::home() { // raw_fd_ostream //===----------------------------------------------------------------------===// @@ -1286,7 +1307,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8 sys::fs::CreationDisposition Disp, sys::fs::FileAccess Access, sys::fs::OpenFlags Flags) { assert((Access & sys::fs::FA_Write) && -@@ -595,25 +595,25 @@ static int getFD(StringRef Filename, std::error_code &EC, +@@ -596,25 +596,25 @@ static int getFD(StringRef Filename, std::error_code &EC, return FD; } @@ -1317,7 +1338,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8 sys::fs::CreationDisposition Disp, sys::fs::FileAccess Access, sys::fs::OpenFlags Flags) -@@ -685,8 +685,7 @@ raw_fd_ostream::~raw_fd_ostream() { +@@ -686,8 +686,7 @@ raw_fd_ostream::~raw_fd_ostream() { // has_error() and clear the error flag with clear_error() before // destructing raw_ostream objects which may have errors. if (has_error()) @@ -1327,7 +1348,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8 /*gen_crash_diag=*/false); } -@@ -705,7 +704,7 @@ raw_fd_ostream::~raw_fd_ostream() { +@@ -706,7 +705,7 @@ raw_fd_ostream::~raw_fd_ostream() { // the input is UTF-8 or transcode from the local codepage to UTF-8 before // quoting it. If they don't, this may mess up the encoding, but this is still // probably the best compromise we can make. @@ -1336,7 +1357,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8 SmallVector WideText; // Fall back to ::write if it wasn't valid UTF-8. -@@ -748,7 +747,7 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { +@@ -749,7 +748,7 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { // If this is a Windows console device, try re-encoding from UTF-8 to UTF-16 // and using WriteConsoleW. If that fails, fall back to plain write(). if (IsWindowsConsole) @@ -1345,7 +1366,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8 return; #endif -@@ -919,7 +918,7 @@ raw_ostream &llvm::nulls() { +@@ -925,7 +924,7 @@ raw_ostream &llvm::nulls() { // File Streams //===----------------------------------------------------------------------===// @@ -1354,7 +1375,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8 : raw_fd_ostream(getFD(Filename, EC, sys::fs::CD_CreateAlways, sys::fs::FA_Write | sys::fs::FA_Read, sys::fs::OF_None), -@@ -997,7 +996,7 @@ void buffer_ostream::anchor() {} +@@ -998,7 +997,7 @@ void buffer_ostream::anchor() {} void buffer_unique_ostream::anchor() {} @@ -1493,7 +1514,7 @@ index fc856a976946bf6decda9b6724cac66afc7bdcd6..aff9d61c7f0d48834123b04b74a2e4f7 TEST(UniqueFunctionTest, SFINAE) { EXPECT_EQ("not a function", returns("boo!")); diff --git a/llvm/unittests/ADT/HashingTest.cpp b/llvm/unittests/ADT/HashingTest.cpp -index 01a8a962b8e2e33ca8f189c049e9548ced42ec3a..62aff9c3b21eea785ca71c6e290c9c4f3a20ae00 100644 +index ab13ee833ce556945fb9526fd13d8bd5f3e5c95a..3e80467ebd0efddcf2cbbe003bb91f1475ca9cb3 100644 --- a/llvm/unittests/ADT/HashingTest.cpp +++ b/llvm/unittests/ADT/HashingTest.cpp @@ -295,7 +295,7 @@ TEST(HashingTest, HashCombineRangeGoldenTest) { diff --git a/upstream_utils/llvm_patches/0002-Wrap-std-min-max-calls-in-parens-for-Windows-warning.patch b/upstream_utils/llvm_patches/0002-Wrap-std-min-max-calls-in-parens-for-Windows-warning.patch index 0648e239f4..8adb0bccb3 100644 --- a/upstream_utils/llvm_patches/0002-Wrap-std-min-max-calls-in-parens-for-Windows-warning.patch +++ b/upstream_utils/llvm_patches/0002-Wrap-std-min-max-calls-in-parens-for-Windows-warning.patch @@ -1,14 +1,14 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sat, 7 May 2022 22:12:41 -0400 -Subject: [PATCH 02/34] Wrap std::min/max calls in parens, for Windows warnings +Subject: [PATCH 02/35] Wrap std::min/max calls in parens, for Windows warnings --- llvm/include/llvm/ADT/DenseMap.h | 4 ++-- - llvm/include/llvm/ADT/SmallVector.h | 12 ++++++------ + llvm/include/llvm/ADT/SmallVector.h | 6 +++--- llvm/include/llvm/Support/ConvertUTF.h | 2 +- llvm/include/llvm/Support/MathExtras.h | 18 +++++++++--------- - 4 files changed, 18 insertions(+), 18 deletions(-) + 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h index 3ef6a7cd1b4b587e61fcb9475d9f3516018bf2ee..108193f04486425f3b7f039cd9d2004be6facafb 100644 @@ -33,10 +33,10 @@ index 3ef6a7cd1b4b587e61fcb9475d9f3516018bf2ee..108193f04486425f3b7f039cd9d2004b this->BaseT::initEmpty(); return; diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h -index 4559864ed231206b098936dae4fc378bfa986371..84f4d0931a30f4be29549354c85cb4c0489e14c9 100644 +index c96fd0e4956ee6d586f85dc79623de137e781ce0..d7600fe209a58deb07c63e2553f9dad62e06e973 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h -@@ -55,12 +55,12 @@ protected: +@@ -55,7 +55,7 @@ protected: /// The maximum value of the Size_T used. static constexpr size_t SizeTypeMax() { @@ -45,22 +45,7 @@ index 4559864ed231206b098936dae4fc378bfa986371..84f4d0931a30f4be29549354c85cb4c0 } SmallVectorBase() = delete; - SmallVectorBase(void *FirstEl, size_t TotalCapacity) -- : BeginX(FirstEl), Capacity(TotalCapacity) {} -+ : BeginX(FirstEl), Capacity(static_cast(TotalCapacity)) {} - - /// This is a helper for \a grow() that's out of line to reduce code - /// duplication. This function will report a fatal error if it can't grow at -@@ -99,7 +99,7 @@ protected: - /// This does not construct or destroy any elements in the vector. - void set_size(size_t N) { - assert(N <= capacity()); -- Size = N; -+ Size = static_cast(N); - } - }; - -@@ -279,7 +279,7 @@ public: +@@ -289,7 +289,7 @@ public: size_type size_in_bytes() const { return size() * sizeof(T); } size_type max_size() const { @@ -69,16 +54,7 @@ index 4559864ed231206b098936dae4fc378bfa986371..84f4d0931a30f4be29549354c85cb4c0 } size_t capacity_in_bytes() const { return capacity() * sizeof(T); } -@@ -467,7 +467,7 @@ void SmallVectorTemplateBase::takeAllocationForGrow( - free(this->begin()); - - this->BeginX = NewElts; -- this->Capacity = NewCapacity; -+ this->Capacity = static_cast(NewCapacity); - } - - /// SmallVectorTemplateBase - This is where we put -@@ -712,7 +712,7 @@ public: +@@ -721,7 +721,7 @@ public: } // Assign over existing elements. @@ -101,7 +77,7 @@ index 5c0e3009c25446a34882fb98329b1d955231bb39..72321022beb373945f7935ed72944fd6 /* Some fundamental constants */ #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h -index dc095941fdc8a9f2b3b822e6e014f0640676c0d3..0bd572d07fcbf2ff56998dbf366215068b62f527 100644 +index aa4f4d2ed42e262f27e3f7f5ce275baf7e556c2d..5cabfdd6493fee33fbc74b831dc1fa3c91ba725d 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h @@ -311,26 +311,26 @@ template <> constexpr inline size_t CTLog2<1>() { return 0; } @@ -135,7 +111,7 @@ index dc095941fdc8a9f2b3b822e6e014f0640676c0d3..0bd572d07fcbf2ff56998dbf36621506 } /// A and B are either alignments or offsets. Return the minimum alignment that -@@ -479,7 +479,7 @@ SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) { +@@ -482,7 +482,7 @@ SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) { T Z = X + Y; Overflowed = (Z < X || Z < Y); if (Overflowed) @@ -144,7 +120,7 @@ index dc095941fdc8a9f2b3b822e6e014f0640676c0d3..0bd572d07fcbf2ff56998dbf36621506 else return Z; } -@@ -492,7 +492,7 @@ std::enable_if_t, T> SaturatingAdd(T X, T Y, T Z, +@@ -495,7 +495,7 @@ std::enable_if_t, T> SaturatingAdd(T X, T Y, T Z, bool Overflowed = false; T XY = SaturatingAdd(X, Y, &Overflowed); if (Overflowed) @@ -153,7 +129,7 @@ index dc095941fdc8a9f2b3b822e6e014f0640676c0d3..0bd572d07fcbf2ff56998dbf36621506 return SaturatingAdd(XY, Z, Args...); } -@@ -516,7 +516,7 @@ SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) { +@@ -519,7 +519,7 @@ SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) { // Special case: if X or Y is 0, Log2_64 gives -1, and Log2Z // will necessarily be less than Log2Max as desired. int Log2Z = Log2_64(X) + Log2_64(Y); @@ -162,7 +138,7 @@ index dc095941fdc8a9f2b3b822e6e014f0640676c0d3..0bd572d07fcbf2ff56998dbf36621506 int Log2Max = Log2_64(Max); if (Log2Z < Log2Max) { return X * Y; -@@ -636,9 +636,9 @@ std::enable_if_t, T> MulOverflow(T X, T Y, T &Result) { +@@ -639,9 +639,9 @@ std::enable_if_t, T> MulOverflow(T X, T Y, T &Result) { // Check how the max allowed absolute value (2^n for negative, 2^(n-1) for // positive) divided by an argument compares to the other. if (IsNegative) diff --git a/upstream_utils/llvm_patches/0003-Change-unique_function-storage-size.patch b/upstream_utils/llvm_patches/0003-Change-unique_function-storage-size.patch index 765515504a..8c8ede4797 100644 --- a/upstream_utils/llvm_patches/0003-Change-unique_function-storage-size.patch +++ b/upstream_utils/llvm_patches/0003-Change-unique_function-storage-size.patch @@ -1,17 +1,17 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sat, 7 May 2022 22:13:55 -0400 -Subject: [PATCH 03/34] Change unique_function storage size +Subject: [PATCH 03/35] Change unique_function storage size --- llvm/include/llvm/ADT/FunctionExtras.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h -index 4cf1de488c7bde2692d4878ccb4c4d60241e3a66..9d10b16e3cbe9c0df818a3254fcd3a6032d54b39 100644 +index c0bc30c7450fe4b2bc6b9b448824eedc8b132e52..5641a913d0a35ee2911cf872ad90c3dc864f20f5 100644 --- a/llvm/include/llvm/ADT/FunctionExtras.h +++ b/llvm/include/llvm/ADT/FunctionExtras.h -@@ -78,7 +78,7 @@ using EnableIfCallable = std::enable_if_t class UniqueFunctionBase { protected: @@ -20,7 +20,7 @@ index 4cf1de488c7bde2692d4878ccb4c4d60241e3a66..9d10b16e3cbe9c0df818a3254fcd3a60 template struct IsSizeLessThanThresholdT : std::false_type {}; -@@ -157,7 +157,7 @@ protected: +@@ -158,7 +158,7 @@ protected: "Should always use all of the out-of-line storage for inline storage!"); // For in-line storage, we just provide an aligned character buffer. We diff --git a/upstream_utils/llvm_patches/0004-Threading-updates.patch b/upstream_utils/llvm_patches/0004-Threading-updates.patch index 9cb2cf807f..4e4c519600 100644 --- a/upstream_utils/llvm_patches/0004-Threading-updates.patch +++ b/upstream_utils/llvm_patches/0004-Threading-updates.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sat, 7 May 2022 22:17:19 -0400 -Subject: [PATCH 04/34] Threading updates +Subject: [PATCH 04/35] Threading updates - Remove guards for threads and exception - Prefer scope gaurd over lock gaurd @@ -12,10 +12,10 @@ Subject: [PATCH 04/34] Threading updates 3 files changed, 11 insertions(+), 43 deletions(-) diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h -index 92376629c607461061bc60597a47aed1e535af52..2662839b27bf368cd5da0668099c4b44cbc6435d 100644 +index 6789f0413d8dc94cb465b6e66506b036449ee186..e608f8ea3a837a04d9c29c8bb7a1fab527d512bb 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h -@@ -530,7 +530,6 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); +@@ -555,7 +555,6 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); /// initialize to some constant value. In almost all circumstances this is most /// appropriate for use with a pointer, integer, or small aggregation of /// pointers and integers. @@ -23,7 +23,7 @@ index 92376629c607461061bc60597a47aed1e535af52..2662839b27bf368cd5da0668099c4b44 #if __has_feature(cxx_thread_local) || defined(_MSC_VER) #define LLVM_THREAD_LOCAL thread_local #else -@@ -538,11 +537,6 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); +@@ -563,11 +562,6 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); // we only need the restricted functionality that provides. #define LLVM_THREAD_LOCAL __thread #endif diff --git a/upstream_utils/llvm_patches/0005-ifdef-guard-safety.patch b/upstream_utils/llvm_patches/0005-ifdef-guard-safety.patch index 3a9ae56980..803403be99 100644 --- a/upstream_utils/llvm_patches/0005-ifdef-guard-safety.patch +++ b/upstream_utils/llvm_patches/0005-ifdef-guard-safety.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sat, 7 May 2022 22:28:13 -0400 -Subject: [PATCH 05/34] \#ifdef guard safety +Subject: [PATCH 05/35] \#ifdef guard safety Prevents redefinition if someone is pulling in real LLVM, since the macros are in global namespace --- @@ -9,7 +9,7 @@ Prevents redefinition if someone is pulling in real LLVM, since the macros are i 1 file changed, 42 insertions(+) diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h -index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e848519998685b 100644 +index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2a451c037 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -90,6 +90,7 @@ @@ -50,7 +50,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 #if defined(__clang__) #define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX))) -@@ -178,11 +184,13 @@ +@@ -197,11 +203,13 @@ // more portable solution: // (void)unused_var_name; // Prefer cast-to-void wherever it is sufficient. @@ -64,7 +64,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 // FIXME: Provide this for PE/COFF targets. #if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \ -@@ -192,6 +200,7 @@ +@@ -211,6 +219,7 @@ #define LLVM_ATTRIBUTE_WEAK #endif @@ -72,7 +72,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 // Prior to clang 3.2, clang did not accept any spelling of // __has_attribute(const), so assume it is supported. #if defined(__clang__) || defined(__GNUC__) -@@ -200,13 +209,16 @@ +@@ -219,13 +228,16 @@ #else #define LLVM_READNONE #endif @@ -89,7 +89,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 #if __has_attribute(minsize) #define LLVM_ATTRIBUTE_MINSIZE __attribute__((minsize)) -@@ -214,6 +226,7 @@ +@@ -233,6 +245,7 @@ #define LLVM_ATTRIBUTE_MINSIZE #endif @@ -97,7 +97,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 #if __has_builtin(__builtin_expect) || defined(__GNUC__) #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true) #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false) -@@ -221,9 +234,11 @@ +@@ -240,9 +253,11 @@ #define LLVM_LIKELY(EXPR) (EXPR) #define LLVM_UNLIKELY(EXPR) (EXPR) #endif @@ -109,7 +109,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 #if __has_attribute(noinline) #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline)) #elif defined(_MSC_VER) -@@ -231,9 +246,11 @@ +@@ -250,9 +265,11 @@ #else #define LLVM_ATTRIBUTE_NOINLINE #endif @@ -121,7 +121,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 #if __has_attribute(always_inline) #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline)) #elif defined(_MSC_VER) -@@ -241,6 +258,7 @@ +@@ -260,6 +277,7 @@ #else #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline #endif @@ -129,7 +129,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 /// LLVM_ATTRIBUTE_NO_DEBUG - On compilers where we have a directive to do /// so, mark a method "no debug" because debug info makes the debugger -@@ -251,6 +269,7 @@ +@@ -270,6 +288,7 @@ #define LLVM_ATTRIBUTE_NODEBUG #endif @@ -137,7 +137,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 #if __has_attribute(returns_nonnull) #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull)) #elif defined(_MSC_VER) -@@ -258,9 +277,11 @@ +@@ -277,9 +296,11 @@ #else #define LLVM_ATTRIBUTE_RETURNS_NONNULL #endif @@ -149,7 +149,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 #ifdef __GNUC__ #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) #elif defined(_MSC_VER) -@@ -268,8 +289,10 @@ +@@ -287,8 +308,10 @@ #else #define LLVM_ATTRIBUTE_RETURNS_NOALIAS #endif @@ -160,7 +160,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 #if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough) #define LLVM_FALLTHROUGH [[fallthrough]] #elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough) -@@ -281,6 +304,7 @@ +@@ -300,6 +323,7 @@ #else #define LLVM_FALLTHROUGH #endif @@ -168,7 +168,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 /// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that /// they are constant initialized. -@@ -309,11 +333,13 @@ +@@ -334,11 +358,13 @@ /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress /// pedantic diagnostics. @@ -182,7 +182,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands /// to an expression which states that it is undefined behavior for the -@@ -322,14 +348,17 @@ +@@ -347,14 +373,17 @@ /// '#else' is intentionally left out so that other macro logic (e.g., /// LLVM_ASSUME_ALIGNED and llvm_unreachable()) can detect whether /// LLVM_BUILTIN_UNREACHABLE has a definition. @@ -200,7 +200,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 #if __has_builtin(__builtin_trap) || defined(__GNUC__) # define LLVM_BUILTIN_TRAP __builtin_trap() #elif defined(_MSC_VER) -@@ -341,10 +370,12 @@ +@@ -366,10 +395,12 @@ #else # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0 #endif @@ -213,7 +213,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 #if __has_builtin(__builtin_debugtrap) # define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap() #elif defined(_MSC_VER) -@@ -358,9 +389,11 @@ +@@ -383,9 +414,11 @@ // program to abort if encountered. # define LLVM_BUILTIN_DEBUGTRAP #endif @@ -225,7 +225,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 #if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__) # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a) #elif defined(LLVM_BUILTIN_UNREACHABLE) -@@ -369,6 +402,7 @@ +@@ -394,6 +427,7 @@ #else # define LLVM_ASSUME_ALIGNED(p, a) (p) #endif @@ -233,7 +233,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 /// \macro LLVM_PACKED /// Used to specify a packed structure. -@@ -388,6 +422,7 @@ +@@ -413,6 +447,7 @@ /// long long l; /// }; /// LLVM_PACKED_END @@ -241,7 +241,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 #ifdef _MSC_VER # define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop)) # define LLVM_PACKED_START __pragma(pack(push, 1)) -@@ -397,6 +432,7 @@ +@@ -422,6 +457,7 @@ # define LLVM_PACKED_START _Pragma("pack(push, 1)") # define LLVM_PACKED_END _Pragma("pack(pop)") #endif @@ -249,7 +249,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 /// \macro LLVM_MEMORY_SANITIZER_BUILD /// Whether LLVM itself is built with MemorySanitizer instrumentation. -@@ -488,11 +524,13 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); +@@ -513,11 +549,13 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); /// \macro LLVM_NO_SANITIZE /// Disable a particular sanitizer for a function. @@ -263,7 +263,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 /// Mark debug helper function definitions like dump() that should not be /// stripped from debug builds. -@@ -500,17 +538,20 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); +@@ -525,17 +563,20 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); /// `#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)` so they do always /// get stripped in release builds. // FIXME: Move this to a private config.h as it's not usable in public headers. @@ -284,7 +284,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851 #if defined(_MSC_VER) #define LLVM_PRETTY_FUNCTION __FUNCSIG__ #elif defined(__GNUC__) || defined(__clang__) -@@ -518,6 +559,7 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); +@@ -543,6 +584,7 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); #else #define LLVM_PRETTY_FUNCTION __func__ #endif diff --git a/upstream_utils/llvm_patches/0006-Explicitly-use-std.patch b/upstream_utils/llvm_patches/0006-Explicitly-use-std.patch index 2217c4d0b0..a7515301b3 100644 --- a/upstream_utils/llvm_patches/0006-Explicitly-use-std.patch +++ b/upstream_utils/llvm_patches/0006-Explicitly-use-std.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sat, 7 May 2022 22:37:34 -0400 -Subject: [PATCH 06/34] Explicitly use std:: +Subject: [PATCH 06/35] Explicitly use std:: --- llvm/include/llvm/ADT/SmallSet.h | 2 +- diff --git a/upstream_utils/llvm_patches/0007-Remove-format_provider.patch b/upstream_utils/llvm_patches/0007-Remove-format_provider.patch index 6249648e93..1219cc018b 100644 --- a/upstream_utils/llvm_patches/0007-Remove-format_provider.patch +++ b/upstream_utils/llvm_patches/0007-Remove-format_provider.patch @@ -1,16 +1,16 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sat, 7 May 2022 22:53:50 -0400 -Subject: [PATCH 07/34] Remove format_provider +Subject: [PATCH 07/35] Remove format_provider --- - llvm/include/llvm/Support/Chrono.h | 109 ------------------------ + llvm/include/llvm/Support/Chrono.h | 114 ------------------------ llvm/include/llvm/Support/raw_ostream.h | 6 -- - llvm/unittests/Support/Chrono.cpp | 67 --------------- - 3 files changed, 182 deletions(-) + 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 a7dea19d9193bcff4bc6b553b80a10b2bc7b64af..9f9a2b5cab270327898cee3f97d9ae7cf77eb564 100644 +index 9c9ba7002310eba5113c14957f769702c61f4326..b269ff8bb5db7bb3c62c3a87daf255b18ece4cd7 100644 --- a/llvm/include/llvm/Support/Chrono.h +++ b/llvm/include/llvm/Support/Chrono.h @@ -10,7 +10,6 @@ @@ -21,9 +21,9 @@ index a7dea19d9193bcff4bc6b553b80a10b2bc7b64af..9f9a2b5cab270327898cee3f97d9ae7c #include #include -@@ -59,114 +58,6 @@ toTimePoint(std::time_t T, uint32_t nsec) { - +@@ -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<> -/// @@ -39,6 +39,11 @@ index a7dea19d9193bcff4bc6b553b80a10b2bc7b64af..9f9a2b5cab270327898cee3f97d9ae7c - std::string_view Style); -}; - +-template <> struct format_provider> { +- static void format(const sys::UtcTime &TP, +- llvm::raw_ostream &OS, StringRef Style); +-}; +- -namespace detail { -template struct unit { static const char value[]; }; -template const char unit::value[] = ""; @@ -137,7 +142,7 @@ index a7dea19d9193bcff4bc6b553b80a10b2bc7b64af..9f9a2b5cab270327898cee3f97d9ae7c #endif // LLVM_SUPPORT_CHRONO_H diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h -index 2463f1af612a78cafafe3c0e16d496e607cdc322..5d08596b4cf6bf9e9b8e2c2c1aef731bb8832da5 100644 +index 9345348d9ba555022b31f94299684316ffa15939..862a1db876e9b8467a8839dae8f6632f18d5e7a0 100644 --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -27,12 +27,6 @@ @@ -154,10 +159,10 @@ index 2463f1af612a78cafafe3c0e16d496e607cdc322..5d08596b4cf6bf9e9b8e2c2c1aef731b namespace sys { diff --git a/llvm/unittests/Support/Chrono.cpp b/llvm/unittests/Support/Chrono.cpp -index daf8a8a350f08c748ba05af44f43f3faca8e2c61..3c049de18c0a80465f4b0a8c054df2602d5e9b1c 100644 +index 7dfc5dd2c29348ea8df9ce87c80f357aaad1a73b..a4d166d435d6d679f773dcf3eab985f0631e12d2 100644 --- a/llvm/unittests/Support/Chrono.cpp +++ b/llvm/unittests/Support/Chrono.cpp -@@ -30,43 +30,6 @@ TEST(Chrono, TimeTConversion) { +@@ -29,43 +29,6 @@ TEST(Chrono, TimeTConversion) { EXPECT_EQ(TP, toTimePoint(toTimeT(TP))); } @@ -201,7 +206,7 @@ index daf8a8a350f08c748ba05af44f43f3faca8e2c61..3c049de18c0a80465f4b0a8c054df260 // Test that toTimePoint and toTimeT can be called with a arguments with varying // precisions. TEST(Chrono, ImplicitConversions) { -@@ -84,34 +47,4 @@ TEST(Chrono, ImplicitConversions) { +@@ -83,34 +46,4 @@ TEST(Chrono, ImplicitConversions) { EXPECT_EQ(TimeT, toTimeT(Nano)); } diff --git a/upstream_utils/llvm_patches/0008-Add-compiler-warning-pragmas.patch b/upstream_utils/llvm_patches/0008-Add-compiler-warning-pragmas.patch index 8a889a7b14..c0e51d0ea9 100644 --- a/upstream_utils/llvm_patches/0008-Add-compiler-warning-pragmas.patch +++ b/upstream_utils/llvm_patches/0008-Add-compiler-warning-pragmas.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sun, 8 May 2022 13:34:07 -0400 -Subject: [PATCH 08/34] Add compiler warning pragmas +Subject: [PATCH 08/35] Add compiler warning pragmas --- llvm/include/llvm/ADT/FunctionExtras.h | 11 +++++++++++ @@ -17,10 +17,10 @@ Subject: [PATCH 08/34] Add compiler warning pragmas 10 files changed, 72 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h -index 9d10b16e3cbe9c0df818a3254fcd3a6032d54b39..1daeae915eb506b32a2d1296d2f0fe4e6dab606e 100644 +index 5641a913d0a35ee2911cf872ad90c3dc864f20f5..043d8d90fff03d571a923c264b49be37a5dffa09 100644 --- a/llvm/include/llvm/ADT/FunctionExtras.h +++ b/llvm/include/llvm/ADT/FunctionExtras.h -@@ -55,6 +55,13 @@ namespace llvm { +@@ -56,6 +56,13 @@ namespace llvm { /// It can hold functions with a non-const operator(), like mutable lambdas. template class unique_function; @@ -34,7 +34,7 @@ index 9d10b16e3cbe9c0df818a3254fcd3a6032d54b39..1daeae915eb506b32a2d1296d2f0fe4e namespace detail { template -@@ -409,6 +416,10 @@ public: +@@ -412,6 +419,10 @@ public: } }; @@ -46,7 +46,7 @@ index 9d10b16e3cbe9c0df818a3254fcd3a6032d54b39..1daeae915eb506b32a2d1296d2f0fe4e #endif // LLVM_ADT_FUNCTIONEXTRAS_H diff --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h -index ef983105c7bae67bb2ef832e4473939a0406e0df..781bdb7416392e3f60a1ac3a38fbcf5324b5395f 100644 +index a5477362a50793985e1e9df9dc77c8a1d5b5846b..08d6edb14eb3cd51405329aae61b9782266a2590 100644 --- a/llvm/include/llvm/ADT/Hashing.h +++ b/llvm/include/llvm/ADT/Hashing.h @@ -56,6 +56,11 @@ @@ -61,9 +61,9 @@ index ef983105c7bae67bb2ef832e4473939a0406e0df..781bdb7416392e3f60a1ac3a38fbcf53 namespace llvm { template struct DenseMapInfo; -@@ -683,4 +688,8 @@ template <> struct DenseMapInfo { +@@ -697,4 +702,8 @@ struct hash { - } // namespace llvm + } // namespace std; +#ifdef _WIN32 +#pragma warning(pop) @@ -71,7 +71,7 @@ index ef983105c7bae67bb2ef832e4473939a0406e0df..781bdb7416392e3f60a1ac3a38fbcf53 + #endif diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h -index 84f4d0931a30f4be29549354c85cb4c0489e14c9..b42438a9b16c273f9ef5b5cce6192873c78cb964 100644 +index d7600fe209a58deb07c63e2553f9dad62e06e973..d7788e94b5379f5eba6fbddee50e4b4359da9d80 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -14,6 +14,14 @@ @@ -90,7 +90,7 @@ index 84f4d0931a30f4be29549354c85cb4c0489e14c9..b42438a9b16c273f9ef5b5cce6192873 #include "llvm/Support/type_traits.h" #include diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h -index 0bd572d07fcbf2ff56998dbf366215068b62f527..cd5a64a746b2eb7491e9b6cf8570bdf436d94a6d 100644 +index 5cabfdd6493fee33fbc74b831dc1fa3c91ba725d..7541447fa2db5e1634d952b1f39957eb725611f4 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h @@ -208,6 +208,11 @@ inline uint64_t maxUIntN(uint64_t N) { @@ -117,7 +117,7 @@ index 0bd572d07fcbf2ff56998dbf366215068b62f527..cd5a64a746b2eb7491e9b6cf8570bdf4 inline int64_t maxIntN(int64_t N) { assert(N > 0 && N <= 64 && "integer width out of range"); diff --git a/llvm/include/llvm/Support/MemAlloc.h b/llvm/include/llvm/Support/MemAlloc.h -index d6012bd5a6985d8405136039aa85931605cd8a40..01007deb89bba625b1b3ad3e703d0c16ed6f757b 100644 +index f3f378b7697a18f57b189c5322b080fe23d45bec..0028e871f6a05baf6172c60c602b8b26e5f116c6 100644 --- a/llvm/include/llvm/Support/MemAlloc.h +++ b/llvm/include/llvm/Support/MemAlloc.h @@ -22,6 +22,14 @@ @@ -146,7 +146,7 @@ index d6012bd5a6985d8405136039aa85931605cd8a40..01007deb89bba625b1b3ad3e703d0c16 + #endif diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index 9966a0056ae4f24a7a38346ee1c2f5d83ac20248..a23f567a37abdc199363607446f33f29e021d7ad 100644 +index 220d850b9bc69f8fc2fba7cd23629eca487cde23..65810ca93fdc1290e3188b5f4fb292a1e1e79b60 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -10,6 +10,10 @@ @@ -176,7 +176,7 @@ index b710ac07461ba58faa99cedeae7f209dc0f5902b..1f232d3046292c0da940ba4bef7d5060 #include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/DenseMapInfoVariant.h" diff --git a/llvm/unittests/ADT/MapVectorTest.cpp b/llvm/unittests/ADT/MapVectorTest.cpp -index 1a371cbfba81e8ea4b57c4077ca94c86c3db8991..62fafcaf04a67d4c67b98b8f42d837ccca245fe9 100644 +index e0f11b60a0223da7c00a47c20b61136bd608bae6..9c802ab30721c9ce58ed65052a6ab467039226ff 100644 --- a/llvm/unittests/ADT/MapVectorTest.cpp +++ b/llvm/unittests/ADT/MapVectorTest.cpp @@ -6,6 +6,13 @@ diff --git a/upstream_utils/llvm_patches/0009-Remove-unused-functions.patch b/upstream_utils/llvm_patches/0009-Remove-unused-functions.patch index bff9ff2c79..3a38304093 100644 --- a/upstream_utils/llvm_patches/0009-Remove-unused-functions.patch +++ b/upstream_utils/llvm_patches/0009-Remove-unused-functions.patch @@ -1,52 +1,50 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sun, 8 May 2022 13:43:50 -0400 -Subject: [PATCH 09/34] Remove unused functions +Subject: [PATCH 09/35] Remove unused functions --- - llvm/include/llvm/ADT/SmallString.h | 85 +----- + llvm/include/llvm/ADT/SmallString.h | 79 ------ llvm/include/llvm/Support/Errno.h | 9 - llvm/include/llvm/Support/VersionTuple.h | 39 --- - llvm/include/llvm/Support/raw_ostream.h | 127 +-------- - llvm/lib/Support/raw_ostream.cpp | 329 ----------------------- - 5 files changed, 10 insertions(+), 579 deletions(-) + llvm/include/llvm/Support/raw_ostream.h | 129 +-------- + llvm/lib/Support/raw_ostream.cpp | 332 ----------------------- + 5 files changed, 8 insertions(+), 580 deletions(-) diff --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h -index 4d673cc8b1c49cf8a3f19653de53881cd12662ee..bfa965fd68a09d7ca3b332e38585ae37a5982ed0 100644 +index 45fbf13a43a081731186b0f41c553413b0e36e0f..cb6136d8fd1886e8dc444cb807b33a5f1e18aa44 100644 --- a/llvm/include/llvm/ADT/SmallString.h +++ b/llvm/include/llvm/ADT/SmallString.h -@@ -88,49 +88,12 @@ public: +@@ -88,17 +88,6 @@ public: /// @name String Comparison /// @{ - /// Check for string equality. This is more efficient than compare() when - /// the relative ordering of inequal strings isn't needed. -- bool equals(std::string_view RHS) const { +- [[nodiscard]] bool equals(std::string_view RHS) const { - return str().equals(RHS); - } - - /// Check for string equality, ignoring case. -- bool equals_insensitive(std::string_view RHS) const { +- [[nodiscard]] bool equals_insensitive(std::string_view RHS) const { - return str().equals_insensitive(RHS); - } - -- /// compare - Compare two strings; the result is negative, zero, or positive -- /// if this string is lexicographically less than, equal to, or greater than -- /// the \p RHS. -+ /// Compare two strings; the result is -1, 0, or 1 if this string is -+ /// lexicographically less than, equal to, or greater than the \p RHS. - int compare(std::string_view RHS) const { + /// compare - Compare two strings; the result is negative, zero, or positive + /// if this string is lexicographically less than, equal to, or greater than + /// the \p RHS. +@@ -106,31 +95,6 @@ public: return str().compare(RHS); } - /// compare_insensitive - Compare two strings, ignoring case. -- int compare_insensitive(std::string_view RHS) const { +- [[nodiscard]] int compare_insensitive(std::string_view RHS) const { - return str().compare_insensitive(RHS); - } - - /// compare_numeric - Compare two strings, treating sequences of digits as - /// numbers. -- int compare_numeric(std::string_view RHS) const { +- [[nodiscard]] int compare_numeric(std::string_view RHS) const { - return str().compare_numeric(RHS); - } - @@ -55,19 +53,19 @@ index 4d673cc8b1c49cf8a3f19653de53881cd12662ee..bfa965fd68a09d7ca3b332e38585ae37 - /// @{ - - /// startswith - Check if this string starts with the given \p Prefix. -- bool startswith(std::string_view Prefix) const { +- [[nodiscard]] bool startswith(std::string_view Prefix) const { - return str().startswith(Prefix); - } - - /// endswith - Check if this string ends with the given \p Suffix. -- bool endswith(std::string_view Suffix) const { +- [[nodiscard]] bool endswith(std::string_view Suffix) const { - return str().endswith(Suffix); - } - /// @} /// @name String Searching /// @{ -@@ -211,50 +174,6 @@ public: +@@ -215,49 +179,6 @@ public: } /// @} @@ -75,13 +73,11 @@ index 4d673cc8b1c49cf8a3f19653de53881cd12662ee..bfa965fd68a09d7ca3b332e38585ae37 - /// @{ - - /// Return the number of occurrences of \p C in the string. -- size_t count(char C) const { -- return str().count(C); -- } +- [[nodiscard]] size_t count(char C) const { return str().count(C); } - - /// Return the number of non-overlapped occurrences of \p Str in the - /// string. -- size_t count(std::string_view Str) const { +- [[nodiscard]] size_t count(std::string_view Str) const { - return str().count(Str); - } - @@ -98,7 +94,8 @@ index 4d673cc8b1c49cf8a3f19653de53881cd12662ee..bfa965fd68a09d7ca3b332e38585ae37 - /// \param N The number of characters to included in the substring. If \p N - /// exceeds the number of characters remaining in the string, the string - /// suffix (starting with \p Start) will be returned. -- std::string_view substr(size_t Start, size_t N = std::string_view::npos) const { +- [[nodiscard]] std::string_view substr( +- size_t Start, size_t N = std::string_view::npos) const { - return str().substr(Start, N); - } - @@ -112,7 +109,7 @@ index 4d673cc8b1c49cf8a3f19653de53881cd12662ee..bfa965fd68a09d7ca3b332e38585ae37 - /// substring. If this is npos, or less than \p Start, or exceeds the - /// number of characters remaining in the string, the string suffix - /// (starting with \p Start) will be returned. -- std::string_view slice(size_t Start, size_t End) const { +- [[nodiscard]] std::string_view slice(size_t Start, size_t End) const { - return str().slice(Start, End); - } @@ -139,10 +136,10 @@ index e095c66b90860001d90b5c2eb74f6032de6de454..787805dac6c5e3c8cb85dabeb8025444 inline decltype(auto) RetryAfterSignal(const FailT &Fail, const Fun &F, const Args &... As) { diff --git a/llvm/include/llvm/Support/VersionTuple.h b/llvm/include/llvm/Support/VersionTuple.h -index 953b40701dc934c1a356b5413c9c6c692d5f5679..30cf717973fb15ff65a47a2d80795c351b0d2768 100644 +index e1cdce77ce8659305c99a21e01f9b3cc3481a5fd..9102ff063afedc03bd524b2805cba98ea5afeba8 100644 --- a/llvm/include/llvm/Support/VersionTuple.h +++ b/llvm/include/llvm/Support/VersionTuple.h -@@ -168,45 +168,6 @@ public: +@@ -166,45 +166,6 @@ public: friend bool operator>=(const VersionTuple &X, const VersionTuple &Y) { return !(X < Y); } @@ -151,8 +148,8 @@ index 953b40701dc934c1a356b5413c9c6c692d5f5679..30cf717973fb15ff65a47a2d80795c35 - return hash_combine(VT.Major, VT.Minor, VT.Subminor, VT.Build); - } - -- template -- friend void addHash(HashBuilderImpl &HBuilder, +- template +- friend void addHash(HashBuilder &HBuilder, - const VersionTuple &VT) { - HBuilder.add(VT.Major, VT.Minor, VT.Subminor, VT.Build); - } @@ -189,7 +186,7 @@ index 953b40701dc934c1a356b5413c9c6c692d5f5679..30cf717973fb15ff65a47a2d80795c35 } // end namespace llvm diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h -index 5d08596b4cf6bf9e9b8e2c2c1aef731bb8832da5..95019180a9deb406ed4f2991c664a4cc4e956dac 100644 +index 862a1db876e9b8467a8839dae8f6632f18d5e7a0..95019180a9deb406ed4f2991c664a4cc4e956dac 100644 --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -261,32 +261,6 @@ public: @@ -339,10 +336,12 @@ index 5d08596b4cf6bf9e9b8e2c2c1aef731bb8832da5..95019180a9deb406ed4f2991c664a4cc }; /// This returns a reference to a raw_fd_ostream for standard output. Use it -@@ -619,17 +542,6 @@ public: +@@ -619,19 +542,6 @@ public: /// immediately destroyed. raw_fd_stream(std::string_view Filename, std::error_code &EC); +- raw_fd_stream(int fd, bool shouldClose); +- - /// This reads the \p Size bytes into a buffer pointed by \p Ptr. - /// - /// \param Ptr The start of the buffer to hold data to be read. @@ -357,7 +356,7 @@ index 5d08596b4cf6bf9e9b8e2c2c1aef731bb8832da5..95019180a9deb406ed4f2991c664a4cc /// Check if \p OS is a pointer of type raw_fd_stream*. static bool classof(const raw_ostream *OS); }; -@@ -747,29 +659,6 @@ public: +@@ -749,29 +659,6 @@ public: ~buffer_unique_ostream() override { *OS << str(); } }; @@ -388,18 +387,18 @@ index 5d08596b4cf6bf9e9b8e2c2c1aef731bb8832da5..95019180a9deb406ed4f2991c664a4cc #endif // LLVM_SUPPORT_RAW_OSTREAM_H diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index a23f567a37abdc199363607446f33f29e021d7ad..76c32155b4296fbbf3f4b164cd58d63f472ccd5e 100644 +index 65810ca93fdc1290e3188b5f4fb292a1e1e79b60..c65fb70a4d22db51f4140b910c308333289b6248 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp -@@ -18,7 +18,6 @@ - #include "llvm/ADT/StringExtras.h" +@@ -19,7 +19,6 @@ #include "llvm/Config/config.h" + #include "llvm/Support/AutoConvert.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" -@@ -127,49 +126,6 @@ void raw_ostream::SetBufferAndMode(char *BufferStart, size_t Size, +@@ -128,49 +127,6 @@ void raw_ostream::SetBufferAndMode(char *BufferStart, size_t Size, assert(OutBufStart <= OutBufEnd && "Invalid size!"); } @@ -449,7 +448,7 @@ index a23f567a37abdc199363607446f33f29e021d7ad..76c32155b4296fbbf3f4b164cd58d63f raw_ostream &raw_ostream::write_escaped(std::string_view Str, bool UseHexEscapes) { for (unsigned char c : Str) { -@@ -315,173 +271,6 @@ void raw_ostream::flush_tied_then_write(const char *Ptr, size_t Size) { +@@ -316,173 +272,6 @@ void raw_ostream::flush_tied_then_write(const char *Ptr, size_t Size) { write_impl(Ptr, Size); } @@ -623,7 +622,7 @@ index a23f567a37abdc199363607446f33f29e021d7ad..76c32155b4296fbbf3f4b164cd58d63f template static raw_ostream &write_padding(raw_ostream &OS, unsigned NumChars) { static const char Chars[] = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, -@@ -512,63 +301,8 @@ raw_ostream &raw_ostream::write_zeros(unsigned NumZeros) { +@@ -513,63 +302,8 @@ raw_ostream &raw_ostream::write_zeros(unsigned NumZeros) { return write_padding<'\0'>(*this, NumZeros); } @@ -687,7 +686,7 @@ index a23f567a37abdc199363607446f33f29e021d7ad..76c32155b4296fbbf3f4b164cd58d63f //===----------------------------------------------------------------------===// // raw_fd_ostream //===----------------------------------------------------------------------===// -@@ -867,31 +601,6 @@ size_t raw_fd_ostream::preferred_buffer_size() const { +@@ -865,31 +599,6 @@ size_t raw_fd_ostream::preferred_buffer_size() const { #endif } @@ -719,10 +718,13 @@ index a23f567a37abdc199363607446f33f29e021d7ad..76c32155b4296fbbf3f4b164cd58d63f void raw_fd_ostream::anchor() {} //===----------------------------------------------------------------------===// -@@ -934,16 +643,6 @@ raw_fd_stream::raw_fd_stream(std::string_view Filename, std::error_code &EC) +@@ -940,19 +649,6 @@ raw_fd_stream::raw_fd_stream(std::string_view Filename, std::error_code &EC) EC = std::make_error_code(std::errc::invalid_argument); } +-raw_fd_stream::raw_fd_stream(int fd, bool shouldClose) +- : raw_fd_ostream(fd, shouldClose, false, OStreamKind::OK_FDStream) {} +- -ssize_t raw_fd_stream::read(char *Ptr, size_t Size) { - assert(get_fd() >= 0 && "File already closed."); - ssize_t Ret = ::read(get_fd(), (void *)Ptr, Size); @@ -736,7 +738,7 @@ index a23f567a37abdc199363607446f33f29e021d7ad..76c32155b4296fbbf3f4b164cd58d63f bool raw_fd_stream::classof(const raw_ostream *OS) { return OS->get_kind() == OStreamKind::OK_FDStream; } -@@ -999,31 +698,3 @@ void raw_pwrite_stream::anchor() {} +@@ -1000,31 +696,3 @@ void raw_pwrite_stream::anchor() {} void buffer_ostream::anchor() {} void buffer_unique_ostream::anchor() {} diff --git a/upstream_utils/llvm_patches/0010-Detemplatize-SmallVectorBase.patch b/upstream_utils/llvm_patches/0010-Detemplatize-SmallVectorBase.patch index 484ac22435..5ab041a118 100644 --- a/upstream_utils/llvm_patches/0010-Detemplatize-SmallVectorBase.patch +++ b/upstream_utils/llvm_patches/0010-Detemplatize-SmallVectorBase.patch @@ -1,18 +1,18 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Thu, 5 May 2022 23:18:34 -0400 -Subject: [PATCH 10/34] Detemplatize SmallVectorBase +Subject: [PATCH 10/35] Detemplatize SmallVectorBase --- - llvm/include/llvm/ADT/SmallVector.h | 27 +++++++-------------- + llvm/include/llvm/ADT/SmallVector.h | 35 ++++++++++----------------- llvm/lib/Support/SmallVector.cpp | 37 +++++------------------------ - 2 files changed, 14 insertions(+), 50 deletions(-) + 2 files changed, 18 insertions(+), 54 deletions(-) diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h -index b42438a9b16c273f9ef5b5cce6192873c78cb964..7775ed7e8e083908f033529c30b1e4beae91b10a 100644 +index d7788e94b5379f5eba6fbddee50e4b4359da9d80..b953ae45a34772eb7fd04c3af0275a7d093e1242 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h -@@ -56,14 +56,14 @@ using EnableIfConvertibleToInputIterator = std::enable_if_t, where a /// 32 bit size would limit the vector to ~4GB. SmallVectors are used for /// buffering bitcode output - which can exceed 4GB. @@ -23,14 +23,35 @@ index b42438a9b16c273f9ef5b5cce6192873c78cb964..7775ed7e8e083908f033529c30b1e4be - Size_T Size = 0, Capacity; + unsigned Size = 0, Capacity; - /// The maximum value of the Size_T used. +- /// The maximum value of the Size_T used. ++ /// The maximum value of the unsigned used. static constexpr size_t SizeTypeMax() { - return (std::numeric_limits::max)(); + return (std::numeric_limits::max)(); } SmallVectorBase() = delete; -@@ -111,15 +111,10 @@ protected: + SmallVectorBase(void *FirstEl, size_t TotalCapacity) +- : BeginX(FirstEl), Capacity(static_cast(TotalCapacity)) {} ++ : BeginX(FirstEl), Capacity(static_cast(TotalCapacity)) {} + + /// This is a helper for \a grow() that's out of line to reduce code + /// duplication. This function will report a fatal error if it can't grow at +@@ -107,7 +107,7 @@ protected: + /// This does not construct or destroy any elements in the vector. + void set_size(size_t N) { + assert(N <= capacity()); // implies no overflow in assignment +- Size = static_cast(N); ++ Size = static_cast(N); + } + + /// Set the array data pointer to \p Begin and capacity to \p N. +@@ -117,19 +117,14 @@ protected: + void set_allocation_range(void *Begin, size_t N) { + assert(N <= SizeTypeMax()); + BeginX = Begin; +- Capacity = static_cast(N); ++ Capacity = static_cast(N); } }; @@ -48,7 +69,7 @@ index b42438a9b16c273f9ef5b5cce6192873c78cb964..7775ed7e8e083908f033529c30b1e4be alignas(T) char FirstEl[sizeof(T)]; }; -@@ -128,8 +123,8 @@ template struct SmallVectorAlignmentAndSize { +@@ -138,8 +133,8 @@ template struct SmallVectorAlignmentAndSize { /// to avoid unnecessarily requiring T to be complete. template class SmallVectorTemplateCommon @@ -59,7 +80,7 @@ index b42438a9b16c273f9ef5b5cce6192873c78cb964..7775ed7e8e083908f033529c30b1e4be protected: /// Find the address of the first element. For this pointer math to be valid -@@ -451,7 +446,7 @@ template +@@ -461,7 +456,7 @@ template T *SmallVectorTemplateBase::mallocForGrow( size_t MinSize, size_t &NewCapacity) { return static_cast( @@ -68,7 +89,7 @@ index b42438a9b16c273f9ef5b5cce6192873c78cb964..7775ed7e8e083908f033529c30b1e4be this->getFirstEl(), MinSize, sizeof(T), NewCapacity)); } -@@ -1324,12 +1319,6 @@ template SmallVector to_vector_of(R &&Range) { +@@ -1333,12 +1328,6 @@ template SmallVector to_vector_of(R &&Range) { return {std::begin(Range), std::end(Range)}; } @@ -82,7 +103,7 @@ index b42438a9b16c273f9ef5b5cce6192873c78cb964..7775ed7e8e083908f033529c30b1e4be namespace std { diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp -index 6cefdff7c28060ca18b522acf5279af3a206e23a..ae64a36dcf4b9ceaf8767adbf8100f164f3738ac 100644 +index 4f6fee18b659adcbfd79822832f914170cbb1635..7ef023084d791cf746c346cb1655c9da36a6beb5 100644 --- a/llvm/lib/Support/SmallVector.cpp +++ b/llvm/lib/Support/SmallVector.cpp @@ -51,10 +51,6 @@ static_assert(sizeof(SmallVector) == @@ -144,9 +165,9 @@ index 6cefdff7c28060ca18b522acf5279af3a206e23a..ae64a36dcf4b9ceaf8767adbf8100f16 void *NewElts; if (BeginX == FirstEl) { NewElts = llvm::safe_malloc(NewCapacity * TSize); -@@ -155,20 +147,3 @@ void SmallVectorBase::grow_pod(void *FirstEl, size_t MinSize, - this->BeginX = NewElts; - this->Capacity = NewCapacity; +@@ -154,20 +146,3 @@ void SmallVectorBase::grow_pod(void *FirstEl, size_t MinSize, + + this->set_allocation_range(NewElts, NewCapacity); } - -template class llvm::SmallVectorBase; diff --git a/upstream_utils/llvm_patches/0011-Add-vectors-to-raw_ostream.patch b/upstream_utils/llvm_patches/0011-Add-vectors-to-raw_ostream.patch index 095729e597..17e59aa376 100644 --- a/upstream_utils/llvm_patches/0011-Add-vectors-to-raw_ostream.patch +++ b/upstream_utils/llvm_patches/0011-Add-vectors-to-raw_ostream.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sun, 8 May 2022 13:48:59 -0400 -Subject: [PATCH 11/34] Add vectors to raw_ostream +Subject: [PATCH 11/35] Add vectors to raw_ostream --- llvm/include/llvm/Support/raw_ostream.h | 115 ++++++++++++++++++++++++ @@ -155,10 +155,10 @@ index 95019180a9deb406ed4f2991c664a4cc4e956dac..e7526e016a858ad728feb7cf1c5014b9 class raw_null_ostream : public raw_pwrite_stream { /// See raw_ostream::write_impl. diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index 76c32155b4296fbbf3f4b164cd58d63f472ccd5e..dcdfdfd7a8e3fcc4019538a4fc9e158aeda0a8b8 100644 +index c65fb70a4d22db51f4140b910c308333289b6248..57d3091fd5cc5b416e814f9f33811f0fa7afe9cf 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp -@@ -670,6 +670,53 @@ void raw_svector_ostream::pwrite_impl(const char *Ptr, size_t Size, +@@ -668,6 +668,53 @@ void raw_svector_ostream::pwrite_impl(const char *Ptr, size_t Size, memcpy(OS.data() + Offset, Ptr, Size); } diff --git a/upstream_utils/llvm_patches/0012-Extra-collections-features.patch b/upstream_utils/llvm_patches/0012-Extra-collections-features.patch index 833e80bbcb..50da0be1b2 100644 --- a/upstream_utils/llvm_patches/0012-Extra-collections-features.patch +++ b/upstream_utils/llvm_patches/0012-Extra-collections-features.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Tue, 3 May 2022 22:16:10 -0400 -Subject: [PATCH 12/34] Extra collections features +Subject: [PATCH 12/35] Extra collections features --- llvm/include/llvm/ADT/StringMap.h | 103 +++++++++++++++++++++++++++++- @@ -142,10 +142,10 @@ index 34dfbf83c681f4e81a9dadd9382ddca6ef8d6c1d..c133e84f9b2e3a225cdac782c011fadb #endif // LLVM_ADT_STRINGMAP_H diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index dcdfdfd7a8e3fcc4019538a4fc9e158aeda0a8b8..b2a726633b48b179abfd24a5de110a2301e0f877 100644 +index 57d3091fd5cc5b416e814f9f33811f0fa7afe9cf..5bec803ccc76ce287b7ff3ea037d5e490a7af20c 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp -@@ -76,6 +76,14 @@ constexpr raw_ostream::Colors raw_ostream::WHITE; +@@ -77,6 +77,14 @@ constexpr raw_ostream::Colors raw_ostream::WHITE; constexpr raw_ostream::Colors raw_ostream::SAVEDCOLOR; constexpr raw_ostream::Colors raw_ostream::RESET; diff --git a/upstream_utils/llvm_patches/0013-EpochTracker-ABI-macro.patch b/upstream_utils/llvm_patches/0013-EpochTracker-ABI-macro.patch index e02790e755..3c4ebfe9cc 100644 --- a/upstream_utils/llvm_patches/0013-EpochTracker-ABI-macro.patch +++ b/upstream_utils/llvm_patches/0013-EpochTracker-ABI-macro.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Wed, 4 May 2022 00:01:00 -0400 -Subject: [PATCH 13/34] EpochTracker ABI macro +Subject: [PATCH 13/35] EpochTracker ABI macro --- llvm/include/llvm/ADT/EpochTracker.h | 2 +- diff --git a/upstream_utils/llvm_patches/0014-Delete-numbers-from-MathExtras.patch b/upstream_utils/llvm_patches/0014-Delete-numbers-from-MathExtras.patch index d8114c90b4..9e66e4e448 100644 --- a/upstream_utils/llvm_patches/0014-Delete-numbers-from-MathExtras.patch +++ b/upstream_utils/llvm_patches/0014-Delete-numbers-from-MathExtras.patch @@ -1,14 +1,14 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Thu, 5 May 2022 18:09:45 -0400 -Subject: [PATCH 14/34] Delete numbers from MathExtras +Subject: [PATCH 14/35] Delete numbers from MathExtras --- llvm/include/llvm/Support/MathExtras.h | 36 -------------------------- 1 file changed, 36 deletions(-) diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h -index cd5a64a746b2eb7491e9b6cf8570bdf436d94a6d..cdf859ccfaca22a04b08a351d7c2c9789a70627e 100644 +index 7541447fa2db5e1634d952b1f39957eb725611f4..60b3b9012a32dda5e7c3ba1dc5923ffa68df8215 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h @@ -24,42 +24,6 @@ diff --git a/upstream_utils/llvm_patches/0015-Add-lerp-and-sgn.patch b/upstream_utils/llvm_patches/0015-Add-lerp-and-sgn.patch index c642e12c59..5bad666c40 100644 --- a/upstream_utils/llvm_patches/0015-Add-lerp-and-sgn.patch +++ b/upstream_utils/llvm_patches/0015-Add-lerp-and-sgn.patch @@ -1,17 +1,17 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Tue, 3 May 2022 22:50:24 -0400 -Subject: [PATCH 15/34] Add lerp and sgn +Subject: [PATCH 15/35] Add lerp and sgn --- llvm/include/llvm/Support/MathExtras.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h -index cdf859ccfaca22a04b08a351d7c2c9789a70627e..b82d9883c41008dcbbd933709c6e854ad74c5b58 100644 +index 60b3b9012a32dda5e7c3ba1dc5923ffa68df8215..daa79d99578e934ca001d1de5d2772ff961b8fc3 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h -@@ -614,6 +614,26 @@ std::enable_if_t, T> MulOverflow(T X, T Y, T &Result) { +@@ -617,6 +617,26 @@ std::enable_if_t, T> MulOverflow(T X, T Y, T &Result) { return UX > (static_cast((std::numeric_limits::max)())) / UY; } diff --git a/upstream_utils/llvm_patches/0016-Fixup-includes.patch b/upstream_utils/llvm_patches/0016-Fixup-includes.patch index 0200b2bef0..f72802f85a 100644 --- a/upstream_utils/llvm_patches/0016-Fixup-includes.patch +++ b/upstream_utils/llvm_patches/0016-Fixup-includes.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sun, 8 May 2022 16:38:11 -0400 -Subject: [PATCH 16/34] Fixup includes +Subject: [PATCH 16/35] Fixup includes --- llvm/include/llvm/ADT/StringMap.h | 4 ++++ @@ -91,7 +91,7 @@ index 0b87b375de67dc18647e3ebe646bf323dd05e8c5..3a88178cfbbcf7062a958c7de820247b using namespace llvm; diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index b2a726633b48b179abfd24a5de110a2301e0f877..3b7d8d6db5f0df31e18b91be716a4fd21e7e3549 100644 +index 5bec803ccc76ce287b7ff3ea037d5e490a7af20c..ae5428825f7f62ad8e742490448d40aea7506990 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -15,6 +15,8 @@ @@ -102,8 +102,8 @@ index b2a726633b48b179abfd24a5de110a2301e0f877..3b7d8d6db5f0df31e18b91be716a4fd2 +#include "wpi/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Config/config.h" - #include "llvm/Support/Compiler.h" -@@ -32,12 +34,11 @@ + #include "llvm/Support/AutoConvert.h" +@@ -33,12 +35,11 @@ #include // may provide O_BINARY. @@ -119,7 +119,7 @@ index b2a726633b48b179abfd24a5de110a2301e0f877..3b7d8d6db5f0df31e18b91be716a4fd2 #endif #if defined(__CYGWIN__) -@@ -60,7 +61,7 @@ +@@ -61,7 +62,7 @@ #ifdef _WIN32 #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/Signals.h" diff --git a/upstream_utils/llvm_patches/0017-Use-std-is_trivially_copy_constructible.patch b/upstream_utils/llvm_patches/0017-Use-std-is_trivially_copy_constructible.patch index a2b520bab8..f95870f3b9 100644 --- a/upstream_utils/llvm_patches/0017-Use-std-is_trivially_copy_constructible.patch +++ b/upstream_utils/llvm_patches/0017-Use-std-is_trivially_copy_constructible.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sun, 8 May 2022 16:42:09 -0400 -Subject: [PATCH 17/34] Use std::is_trivially_copy_constructible +Subject: [PATCH 17/35] Use std::is_trivially_copy_constructible --- llvm/include/llvm/Support/type_traits.h | 16 ---------------- diff --git a/upstream_utils/llvm_patches/0018-Use-std-is_trivially_copy_constructible.patch b/upstream_utils/llvm_patches/0018-Use-std-is_trivially_copy_constructible.patch deleted file mode 100644 index 47fdf0a91c..0000000000 --- a/upstream_utils/llvm_patches/0018-Use-std-is_trivially_copy_constructible.patch +++ /dev/null @@ -1,60 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: PJ Reiniger -Date: Sun, 8 May 2022 16:42:09 -0400 -Subject: [PATCH 18/31] Use std::is_trivially_copy_constructible - ---- - llvm/include/llvm/Support/type_traits.h | 37 ++----------------------- - 1 file changed, 2 insertions(+), 35 deletions(-) - -diff --git a/llvm/include/llvm/Support/type_traits.h b/llvm/include/llvm/Support/type_traits.h -index a6046de87d1e3e1264a0040826ea347b870a8f9e..292a2cb78b93717647cf88d00f88c2eec14f52f6 100644 ---- a/llvm/include/llvm/Support/type_traits.h -+++ b/llvm/include/llvm/Support/type_traits.h -@@ -92,44 +92,11 @@ union trivial_helper { - - } // end namespace detail - --/// An implementation of `std::is_trivially_copy_constructible` since we have --/// users with STLs that don't yet include it. - template --struct is_trivially_copy_constructible -- : std::is_copy_constructible< -- ::llvm::detail::copy_construction_triviality_helper> {}; --template --struct is_trivially_copy_constructible : std::true_type {}; --template --struct is_trivially_copy_constructible : std::false_type {}; -+using is_trivially_move_constructible = std::is_trivially_move_constructible; - --/// An implementation of `std::is_trivially_move_constructible` since we have --/// users with STLs that don't yet include it. --template --struct is_trivially_move_constructible -- : std::is_move_constructible< -- ::llvm::detail::move_construction_triviality_helper> {}; - template --struct is_trivially_move_constructible : std::true_type {}; --template --struct is_trivially_move_constructible : std::true_type {}; -- -- --template --struct is_copy_assignable { -- template -- static auto get(F*) -> decltype(std::declval() = std::declval(), std::true_type{}); -- static std::false_type get(...); -- static constexpr bool value = decltype(get((T*)nullptr))::value; --}; -- --template --struct is_move_assignable { -- template -- static auto get(F*) -> decltype(std::declval() = std::declval(), std::true_type{}); -- static std::false_type get(...); -- static constexpr bool value = decltype(get((T*)nullptr))::value; --}; -+using is_trivially_copy_constructible = std::is_trivially_copy_constructible; - - } // end namespace llvm - diff --git a/upstream_utils/llvm_patches/0018-Windows-support.patch b/upstream_utils/llvm_patches/0018-Windows-support.patch index 13d4275dfd..af4a94f729 100644 --- a/upstream_utils/llvm_patches/0018-Windows-support.patch +++ b/upstream_utils/llvm_patches/0018-Windows-support.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Tue, 3 May 2022 20:22:38 -0400 -Subject: [PATCH 18/34] Windows support +Subject: [PATCH 18/35] Windows support --- .../llvm/Support/Windows/WindowsSupport.h | 45 +++++---- @@ -204,10 +204,10 @@ index bc04c5ab5113563fb82d7b3b168985369b611f4b..57eb64a6017a6964ab14b40b8c6b3563 ConvertUTF_RESTORE_WARNINGS diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index 3b7d8d6db5f0df31e18b91be716a4fd21e7e3549..4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f 100644 +index ae5428825f7f62ad8e742490448d40aea7506990..9ea41cad8fed864b53e2e463450c066fb4e00131 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp -@@ -534,7 +534,6 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { +@@ -535,7 +535,6 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { DWORD WinLastError = GetLastError(); if (WinLastError == ERROR_BROKEN_PIPE || (WinLastError == ERROR_NO_DATA && errno == EINVAL)) { diff --git a/upstream_utils/llvm_patches/0019-Prefer-fmtlib.patch b/upstream_utils/llvm_patches/0019-Prefer-fmtlib.patch index e505363e39..abad272c91 100644 --- a/upstream_utils/llvm_patches/0019-Prefer-fmtlib.patch +++ b/upstream_utils/llvm_patches/0019-Prefer-fmtlib.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sun, 8 May 2022 16:46:20 -0400 -Subject: [PATCH 19/34] Prefer fmtlib +Subject: [PATCH 19/35] Prefer fmtlib --- llvm/lib/Support/ErrorHandling.cpp | 20 ++++++-------------- diff --git a/upstream_utils/llvm_patches/0020-Prefer-wpi-s-fs.h.patch b/upstream_utils/llvm_patches/0020-Prefer-wpi-s-fs.h.patch index cc55df5db5..1d4ca32a57 100644 --- a/upstream_utils/llvm_patches/0020-Prefer-wpi-s-fs.h.patch +++ b/upstream_utils/llvm_patches/0020-Prefer-wpi-s-fs.h.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sun, 8 May 2022 16:49:36 -0400 -Subject: [PATCH 20/34] Prefer wpi's fs.h +Subject: [PATCH 20/35] Prefer wpi's fs.h --- llvm/include/llvm/Support/raw_ostream.h | 7 ++----- diff --git a/upstream_utils/llvm_patches/0021-Remove-unused-functions.patch b/upstream_utils/llvm_patches/0021-Remove-unused-functions.patch index 53c08111d6..58544cada1 100644 --- a/upstream_utils/llvm_patches/0021-Remove-unused-functions.patch +++ b/upstream_utils/llvm_patches/0021-Remove-unused-functions.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sun, 8 May 2022 19:16:51 -0400 -Subject: [PATCH 21/34] Remove unused functions +Subject: [PATCH 21/35] Remove unused functions --- llvm/include/llvm/Support/raw_ostream.h | 5 +- @@ -62,10 +62,10 @@ index 54137a331ca9e752b02c0f16ae996094a6f2fafa..e253d6f7a5ca3aee75823efdb9717dcd #include diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d78b6a5b02 100644 +index 9ea41cad8fed864b53e2e463450c066fb4e00131..44149e85876f089756dcce151670a6060eadfee1 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp -@@ -175,16 +175,6 @@ raw_ostream &raw_ostream::write_escaped(std::string_view Str, +@@ -176,16 +176,6 @@ raw_ostream &raw_ostream::write_escaped(std::string_view Str, return *this; } @@ -82,7 +82,7 @@ index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d7 void raw_ostream::flush_nonempty() { assert(OutBufCur > OutBufStart && "Invalid call to flush_nonempty."); size_t Length = OutBufCur - OutBufStart; -@@ -327,15 +317,22 @@ static int getFD(std::string_view Filename, std::error_code &EC, +@@ -328,15 +318,22 @@ static int getFD(std::string_view Filename, std::error_code &EC, if (Filename == "-") { EC = std::error_code(); // Change stdout's text/binary mode based on the Flags. @@ -110,7 +110,7 @@ index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d7 if (EC) return -1; -@@ -395,12 +392,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered, +@@ -396,12 +393,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered, // Get the starting position. off_t loc = ::lseek(FD, 0, SEEK_CUR); @@ -124,7 +124,7 @@ index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d7 #else SupportsSeeking = !EC && loc != (off_t)-1; #endif -@@ -413,10 +406,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered, +@@ -414,10 +407,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered, raw_fd_ostream::~raw_fd_ostream() { if (FD >= 0) { flush(); @@ -137,7 +137,7 @@ index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d7 } #ifdef __MINGW32__ -@@ -511,7 +502,11 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { +@@ -512,7 +503,11 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { do { size_t ChunkSize = std::min(Size, MaxWriteSize); @@ -149,7 +149,7 @@ index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d7 if (ret < 0) { // If it's a recoverable error, swallow it and retry the write. -@@ -554,8 +549,8 @@ void raw_fd_ostream::close() { +@@ -555,8 +550,8 @@ void raw_fd_ostream::close() { assert(ShouldClose); ShouldClose = false; flush(); diff --git a/upstream_utils/llvm_patches/0022-OS-specific-changes.patch b/upstream_utils/llvm_patches/0022-OS-specific-changes.patch index c58ddaa0f8..a3fe10e63a 100644 --- a/upstream_utils/llvm_patches/0022-OS-specific-changes.patch +++ b/upstream_utils/llvm_patches/0022-OS-specific-changes.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sun, 8 May 2022 19:30:43 -0400 -Subject: [PATCH 22/34] OS-specific changes +Subject: [PATCH 22/35] OS-specific changes --- llvm/lib/Support/ErrorHandling.cpp | 16 +++++++--------- diff --git a/upstream_utils/llvm_patches/0023-Use-SmallVector-for-UTF-conversion.patch b/upstream_utils/llvm_patches/0023-Use-SmallVector-for-UTF-conversion.patch index f831a90677..81806128be 100644 --- a/upstream_utils/llvm_patches/0023-Use-SmallVector-for-UTF-conversion.patch +++ b/upstream_utils/llvm_patches/0023-Use-SmallVector-for-UTF-conversion.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Mon, 9 May 2022 00:04:30 -0400 -Subject: [PATCH 23/34] Use SmallVector for UTF conversion +Subject: [PATCH 23/35] Use SmallVector for UTF conversion --- llvm/include/llvm/Support/ConvertUTF.h | 6 +++--- diff --git a/upstream_utils/llvm_patches/0024-Prefer-to-use-static-pointers-in-raw_ostream.patch b/upstream_utils/llvm_patches/0024-Prefer-to-use-static-pointers-in-raw_ostream.patch index fd6f137209..f40be976c7 100644 --- a/upstream_utils/llvm_patches/0024-Prefer-to-use-static-pointers-in-raw_ostream.patch +++ b/upstream_utils/llvm_patches/0024-Prefer-to-use-static-pointers-in-raw_ostream.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Thu, 19 May 2022 00:58:36 -0400 -Subject: [PATCH 24/34] Prefer to use static pointers in raw_ostream +Subject: [PATCH 24/35] Prefer to use static pointers in raw_ostream See #1401 --- @@ -9,13 +9,13 @@ See #1401 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index f9928ac969932b6baea60a80750477d78b6a5b02..1de34976844d500970b833fca35324e2948733b7 100644 +index 44149e85876f089756dcce151670a6060eadfee1..8fe686142b8cdba76287a3b8b97569fde922f2bf 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp -@@ -613,15 +613,15 @@ void raw_fd_ostream::anchor() {} - raw_fd_ostream &llvm::outs() { - // Set buffer settings to model stdout behavior. - std::error_code EC; +@@ -615,9 +615,9 @@ raw_fd_ostream &llvm::outs() { + EC = enableAutoConversion(STDOUT_FILENO); + assert(!EC); + #endif - static raw_fd_ostream S("-", EC, sys::fs::OF_None); + static raw_fd_ostream* S = new raw_fd_ostream("-", EC, sys::fs::OF_None); assert(!EC); @@ -24,7 +24,10 @@ index f9928ac969932b6baea60a80750477d78b6a5b02..1de34976844d500970b833fca35324e2 } raw_fd_ostream &llvm::errs() { - // Set standard error to be unbuffered and tied to outs() by default. +@@ -626,8 +626,8 @@ raw_fd_ostream &llvm::errs() { + std::error_code EC = enableAutoConversion(STDERR_FILENO); + assert(!EC); + #endif - static raw_fd_ostream S(STDERR_FILENO, false, true); - return S; + static raw_fd_ostream* S = new raw_fd_ostream(STDERR_FILENO, false, true); diff --git a/upstream_utils/llvm_patches/0025-constexpr-endian-byte-swap.patch b/upstream_utils/llvm_patches/0025-constexpr-endian-byte-swap.patch index 6b3367b491..2e16d48ba2 100644 --- a/upstream_utils/llvm_patches/0025-constexpr-endian-byte-swap.patch +++ b/upstream_utils/llvm_patches/0025-constexpr-endian-byte-swap.patch @@ -1,22 +1,22 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger -Date: Thu, 19 May 2022 01:12:41 -0400 -Subject: [PATCH 25/34] constexpr endian byte swap +Date: Fri, 1 Mar 2024 11:56:17 -0800 +Subject: [PATCH 25/35] constexpr endian byte swap --- llvm/include/llvm/Support/Endian.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/Support/Endian.h b/llvm/include/llvm/Support/Endian.h -index 5e7c1e961b9d1e0fd6bcd0c923f678a5e1596860..2e883ff05b7e287151b6031f66d3b4aefd1bf297 100644 +index 4c0405cf1e2f69c6268d708badc2aef6dd968b51..f31fbf70fb723d19634e61ea4f21549fc767e58c 100644 --- a/llvm/include/llvm/Support/Endian.h +++ b/llvm/include/llvm/Support/Endian.h -@@ -55,7 +55,9 @@ inline value_type byte_swap(value_type value, endianness endian) { +@@ -50,7 +50,9 @@ template /// Swap the bytes of value to match the given endianness. - template - inline value_type byte_swap(value_type value) { + template + [[nodiscard]] inline value_type byte_swap(value_type value) { - return byte_swap(value, endian); -+ if constexpr ((endian != native) && (endian != system_endianness())) ++ if constexpr (endian != llvm::endianness::native) + sys::swapByteOrder(value); + return value; } diff --git a/upstream_utils/llvm_patches/0026-Copy-type-traits-from-STLExtras.h-into-PointerUnion..patch b/upstream_utils/llvm_patches/0026-Copy-type-traits-from-STLExtras.h-into-PointerUnion..patch index 52ec43dac5..c824ea34e2 100644 --- a/upstream_utils/llvm_patches/0026-Copy-type-traits-from-STLExtras.h-into-PointerUnion..patch +++ b/upstream_utils/llvm_patches/0026-Copy-type-traits-from-STLExtras.h-into-PointerUnion..patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 10 Aug 2022 17:07:52 -0700 -Subject: [PATCH 26/34] Copy type traits from STLExtras.h into PointerUnion.h +Subject: [PATCH 26/35] Copy type traits from STLExtras.h into PointerUnion.h --- llvm/include/llvm/ADT/PointerUnion.h | 46 ++++++++++++++++++++++++++++ diff --git a/upstream_utils/llvm_patches/0027-Remove-StringMap-test-for-llvm-sort.patch b/upstream_utils/llvm_patches/0027-Remove-StringMap-test-for-llvm-sort.patch index 2c9d4ef3c3..bed9cf3e58 100644 --- a/upstream_utils/llvm_patches/0027-Remove-StringMap-test-for-llvm-sort.patch +++ b/upstream_utils/llvm_patches/0027-Remove-StringMap-test-for-llvm-sort.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 10 Aug 2022 22:35:00 -0700 -Subject: [PATCH 27/34] Remove StringMap test for llvm::sort() +Subject: [PATCH 27/35] Remove StringMap test for llvm::sort() --- llvm/unittests/ADT/StringMapTest.cpp | 14 -------------- diff --git a/upstream_utils/llvm_patches/0028-Unused-variable-in-release-mode.patch b/upstream_utils/llvm_patches/0028-Unused-variable-in-release-mode.patch index 44e4f85fa2..bbcf411ff3 100644 --- a/upstream_utils/llvm_patches/0028-Unused-variable-in-release-mode.patch +++ b/upstream_utils/llvm_patches/0028-Unused-variable-in-release-mode.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Leander Schulten Date: Mon, 10 Jul 2023 00:53:43 +0200 -Subject: [PATCH 28/34] Unused variable in release mode +Subject: [PATCH 28/35] Unused variable in release mode --- llvm/include/llvm/ADT/DenseMap.h | 2 +- diff --git a/upstream_utils/llvm_patches/0029-Use-C-20-bit-header.patch b/upstream_utils/llvm_patches/0029-Use-C-20-bit-header.patch index cc66628659..6ba144a2bf 100644 --- a/upstream_utils/llvm_patches/0029-Use-C-20-bit-header.patch +++ b/upstream_utils/llvm_patches/0029-Use-C-20-bit-header.patch @@ -1,14 +1,14 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Tue, 11 Jul 2023 22:56:09 -0700 -Subject: [PATCH 29/34] Use C++20 header +Subject: [PATCH 29/35] Use C++20 header --- llvm/include/llvm/ADT/DenseMap.h | 3 +- llvm/include/llvm/ADT/Hashing.h | 35 +-- - llvm/include/llvm/ADT/bit.h | 287 ------------------------- + llvm/include/llvm/ADT/bit.h | 313 ------------------------- llvm/include/llvm/Support/MathExtras.h | 21 +- - 4 files changed, 31 insertions(+), 315 deletions(-) + 4 files changed, 31 insertions(+), 341 deletions(-) diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h index e9bd3bfa4a6fe0fa26ff20069bbadc816c8baa65..93b50c9e53af4ea3af5fd0329a8a03bdce659e9d 100644 @@ -32,7 +32,7 @@ index e9bd3bfa4a6fe0fa26ff20069bbadc816c8baa65..93b50c9e53af4ea3af5fd0329a8a03bd } diff --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h -index 781bdb7416392e3f60a1ac3a38fbcf5324b5395f..28934add722f518ae1e9cb9c4a23d2212a47cbdf 100644 +index 08d6edb14eb3cd51405329aae61b9782266a2590..e84d53e6bf2f741be562b9d66bf0bdfe4a79f936 100644 --- a/llvm/include/llvm/ADT/Hashing.h +++ b/llvm/include/llvm/ADT/Hashing.h @@ -49,6 +49,7 @@ @@ -123,13 +123,39 @@ index 781bdb7416392e3f60a1ac3a38fbcf5324b5395f..28934add722f518ae1e9cb9c4a23d221 h4 = h0 + h5; mix_32_bytes(s, h3, h4); diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h -index 2840c5f608d3ea896e1867dd4710685da9572f2d..0a4a3634820efbc0a8ca675e3ad7c98469260d0b 100644 +index c42b5e686bdc9cf3da71d8edaddc08216fe5fb2a..a19b6a9b80da2965f1308d3e7b0ade593b522a08 100644 --- a/llvm/include/llvm/ADT/bit.h +++ b/llvm/include/llvm/ADT/bit.h -@@ -27,18 +27,6 @@ +@@ -27,44 +27,6 @@ #include // for _byteswap_{ushort,ulong,uint64} #endif +-#if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) || \ +- defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || \ +- defined(__OpenBSD__) || defined(__DragonFly__) +-#include +-#elif defined(_AIX) +-#include +-#elif defined(__sun) +-/* Solaris provides _BIG_ENDIAN/_LITTLE_ENDIAN selector in sys/types.h */ +-#include +-#define BIG_ENDIAN 4321 +-#define LITTLE_ENDIAN 1234 +-#if defined(_BIG_ENDIAN) +-#define BYTE_ORDER BIG_ENDIAN +-#else +-#define BYTE_ORDER LITTLE_ENDIAN +-#endif +-#elif defined(__MVS__) +-#define BIG_ENDIAN 4321 +-#define LITTLE_ENDIAN 1234 +-#define BYTE_ORDER BIG_ENDIAN +-#else +-#if !defined(BYTE_ORDER) && !defined(_WIN32) +-#include +-#endif +-#endif +- -#ifdef _MSC_VER -// Declare these intrinsics manually rather including intrin.h. It's very -// expensive, and bit.h is popular via MathExtras.h. @@ -144,8 +170,8 @@ index 2840c5f608d3ea896e1867dd4710685da9572f2d..0a4a3634820efbc0a8ca675e3ad7c984 - namespace llvm { - // This implementation of bit_cast is different from the C++20 one in two ways: -@@ -106,281 +94,6 @@ template >> + enum class endianness { +@@ -142,281 +104,6 @@ template >> } } @@ -428,7 +454,7 @@ index 2840c5f608d3ea896e1867dd4710685da9572f2d..0a4a3634820efbc0a8ca675e3ad7c984 #endif diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h -index b82d9883c41008dcbbd933709c6e854ad74c5b58..5f034b694989d8ef24e0b249abd12a5c20146b97 100644 +index daa79d99578e934ca001d1de5d2772ff961b8fc3..f66e64b601d01f17dc6c7a4e568cc4eb1d9bb985 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h @@ -15,6 +15,7 @@ diff --git a/upstream_utils/llvm_patches/0030-Remove-DenseMap-GTest-printer-test.patch b/upstream_utils/llvm_patches/0030-Remove-DenseMap-GTest-printer-test.patch index e8c9f976f5..7648ab8743 100644 --- a/upstream_utils/llvm_patches/0030-Remove-DenseMap-GTest-printer-test.patch +++ b/upstream_utils/llvm_patches/0030-Remove-DenseMap-GTest-printer-test.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sun, 30 Jul 2023 14:17:37 -0700 -Subject: [PATCH 30/34] Remove DenseMap GTest printer test +Subject: [PATCH 30/35] Remove DenseMap GTest printer test LLVM modifies internal GTest headers to support it, which we can't do. --- diff --git a/upstream_utils/llvm_patches/0031-Replace-deprecated-std-aligned_storage_t.patch b/upstream_utils/llvm_patches/0031-Replace-deprecated-std-aligned_storage_t.patch index a8bc557b48..add9be5db9 100644 --- a/upstream_utils/llvm_patches/0031-Replace-deprecated-std-aligned_storage_t.patch +++ b/upstream_utils/llvm_patches/0031-Replace-deprecated-std-aligned_storage_t.patch @@ -1,25 +1,25 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Fri, 15 Sep 2023 18:26:50 -0700 -Subject: [PATCH 31/34] Replace deprecated std::aligned_storage_t +Subject: [PATCH 31/35] Replace deprecated std::aligned_storage_t --- llvm/include/llvm/ADT/FunctionExtras.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h -index 1daeae915eb506b32a2d1296d2f0fe4e6dab606e..2e60e34d69914bd9b2197fc0a0e75a8e025674b2 100644 +index 043d8d90fff03d571a923c264b49be37a5dffa09..a62d5ce00d784def5ae21b8d91cea40cee7bf942 100644 --- a/llvm/include/llvm/ADT/FunctionExtras.h +++ b/llvm/include/llvm/ADT/FunctionExtras.h -@@ -37,6 +37,7 @@ - #include "llvm/ADT/STLForwardCompat.h" +@@ -38,6 +38,7 @@ + #include "llvm/Support/Compiler.h" #include "llvm/Support/MemAlloc.h" #include "llvm/Support/type_traits.h" +#include #include #include #include -@@ -167,8 +168,7 @@ protected: +@@ -168,8 +169,7 @@ protected: // provide four pointers worth of storage here. // This is mutable as an inlined `const unique_function` may // still modify its own mutable members. diff --git a/upstream_utils/llvm_patches/0032-Fix-compilation-of-MathExtras.h-on-Windows-with-sdl.patch b/upstream_utils/llvm_patches/0032-Fix-compilation-of-MathExtras.h-on-Windows-with-sdl.patch deleted file mode 100644 index 09b7c03f7f..0000000000 --- a/upstream_utils/llvm_patches/0032-Fix-compilation-of-MathExtras.h-on-Windows-with-sdl.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Benjamin Hall -Date: Mon, 23 Oct 2023 21:36:40 -0400 -Subject: [PATCH 32/34] Fix compilation of MathExtras.h on Windows with /sdl - -See https://github.com/llvm/llvm-project/pull/68978 ---- - llvm/include/llvm/Support/MathExtras.h | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h -index 5f034b694989d8ef24e0b249abd12a5c20146b97..03db6e4d92cb3b62ac3d8b3cbd97783817c6326b 100644 ---- a/llvm/include/llvm/Support/MathExtras.h -+++ b/llvm/include/llvm/Support/MathExtras.h -@@ -356,7 +356,10 @@ inline uint64_t alignTo(uint64_t Value, uint64_t Align) { - inline uint64_t alignToPowerOf2(uint64_t Value, uint64_t Align) { - assert(Align != 0 && (Align & (Align - 1)) == 0 && - "Align must be a power of 2"); -- return (Value + Align - 1) & -Align; -+ // Replace unary minus to avoid compilation error on Windows: -+ // "unary minus operator applied to unsigned type, result still unsigned" -+ uint64_t negAlign = (~Align) + 1; -+ return (Value + Align - 1) & negAlign; - } - - /// If non-zero \p Skew is specified, the return value will be a minimal integer diff --git a/upstream_utils/llvm_patches/0033-raw_ostream-Add-SetNumBytesInBuffer.patch b/upstream_utils/llvm_patches/0032-raw_ostream-Add-SetNumBytesInBuffer.patch similarity index 93% rename from upstream_utils/llvm_patches/0033-raw_ostream-Add-SetNumBytesInBuffer.patch rename to upstream_utils/llvm_patches/0032-raw_ostream-Add-SetNumBytesInBuffer.patch index f4699c4dfe..37c352331c 100644 --- a/upstream_utils/llvm_patches/0033-raw_ostream-Add-SetNumBytesInBuffer.patch +++ b/upstream_utils/llvm_patches/0032-raw_ostream-Add-SetNumBytesInBuffer.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 29 Oct 2023 23:00:08 -0700 -Subject: [PATCH 33/34] raw_ostream: Add SetNumBytesInBuffer +Subject: [PATCH 32/35] raw_ostream: Add SetNumBytesInBuffer --- llvm/include/llvm/Support/raw_ostream.h | 5 +++++ diff --git a/upstream_utils/llvm_patches/0034-type_traits.h-Add-is_constexpr.patch b/upstream_utils/llvm_patches/0033-type_traits.h-Add-is_constexpr.patch similarity index 94% rename from upstream_utils/llvm_patches/0034-type_traits.h-Add-is_constexpr.patch rename to upstream_utils/llvm_patches/0033-type_traits.h-Add-is_constexpr.patch index b881452fb2..1a39b5ef3e 100644 --- a/upstream_utils/llvm_patches/0034-type_traits.h-Add-is_constexpr.patch +++ b/upstream_utils/llvm_patches/0033-type_traits.h-Add-is_constexpr.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 2 Dec 2023 15:21:32 -0800 -Subject: [PATCH 34/34] type_traits.h: Add is_constexpr() +Subject: [PATCH 33/35] type_traits.h: Add is_constexpr() --- llvm/include/llvm/Support/type_traits.h | 5 +++++ diff --git a/upstream_utils/llvm_patches/0034-Add-back-removed-raw_string_ostream-write_impl.patch b/upstream_utils/llvm_patches/0034-Add-back-removed-raw_string_ostream-write_impl.patch new file mode 100644 index 0000000000..b5cf207231 --- /dev/null +++ b/upstream_utils/llvm_patches/0034-Add-back-removed-raw_string_ostream-write_impl.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Tyler Veness +Date: Fri, 1 Mar 2024 11:37:36 -0800 +Subject: [PATCH 34/35] Add back removed raw_string_ostream::write_impl() + +--- + llvm/lib/Support/raw_ostream.cpp | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp +index 8fe686142b8cdba76287a3b8b97569fde922f2bf..9134f3d3db220ec5afb87b72cb9aed76c52a80ca 100644 +--- a/llvm/lib/Support/raw_ostream.cpp ++++ b/llvm/lib/Support/raw_ostream.cpp +@@ -656,6 +656,14 @@ bool raw_fd_stream::classof(const raw_ostream *OS) { + return OS->get_kind() == OStreamKind::OK_FDStream; + } + ++//===----------------------------------------------------------------------===// ++// raw_string_ostream ++//===----------------------------------------------------------------------===// ++ ++void raw_string_ostream::write_impl(const char *Ptr, size_t Size) { ++ OS.append(Ptr, Size); ++} ++ + //===----------------------------------------------------------------------===// + // raw_svector_ostream + //===----------------------------------------------------------------------===// diff --git a/upstream_utils/llvm_patches/0035-Remove-auto-conversion-from-raw_ostream.patch b/upstream_utils/llvm_patches/0035-Remove-auto-conversion-from-raw_ostream.patch new file mode 100644 index 0000000000..e992d6902c --- /dev/null +++ b/upstream_utils/llvm_patches/0035-Remove-auto-conversion-from-raw_ostream.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Tyler Veness +Date: Sun, 17 Mar 2024 14:51:11 -0700 +Subject: [PATCH 35/35] Remove auto-conversion from raw_ostream + +--- + llvm/lib/Support/raw_ostream.cpp | 9 --------- + 1 file changed, 9 deletions(-) + +diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp +index 9134f3d3db220ec5afb87b72cb9aed76c52a80ca..efba615e1b77de335ab343cc56ce9b00ccf3f462 100644 +--- a/llvm/lib/Support/raw_ostream.cpp ++++ b/llvm/lib/Support/raw_ostream.cpp +@@ -19,7 +19,6 @@ + #include "wpi/SmallVector.h" + #include "llvm/ADT/StringExtras.h" + #include "llvm/Config/config.h" +-#include "llvm/Support/AutoConvert.h" + #include "llvm/Support/Compiler.h" + #include "llvm/Support/ErrorHandling.h" + #include "llvm/Support/FileSystem.h" +@@ -611,10 +610,6 @@ void raw_fd_ostream::anchor() {} + raw_fd_ostream &llvm::outs() { + // Set buffer settings to model stdout behavior. + std::error_code EC; +-#ifdef __MVS__ +- EC = enableAutoConversion(STDOUT_FILENO); +- assert(!EC); +-#endif + static raw_fd_ostream* S = new raw_fd_ostream("-", EC, sys::fs::OF_None); + assert(!EC); + return *S; +@@ -622,10 +617,6 @@ raw_fd_ostream &llvm::outs() { + + raw_fd_ostream &llvm::errs() { + // Set standard error to be unbuffered and tied to outs() by default. +-#ifdef __MVS__ +- std::error_code EC = enableAutoConversion(STDERR_FILENO); +- assert(!EC); +-#endif + static raw_fd_ostream* S = new raw_fd_ostream(STDERR_FILENO, false, true); + return *S; + } diff --git a/upstream_utils/update_llvm.py b/upstream_utils/update_llvm.py index 5c221ee5e7..d43527e3d1 100755 --- a/upstream_utils/update_llvm.py +++ b/upstream_utils/update_llvm.py @@ -171,7 +171,7 @@ def overwrite_tests(wpiutil_root, llvm_root): def main(): - upstream_root = clone_repo("https://github.com/llvm/llvm-project", "llvmorg-17.0.5") + upstream_root = clone_repo("https://github.com/llvm/llvm-project", "llvmorg-18.1.1") wpilib_root = get_repo_root() wpiutil = os.path.join(wpilib_root, "wpiutil") @@ -209,9 +209,10 @@ def main(): "0029-Use-C-20-bit-header.patch", "0030-Remove-DenseMap-GTest-printer-test.patch", "0031-Replace-deprecated-std-aligned_storage_t.patch", - "0032-Fix-compilation-of-MathExtras.h-on-Windows-with-sdl.patch", - "0033-raw_ostream-Add-SetNumBytesInBuffer.patch", - "0034-type_traits.h-Add-is_constexpr.patch", + "0032-raw_ostream-Add-SetNumBytesInBuffer.patch", + "0033-type_traits.h-Add-is_constexpr.patch", + "0034-Add-back-removed-raw_string_ostream-write_impl.patch", + "0035-Remove-auto-conversion-from-raw_ostream.patch", ]: git_am( os.path.join(wpilib_root, "upstream_utils/llvm_patches", f), diff --git a/wpiutil/src/main/native/cpp/DataLog.cpp b/wpiutil/src/main/native/cpp/DataLog.cpp index bbde5e7b7c..ab9cbf7c6c 100644 --- a/wpiutil/src/main/native/cpp/DataLog.cpp +++ b/wpiutil/src/main/native/cpp/DataLog.cpp @@ -20,6 +20,7 @@ #endif #include +#include #include #include #include @@ -821,8 +822,7 @@ void DataLog::AppendFloat(int entry, float value, int64_t timestamp) { [[unlikely]] return; } uint8_t* buf = StartRecord(entry, timestamp, 4, 4); - if constexpr (wpi::support::endian::system_endianness() == - wpi::support::little) { + if constexpr (std::endian::native == std::endian::little) { std::memcpy(buf, &value, 4); } else { wpi::support::endian::write32le(buf, wpi::bit_cast(value)); @@ -838,8 +838,7 @@ void DataLog::AppendDouble(int entry, double value, int64_t timestamp) { [[unlikely]] return; } uint8_t* buf = StartRecord(entry, timestamp, 8, 8); - if constexpr (wpi::support::endian::system_endianness() == - wpi::support::little) { + if constexpr (std::endian::native == std::endian::little) { std::memcpy(buf, &value, 8); } else { wpi::support::endian::write64le(buf, wpi::bit_cast(value)); @@ -908,8 +907,7 @@ void DataLog::AppendBooleanArray(int entry, std::span arr, void DataLog::AppendIntegerArray(int entry, std::span arr, int64_t timestamp) { - if constexpr (wpi::support::endian::system_endianness() == - wpi::support::little) { + if constexpr (std::endian::native == std::endian::little) { AppendRaw(entry, {reinterpret_cast(arr.data()), arr.size() * 8}, timestamp); @@ -941,8 +939,7 @@ void DataLog::AppendIntegerArray(int entry, std::span arr, void DataLog::AppendFloatArray(int entry, std::span arr, int64_t timestamp) { - if constexpr (wpi::support::endian::system_endianness() == - wpi::support::little) { + if constexpr (std::endian::native == std::endian::little) { AppendRaw(entry, {reinterpret_cast(arr.data()), arr.size() * 4}, timestamp); @@ -974,8 +971,7 @@ void DataLog::AppendFloatArray(int entry, std::span arr, void DataLog::AppendDoubleArray(int entry, std::span arr, int64_t timestamp) { - if constexpr (wpi::support::endian::system_endianness() == - wpi::support::little) { + if constexpr (std::endian::native == std::endian::little) { AppendRaw(entry, {reinterpret_cast(arr.data()), arr.size() * 8}, timestamp); diff --git a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/SmallVector.cpp b/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/SmallVector.cpp index 803523af25..488fb7aea9 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/SmallVector.cpp +++ b/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/SmallVector.cpp @@ -144,6 +144,5 @@ void SmallVectorBase::grow_pod(void *FirstEl, size_t MinSize, NewElts = replaceAllocation(NewElts, TSize, NewCapacity, size()); } - this->BeginX = NewElts; - this->Capacity = NewCapacity; + this->set_allocation_range(NewElts, NewCapacity); } diff --git a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/raw_ostream.cpp b/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/raw_ostream.cpp index 05036a84a3..ba5bf13125 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/raw_ostream.cpp +++ b/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/raw_ostream.cpp @@ -578,8 +578,7 @@ size_t raw_fd_ostream::preferred_buffer_size() const { if (IsWindowsConsole) return 0; return raw_ostream::preferred_buffer_size(); -#elif !defined(__minix) - // Minix has no st_blksize. +#else assert(FD >= 0 && "File not yet open!"); struct stat statbuf; if (fstat(FD, &statbuf) != 0) @@ -592,8 +591,6 @@ size_t raw_fd_ostream::preferred_buffer_size() const { return 0; // Return the preferred block size. return statbuf.st_blksize; -#else - return raw_ostream::preferred_buffer_size(); #endif } diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Casting.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Casting.h index c91f1b772a..60692f2b4d 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Casting.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Casting.h @@ -351,10 +351,10 @@ struct UniquePtrCast : public CastIsPossible { static inline CastResultType castFailed() { return CastResultType(nullptr); } - static inline CastResultType doCastIfPossible(std::unique_ptr &&f) { - if (!Self::isPossible(f)) + static inline CastResultType doCastIfPossible(std::unique_ptr &f) { + if (!Self::isPossible(f.get())) return castFailed(); - return doCast(f); + return doCast(std::move(f)); } }; @@ -664,10 +664,9 @@ template } template -[[nodiscard]] inline decltype(auto) dyn_cast(std::unique_ptr &&Val) { +[[nodiscard]] inline decltype(auto) dyn_cast(std::unique_ptr &Val) { assert(detail::isPresent(Val) && "dyn_cast on a non-existent value"); - return CastInfo>::doCastIfPossible( - std::forward &&>(Val)); + return CastInfo>::doCastIfPossible(Val); } /// isa_and_present - Functionally identical to isa, except that a null value diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Chrono.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Chrono.h index 221f6dc19b..299e822651 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Chrono.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Chrono.h @@ -32,6 +32,19 @@ namespace sys { template using TimePoint = std::chrono::time_point; +// utc_clock and utc_time are only available since C++20. Add enough code to +// support formatting date/time in UTC. +class UtcClock : public std::chrono::system_clock {}; + +template +using UtcTime = std::chrono::time_point; + +/// Convert a std::time_t to a UtcTime +inline UtcTime toUtcTime(std::time_t T) { + using namespace std::chrono; + return UtcTime(seconds(T)); +} + /// Convert a TimePoint to std::time_t inline std::time_t toTimeT(TimePoint<> TP) { using namespace std::chrono; @@ -39,6 +52,13 @@ inline std::time_t toTimeT(TimePoint<> TP) { time_point_cast(TP)); } +/// Convert a UtcTime to std::time_t +inline std::time_t toTimeT(UtcTime<> TP) { + using namespace std::chrono; + return system_clock::to_time_t(time_point( + duration_cast(TP.time_since_epoch()))); +} + /// Convert a std::time_t to a TimePoint inline TimePoint toTimePoint(std::time_t T) { @@ -57,6 +77,7 @@ toTimePoint(std::time_t T, uint32_t nsec) { } // namespace sys raw_ostream &operator<<(raw_ostream &OS, sys::TimePoint<> TP); +raw_ostream &operator<<(raw_ostream &OS, sys::UtcTime<> TP); } // namespace wpi diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Compiler.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Compiler.h index 121ed5416d..59362dc1da 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Compiler.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Compiler.h @@ -162,6 +162,25 @@ #define LLVM_DEPRECATED(MSG, FIX) [[deprecated(MSG)]] #endif +// clang-format off +#if defined(__clang__) || defined(__GNUC__) +#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP \ + _Pragma("GCC diagnostic pop") +#elif defined(_MSC_VER) +#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \ + _Pragma("warning(push)") \ + _Pragma("warning(disable : 4996)") +#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP \ + _Pragma("warning(pop)") +#else +#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH +#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP +#endif +// clang-format on + // Indicate that a non-static, non-const C++ member function reinitializes // the entire object to a known state, independent of the previous state of // the object. @@ -330,6 +349,12 @@ #define LLVM_GSL_POINTER #endif +#if LLVM_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L +#define LLVM_CTOR_NODISCARD [[nodiscard]] +#else +#define LLVM_CTOR_NODISCARD +#endif + /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress /// pedantic diagnostics. #ifndef LLVM_EXTENSION @@ -598,4 +623,12 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); #define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION #endif +/// \macro LLVM_PREFERRED_TYPE +/// Adjust type of bit-field in debug info. +#if __has_attribute(preferred_type) +#define LLVM_PREFERRED_TYPE(T) __attribute__((preferred_type(T))) +#else +#define LLVM_PREFERRED_TYPE(T) +#endif + #endif diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Endian.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Endian.h index d243a13c4f..bfbf1e7eb3 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Endian.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Endian.h @@ -13,6 +13,7 @@ #ifndef WPIUTIL_WPI_ENDIAN_H #define WPIUTIL_WPI_ENDIAN_H +#include "wpi/bit.h" #include "wpi/Compiler.h" #include "wpi/SwapByteOrder.h" #include @@ -24,8 +25,6 @@ namespace wpi { namespace support { -enum endianness {big, little, native}; - // These are named values for common alignments. enum {aligned = 0, unaligned = 1}; @@ -41,28 +40,24 @@ struct PickAlignment { namespace endian { -constexpr endianness system_endianness() { - return sys::IsBigEndianHost ? big : little; -} - template -inline value_type byte_swap(value_type value, endianness endian) { - if ((endian != native) && (endian != system_endianness())) +[[nodiscard]] inline value_type byte_swap(value_type value, endianness endian) { + if (endian != wpi::endianness::native) sys::swapByteOrder(value); return value; } /// Swap the bytes of value to match the given endianness. -template -inline value_type byte_swap(value_type value) { - if constexpr ((endian != native) && (endian != system_endianness())) +template +[[nodiscard]] inline value_type byte_swap(value_type value) { + if constexpr (endian != wpi::endianness::native) sys::swapByteOrder(value); return value; } /// Read a value of a particular endianness from memory. -template -inline value_type read(const void *memory, endianness endian) { +template +[[nodiscard]] inline value_type read(const void *memory, endianness endian) { value_type ret; memcpy(&ret, @@ -72,30 +67,29 @@ inline value_type read(const void *memory, endianness endian) { return byte_swap(ret, endian); } -template -inline value_type read(const void *memory) { +template +[[nodiscard]] inline value_type read(const void *memory) { return read(memory, endian); } /// Read a value of a particular endianness from a buffer, and increment the /// buffer past that value. template -inline value_type readNext(const CharT *&memory, endianness endian) { +[[nodiscard]] inline value_type readNext(const CharT *&memory, + endianness endian) { value_type ret = read(memory, endian); memory += sizeof(value_type); return ret; } -template -inline value_type readNext(const CharT *&memory) { +template +[[nodiscard]] inline value_type readNext(const CharT *&memory) { return readNext(memory, endian); } /// Write a value to memory with a particular endianness. -template +template inline void write(void *memory, value_type value, endianness endian) { value = byte_swap(value, endian); memcpy(LLVM_ASSUME_ALIGNED( @@ -116,7 +110,8 @@ using make_unsigned_t = std::make_unsigned_t; /// Read a value of a particular endianness from memory, for a location /// that starts at the given bit offset within the first byte. template -inline value_type readAtBitAlignment(const void *memory, uint64_t startBit) { +[[nodiscard]] inline value_type readAtBitAlignment(const void *memory, + uint64_t startBit) { assert(startBit < 8); if (startBit == 0) return read(memory); @@ -269,125 +264,164 @@ public: } // end namespace detail using ulittle16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using ulittle32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using ulittle64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using little16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using little32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using little64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_ulittle16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_ulittle32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_ulittle64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_little16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_little32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_little64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using ubig16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using ubig32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using ubig64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using big16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using big32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using big64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_ubig16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_ubig32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_ubig64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_big16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_big32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_big64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using unaligned_uint16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using unaligned_uint32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using unaligned_uint64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using unaligned_int16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using unaligned_int32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using unaligned_int64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; template -using little_t = detail::packed_endian_specific_integral; +using little_t = + detail::packed_endian_specific_integral; template -using big_t = detail::packed_endian_specific_integral; +using big_t = detail::packed_endian_specific_integral; template using aligned_little_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; template -using aligned_big_t = detail::packed_endian_specific_integral; +using aligned_big_t = + detail::packed_endian_specific_integral; namespace endian { -template inline T read(const void *P, endianness E) { - return read(P, E); -} - -template inline T read(const void *P) { +template [[nodiscard]] inline T read(const void *P) { return *(const detail::packed_endian_specific_integral *)P; } -inline uint16_t read16(const void *P, endianness E) { +[[nodiscard]] inline uint16_t read16(const void *P, endianness E) { return read(P, E); } -inline uint32_t read32(const void *P, endianness E) { +[[nodiscard]] inline uint32_t read32(const void *P, endianness E) { return read(P, E); } -inline uint64_t read64(const void *P, endianness E) { +[[nodiscard]] inline uint64_t read64(const void *P, endianness E) { return read(P, E); } -template inline uint16_t read16(const void *P) { +template [[nodiscard]] inline uint16_t read16(const void *P) { return read(P); } -template inline uint32_t read32(const void *P) { +template [[nodiscard]] inline uint32_t read32(const void *P) { return read(P); } -template inline uint64_t read64(const void *P) { +template [[nodiscard]] inline uint64_t read64(const void *P) { return read(P); } -inline uint16_t read16le(const void *P) { return read16(P); } -inline uint32_t read32le(const void *P) { return read32(P); } -inline uint64_t read64le(const void *P) { return read64(P); } -inline uint16_t read16be(const void *P) { return read16(P); } -inline uint32_t read32be(const void *P) { return read32(P); } -inline uint64_t read64be(const void *P) { return read64(P); } - -template inline void write(void *P, T V, endianness E) { - write(P, V, E); +[[nodiscard]] inline uint16_t read16le(const void *P) { + return read16(P); +} +[[nodiscard]] inline uint32_t read32le(const void *P) { + return read32(P); +} +[[nodiscard]] inline uint64_t read64le(const void *P) { + return read64(P); +} +[[nodiscard]] inline uint16_t read16be(const void *P) { + return read16(P); +} +[[nodiscard]] inline uint32_t read32be(const void *P) { + return read32(P); +} +[[nodiscard]] inline uint64_t read64be(const void *P) { + return read64(P); } template inline void write(void *P, T V) { @@ -414,12 +448,24 @@ template inline void write64(void *P, uint64_t V) { write(P, V); } -inline void write16le(void *P, uint16_t V) { write16(P, V); } -inline void write32le(void *P, uint32_t V) { write32(P, V); } -inline void write64le(void *P, uint64_t V) { write64(P, V); } -inline void write16be(void *P, uint16_t V) { write16(P, V); } -inline void write32be(void *P, uint32_t V) { write32(P, V); } -inline void write64be(void *P, uint64_t V) { write64(P, V); } +inline void write16le(void *P, uint16_t V) { + write16(P, V); +} +inline void write32le(void *P, uint32_t V) { + write32(P, V); +} +inline void write64le(void *P, uint64_t V) { + write64(P, V); +} +inline void write16be(void *P, uint16_t V) { + write16(P, V); +} +inline void write32be(void *P, uint32_t V) { + write32(P, V); +} +inline void write64be(void *P, uint64_t V) { + write64(P, V); +} } // end namespace endian diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/FunctionExtras.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/FunctionExtras.h index 8c6d8472a2..a0ae149fb3 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/FunctionExtras.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/FunctionExtras.h @@ -35,6 +35,7 @@ #include "wpi/PointerIntPair.h" #include "wpi/PointerUnion.h" #include "wpi/STLForwardCompat.h" +#include "wpi/Compiler.h" #include "wpi/MemAlloc.h" #include "wpi/type_traits.h" #include @@ -324,8 +325,10 @@ protected: // Clear the old callback and inline flag to get back to as-if-null. RHS.CallbackAndInlineFlag = {}; -#ifndef NDEBUG - // In debug builds, we also scribble across the rest of the storage. +#if !defined(NDEBUG) && !LLVM_ADDRESS_SANITIZER_BUILD + // In debug builds without ASan, we also scribble across the rest of the + // storage. Scribbling under AddressSanitizer (ASan) is disabled to prevent + // overwriting poisoned objects (e.g., annotated short strings). memset(RHS.getInlineStorage(), 0xAD, InlineStorageSize); #endif } diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Hashing.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Hashing.h index bdb439c217..a232488ef5 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Hashing.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Hashing.h @@ -682,12 +682,26 @@ template hash_code hash_value(const std::optional &arg) { template <> struct DenseMapInfo { static inline hash_code getEmptyKey() { return hash_code(-1); } static inline hash_code getTombstoneKey() { return hash_code(-2); } - static unsigned getHashValue(hash_code val) { return val; } + static unsigned getHashValue(hash_code val) { + return static_cast(size_t(val)); + } static bool isEqual(hash_code LHS, hash_code RHS) { return LHS == RHS; } }; } // namespace wpi +/// Implement std::hash so that hash_code can be used in STL containers. +namespace std { + +template<> +struct hash { + size_t operator()(wpi::hash_code const& Val) const { + return Val; + } +}; + +} // namespace std; + #ifdef _WIN32 #pragma warning(pop) #endif diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MapVector.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MapVector.h index ce6fe78702..9d845af31b 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MapVector.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MapVector.h @@ -114,29 +114,50 @@ public: return Pos == Map.end()? ValueT() : Vector[Pos->second].second; } - std::pair insert(const std::pair &KV) { - std::pair Pair = std::make_pair(KV.first, 0); - std::pair Result = Map.insert(Pair); - auto &I = Result.first->second; - if (Result.second) { - Vector.push_back(std::make_pair(KV.first, KV.second)); - I = Vector.size() - 1; + template + std::pair try_emplace(const KeyT &Key, Ts &&...Args) { + auto [It, Inserted] = Map.insert(std::make_pair(Key, 0)); + if (Inserted) { + It->second = Vector.size(); + Vector.emplace_back(std::piecewise_construct, std::forward_as_tuple(Key), + std::forward_as_tuple(std::forward(Args)...)); return std::make_pair(std::prev(end()), true); } - return std::make_pair(begin() + I, false); + return std::make_pair(begin() + It->second, false); + } + template + std::pair try_emplace(KeyT &&Key, Ts &&...Args) { + auto [It, Inserted] = Map.insert(std::make_pair(Key, 0)); + if (Inserted) { + It->second = Vector.size(); + Vector.emplace_back(std::piecewise_construct, + std::forward_as_tuple(std::move(Key)), + std::forward_as_tuple(std::forward(Args)...)); + return std::make_pair(std::prev(end()), true); + } + return std::make_pair(begin() + It->second, false); } + std::pair insert(const std::pair &KV) { + return try_emplace(KV.first, KV.second); + } std::pair insert(std::pair &&KV) { - // Copy KV.first into the map, then move it into the vector. - std::pair Pair = std::make_pair(KV.first, 0); - std::pair Result = Map.insert(Pair); - auto &I = Result.first->second; - if (Result.second) { - Vector.push_back(std::move(KV)); - I = Vector.size() - 1; - return std::make_pair(std::prev(end()), true); - } - return std::make_pair(begin() + I, false); + return try_emplace(std::move(KV.first), std::move(KV.second)); + } + + template + std::pair insert_or_assign(const KeyT &Key, V &&Val) { + auto Ret = try_emplace(Key, std::forward(Val)); + if (!Ret.second) + Ret.first->second = std::forward(Val); + return Ret; + } + template + std::pair insert_or_assign(KeyT &&Key, V &&Val) { + auto Ret = try_emplace(std::move(Key), std::forward(Val)); + if (!Ret.second) + Ret.first->second = std::forward(Val); + return Ret; } bool contains(const KeyT &Key) const { return Map.find(Key) != Map.end(); } diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MathExtras.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MathExtras.h index ed3b2b1efc..4ccea3e3f8 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MathExtras.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MathExtras.h @@ -333,9 +333,9 @@ constexpr inline uint64_t NextPowerOf2(uint64_t A) { /// Returns the power of two which is greater than or equal to the given value. /// Essentially, it is a ceil operation across the domain of powers of two. inline uint64_t PowerOf2Ceil(uint64_t A) { - if (!A) + if (!A || A > UINT64_MAX / 2) return 0; - return NextPowerOf2(A - 1); + return UINT64_C(1) << Log2_64_Ceil(A); } /// Returns the next integer (mod 2**64) that is greater than or equal to diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MemAlloc.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MemAlloc.h index 32909ff38d..cf5354589e 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MemAlloc.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MemAlloc.h @@ -72,7 +72,7 @@ LLVM_ATTRIBUTE_RETURNS_NONNULL inline void *safe_realloc(void *Ptr, size_t Sz) { /// Allocate a buffer of memory with the given size and alignment. /// -/// When the compiler supports aligned operator new, this will use it to to +/// When the compiler supports aligned operator new, this will use it to /// handle even over-aligned allocations. /// /// However, this doesn't make any attempt to leverage the fancier techniques diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/STLForwardCompat.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/STLForwardCompat.h index 02cf826989..d39f8ca65f 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/STLForwardCompat.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/STLForwardCompat.h @@ -60,6 +60,13 @@ auto transformOptional(std::optional &&O, const Function &F) return std::nullopt; } +/// Returns underlying integer value of an enum. Backport of C++23 +/// std::to_underlying. +template +[[nodiscard]] constexpr std::underlying_type_t to_underlying(Enum E) { + return static_cast>(E); +} + } // namespace wpi #endif // WPIUTIL_WPI_STLFORWARDCOMPAT_H diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallString.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallString.h index 4a53feee59..35d0a4a818 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallString.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallString.h @@ -88,9 +88,10 @@ public: /// @name String Comparison /// @{ - /// Compare two strings; the result is -1, 0, or 1 if this string is - /// lexicographically less than, equal to, or greater than the \p RHS. - int compare(std::string_view RHS) const { + /// compare - Compare two strings; the result is negative, zero, or positive + /// if this string is lexicographically less than, equal to, or greater than + /// the \p RHS. + [[nodiscard]] int compare(std::string_view RHS) const { return str().compare(RHS); } @@ -102,7 +103,7 @@ public: /// /// \return - The index of the first occurrence of \p C, or npos if not /// found. - size_t find(char C, size_t From = 0) const { + [[nodiscard]] size_t find(char C, size_t From = 0) const { return str().find(C, From); } @@ -110,7 +111,7 @@ public: /// /// \returns The index of the first occurrence of \p Str, or npos if not /// found. - size_t find(std::string_view Str, size_t From = 0) const { + [[nodiscard]] size_t find(std::string_view Str, size_t From = 0) const { return str().find(Str, From); } @@ -118,7 +119,8 @@ public: /// /// \returns The index of the last occurrence of \p C, or npos if not /// found. - size_t rfind(char C, size_t From = std::string_view::npos) const { + [[nodiscard]] size_t rfind(char C, + size_t From = std::string_view::npos) const { return str().rfind(C, From); } @@ -126,13 +128,13 @@ public: /// /// \returns The index of the last occurrence of \p Str, or npos if not /// found. - size_t rfind(std::string_view Str) const { + [[nodiscard]] size_t rfind(std::string_view Str) const { return str().rfind(Str); } /// Find the first character in the string that is \p C, or npos if not /// found. Same as find. - size_t find_first_of(char C, size_t From = 0) const { + [[nodiscard]] size_t find_first_of(char C, size_t From = 0) const { return str().find_first_of(C, From); } @@ -140,13 +142,14 @@ public: /// not found. /// /// Complexity: O(size() + Chars.size()) - size_t find_first_of(std::string_view Chars, size_t From = 0) const { + [[nodiscard]] size_t find_first_of(std::string_view Chars, + size_t From = 0) const { return str().find_first_of(Chars, From); } /// Find the first character in the string that is not \p C or npos if not /// found. - size_t find_first_not_of(char C, size_t From = 0) const { + [[nodiscard]] size_t find_first_not_of(char C, size_t From = 0) const { return str().find_first_not_of(C, From); } @@ -154,13 +157,15 @@ public: /// \p Chars, or npos if not found. /// /// Complexity: O(size() + Chars.size()) - size_t find_first_not_of(std::string_view Chars, size_t From = 0) const { + [[nodiscard]] size_t find_first_not_of(std::string_view Chars, + size_t From = 0) const { return str().find_first_not_of(Chars, From); } /// Find the last character in the string that is \p C, or npos if not /// found. - size_t find_last_of(char C, size_t From = std::string_view::npos) const { + [[nodiscard]] size_t find_last_of( + char C, size_t From = std::string_view::npos) const { return str().find_last_of(C, From); } @@ -168,7 +173,7 @@ public: /// found. /// /// Complexity: O(size() + Chars.size()) - size_t find_last_of( + [[nodiscard]] size_t find_last_of( std::string_view Chars, size_t From = std::string_view::npos) const { return str().find_last_of(Chars, From); } @@ -178,7 +183,9 @@ public: // Extra methods. /// Explicit conversion to std::string_view. - std::string_view str() const { return std::string_view(this->begin(), this->size()); } + [[nodiscard]] std::string_view str() const { + return std::string_view(this->begin(), this->size()); + } // TODO: Make this const, if it's safe... const char* c_str() { diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallVector.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallVector.h index 3b4b890db5..3e69345e40 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallVector.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallVector.h @@ -61,7 +61,7 @@ protected: void *BeginX; unsigned Size = 0, Capacity; - /// The maximum value of the Size_T used. + /// The maximum value of the unsigned used. static constexpr size_t SizeTypeMax() { return (std::numeric_limits::max)(); } @@ -106,9 +106,19 @@ protected: /// /// This does not construct or destroy any elements in the vector. void set_size(size_t N) { - assert(N <= capacity()); + assert(N <= capacity()); // implies no overflow in assignment Size = static_cast(N); } + + /// Set the array data pointer to \p Begin and capacity to \p N. + /// + /// This does not construct or destroy any elements in the vector. + // This does not clean up any existing allocation. + void set_allocation_range(void *Begin, size_t N) { + assert(N <= SizeTypeMax()); + BeginX = Begin; + Capacity = static_cast(N); + } }; /// Figure out the offset of the first element. @@ -469,8 +479,7 @@ void SmallVectorTemplateBase::takeAllocationForGrow( if (!this->isSmall()) free(this->begin()); - this->BeginX = NewElts; - this->Capacity = static_cast(NewCapacity); + this->set_allocation_range(NewElts, NewCapacity); } /// SmallVectorTemplateBase - This is where we put @@ -603,9 +612,6 @@ protected: RHS.resetToSmall(); } -public: - SmallVectorImpl(const SmallVectorImpl &) = delete; - ~SmallVectorImpl() { // Subclass has already destructed this vector's elements. // If this wasn't grown from the inline copy, deallocate the old space. @@ -613,6 +619,9 @@ public: free(this->begin()); } +public: + SmallVectorImpl(const SmallVectorImpl &) = delete; + void clear() { this->destroy_range(this->begin(), this->end()); this->Size = 0; diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SwapByteOrder.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SwapByteOrder.h index af7fcf9eb8..c908401c4e 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SwapByteOrder.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SwapByteOrder.h @@ -14,45 +14,17 @@ #ifndef WPIUTIL_WPI_SWAPBYTEORDER_H #define WPIUTIL_WPI_SWAPBYTEORDER_H +#include "wpi/STLForwardCompat.h" #include "wpi/bit.h" -#include #include #include -#if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) || \ - defined(__Fuchsia__) || defined(__EMSCRIPTEN__) -#include -#elif defined(_AIX) -#include -#elif defined(__sun) -/* Solaris provides _BIG_ENDIAN/_LITTLE_ENDIAN selector in sys/types.h */ -#include -#define BIG_ENDIAN 4321 -#define LITTLE_ENDIAN 1234 -#if defined(_BIG_ENDIAN) -#define BYTE_ORDER BIG_ENDIAN -#else -#define BYTE_ORDER LITTLE_ENDIAN -#endif -#elif defined(__MVS__) -#define BIG_ENDIAN 4321 -#define LITTLE_ENDIAN 1234 -#define BYTE_ORDER BIG_ENDIAN -#else -#if !defined(BYTE_ORDER) && !defined(_WIN32) -#include -#endif -#endif - namespace wpi { namespace sys { -#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN -constexpr bool IsBigEndianHost = true; -#else -constexpr bool IsBigEndianHost = false; -#endif +constexpr bool IsBigEndianHost = + wpi::endianness::native == wpi::endianness::big; static const bool IsLittleEndianHost = !IsBigEndianHost; @@ -73,29 +45,16 @@ inline unsigned long long getSwappedBytes(unsigned long long C) { return wpi::by inline signed long long getSwappedBytes( signed long long C) { return wpi::byteswap(C); } inline float getSwappedBytes(float C) { - union { - uint32_t i; - float f; - } in, out; - in.f = C; - out.i = wpi::byteswap(in.i); - return out.f; + return wpi::bit_cast(wpi::byteswap(wpi::bit_cast(C))); } inline double getSwappedBytes(double C) { - union { - uint64_t i; - double d; - } in, out; - in.d = C; - out.i = wpi::byteswap(in.i); - return out.d; + return wpi::bit_cast(wpi::byteswap(wpi::bit_cast(C))); } template inline std::enable_if_t, T> getSwappedBytes(T C) { - return static_cast( - wpi::byteswap(static_cast>(C))); + return static_cast(wpi::byteswap(wpi::to_underlying(C))); } template diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/VersionTuple.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/VersionTuple.h index 02f24dd7c4..3c6d5d0122 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/VersionTuple.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/VersionTuple.h @@ -16,14 +16,12 @@ #include "wpi/DenseMapInfo.h" #include "wpi/Hashing.h" -#include "wpi/Endian.h" #include #include #include namespace wpi { -template -class HashBuilderImpl; +template class HashBuilder; class raw_ostream; /// Represents a version number in the form major[.minor[.subminor[.build]]]. diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/bit.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/bit.h index fce6d85201..8fa495af37 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/bit.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/bit.h @@ -29,6 +29,16 @@ namespace wpi { +enum class endianness { + big, + little, +#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN + native = big +#else + native = little +#endif +}; + // This implementation of bit_cast is different from the C++20 one in two ways: // - It isn't constexpr because that requires compiler support. // - It requires trivially-constructible To, to avoid UB in the implementation. diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/iterator_range.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/iterator_range.h index afb7343636..3e0b56b704 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/iterator_range.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/iterator_range.h @@ -43,8 +43,8 @@ class iterator_range { IteratorT begin_iterator, end_iterator; public: -#if __GNUC__ == 7 - // Be careful no to break gcc-7 on the mlir target. +#if __GNUC__ == 7 || (__GNUC__ == 8 && __GNUC_MINOR__ < 4) + // Be careful no to break gcc-7 and gcc-8 < 8.4 on the mlir target. // See https://github.com/llvm/llvm-project/issues/63843 template #else @@ -53,8 +53,7 @@ public: detail::IterOfRange, IteratorT>::value> * = nullptr> #endif iterator_range(Container &&c) - : begin_iterator(adl_begin(std::forward(c))), - end_iterator(adl_end(std::forward(c))) { + : begin_iterator(adl_begin(c)), end_iterator(adl_end(c)) { } iterator_range(IteratorT begin_iterator, IteratorT end_iterator) : begin_iterator(std::move(begin_iterator)), diff --git a/wpiutil/src/test/native/cpp/llvm/Chrono.cpp b/wpiutil/src/test/native/cpp/llvm/Chrono.cpp index 5fe3e65af3..1a8369ff98 100644 --- a/wpiutil/src/test/native/cpp/llvm/Chrono.cpp +++ b/wpiutil/src/test/native/cpp/llvm/Chrono.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "wpi/Chrono.h" -#include "wpi/SmallVector.h" #include "gtest/gtest.h" using namespace wpi; diff --git a/wpiutil/src/test/native/cpp/llvm/EndianTest.cpp b/wpiutil/src/test/native/cpp/llvm/EndianTest.cpp index 89edec4990..a8234552f7 100644 --- a/wpiutil/src/test/native/cpp/llvm/EndianTest.cpp +++ b/wpiutil/src/test/native/cpp/llvm/EndianTest.cpp @@ -22,12 +22,17 @@ TEST(Endian, Read) { unsigned char bigval[] = {0x00, 0x01, 0x02, 0x03, 0x04}; unsigned char littleval[] = {0x00, 0x04, 0x03, 0x02, 0x01}; int32_t BigAsHost = 0x00010203; - EXPECT_EQ(BigAsHost, (endian::read(bigval))); + EXPECT_EQ(BigAsHost, + (endian::read(bigval))); int32_t LittleAsHost = 0x02030400; - EXPECT_EQ(LittleAsHost,(endian::read(littleval))); + EXPECT_EQ( + LittleAsHost, + (endian::read(littleval))); - EXPECT_EQ((endian::read(bigval + 1)), - (endian::read(littleval + 1))); + EXPECT_EQ( + (endian::read(bigval + 1)), + (endian::read(littleval + + 1))); } TEST(Endian, ReadBitAligned) { @@ -35,35 +40,43 @@ TEST(Endian, ReadBitAligned) { unsigned char littleval[] = {0x3f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff}; unsigned char bigval[] = {0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xc0}; EXPECT_EQ( - (endian::readAtBitAlignment(&littleval[0], 6)), + (endian::readAtBitAlignment( + &littleval[0], 6)), 0x0); - EXPECT_EQ((endian::readAtBitAlignment(&bigval[0], 6)), + EXPECT_EQ((endian::readAtBitAlignment( + &bigval[0], 6)), 0x0); // Test to make sure that signed right shift of 0xf0000000 is masked // properly. unsigned char littleval2[] = {0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00}; unsigned char bigval2[] = {0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; EXPECT_EQ( - (endian::readAtBitAlignment(&littleval2[0], 4)), + (endian::readAtBitAlignment( + &littleval2[0], 4)), 0x0f000000); - EXPECT_EQ((endian::readAtBitAlignment(&bigval2[0], 4)), + EXPECT_EQ((endian::readAtBitAlignment( + &bigval2[0], 4)), 0x0f000000); // Test to make sure left shift of start bit doesn't overflow. EXPECT_EQ( - (endian::readAtBitAlignment(&littleval2[0], 1)), + (endian::readAtBitAlignment( + &littleval2[0], 1)), 0x78000000); - EXPECT_EQ((endian::readAtBitAlignment(&bigval2[0], 1)), + EXPECT_EQ((endian::readAtBitAlignment( + &bigval2[0], 1)), 0x78000000); // Test to make sure 64-bit int doesn't overflow. unsigned char littleval3[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; unsigned char bigval3[] = {0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - EXPECT_EQ((endian::readAtBitAlignment( - &littleval3[0], 4)), - 0x0f00000000000000); EXPECT_EQ( - (endian::readAtBitAlignment(&bigval3[0], 4)), + (endian::readAtBitAlignment( + &littleval3[0], 4)), + 0x0f00000000000000); + EXPECT_EQ( + (endian::readAtBitAlignment( + &bigval3[0], 4)), 0x0f00000000000000); } @@ -71,8 +84,8 @@ TEST(Endian, WriteBitAligned) { // This test ensures that signed right shift of 0xffffaa is masked // properly. unsigned char bigval[8] = {0x00}; - endian::writeAtBitAlignment(bigval, (int)0xffffaaaa, - 4); + endian::writeAtBitAlignment( + bigval, (int)0xffffaaaa, 4); EXPECT_EQ(bigval[0], 0xff); EXPECT_EQ(bigval[1], 0xfa); EXPECT_EQ(bigval[2], 0xaa); @@ -83,8 +96,8 @@ TEST(Endian, WriteBitAligned) { EXPECT_EQ(bigval[7], 0x0f); unsigned char littleval[8] = {0x00}; - endian::writeAtBitAlignment(littleval, - (int)0xffffaaaa, 4); + endian::writeAtBitAlignment( + littleval, (int)0xffffaaaa, 4); EXPECT_EQ(littleval[0], 0xa0); EXPECT_EQ(littleval[1], 0xaa); EXPECT_EQ(littleval[2], 0xfa); @@ -97,8 +110,8 @@ TEST(Endian, WriteBitAligned) { // This test makes sure 1<<31 doesn't overflow. // Test to make sure left shift of start bit doesn't overflow. unsigned char bigval2[8] = {0x00}; - endian::writeAtBitAlignment(bigval2, (int)0xffffffff, - 1); + endian::writeAtBitAlignment( + bigval2, (int)0xffffffff, 1); EXPECT_EQ(bigval2[0], 0xff); EXPECT_EQ(bigval2[1], 0xff); EXPECT_EQ(bigval2[2], 0xff); @@ -109,8 +122,8 @@ TEST(Endian, WriteBitAligned) { EXPECT_EQ(bigval2[7], 0x01); unsigned char littleval2[8] = {0x00}; - endian::writeAtBitAlignment(littleval2, - (int)0xffffffff, 1); + endian::writeAtBitAlignment( + littleval2, (int)0xffffffff, 1); EXPECT_EQ(littleval2[0], 0xfe); EXPECT_EQ(littleval2[1], 0xff); EXPECT_EQ(littleval2[2], 0xff); @@ -122,7 +135,7 @@ TEST(Endian, WriteBitAligned) { // Test to make sure 64-bit int doesn't overflow. unsigned char bigval64[16] = {0x00}; - endian::writeAtBitAlignment( + endian::writeAtBitAlignment( bigval64, (int64_t)0xffffffffffffffff, 1); EXPECT_EQ(bigval64[0], 0xff); EXPECT_EQ(bigval64[1], 0xff); @@ -142,7 +155,7 @@ TEST(Endian, WriteBitAligned) { EXPECT_EQ(bigval64[15], 0x01); unsigned char littleval64[16] = {0x00}; - endian::writeAtBitAlignment( + endian::writeAtBitAlignment( littleval64, (int64_t)0xffffffffffffffff, 1); EXPECT_EQ(littleval64[0], 0xfe); EXPECT_EQ(littleval64[1], 0xff); @@ -164,23 +177,26 @@ TEST(Endian, WriteBitAligned) { TEST(Endian, Write) { unsigned char data[5]; - endian::write(data, -1362446643); + endian::write(data, -1362446643); EXPECT_EQ(data[0], 0xAE); EXPECT_EQ(data[1], 0xCA); EXPECT_EQ(data[2], 0xB6); EXPECT_EQ(data[3], 0xCD); - endian::write(data + 1, -1362446643); + endian::write(data + 1, + -1362446643); EXPECT_EQ(data[1], 0xAE); EXPECT_EQ(data[2], 0xCA); EXPECT_EQ(data[3], 0xB6); EXPECT_EQ(data[4], 0xCD); - endian::write(data, -1362446643); + endian::write(data, + -1362446643); EXPECT_EQ(data[0], 0xCD); EXPECT_EQ(data[1], 0xB6); EXPECT_EQ(data[2], 0xCA); EXPECT_EQ(data[3], 0xAE); - endian::write(data + 1, -1362446643); + endian::write(data + 1, + -1362446643); EXPECT_EQ(data[1], 0xCD); EXPECT_EQ(data[2], 0xB6); EXPECT_EQ(data[3], 0xCA); diff --git a/wpiutil/src/test/native/cpp/llvm/MapVectorTest.cpp b/wpiutil/src/test/native/cpp/llvm/MapVectorTest.cpp index 4bfa6b2040..c3507dd414 100644 --- a/wpiutil/src/test/native/cpp/llvm/MapVectorTest.cpp +++ b/wpiutil/src/test/native/cpp/llvm/MapVectorTest.cpp @@ -16,10 +16,38 @@ #include "wpi/MapVector.h" #include "wpi/iterator_range.h" #include "gtest/gtest.h" +#include #include using namespace wpi; +namespace { +struct CountCopyAndMove { + CountCopyAndMove() = default; + CountCopyAndMove(const CountCopyAndMove &) { copy = 1; } + CountCopyAndMove(CountCopyAndMove &&) { move = 1; } + void operator=(const CountCopyAndMove &) { ++copy; } + void operator=(CountCopyAndMove &&) { ++move; } + int copy = 0; + int move = 0; +}; + +struct A : CountCopyAndMove { + A(int v) : v(v) {} + int v; +}; +} // namespace + +namespace wpi { +template <> struct DenseMapInfo { + static inline A getEmptyKey() { return 0x7fffffff; } + static inline A getTombstoneKey() { return -0x7fffffff - 1; } + static unsigned getHashValue(const A &Val) { return (unsigned)(Val.v * 37U); } + static bool isEqual(const A &LHS, const A &RHS) { return LHS.v == RHS.v; } +}; +} // namespace wpi + +namespace { TEST(MapVectorTest, swap) { MapVector MV1, MV2; std::pair::iterator, bool> R; @@ -86,6 +114,87 @@ TEST(MapVectorTest, insert_pop) { EXPECT_EQ(MV[4], 7); } +TEST(MapVectorTest, try_emplace) { + struct AAndU { + A a; + std::unique_ptr b; + AAndU(A a, std::unique_ptr b) : a(a), b(std::move(b)) {} + }; + MapVector mv; + + A zero(0); + auto try0 = mv.try_emplace(zero, zero, nullptr); + EXPECT_TRUE(try0.second); + EXPECT_EQ(0, try0.first->second.a.v); + EXPECT_EQ(1, try0.first->second.a.copy); + EXPECT_EQ(0, try0.first->second.a.move); + + auto try1 = mv.try_emplace(zero, zero, nullptr); + EXPECT_FALSE(try1.second); + EXPECT_EQ(0, try1.first->second.a.v); + EXPECT_EQ(1, try1.first->second.a.copy); + EXPECT_EQ(0, try1.first->second.a.move); + + EXPECT_EQ(try0.first, try1.first); + EXPECT_EQ(1, try1.first->first.copy); + EXPECT_EQ(0, try1.first->first.move); + + A two(2); + auto try2 = mv.try_emplace(2, std::move(two), std::make_unique(2)); + EXPECT_TRUE(try2.second); + EXPECT_EQ(2, try2.first->second.a.v); + EXPECT_EQ(0, try2.first->second.a.move); + + std::unique_ptr p(new int(3)); + auto try3 = mv.try_emplace(std::move(two), 3, std::move(p)); + EXPECT_FALSE(try3.second); + EXPECT_EQ(2, try3.first->second.a.v); + EXPECT_EQ(1, try3.first->second.a.copy); + EXPECT_EQ(0, try3.first->second.a.move); + + EXPECT_EQ(try2.first, try3.first); + EXPECT_EQ(0, try3.first->first.copy); + EXPECT_EQ(1, try3.first->first.move); + EXPECT_NE(nullptr, p); +} + +TEST(MapVectorTest, insert_or_assign) { + MapVector mv; + + A zero(0); + auto try0 = mv.insert_or_assign(zero, zero); + EXPECT_TRUE(try0.second); + EXPECT_EQ(0, try0.first->second.v); + EXPECT_EQ(1, try0.first->second.copy); + EXPECT_EQ(0, try0.first->second.move); + + auto try1 = mv.insert_or_assign(zero, zero); + EXPECT_FALSE(try1.second); + EXPECT_EQ(0, try1.first->second.v); + EXPECT_EQ(2, try1.first->second.copy); + EXPECT_EQ(0, try1.first->second.move); + + EXPECT_EQ(try0.first, try1.first); + EXPECT_EQ(1, try1.first->first.copy); + EXPECT_EQ(0, try1.first->first.move); + + A two(2); + auto try2 = mv.try_emplace(2, std::move(two)); + EXPECT_TRUE(try2.second); + EXPECT_EQ(2, try2.first->second.v); + EXPECT_EQ(1, try2.first->second.move); + + auto try3 = mv.insert_or_assign(std::move(two), 3); + EXPECT_FALSE(try3.second); + EXPECT_EQ(3, try3.first->second.v); + EXPECT_EQ(0, try3.first->second.copy); + EXPECT_EQ(2, try3.first->second.move); + + EXPECT_EQ(try2.first, try3.first); + EXPECT_EQ(0, try3.first->first.copy); + EXPECT_EQ(1, try3.first->first.move); +} + TEST(MapVectorTest, erase) { MapVector MV; @@ -430,3 +539,4 @@ TEST(SmallMapVectorLargeTest, iteration_test) { count--; } } +} // namespace diff --git a/wpiutil/src/test/native/cpp/llvm/STLForwardCompatTest.cpp b/wpiutil/src/test/native/cpp/llvm/STLForwardCompatTest.cpp index 153305bb21..0f0af563cf 100644 --- a/wpiutil/src/test/native/cpp/llvm/STLForwardCompatTest.cpp +++ b/wpiutil/src/test/native/cpp/llvm/STLForwardCompatTest.cpp @@ -119,4 +119,21 @@ TEST(TransformTest, MoveTransformLlvm) { EXPECT_EQ(0u, MoveOnly::Destructions); } +TEST(TransformTest, ToUnderlying) { + enum E { A1 = 0, B1 = -1 }; + static_assert(wpi::to_underlying(A1) == 0); + static_assert(wpi::to_underlying(B1) == -1); + + enum E2 : unsigned char { A2 = 0, B2 }; + static_assert( + std::is_same_v); + static_assert(wpi::to_underlying(A2) == 0); + static_assert(wpi::to_underlying(B2) == 1); + + enum class E3 { A3 = -1, B3 }; + static_assert(std::is_same_v); + static_assert(wpi::to_underlying(E3::A3) == -1); + static_assert(wpi::to_underlying(E3::B3) == 0); +} + } // namespace From 5370f249a1c86d859b16706b6b973e5ed836ba1b Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Mon, 18 Mar 2024 23:11:20 -0700 Subject: [PATCH 06/10] [build] Upgrade to wpiformat 2024.33 (#6449) This upgrades to clang-format and clang-tidy 18.1.1. This has the constructor attribute formatting fix, so we can remove our WPI_DEPRECATED macro. --- .clang-format | 21 ++++++++++++---- .github/workflows/lint-format.yml | 2 +- .../main/native/include/LifetimeWrappers.h | 12 +++++----- .../src/main/native/cpp/MjpegServerImpl.cpp | 7 ++---- docs/build.gradle | 4 +--- ntcore/src/main/native/cpp/NetworkServer.cpp | 3 +-- .../include/networktables/StructArrayTopic.h | 9 ++++--- .../include/networktables/StructTopic.h | 9 ++++--- .../main/native/cpp/frc2/command/Command.cpp | 3 +-- .../native/include/frc2/command/CommandBase.h | 4 +--- .../include/frc2/command/CommandHelper.h | 7 +++--- .../include/frc2/command/SelectCommand.h | 6 ++--- .../frc2/command/TrapezoidProfileCommand.h | 4 ++-- .../native/cpp/frc2/command/make_vector.h | 4 ++-- wpilibc/src/main/native/cpp/ADXRS450_Gyro.cpp | 3 +-- wpilibc/src/main/native/cpp/AnalogGyro.cpp | 3 +-- .../main/native/cpp/AnalogPotentiometer.cpp | 3 +-- .../main/native/cpp/BuiltInAccelerometer.cpp | 9 +++---- wpilibc/src/main/native/cpp/Counter.cpp | 3 +-- wpilibc/src/main/native/cpp/DigitalInput.cpp | 3 +-- wpilibc/src/main/native/cpp/Encoder.cpp | 3 +-- .../cpp/counter/ExternalDirectionCounter.cpp | 3 +-- .../main/native/cpp/counter/UpDownCounter.cpp | 3 +-- .../test/native/cpp/util/Color8BitTest.cpp | 3 ++- .../src/test/native/cpp/util/ColorTest.cpp | 3 ++- .../src/main/native/cpp/PreferencesTest.cpp | 4 ++-- .../cpp/controller/BangBangController.cpp | 3 +-- .../LTVDifferentialDriveController.cpp | 9 ++++--- .../cpp/controller/LTVUnicycleController.cpp | 3 ++- .../include/frc/filter/SlewRateLimiter.h | 1 - .../include/frc/trajectory/TrapezoidProfile.h | 6 ++--- wpimath/src/main/native/include/units/math.h | 13 +++++----- .../test/native/cpp/StateSpaceUtilTest.cpp | 7 +++--- .../test/native/cpp/uv/UvGetAddrInfoTest.cpp | 9 +++---- wpiutil/examples/writelog/writelog.cpp | 24 +++++++++---------- wpiutil/src/main/native/include/wpi/DataLog.h | 6 +++-- .../src/main/native/include/wpi/deprecated.h | 4 ---- .../src/main/native/include/wpi/jni_util.h | 4 ++-- wpiutil/src/test/native/cpp/ArrayTest.cpp | 15 +++++++----- wpiutil/src/test/native/cpp/Base64Test.cpp | 5 ++-- wpiutil/src/test/native/cpp/DataLogTest.cpp | 15 ++++++++---- .../src/test/native/cpp/spinlock_bench.cpp | 3 ++- .../src/main/native/cpp/xrp/XRPMotor.cpp | 2 -- 43 files changed, 135 insertions(+), 132 deletions(-) diff --git a/.clang-format b/.clang-format index 111b4a8e0e..d424ff940a 100644 --- a/.clang-format +++ b/.clang-format @@ -28,6 +28,11 @@ AlignConsecutiveMacros: AcrossComments: false AlignCompound: false PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false AlignEscapedNewlines: Left AlignOperands: Align AlignTrailingComments: @@ -141,6 +146,7 @@ IntegerLiteralSeparator: JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false +KeepEmptyLinesAtEOF: false LambdaBodyIndentation: Signature LineEnding: DeriveLF MacroBlockBegin: '' @@ -201,6 +207,7 @@ RawStringFormats: ReferenceAlignment: Pointer ReflowComments: true RemoveBracesLLVM: false +RemoveParentheses: Leave RemoveSemicolon: false RequiresClausePosition: OwnLine RequiresExpressionIndentation: OuterScope @@ -218,6 +225,7 @@ SpaceBeforeCaseColon: false SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false SpaceBeforeParens: ControlStatements SpaceBeforeParensOptions: AfterControlStatements: true @@ -232,23 +240,28 @@ SpaceBeforeParensOptions: SpaceBeforeRangeBasedForLoopColon: true SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false -SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 SpacesInAngles: Never -SpacesInConditionalStatement: false SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false SpacesInLineCommentPrefix: Minimum: 1 Maximum: -1 -SpacesInParentheses: false +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false SpacesInSquareBrackets: false Standard: c++20 +StatementAttributeLikeMacros: + - Q_EMIT StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION TabWidth: 8 UseTab: Never +VerilogBreakBetweenInstancePorts: true WhitespaceSensitiveMacros: - BOOST_PP_STRINGIZE - CF_SWIFT_NAME diff --git a/.github/workflows/lint-format.yml b/.github/workflows/lint-format.yml index abff71e07f..519b55466d 100644 --- a/.github/workflows/lint-format.yml +++ b/.github/workflows/lint-format.yml @@ -27,7 +27,7 @@ jobs: with: python-version: '3.10' - name: Install wpiformat - run: pip3 install wpiformat==2024.32 + run: pip3 install wpiformat==2024.33 - name: Run run: wpiformat - name: Check output diff --git a/crossConnIntegrationTests/src/main/native/include/LifetimeWrappers.h b/crossConnIntegrationTests/src/main/native/include/LifetimeWrappers.h index e196d84e77..7546bfa059 100644 --- a/crossConnIntegrationTests/src/main/native/include/LifetimeWrappers.h +++ b/crossConnIntegrationTests/src/main/native/include/LifetimeWrappers.h @@ -190,12 +190,12 @@ struct RelayHandle { HAL_RelayHandle handle = 0; }; -#define ASSERT_LAST_ERROR_STATUS(status, x) \ - do { \ - ASSERT_EQ(status, HAL_USE_LAST_ERROR); \ - [[maybe_unused]] const char* lastErrorMessageInMacro = \ - HAL_GetLastError(&status); \ - ASSERT_EQ(status, x); \ +#define ASSERT_LAST_ERROR_STATUS(status, x) \ + do { \ + ASSERT_EQ(status, HAL_USE_LAST_ERROR); \ + [[maybe_unused]] \ + const char* lastErrorMessageInMacro = HAL_GetLastError(&status); \ + ASSERT_EQ(status, x); \ } while (0) } // namespace hlt diff --git a/cscore/src/main/native/cpp/MjpegServerImpl.cpp b/cscore/src/main/native/cpp/MjpegServerImpl.cpp index c57dde57f9..b5900b41cd 100644 --- a/cscore/src/main/native/cpp/MjpegServerImpl.cpp +++ b/cscore/src/main/native/cpp/MjpegServerImpl.cpp @@ -438,9 +438,7 @@ void MjpegServerImpl::ConnThread::SendHTML(wpi::raw_ostream& os, os << "

Supported Video Modes:

\n"; os << "\n"; - os << "" - << "" - << "" + os << "" << "" << "" << ""; for (auto mode : source.EnumerateVideoModes(&status)) { os << "
Pixel FormatWidthHeight
Pixel FormatWidthHeightFPS
"; @@ -881,8 +879,7 @@ void MjpegServerImpl::ConnThread::ProcessRequest() { ProcessCommand(os, *source, parameters, true); } else { SendHeader(os, 200, "OK", "text/plain"); - os << "Ignored due to no connected source." - << "\r\n"; + os << "Ignored due to no connected source." << "\r\n"; SDEBUG("Ignored due to no connected source."); } break; diff --git a/docs/build.gradle b/docs/build.gradle index 0d6e87487a..932ee3a4b4 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -180,12 +180,10 @@ doxygen { warn_if_undocumented false warn_no_paramdoc true - //enable doxygen preprocessor expansion of WPI_DEPRECATED to fix MotorController docs enable_preprocessing true macro_expansion true expand_only_predef true - predefined "WPI_DEPRECATED(x)=[[deprecated(x)]]\"\\\n" + - "\"__cplusplus\"\\\n" + + predefined "__cplusplus\"\\\n" + "\"HAL_ENUM(name)=enum name : int32_t" if (project.hasProperty('docWarningsAsErrors')) { diff --git a/ntcore/src/main/native/cpp/NetworkServer.cpp b/ntcore/src/main/native/cpp/NetworkServer.cpp index a6b2ae16d0..e98936a73b 100644 --- a/ntcore/src/main/native/cpp/NetworkServer.cpp +++ b/ntcore/src/main/native/cpp/NetworkServer.cpp @@ -323,8 +323,7 @@ NetworkServer::NetworkServer(std::string_view persistentFilename, HandleLocal(); // load persistent file first, then initialize - uv::QueueWork( - m_loop, [this] { LoadPersistent(); }, [this] { Init(); }); + uv::QueueWork(m_loop, [this] { LoadPersistent(); }, [this] { Init(); }); }); } diff --git a/ntcore/src/main/native/include/networktables/StructArrayTopic.h b/ntcore/src/main/native/include/networktables/StructArrayTopic.h index c4f0083688..009524a8bf 100644 --- a/ntcore/src/main/native/include/networktables/StructArrayTopic.h +++ b/ntcore/src/main/native/include/networktables/StructArrayTopic.h @@ -228,7 +228,8 @@ class StructArraySubscriber : public Subscriber { private: ValueType m_defaultValue; - [[no_unique_address]] std::tuple m_info; + [[no_unique_address]] + std::tuple m_info; }; /** @@ -387,7 +388,8 @@ class StructArrayPublisher : public Publisher { private: wpi::StructArrayBuffer m_buf; std::atomic_bool m_schemaPublished{false}; - [[no_unique_address]] std::tuple m_info; + [[no_unique_address]] + std::tuple m_info; }; /** @@ -702,7 +704,8 @@ class StructArrayTopic final : public Topic { } private: - [[no_unique_address]] std::tuple m_info; + [[no_unique_address]] + std::tuple m_info; }; } // namespace nt diff --git a/ntcore/src/main/native/include/networktables/StructTopic.h b/ntcore/src/main/native/include/networktables/StructTopic.h index b69d0af62b..7097dbc132 100644 --- a/ntcore/src/main/native/include/networktables/StructTopic.h +++ b/ntcore/src/main/native/include/networktables/StructTopic.h @@ -180,7 +180,8 @@ class StructSubscriber : public Subscriber { private: ValueType m_defaultValue; - [[no_unique_address]] std::tuple m_info; + [[no_unique_address]] + std::tuple m_info; }; /** @@ -301,7 +302,8 @@ class StructPublisher : public Publisher { private: std::atomic_bool m_schemaPublished{false}; - [[no_unique_address]] std::tuple m_info; + [[no_unique_address]] + std::tuple m_info; }; /** @@ -522,7 +524,8 @@ class StructTopic final : public Topic { } private: - [[no_unique_address]] std::tuple m_info; + [[no_unique_address]] + std::tuple m_info; }; } // namespace nt diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp index de673f2c41..b9183146c0 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp @@ -174,8 +174,7 @@ std::optional Command::GetPreviousCompositionSite() const { void Command::InitSendable(wpi::SendableBuilder& builder) { builder.SetSmartDashboardType("Command"); - builder.AddStringProperty( - ".name", [this] { return GetName(); }, nullptr); + builder.AddStringProperty(".name", [this] { return GetName(); }, nullptr); builder.AddBooleanProperty( "running", [this] { return IsScheduled(); }, [this](bool value) { diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandBase.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandBase.h index ea24e42d97..d1067698db 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandBase.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandBase.h @@ -4,8 +4,6 @@ #pragma once -#include - #include "frc2/command/Command.h" namespace frc2 { @@ -19,7 +17,7 @@ namespace frc2 { */ class [[deprecated("Use Command instead")]] CommandBase : public Command { protected: - WPI_DEPRECATED("Use Command instead") + [[deprecated("Use Command instead")]] CommandBase(); }; } // namespace frc2 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandHelper.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandHelper.h index ba6fe920b8..83451fe8dc 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandHelper.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandHelper.h @@ -8,8 +8,6 @@ #include #include -#include - #include "frc2/command/Command.h" #include "frc2/command/CommandPtr.h" @@ -36,8 +34,9 @@ class CommandHelper : public Base { } protected: - WPI_DEPRECATED("Use ToPtr() instead") - std::unique_ptr TransferOwnership() && override { + [[deprecated("Use ToPtr() instead")]] + std::unique_ptr TransferOwnership() && + override { return std::make_unique(std::move(*static_cast(this))); } }; diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SelectCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/SelectCommand.h index cc311063b4..5eb8733219 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/SelectCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/SelectCommand.h @@ -17,7 +17,6 @@ #include #include -#include #include #include "frc2/command/Command.h" @@ -135,8 +134,9 @@ class SelectCommand : public CommandHelper> { } protected: - WPI_DEPRECATED("Use ToPtr() instead") - std::unique_ptr TransferOwnership() && override { + [[deprecated("Use ToPtr() instead")]] + std::unique_ptr TransferOwnership() && + override { return std::make_unique(std::move(*this)); } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h index 289b1cb455..837dda3e09 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h @@ -65,9 +65,9 @@ class TrapezoidProfileCommand * @deprecated The new constructor allows you to pass in a supplier for * desired and current state. This allows you to change goals at runtime. */ - WPI_DEPRECATED( + [[deprecated( "The new constructor allows you to pass in a supplier for desired and " - "current state. This allows you to change goals at runtime.") + "current state. This allows you to change goals at runtime.")]] TrapezoidProfileCommand(frc::TrapezoidProfile profile, std::function output, Requirements requirements = {}) diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/make_vector.h b/wpilibNewCommands/src/test/native/cpp/frc2/command/make_vector.h index 295eba7645..8dbf7544ac 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/make_vector.h +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/make_vector.h @@ -24,8 +24,8 @@ std::vector make_vector(Args&&... args) { vec.reserve(sizeof...(Args)); using arr_t = int[]; - [[maybe_unused]] arr_t arr{ - 0, (vec.emplace_back(std::forward(args)), 0)...}; + [[maybe_unused]] + arr_t arr{0, (vec.emplace_back(std::forward(args)), 0)...}; return vec; } diff --git a/wpilibc/src/main/native/cpp/ADXRS450_Gyro.cpp b/wpilibc/src/main/native/cpp/ADXRS450_Gyro.cpp index c134b5c1ee..21e98e2ee3 100644 --- a/wpilibc/src/main/native/cpp/ADXRS450_Gyro.cpp +++ b/wpilibc/src/main/native/cpp/ADXRS450_Gyro.cpp @@ -150,6 +150,5 @@ int ADXRS450_Gyro::GetPort() const { void ADXRS450_Gyro::InitSendable(wpi::SendableBuilder& builder) { builder.SetSmartDashboardType("Gyro"); - builder.AddDoubleProperty( - "Value", [=, this] { return GetAngle(); }, nullptr); + builder.AddDoubleProperty("Value", [=, this] { return GetAngle(); }, nullptr); } diff --git a/wpilibc/src/main/native/cpp/AnalogGyro.cpp b/wpilibc/src/main/native/cpp/AnalogGyro.cpp index df6d33f458..8c0c4709c4 100644 --- a/wpilibc/src/main/native/cpp/AnalogGyro.cpp +++ b/wpilibc/src/main/native/cpp/AnalogGyro.cpp @@ -143,6 +143,5 @@ std::shared_ptr AnalogGyro::GetAnalogInput() const { void AnalogGyro::InitSendable(wpi::SendableBuilder& builder) { builder.SetSmartDashboardType("Gyro"); - builder.AddDoubleProperty( - "Value", [=, this] { return GetAngle(); }, nullptr); + builder.AddDoubleProperty("Value", [=, this] { return GetAngle(); }, nullptr); } diff --git a/wpilibc/src/main/native/cpp/AnalogPotentiometer.cpp b/wpilibc/src/main/native/cpp/AnalogPotentiometer.cpp index d43c84fe75..d8b8b1e0a8 100644 --- a/wpilibc/src/main/native/cpp/AnalogPotentiometer.cpp +++ b/wpilibc/src/main/native/cpp/AnalogPotentiometer.cpp @@ -45,6 +45,5 @@ double AnalogPotentiometer::Get() const { void AnalogPotentiometer::InitSendable(wpi::SendableBuilder& builder) { builder.SetSmartDashboardType("Analog Input"); - builder.AddDoubleProperty( - "Value", [=, this] { return Get(); }, nullptr); + builder.AddDoubleProperty("Value", [=, this] { return Get(); }, nullptr); } diff --git a/wpilibc/src/main/native/cpp/BuiltInAccelerometer.cpp b/wpilibc/src/main/native/cpp/BuiltInAccelerometer.cpp index 857643b658..2189863241 100644 --- a/wpilibc/src/main/native/cpp/BuiltInAccelerometer.cpp +++ b/wpilibc/src/main/native/cpp/BuiltInAccelerometer.cpp @@ -41,10 +41,7 @@ double BuiltInAccelerometer::GetZ() { void BuiltInAccelerometer::InitSendable(wpi::SendableBuilder& builder) { builder.SetSmartDashboardType("3AxisAccelerometer"); - builder.AddDoubleProperty( - "X", [=, this] { return GetX(); }, nullptr); - builder.AddDoubleProperty( - "Y", [=, this] { return GetY(); }, nullptr); - builder.AddDoubleProperty( - "Z", [=, this] { return GetZ(); }, nullptr); + builder.AddDoubleProperty("X", [=, this] { return GetX(); }, nullptr); + builder.AddDoubleProperty("Y", [=, this] { return GetY(); }, nullptr); + builder.AddDoubleProperty("Z", [=, this] { return GetZ(); }, nullptr); } diff --git a/wpilibc/src/main/native/cpp/Counter.cpp b/wpilibc/src/main/native/cpp/Counter.cpp index c33b69bef3..ab69f4ffde 100644 --- a/wpilibc/src/main/native/cpp/Counter.cpp +++ b/wpilibc/src/main/native/cpp/Counter.cpp @@ -320,6 +320,5 @@ bool Counter::GetDirection() const { void Counter::InitSendable(wpi::SendableBuilder& builder) { builder.SetSmartDashboardType("Counter"); - builder.AddDoubleProperty( - "Value", [=, this] { return Get(); }, nullptr); + builder.AddDoubleProperty("Value", [=, this] { return Get(); }, nullptr); } diff --git a/wpilibc/src/main/native/cpp/DigitalInput.cpp b/wpilibc/src/main/native/cpp/DigitalInput.cpp index 02757415de..e3f183dc65 100644 --- a/wpilibc/src/main/native/cpp/DigitalInput.cpp +++ b/wpilibc/src/main/native/cpp/DigitalInput.cpp @@ -68,6 +68,5 @@ int DigitalInput::GetChannel() const { void DigitalInput::InitSendable(wpi::SendableBuilder& builder) { builder.SetSmartDashboardType("Digital Input"); - builder.AddBooleanProperty( - "Value", [=, this] { return Get(); }, nullptr); + builder.AddBooleanProperty("Value", [=, this] { return Get(); }, nullptr); } diff --git a/wpilibc/src/main/native/cpp/Encoder.cpp b/wpilibc/src/main/native/cpp/Encoder.cpp index c6440709ef..1e15ed87bb 100644 --- a/wpilibc/src/main/native/cpp/Encoder.cpp +++ b/wpilibc/src/main/native/cpp/Encoder.cpp @@ -216,8 +216,7 @@ void Encoder::InitSendable(wpi::SendableBuilder& builder) { builder.SetSmartDashboardType("Encoder"); } - builder.AddDoubleProperty( - "Speed", [=, this] { return GetRate(); }, nullptr); + builder.AddDoubleProperty("Speed", [=, this] { return GetRate(); }, nullptr); builder.AddDoubleProperty( "Distance", [=, this] { return GetDistance(); }, nullptr); builder.AddDoubleProperty( diff --git a/wpilibc/src/main/native/cpp/counter/ExternalDirectionCounter.cpp b/wpilibc/src/main/native/cpp/counter/ExternalDirectionCounter.cpp index 24709aab32..071d55063b 100644 --- a/wpilibc/src/main/native/cpp/counter/ExternalDirectionCounter.cpp +++ b/wpilibc/src/main/native/cpp/counter/ExternalDirectionCounter.cpp @@ -98,6 +98,5 @@ void ExternalDirectionCounter::SetEdgeConfiguration( void ExternalDirectionCounter::InitSendable(wpi::SendableBuilder& builder) { builder.SetSmartDashboardType("External Direction Counter"); - builder.AddDoubleProperty( - "Count", [&] { return GetCount(); }, nullptr); + builder.AddDoubleProperty("Count", [&] { return GetCount(); }, nullptr); } diff --git a/wpilibc/src/main/native/cpp/counter/UpDownCounter.cpp b/wpilibc/src/main/native/cpp/counter/UpDownCounter.cpp index 62537ee882..706b2d9673 100644 --- a/wpilibc/src/main/native/cpp/counter/UpDownCounter.cpp +++ b/wpilibc/src/main/native/cpp/counter/UpDownCounter.cpp @@ -101,6 +101,5 @@ void UpDownCounter::SetDownEdgeConfiguration(EdgeConfiguration configuration) { void UpDownCounter::InitSendable(wpi::SendableBuilder& builder) { builder.SetSmartDashboardType("UpDown Counter"); - builder.AddDoubleProperty( - "Count", [&] { return GetCount(); }, nullptr); + builder.AddDoubleProperty("Count", [&] { return GetCount(); }, nullptr); } diff --git a/wpilibc/src/test/native/cpp/util/Color8BitTest.cpp b/wpilibc/src/test/native/cpp/util/Color8BitTest.cpp index d9027be244..775b0a695a 100644 --- a/wpilibc/src/test/native/cpp/util/Color8BitTest.cpp +++ b/wpilibc/src/test/native/cpp/util/Color8BitTest.cpp @@ -62,7 +62,8 @@ TEST(Color8BitTest, ToHexString) { EXPECT_EQ("#FF8040", color1.HexString()); // Ensure conversion to std::string works - [[maybe_unused]] std::string str = color1.HexString(); + [[maybe_unused]] + std::string str = color1.HexString(); frc::Color8Bit color2{255, 128, 64}; EXPECT_EQ("#FF8040", color2.HexString()); diff --git a/wpilibc/src/test/native/cpp/util/ColorTest.cpp b/wpilibc/src/test/native/cpp/util/ColorTest.cpp index cbde770758..a62c0157f1 100644 --- a/wpilibc/src/test/native/cpp/util/ColorTest.cpp +++ b/wpilibc/src/test/native/cpp/util/ColorTest.cpp @@ -73,7 +73,8 @@ TEST(ColorTest, ToHexString) { EXPECT_EQ("#FF8040", color1.HexString()); // Ensure conversion to std::string works - [[maybe_unused]] std::string str = color1.HexString(); + [[maybe_unused]] + std::string str = color1.HexString(); frc::Color color2{255, 128, 64}; EXPECT_EQ("#FF8040", color2.HexString()); diff --git a/wpilibcIntegrationTests/src/main/native/cpp/PreferencesTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/PreferencesTest.cpp index ef58bb4bed..cdc8ecbd42 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/PreferencesTest.cpp +++ b/wpilibcIntegrationTests/src/main/native/cpp/PreferencesTest.cpp @@ -35,8 +35,8 @@ TEST(PreferencesTest, ReadPreferencesFromFile) { << "\"properties\":{\"persistent\":true}}," << std::endl; preferencesFile << "{\"type\":\"int\"," << "\"name\":\"/Preferences/testFileGetInt\"," - << "\"value\":1," - << "\"properties\":{\"persistent\":true}}," << std::endl; + << "\"value\":1," << "\"properties\":{\"persistent\":true}}," + << std::endl; preferencesFile << "{\"type\":\"double\"," << "\"name\":\"/Preferences/testFileGetDouble\"," << "\"value\":0.5," diff --git a/wpimath/src/main/native/cpp/controller/BangBangController.cpp b/wpimath/src/main/native/cpp/controller/BangBangController.cpp index 4a093d68c1..c60517a095 100644 --- a/wpimath/src/main/native/cpp/controller/BangBangController.cpp +++ b/wpimath/src/main/native/cpp/controller/BangBangController.cpp @@ -62,8 +62,7 @@ void BangBangController::InitSendable(wpi::SendableBuilder& builder) { [this](double setpoint) { SetSetpoint(setpoint); }); builder.AddDoubleProperty( "measurement", [this] { return GetMeasurement(); }, nullptr); - builder.AddDoubleProperty( - "error", [this] { return GetError(); }, nullptr); + builder.AddDoubleProperty("error", [this] { return GetError(); }, nullptr); builder.AddBooleanProperty( "atSetpoint", [this] { return AtSetpoint(); }, nullptr); } diff --git a/wpimath/src/main/native/cpp/controller/LTVDifferentialDriveController.cpp b/wpimath/src/main/native/cpp/controller/LTVDifferentialDriveController.cpp index 173f2ea7bd..e100c7f8c8 100644 --- a/wpimath/src/main/native/cpp/controller/LTVDifferentialDriveController.cpp +++ b/wpimath/src/main/native/cpp/controller/LTVDifferentialDriveController.cpp @@ -24,7 +24,8 @@ namespace { class State { public: /// X position in global coordinate frame. - [[maybe_unused]] static constexpr int kX = 0; + [[maybe_unused]] + static constexpr int kX = 0; /// Y position in global coordinate frame. static constexpr int kY = 1; @@ -33,10 +34,12 @@ class State { static constexpr int kHeading = 2; /// Left encoder velocity. - [[maybe_unused]] static constexpr int kLeftVelocity = 3; + [[maybe_unused]] + static constexpr int kLeftVelocity = 3; /// Right encoder velocity. - [[maybe_unused]] static constexpr int kRightVelocity = 4; + [[maybe_unused]] + static constexpr int kRightVelocity = 4; }; } // namespace diff --git a/wpimath/src/main/native/cpp/controller/LTVUnicycleController.cpp b/wpimath/src/main/native/cpp/controller/LTVUnicycleController.cpp index aca317a4bb..505569981c 100644 --- a/wpimath/src/main/native/cpp/controller/LTVUnicycleController.cpp +++ b/wpimath/src/main/native/cpp/controller/LTVUnicycleController.cpp @@ -23,7 +23,8 @@ namespace { class State { public: /// X position in global coordinate frame. - [[maybe_unused]] static constexpr int kX = 0; + [[maybe_unused]] + static constexpr int kX = 0; /// Y position in global coordinate frame. static constexpr int kY = 1; diff --git a/wpimath/src/main/native/include/frc/filter/SlewRateLimiter.h b/wpimath/src/main/native/include/frc/filter/SlewRateLimiter.h index ceba4ca2bc..f04aac4855 100644 --- a/wpimath/src/main/native/include/frc/filter/SlewRateLimiter.h +++ b/wpimath/src/main/native/include/frc/filter/SlewRateLimiter.h @@ -6,7 +6,6 @@ #include -#include #include #include "units/time.h" diff --git a/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.h b/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.h index 79d22adfeb..15b101dfe8 100644 --- a/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.h +++ b/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.h @@ -4,8 +4,6 @@ #pragma once -#include - #include "units/time.h" #include "wpimath/MathShared.h" @@ -114,10 +112,10 @@ class TrapezoidProfile { * @deprecated Pass the desired and current state into calculate instead of * constructing a new TrapezoidProfile with the desired and current state */ - WPI_DEPRECATED( + [[deprecated( "Pass the desired and current state into calculate instead of " "constructing a new TrapezoidProfile with the desired and current " - "state") + "state")]] TrapezoidProfile(Constraints constraints, State goal, State initial = State{Distance_t{0}, Velocity_t{0}}); diff --git a/wpimath/src/main/native/include/units/math.h b/wpimath/src/main/native/include/units/math.h index 727aee62fb..a5cf357b5f 100644 --- a/wpimath/src/main/native/include/units/math.h +++ b/wpimath/src/main/native/include/units/math.h @@ -482,10 +482,11 @@ constexpr dimensionless::scalar_t log2(const ScalarUnit x) noexcept { template < class UnitType, std::enable_if_t::value, int> = 0> -inline constexpr auto sqrt(const UnitType& value) noexcept -> unit_t< - square_root::unit_type>, - typename units::traits::unit_t_traits::underlying_type, - linear_scale> { +inline constexpr auto sqrt(const UnitType& value) noexcept + -> unit_t< + square_root::unit_type>, + typename units::traits::unit_t_traits::underlying_type, + linear_scale> { return unit_t< square_root::unit_type>, typename units::traits::unit_t_traits::underlying_type, @@ -741,8 +742,8 @@ template ::value && traits::is_unit_t::value && traits::is_unit_t::value>> -auto fma(const UnitTypeLhs x, const UnitMultiply y, const UnitAdd z) noexcept - -> decltype(x * y) { +auto fma(const UnitTypeLhs x, const UnitMultiply y, + const UnitAdd z) noexcept -> decltype(x * y) { using resultType = decltype(x * y); static_assert( traits::is_convertible_unit_t< diff --git a/wpimath/src/test/native/cpp/StateSpaceUtilTest.cpp b/wpimath/src/test/native/cpp/StateSpaceUtilTest.cpp index 4de13d3684..cce1137e46 100644 --- a/wpimath/src/test/native/cpp/StateSpaceUtilTest.cpp +++ b/wpimath/src/test/native/cpp/StateSpaceUtilTest.cpp @@ -63,12 +63,13 @@ TEST(StateSpaceUtilTest, CovArray) { } TEST(StateSpaceUtilTest, WhiteNoiseVectorParameterPack) { - [[maybe_unused]] frc::Vectord<2> vec = frc::MakeWhiteNoiseVector(2.0, 3.0); + [[maybe_unused]] + frc::Vectord<2> vec = frc::MakeWhiteNoiseVector(2.0, 3.0); } TEST(StateSpaceUtilTest, WhiteNoiseVectorArray) { - [[maybe_unused]] frc::Vectord<2> vec = - frc::MakeWhiteNoiseVector<2>({2.0, 3.0}); + [[maybe_unused]] + frc::Vectord<2> vec = frc::MakeWhiteNoiseVector<2>({2.0, 3.0}); } TEST(StateSpaceUtilTest, IsStabilizable) { diff --git a/wpinet/src/test/native/cpp/uv/UvGetAddrInfoTest.cpp b/wpinet/src/test/native/cpp/uv/UvGetAddrInfoTest.cpp index 78bb4c29c8..ac87737b74 100644 --- a/wpinet/src/test/native/cpp/uv/UvGetAddrInfoTest.cpp +++ b/wpinet/src/test/native/cpp/uv/UvGetAddrInfoTest.cpp @@ -42,8 +42,7 @@ TEST(UvGetAddrInfoTest, BothNull) { fail_cb_called++; }); - GetAddrInfo( - loop, [](const addrinfo&) { FAIL(); }, ""); + GetAddrInfo(loop, [](const addrinfo&) { FAIL(); }, ""); loop->Run(); ASSERT_EQ(fail_cb_called, 1); } @@ -59,8 +58,7 @@ TEST(UvGetAddrInfoTest, FailedLookup) { }); // Use a FQDN by ending in a period - GetAddrInfo( - loop, [](const addrinfo&) { FAIL(); }, "xyzzy.xyzzy.xyzzy."); + GetAddrInfo(loop, [](const addrinfo&) { FAIL(); }, "xyzzy.xyzzy.xyzzy."); loop->Run(); ASSERT_EQ(fail_cb_called, 1); } @@ -71,8 +69,7 @@ TEST(UvGetAddrInfoTest, Basic) { auto loop = Loop::Create(); loop->error.connect([](Error) { FAIL(); }); - GetAddrInfo( - loop, [&](const addrinfo&) { getaddrinfo_cbs++; }, "localhost"); + GetAddrInfo(loop, [&](const addrinfo&) { getaddrinfo_cbs++; }, "localhost"); loop->Run(); diff --git a/wpiutil/examples/writelog/writelog.cpp b/wpiutil/examples/writelog/writelog.cpp index bd5e14f441..3312de0763 100644 --- a/wpiutil/examples/writelog/writelog.cpp +++ b/wpiutil/examples/writelog/writelog.cpp @@ -50,19 +50,19 @@ int main(int argc, char** argv) { } }}); - testVec.push_back( - {"Double array append", [](auto& log) { - wpi::log::DoubleArrayLogEntry entry{log, "double_array", 1}; - entry.Append({1, 2, 3}, 20000); - entry.Append({4, 5}, 30000); - }}); + testVec.push_back({"Double array append", [](auto& log) { + wpi::log::DoubleArrayLogEntry entry{log, "double_array", + 1}; + entry.Append({1, 2, 3}, 20000); + entry.Append({4, 5}, 30000); + }}); - testVec.push_back( - {"String array append", [](auto& log) { - wpi::log::StringArrayLogEntry entry{log, "string_array", 1}; - entry.Append({"Hello", "World"}, 20000); - entry.Append({"This", "Is", "Fun"}, 30000); - }}); + testVec.push_back({"String array append", [](auto& log) { + wpi::log::StringArrayLogEntry entry{log, "string_array", + 1}; + entry.Append({"Hello", "World"}, 20000); + entry.Append({"This", "Is", "Fun"}, 30000); + }}); for (const auto& [name, fn] : testVec) { auto resVec = std::vector(); diff --git a/wpiutil/src/main/native/include/wpi/DataLog.h b/wpiutil/src/main/native/include/wpi/DataLog.h index 6187662c00..f6e4b3c7a1 100644 --- a/wpiutil/src/main/native/include/wpi/DataLog.h +++ b/wpiutil/src/main/native/include/wpi/DataLog.h @@ -991,7 +991,8 @@ class StructLogEntry : public DataLogEntry { } private: - [[no_unique_address]] std::tuple m_info; + [[no_unique_address]] + std::tuple m_info; }; /** @@ -1059,7 +1060,8 @@ class StructArrayLogEntry : public DataLogEntry { private: StructArrayBuffer m_buf; - [[no_unique_address]] std::tuple m_info; + [[no_unique_address]] + std::tuple m_info; }; /** diff --git a/wpiutil/src/main/native/include/wpi/deprecated.h b/wpiutil/src/main/native/include/wpi/deprecated.h index ccd6bbaa40..7947010aaf 100644 --- a/wpiutil/src/main/native/include/wpi/deprecated.h +++ b/wpiutil/src/main/native/include/wpi/deprecated.h @@ -5,10 +5,6 @@ #ifndef WPIUTIL_WPI_DEPRECATED_H_ #define WPIUTIL_WPI_DEPRECATED_H_ -#ifndef WPI_DEPRECATED -#define WPI_DEPRECATED(msg) [[deprecated(msg)]] -#endif - #ifndef WPI_IGNORE_DEPRECATED #ifdef __GNUC__ #define WPI_IGNORE_DEPRECATED \ diff --git a/wpiutil/src/main/native/include/wpi/jni_util.h b/wpiutil/src/main/native/include/wpi/jni_util.h index 31bdf93ed8..aabe54c0d8 100644 --- a/wpiutil/src/main/native/include/wpi/jni_util.h +++ b/wpiutil/src/main/native/include/wpi/jni_util.h @@ -225,8 +225,8 @@ using copy_cv_t = typename copy_cv::type; template constexpr bool is_qualification_convertible_v = - !(std::is_const_v && !std::is_const_v)&&!( - std::is_volatile_v && !std::is_volatile_v); + !(std::is_const_v && !std::is_const_v) && + !(std::is_volatile_v && !std::is_volatile_v); /** * Helper class for working with JNI arrays. diff --git a/wpiutil/src/test/native/cpp/ArrayTest.cpp b/wpiutil/src/test/native/cpp/ArrayTest.cpp index d3a12a4bb9..ccc86d4762 100644 --- a/wpiutil/src/test/native/cpp/ArrayTest.cpp +++ b/wpiutil/src/test/native/cpp/ArrayTest.cpp @@ -16,17 +16,20 @@ class MoveOnlyType { } // namespace TEST(ArrayTest, CopyableTypeCompiles) { - [[maybe_unused]] constexpr wpi::array arr1{1, 2, 3}; + [[maybe_unused]] + constexpr wpi::array arr1{1, 2, 3}; // Test deduction guide - [[maybe_unused]] constexpr wpi::array arr2{1, 2, 3}; + [[maybe_unused]] + constexpr wpi::array arr2{1, 2, 3}; } TEST(ArrayTest, MoveOnlyTypeCompiles) { - [[maybe_unused]] constexpr wpi::array arr1{ - MoveOnlyType{}, MoveOnlyType{}, MoveOnlyType{}}; + [[maybe_unused]] + constexpr wpi::array arr1{MoveOnlyType{}, MoveOnlyType{}, + MoveOnlyType{}}; // Test deduction guide - [[maybe_unused]] constexpr wpi::array arr2{MoveOnlyType{}, MoveOnlyType{}, - MoveOnlyType{}}; + [[maybe_unused]] + constexpr wpi::array arr2{MoveOnlyType{}, MoveOnlyType{}, MoveOnlyType{}}; } diff --git a/wpiutil/src/test/native/cpp/Base64Test.cpp b/wpiutil/src/test/native/cpp/Base64Test.cpp index 514bb55bf5..9db4349503 100644 --- a/wpiutil/src/test/native/cpp/Base64Test.cpp +++ b/wpiutil/src/test/native/cpp/Base64Test.cpp @@ -16,9 +16,8 @@ struct Base64TestParam { }; std::ostream& operator<<(std::ostream& os, const Base64TestParam& param) { - os << "Base64TestParam(Len: " << param.plain_len << ", " - << "Plain: \"" << param.plain << "\", " - << "Encoded: \"" << param.encoded << "\")"; + os << "Base64TestParam(Len: " << param.plain_len << ", " << "Plain: \"" + << param.plain << "\", " << "Encoded: \"" << param.encoded << "\")"; return os; } diff --git a/wpiutil/src/test/native/cpp/DataLogTest.cpp b/wpiutil/src/test/native/cpp/DataLogTest.cpp index d06ad339a3..dd0f3d12d7 100644 --- a/wpiutil/src/test/native/cpp/DataLogTest.cpp +++ b/wpiutil/src/test/native/cpp/DataLogTest.cpp @@ -131,7 +131,8 @@ TEST(DataLogTest, SimpleInt) { TEST(DataLogTest, StructA) { wpi::log::DataLog log{[](auto) {}}; - [[maybe_unused]] wpi::log::StructLogEntry entry0; + [[maybe_unused]] + wpi::log::StructLogEntry entry0; wpi::log::StructLogEntry entry{log, "a", 5}; entry.Append(ThingA{}); entry.Append(ThingA{}, 7); @@ -139,7 +140,8 @@ TEST(DataLogTest, StructA) { TEST(DataLogTest, StructArrayA) { wpi::log::DataLog log{[](auto) {}}; - [[maybe_unused]] wpi::log::StructArrayLogEntry entry0; + [[maybe_unused]] + wpi::log::StructArrayLogEntry entry0; wpi::log::StructArrayLogEntry entry{log, "a", 5}; entry.Append({{ThingA{}, ThingA{}}}); entry.Append({{ThingA{}, ThingA{}}}, 7); @@ -147,7 +149,8 @@ TEST(DataLogTest, StructArrayA) { TEST(DataLogTest, StructFixedArrayA) { wpi::log::DataLog log{[](auto) {}}; - [[maybe_unused]] wpi::log::StructArrayLogEntry> entry0; + [[maybe_unused]] + wpi::log::StructArrayLogEntry> entry0; wpi::log::StructLogEntry> entry{log, "a", 5}; std::array arr; entry.Append(arr); @@ -157,7 +160,8 @@ TEST(DataLogTest, StructFixedArrayA) { TEST(DataLogTest, StructB) { wpi::log::DataLog log{[](auto) {}}; Info1 info; - [[maybe_unused]] wpi::log::StructLogEntry entry0; + [[maybe_unused]] + wpi::log::StructLogEntry entry0; wpi::log::StructLogEntry entry{log, "b", info, 5}; entry.Append(ThingB{}); entry.Append(ThingB{}, 7); @@ -166,7 +170,8 @@ TEST(DataLogTest, StructB) { TEST(DataLogTest, StructArrayB) { wpi::log::DataLog log{[](auto) {}}; Info1 info; - [[maybe_unused]] wpi::log::StructArrayLogEntry entry0; + [[maybe_unused]] + wpi::log::StructArrayLogEntry entry0; wpi::log::StructArrayLogEntry entry{log, "a", info, 5}; entry.Append({{ThingB{}, ThingB{}}}); entry.Append({{ThingB{}, ThingB{}}}, 7); diff --git a/wpiutil/src/test/native/cpp/spinlock_bench.cpp b/wpiutil/src/test/native/cpp/spinlock_bench.cpp index c8af3d26ee..d74c1ad8c3 100644 --- a/wpiutil/src/test/native/cpp/spinlock_bench.cpp +++ b/wpiutil/src/test/native/cpp/spinlock_bench.cpp @@ -29,7 +29,8 @@ TEST(SpinlockTest, Benchmark) { // warmup std::thread thr([]() { - [[maybe_unused]] int value = 0; + [[maybe_unused]] + int value = 0; auto start = high_resolution_clock::now(); for (int i = 0; i < 10000000; i++) { diff --git a/xrpVendordep/src/main/native/cpp/xrp/XRPMotor.cpp b/xrpVendordep/src/main/native/cpp/xrp/XRPMotor.cpp index 6d16f7b6a1..91740798ae 100644 --- a/xrpVendordep/src/main/native/cpp/xrp/XRPMotor.cpp +++ b/xrpVendordep/src/main/native/cpp/xrp/XRPMotor.cpp @@ -6,8 +6,6 @@ #include -#include - using namespace frc; std::map XRPMotor::s_simDeviceMap = { From ff929d4a5f39b8b89acef3369dcbace2d23dd9ef Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 17 Mar 2024 15:58:59 -0700 Subject: [PATCH 07/10] [commands] Cache button and POV triggers This is a common footgun for teams. --- .../command/button/CommandGenericHID.java | 13 ++++++-- .../command/button/CommandJoystick.java | 4 +-- .../command/button/CommandPS4Controller.java | 28 ++++++++--------- .../command/button/CommandPS5Controller.java | 28 ++++++++--------- .../button/CommandStadiaController.java | 30 +++++++++---------- .../command/button/CommandXboxController.java | 20 ++++++------- 6 files changed, 66 insertions(+), 57 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java index fadff92261..844f4bdce8 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java @@ -7,6 +7,8 @@ package edu.wpi.first.wpilibj2.command.button; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.event.EventLoop; import edu.wpi.first.wpilibj2.command.CommandScheduler; +import java.util.HashMap; +import java.util.Map; /** * A version of {@link GenericHID} with {@link Trigger} factories for command-based. @@ -15,6 +17,8 @@ import edu.wpi.first.wpilibj2.command.CommandScheduler; */ public class CommandGenericHID { private final GenericHID m_hid; + private final Map> m_buttonCache = new HashMap<>(); + private final Map> m_povCache = new HashMap<>(); /** * Construct an instance of a device. @@ -54,7 +58,9 @@ public class CommandGenericHID { * @return an event instance representing the button's digital signal attached to the given loop. */ public Trigger button(int button, EventLoop loop) { - return new Trigger(loop, () -> m_hid.getRawButton(button)); + var cache = m_buttonCache.computeIfAbsent(loop, k -> new HashMap<>()); + return cache.computeIfAbsent(button, k -> + new Trigger(loop, () -> m_hid.getRawButton(k))); } /** @@ -85,7 +91,10 @@ public class CommandGenericHID { * @return a Trigger instance based around this angle of a POV on the HID. */ public Trigger pov(int pov, int angle, EventLoop loop) { - return new Trigger(loop, () -> m_hid.getPOV(pov) == angle); + var cache = m_povCache.computeIfAbsent(loop, k -> new HashMap<>()); + // angle can be -1, so use 3600 instead of 360 + return cache.computeIfAbsent(pov * 3600 + angle, k -> + new Trigger(loop, () -> m_hid.getPOV(pov) == angle)); } /** diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandJoystick.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandJoystick.java index f9936096c4..647369f401 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandJoystick.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandJoystick.java @@ -55,7 +55,7 @@ public class CommandJoystick extends CommandGenericHID { * given loop. */ public Trigger trigger(EventLoop loop) { - return m_hid.trigger(loop).castTo(Trigger::new); + return button(Joystick.ButtonType.kTrigger.value, loop); } /** @@ -77,7 +77,7 @@ public class CommandJoystick extends CommandGenericHID { * loop. */ public Trigger top(EventLoop loop) { - return m_hid.top(loop).castTo(Trigger::new); + return button(Joystick.ButtonType.kTop.value, loop); } /** diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java index a7c0ac7c21..042b53243b 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java @@ -55,7 +55,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger L2(EventLoop loop) { - return m_hid.L2(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kL2.value, loop); } /** @@ -76,7 +76,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger R2(EventLoop loop) { - return m_hid.R2(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kR2.value, loop); } /** @@ -97,7 +97,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger L1(EventLoop loop) { - return m_hid.L1(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kL1.value, loop); } /** @@ -118,7 +118,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger R1(EventLoop loop) { - return m_hid.R1(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kR1.value, loop); } /** @@ -139,7 +139,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger L3(EventLoop loop) { - return m_hid.L3(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kL3.value, loop); } /** @@ -160,7 +160,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger R3(EventLoop loop) { - return m_hid.R3(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kR3.value, loop); } /** @@ -181,7 +181,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger square(EventLoop loop) { - return m_hid.square(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kSquare.value, loop); } /** @@ -202,7 +202,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger cross(EventLoop loop) { - return m_hid.cross(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kCross.value, loop); } /** @@ -223,7 +223,7 @@ public class CommandPS4Controller extends CommandGenericHID { * given loop. */ public Trigger triangle(EventLoop loop) { - return m_hid.triangle(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kTriangle.value, loop); } /** @@ -244,7 +244,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger circle(EventLoop loop) { - return m_hid.circle(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kCircle.value, loop); } /** @@ -265,7 +265,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger share(EventLoop loop) { - return m_hid.share(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kShare.value, loop); } /** @@ -286,7 +286,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger PS(EventLoop loop) { - return m_hid.PS(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kPS.value, loop); } /** @@ -307,7 +307,7 @@ public class CommandPS4Controller extends CommandGenericHID { * given loop. */ public Trigger options(EventLoop loop) { - return m_hid.options(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kOptions.value, loop); } /** @@ -328,7 +328,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger touchpad(EventLoop loop) { - return m_hid.touchpad(loop).castTo(Trigger::new); + return button(PS4Controller.Button.kTouchpad.value, loop); } /** diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java index 6b149d62b4..9ff0d70b3e 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java @@ -55,7 +55,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger L2(EventLoop loop) { - return m_hid.L2(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kL2.value, loop); } /** @@ -76,7 +76,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger R2(EventLoop loop) { - return m_hid.R2(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kR2.value, loop); } /** @@ -97,7 +97,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger L1(EventLoop loop) { - return m_hid.L1(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kL1.value, loop); } /** @@ -118,7 +118,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger R1(EventLoop loop) { - return m_hid.R1(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kR1.value, loop); } /** @@ -139,7 +139,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger L3(EventLoop loop) { - return m_hid.L3(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kL3.value, loop); } /** @@ -160,7 +160,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger R3(EventLoop loop) { - return m_hid.R3(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kR3.value, loop); } /** @@ -181,7 +181,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger square(EventLoop loop) { - return m_hid.square(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kSquare.value, loop); } /** @@ -202,7 +202,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger cross(EventLoop loop) { - return m_hid.cross(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kCross.value, loop); } /** @@ -223,7 +223,7 @@ public class CommandPS5Controller extends CommandGenericHID { * given loop. */ public Trigger triangle(EventLoop loop) { - return m_hid.triangle(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kTriangle.value, loop); } /** @@ -244,7 +244,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger circle(EventLoop loop) { - return m_hid.circle(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kCircle.value, loop); } /** @@ -265,7 +265,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger create(EventLoop loop) { - return m_hid.create(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kCreate.value, loop); } /** @@ -286,7 +286,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger PS(EventLoop loop) { - return m_hid.PS(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kPS.value, loop); } /** @@ -307,7 +307,7 @@ public class CommandPS5Controller extends CommandGenericHID { * given loop. */ public Trigger options(EventLoop loop) { - return m_hid.options(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kOptions.value, loop); } /** @@ -328,7 +328,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger touchpad(EventLoop loop) { - return m_hid.touchpad(loop).castTo(Trigger::new); + return button(PS5Controller.Button.kTouchpad.value, loop); } /** diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java index 0d919e5caa..053ebfae6d 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java @@ -56,7 +56,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger leftBumper(EventLoop loop) { - return m_hid.leftBumper(loop).castTo(Trigger::new); + return button(StadiaController.Button.kLeftBumper.value, loop); } /** @@ -78,7 +78,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger rightBumper(EventLoop loop) { - return m_hid.rightBumper(loop).castTo(Trigger::new); + return button(StadiaController.Button.kRightBumper.value, loop); } /** @@ -100,7 +100,7 @@ public class CommandStadiaController extends CommandGenericHID { * given loop. */ public Trigger leftStick(EventLoop loop) { - return m_hid.leftStick(loop).castTo(Trigger::new); + return button(StadiaController.Button.kLeftStick.value, loop); } /** @@ -122,7 +122,7 @@ public class CommandStadiaController extends CommandGenericHID { * given loop. */ public Trigger rightStick(EventLoop loop) { - return m_hid.rightStick(loop).castTo(Trigger::new); + return button(StadiaController.Button.kRightStick.value, loop); } /** @@ -144,7 +144,7 @@ public class CommandStadiaController extends CommandGenericHID { * the given loop. */ public Trigger rightTrigger(EventLoop loop) { - return m_hid.rightTrigger(loop).castTo(Trigger::new); + return button(StadiaController.Button.kRightTrigger.value, loop); } /** @@ -166,7 +166,7 @@ public class CommandStadiaController extends CommandGenericHID { * given loop. */ public Trigger leftTrigger(EventLoop loop) { - return m_hid.leftTrigger(loop).castTo(Trigger::new); + return button(StadiaController.Button.kLeftTrigger.value, loop); } /** @@ -188,7 +188,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger a(EventLoop loop) { - return m_hid.a(loop).castTo(Trigger::new); + return button(StadiaController.Button.kA.value, loop); } /** @@ -210,7 +210,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger b(EventLoop loop) { - return m_hid.b(loop).castTo(Trigger::new); + return button(StadiaController.Button.kB.value, loop); } /** @@ -232,7 +232,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger x(EventLoop loop) { - return m_hid.x(loop).castTo(Trigger::new); + return button(StadiaController.Button.kX.value, loop); } /** @@ -254,7 +254,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger y(EventLoop loop) { - return m_hid.y(loop).castTo(Trigger::new); + return button(StadiaController.Button.kY.value, loop); } /** @@ -276,7 +276,7 @@ public class CommandStadiaController extends CommandGenericHID { * given loop. */ public Trigger ellipses(EventLoop loop) { - return m_hid.ellipses(loop).castTo(Trigger::new); + return button(StadiaController.Button.kEllipses.value, loop); } /** @@ -298,7 +298,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger stadia(EventLoop loop) { - return m_hid.stadia(loop).castTo(Trigger::new); + return button(StadiaController.Button.kStadia.value, loop); } /** @@ -320,7 +320,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger google(EventLoop loop) { - return m_hid.google(loop).castTo(Trigger::new); + return button(StadiaController.Button.kGoogle.value, loop); } /** @@ -342,7 +342,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger frame(EventLoop loop) { - return m_hid.frame(loop).castTo(Trigger::new); + return button(StadiaController.Button.kFrame.value, loop); } /** @@ -364,7 +364,7 @@ public class CommandStadiaController extends CommandGenericHID { * given loop. */ public Trigger hamburger(EventLoop loop) { - return m_hid.hamburger(loop).castTo(Trigger::new); + return button(StadiaController.Button.kHamburger.value, loop); } /** diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java index 6969c98468..c7532f7a00 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java @@ -56,7 +56,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger leftBumper(EventLoop loop) { - return m_hid.leftBumper(loop).castTo(Trigger::new); + return button(XboxController.Button.kLeftBumper.value, loop); } /** @@ -78,7 +78,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger rightBumper(EventLoop loop) { - return m_hid.rightBumper(loop).castTo(Trigger::new); + return button(XboxController.Button.kRightBumper.value, loop); } /** @@ -100,7 +100,7 @@ public class CommandXboxController extends CommandGenericHID { * given loop. */ public Trigger leftStick(EventLoop loop) { - return m_hid.leftStick(loop).castTo(Trigger::new); + return button(XboxController.Button.kLeftStick.value, loop); } /** @@ -122,7 +122,7 @@ public class CommandXboxController extends CommandGenericHID { * given loop. */ public Trigger rightStick(EventLoop loop) { - return m_hid.rightStick(loop).castTo(Trigger::new); + return button(XboxController.Button.kRightStick.value, loop); } /** @@ -144,7 +144,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger a(EventLoop loop) { - return m_hid.a(loop).castTo(Trigger::new); + return button(XboxController.Button.kA.value, loop); } /** @@ -166,7 +166,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger b(EventLoop loop) { - return m_hid.b(loop).castTo(Trigger::new); + return button(XboxController.Button.kB.value, loop); } /** @@ -188,7 +188,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger x(EventLoop loop) { - return m_hid.x(loop).castTo(Trigger::new); + return button(XboxController.Button.kX.value, loop); } /** @@ -210,7 +210,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger y(EventLoop loop) { - return m_hid.y(loop).castTo(Trigger::new); + return button(XboxController.Button.kY.value, loop); } /** @@ -232,7 +232,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger start(EventLoop loop) { - return m_hid.start(loop).castTo(Trigger::new); + return button(XboxController.Button.kStart.value, loop); } /** @@ -254,7 +254,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger back(EventLoop loop) { - return m_hid.back(loop).castTo(Trigger::new); + return button(XboxController.Button.kBack.value, loop); } /** From b38540e1af088fa3d41efa74cb88d70d06e0d194 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 20 Mar 2024 22:53:52 -0700 Subject: [PATCH 08/10] [ci] Pin wpiformat version in comment command (#6458) --- .github/workflows/comment-command.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/comment-command.yml b/.github/workflows/comment-command.yml index 0efdebb985..6cdcf123bd 100644 --- a/.github/workflows/comment-command.yml +++ b/.github/workflows/comment-command.yml @@ -43,7 +43,7 @@ jobs: distribution: 'zulu' java-version: 17 - name: Install wpiformat - run: pip3 install wpiformat + run: pip3 install wpiformat==2024.33 - name: Run wpiformat run: wpiformat - name: Run spotlessApply From 2392c9f278531eb2f624d9abf59971c202949545 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Fri, 22 Mar 2024 09:50:28 -0700 Subject: [PATCH 09/10] Run java format (#6462) --- .../first/wpilibj2/command/button/CommandGenericHID.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java index 844f4bdce8..632694e96a 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java @@ -59,8 +59,7 @@ public class CommandGenericHID { */ public Trigger button(int button, EventLoop loop) { var cache = m_buttonCache.computeIfAbsent(loop, k -> new HashMap<>()); - return cache.computeIfAbsent(button, k -> - new Trigger(loop, () -> m_hid.getRawButton(k))); + return cache.computeIfAbsent(button, k -> new Trigger(loop, () -> m_hid.getRawButton(k))); } /** @@ -93,8 +92,8 @@ public class CommandGenericHID { public Trigger pov(int pov, int angle, EventLoop loop) { var cache = m_povCache.computeIfAbsent(loop, k -> new HashMap<>()); // angle can be -1, so use 3600 instead of 360 - return cache.computeIfAbsent(pov * 3600 + angle, k -> - new Trigger(loop, () -> m_hid.getPOV(pov) == angle)); + return cache.computeIfAbsent( + pov * 3600 + angle, k -> new Trigger(loop, () -> m_hid.getPOV(pov) == angle)); } /** From 33f12f0e310294d5f6da8778971c53b06790c87c Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 26 Mar 2024 00:07:44 -0700 Subject: [PATCH 10/10] Revert "[commands] Cache button and POV triggers" Also revert the associated formatting commit. This was an accidental merge. This reverts commit ff929d4a5f39b8b89acef3369dcbace2d23dd9ef. This reverts commit 2392c9f278531eb2f624d9abf59971c202949545. --- .../command/button/CommandGenericHID.java | 12 ++------ .../command/button/CommandJoystick.java | 4 +-- .../command/button/CommandPS4Controller.java | 28 ++++++++--------- .../command/button/CommandPS5Controller.java | 28 ++++++++--------- .../button/CommandStadiaController.java | 30 +++++++++---------- .../command/button/CommandXboxController.java | 20 ++++++------- 6 files changed, 57 insertions(+), 65 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java index 632694e96a..fadff92261 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java @@ -7,8 +7,6 @@ package edu.wpi.first.wpilibj2.command.button; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.event.EventLoop; import edu.wpi.first.wpilibj2.command.CommandScheduler; -import java.util.HashMap; -import java.util.Map; /** * A version of {@link GenericHID} with {@link Trigger} factories for command-based. @@ -17,8 +15,6 @@ import java.util.Map; */ public class CommandGenericHID { private final GenericHID m_hid; - private final Map> m_buttonCache = new HashMap<>(); - private final Map> m_povCache = new HashMap<>(); /** * Construct an instance of a device. @@ -58,8 +54,7 @@ public class CommandGenericHID { * @return an event instance representing the button's digital signal attached to the given loop. */ public Trigger button(int button, EventLoop loop) { - var cache = m_buttonCache.computeIfAbsent(loop, k -> new HashMap<>()); - return cache.computeIfAbsent(button, k -> new Trigger(loop, () -> m_hid.getRawButton(k))); + return new Trigger(loop, () -> m_hid.getRawButton(button)); } /** @@ -90,10 +85,7 @@ public class CommandGenericHID { * @return a Trigger instance based around this angle of a POV on the HID. */ public Trigger pov(int pov, int angle, EventLoop loop) { - var cache = m_povCache.computeIfAbsent(loop, k -> new HashMap<>()); - // angle can be -1, so use 3600 instead of 360 - return cache.computeIfAbsent( - pov * 3600 + angle, k -> new Trigger(loop, () -> m_hid.getPOV(pov) == angle)); + return new Trigger(loop, () -> m_hid.getPOV(pov) == angle); } /** diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandJoystick.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandJoystick.java index 647369f401..f9936096c4 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandJoystick.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandJoystick.java @@ -55,7 +55,7 @@ public class CommandJoystick extends CommandGenericHID { * given loop. */ public Trigger trigger(EventLoop loop) { - return button(Joystick.ButtonType.kTrigger.value, loop); + return m_hid.trigger(loop).castTo(Trigger::new); } /** @@ -77,7 +77,7 @@ public class CommandJoystick extends CommandGenericHID { * loop. */ public Trigger top(EventLoop loop) { - return button(Joystick.ButtonType.kTop.value, loop); + return m_hid.top(loop).castTo(Trigger::new); } /** diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java index 042b53243b..a7c0ac7c21 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java @@ -55,7 +55,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger L2(EventLoop loop) { - return button(PS4Controller.Button.kL2.value, loop); + return m_hid.L2(loop).castTo(Trigger::new); } /** @@ -76,7 +76,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger R2(EventLoop loop) { - return button(PS4Controller.Button.kR2.value, loop); + return m_hid.R2(loop).castTo(Trigger::new); } /** @@ -97,7 +97,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger L1(EventLoop loop) { - return button(PS4Controller.Button.kL1.value, loop); + return m_hid.L1(loop).castTo(Trigger::new); } /** @@ -118,7 +118,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger R1(EventLoop loop) { - return button(PS4Controller.Button.kR1.value, loop); + return m_hid.R1(loop).castTo(Trigger::new); } /** @@ -139,7 +139,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger L3(EventLoop loop) { - return button(PS4Controller.Button.kL3.value, loop); + return m_hid.L3(loop).castTo(Trigger::new); } /** @@ -160,7 +160,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger R3(EventLoop loop) { - return button(PS4Controller.Button.kR3.value, loop); + return m_hid.R3(loop).castTo(Trigger::new); } /** @@ -181,7 +181,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger square(EventLoop loop) { - return button(PS4Controller.Button.kSquare.value, loop); + return m_hid.square(loop).castTo(Trigger::new); } /** @@ -202,7 +202,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger cross(EventLoop loop) { - return button(PS4Controller.Button.kCross.value, loop); + return m_hid.cross(loop).castTo(Trigger::new); } /** @@ -223,7 +223,7 @@ public class CommandPS4Controller extends CommandGenericHID { * given loop. */ public Trigger triangle(EventLoop loop) { - return button(PS4Controller.Button.kTriangle.value, loop); + return m_hid.triangle(loop).castTo(Trigger::new); } /** @@ -244,7 +244,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger circle(EventLoop loop) { - return button(PS4Controller.Button.kCircle.value, loop); + return m_hid.circle(loop).castTo(Trigger::new); } /** @@ -265,7 +265,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger share(EventLoop loop) { - return button(PS4Controller.Button.kShare.value, loop); + return m_hid.share(loop).castTo(Trigger::new); } /** @@ -286,7 +286,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger PS(EventLoop loop) { - return button(PS4Controller.Button.kPS.value, loop); + return m_hid.PS(loop).castTo(Trigger::new); } /** @@ -307,7 +307,7 @@ public class CommandPS4Controller extends CommandGenericHID { * given loop. */ public Trigger options(EventLoop loop) { - return button(PS4Controller.Button.kOptions.value, loop); + return m_hid.options(loop).castTo(Trigger::new); } /** @@ -328,7 +328,7 @@ public class CommandPS4Controller extends CommandGenericHID { * loop. */ public Trigger touchpad(EventLoop loop) { - return button(PS4Controller.Button.kTouchpad.value, loop); + return m_hid.touchpad(loop).castTo(Trigger::new); } /** diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java index 9ff0d70b3e..6b149d62b4 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java @@ -55,7 +55,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger L2(EventLoop loop) { - return button(PS5Controller.Button.kL2.value, loop); + return m_hid.L2(loop).castTo(Trigger::new); } /** @@ -76,7 +76,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger R2(EventLoop loop) { - return button(PS5Controller.Button.kR2.value, loop); + return m_hid.R2(loop).castTo(Trigger::new); } /** @@ -97,7 +97,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger L1(EventLoop loop) { - return button(PS5Controller.Button.kL1.value, loop); + return m_hid.L1(loop).castTo(Trigger::new); } /** @@ -118,7 +118,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger R1(EventLoop loop) { - return button(PS5Controller.Button.kR1.value, loop); + return m_hid.R1(loop).castTo(Trigger::new); } /** @@ -139,7 +139,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger L3(EventLoop loop) { - return button(PS5Controller.Button.kL3.value, loop); + return m_hid.L3(loop).castTo(Trigger::new); } /** @@ -160,7 +160,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger R3(EventLoop loop) { - return button(PS5Controller.Button.kR3.value, loop); + return m_hid.R3(loop).castTo(Trigger::new); } /** @@ -181,7 +181,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger square(EventLoop loop) { - return button(PS5Controller.Button.kSquare.value, loop); + return m_hid.square(loop).castTo(Trigger::new); } /** @@ -202,7 +202,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger cross(EventLoop loop) { - return button(PS5Controller.Button.kCross.value, loop); + return m_hid.cross(loop).castTo(Trigger::new); } /** @@ -223,7 +223,7 @@ public class CommandPS5Controller extends CommandGenericHID { * given loop. */ public Trigger triangle(EventLoop loop) { - return button(PS5Controller.Button.kTriangle.value, loop); + return m_hid.triangle(loop).castTo(Trigger::new); } /** @@ -244,7 +244,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger circle(EventLoop loop) { - return button(PS5Controller.Button.kCircle.value, loop); + return m_hid.circle(loop).castTo(Trigger::new); } /** @@ -265,7 +265,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger create(EventLoop loop) { - return button(PS5Controller.Button.kCreate.value, loop); + return m_hid.create(loop).castTo(Trigger::new); } /** @@ -286,7 +286,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger PS(EventLoop loop) { - return button(PS5Controller.Button.kPS.value, loop); + return m_hid.PS(loop).castTo(Trigger::new); } /** @@ -307,7 +307,7 @@ public class CommandPS5Controller extends CommandGenericHID { * given loop. */ public Trigger options(EventLoop loop) { - return button(PS5Controller.Button.kOptions.value, loop); + return m_hid.options(loop).castTo(Trigger::new); } /** @@ -328,7 +328,7 @@ public class CommandPS5Controller extends CommandGenericHID { * loop. */ public Trigger touchpad(EventLoop loop) { - return button(PS5Controller.Button.kTouchpad.value, loop); + return m_hid.touchpad(loop).castTo(Trigger::new); } /** diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java index 053ebfae6d..0d919e5caa 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java @@ -56,7 +56,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger leftBumper(EventLoop loop) { - return button(StadiaController.Button.kLeftBumper.value, loop); + return m_hid.leftBumper(loop).castTo(Trigger::new); } /** @@ -78,7 +78,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger rightBumper(EventLoop loop) { - return button(StadiaController.Button.kRightBumper.value, loop); + return m_hid.rightBumper(loop).castTo(Trigger::new); } /** @@ -100,7 +100,7 @@ public class CommandStadiaController extends CommandGenericHID { * given loop. */ public Trigger leftStick(EventLoop loop) { - return button(StadiaController.Button.kLeftStick.value, loop); + return m_hid.leftStick(loop).castTo(Trigger::new); } /** @@ -122,7 +122,7 @@ public class CommandStadiaController extends CommandGenericHID { * given loop. */ public Trigger rightStick(EventLoop loop) { - return button(StadiaController.Button.kRightStick.value, loop); + return m_hid.rightStick(loop).castTo(Trigger::new); } /** @@ -144,7 +144,7 @@ public class CommandStadiaController extends CommandGenericHID { * the given loop. */ public Trigger rightTrigger(EventLoop loop) { - return button(StadiaController.Button.kRightTrigger.value, loop); + return m_hid.rightTrigger(loop).castTo(Trigger::new); } /** @@ -166,7 +166,7 @@ public class CommandStadiaController extends CommandGenericHID { * given loop. */ public Trigger leftTrigger(EventLoop loop) { - return button(StadiaController.Button.kLeftTrigger.value, loop); + return m_hid.leftTrigger(loop).castTo(Trigger::new); } /** @@ -188,7 +188,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger a(EventLoop loop) { - return button(StadiaController.Button.kA.value, loop); + return m_hid.a(loop).castTo(Trigger::new); } /** @@ -210,7 +210,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger b(EventLoop loop) { - return button(StadiaController.Button.kB.value, loop); + return m_hid.b(loop).castTo(Trigger::new); } /** @@ -232,7 +232,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger x(EventLoop loop) { - return button(StadiaController.Button.kX.value, loop); + return m_hid.x(loop).castTo(Trigger::new); } /** @@ -254,7 +254,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger y(EventLoop loop) { - return button(StadiaController.Button.kY.value, loop); + return m_hid.y(loop).castTo(Trigger::new); } /** @@ -276,7 +276,7 @@ public class CommandStadiaController extends CommandGenericHID { * given loop. */ public Trigger ellipses(EventLoop loop) { - return button(StadiaController.Button.kEllipses.value, loop); + return m_hid.ellipses(loop).castTo(Trigger::new); } /** @@ -298,7 +298,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger stadia(EventLoop loop) { - return button(StadiaController.Button.kStadia.value, loop); + return m_hid.stadia(loop).castTo(Trigger::new); } /** @@ -320,7 +320,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger google(EventLoop loop) { - return button(StadiaController.Button.kGoogle.value, loop); + return m_hid.google(loop).castTo(Trigger::new); } /** @@ -342,7 +342,7 @@ public class CommandStadiaController extends CommandGenericHID { * loop. */ public Trigger frame(EventLoop loop) { - return button(StadiaController.Button.kFrame.value, loop); + return m_hid.frame(loop).castTo(Trigger::new); } /** @@ -364,7 +364,7 @@ public class CommandStadiaController extends CommandGenericHID { * given loop. */ public Trigger hamburger(EventLoop loop) { - return button(StadiaController.Button.kHamburger.value, loop); + return m_hid.hamburger(loop).castTo(Trigger::new); } /** diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java index c7532f7a00..6969c98468 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java @@ -56,7 +56,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger leftBumper(EventLoop loop) { - return button(XboxController.Button.kLeftBumper.value, loop); + return m_hid.leftBumper(loop).castTo(Trigger::new); } /** @@ -78,7 +78,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger rightBumper(EventLoop loop) { - return button(XboxController.Button.kRightBumper.value, loop); + return m_hid.rightBumper(loop).castTo(Trigger::new); } /** @@ -100,7 +100,7 @@ public class CommandXboxController extends CommandGenericHID { * given loop. */ public Trigger leftStick(EventLoop loop) { - return button(XboxController.Button.kLeftStick.value, loop); + return m_hid.leftStick(loop).castTo(Trigger::new); } /** @@ -122,7 +122,7 @@ public class CommandXboxController extends CommandGenericHID { * given loop. */ public Trigger rightStick(EventLoop loop) { - return button(XboxController.Button.kRightStick.value, loop); + return m_hid.rightStick(loop).castTo(Trigger::new); } /** @@ -144,7 +144,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger a(EventLoop loop) { - return button(XboxController.Button.kA.value, loop); + return m_hid.a(loop).castTo(Trigger::new); } /** @@ -166,7 +166,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger b(EventLoop loop) { - return button(XboxController.Button.kB.value, loop); + return m_hid.b(loop).castTo(Trigger::new); } /** @@ -188,7 +188,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger x(EventLoop loop) { - return button(XboxController.Button.kX.value, loop); + return m_hid.x(loop).castTo(Trigger::new); } /** @@ -210,7 +210,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger y(EventLoop loop) { - return button(XboxController.Button.kY.value, loop); + return m_hid.y(loop).castTo(Trigger::new); } /** @@ -232,7 +232,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger start(EventLoop loop) { - return button(XboxController.Button.kStart.value, loop); + return m_hid.start(loop).castTo(Trigger::new); } /** @@ -254,7 +254,7 @@ public class CommandXboxController extends CommandGenericHID { * loop. */ public Trigger back(EventLoop loop) { - return button(XboxController.Button.kBack.value, loop); + return m_hid.back(loop).castTo(Trigger::new); } /**