mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
This fixes a bug in Sleipnir's Newton solver (the exit status was inaccurate because unconstrained optimization problems can't be infeasible).
87 lines
2.5 KiB
Diff
87 lines
2.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Tyler Veness <calcmogul@gmail.com>
|
|
Date: Wed, 3 Dec 2025 23:38:53 -0800
|
|
Subject: [PATCH 06/10] Replace std::unreachable()
|
|
|
|
---
|
|
include/sleipnir/autodiff/expression_type.hpp | 6 +++---
|
|
.../sleipnir/optimization/solver/exit_status.hpp | 6 +++---
|
|
include/sleipnir/util/unreachable.hpp | 16 ++++++++++++++++
|
|
3 files changed, 22 insertions(+), 6 deletions(-)
|
|
create mode 100644 include/sleipnir/util/unreachable.hpp
|
|
|
|
diff --git a/include/sleipnir/autodiff/expression_type.hpp b/include/sleipnir/autodiff/expression_type.hpp
|
|
index d06d32dac6c7b6faeedefeaa107cedac8446a3ab..1957fc0339b5538fbdc56a8ea2d8503c89ed4b59 100644
|
|
--- a/include/sleipnir/autodiff/expression_type.hpp
|
|
+++ b/include/sleipnir/autodiff/expression_type.hpp
|
|
@@ -4,10 +4,10 @@
|
|
|
|
#include <stdint.h>
|
|
|
|
-#include <utility>
|
|
-
|
|
#include <fmt/base.h>
|
|
|
|
+#include "sleipnir/util/unreachable.hpp"
|
|
+
|
|
namespace slp {
|
|
|
|
/// Expression type.
|
|
@@ -64,7 +64,7 @@ struct fmt::formatter<slp::ExpressionType> {
|
|
case NONLINEAR:
|
|
return m_underlying.format("nonlinear", ctx);
|
|
default:
|
|
- std::unreachable();
|
|
+ slp::unreachable();
|
|
}
|
|
}
|
|
|
|
diff --git a/include/sleipnir/optimization/solver/exit_status.hpp b/include/sleipnir/optimization/solver/exit_status.hpp
|
|
index 8786d6d64ac44ac88133df65a79636ec133b1b64..d1bf7e62aa844003cfcd7f3df6fd9c9a65563586 100644
|
|
--- a/include/sleipnir/optimization/solver/exit_status.hpp
|
|
+++ b/include/sleipnir/optimization/solver/exit_status.hpp
|
|
@@ -4,10 +4,10 @@
|
|
|
|
#include <stdint.h>
|
|
|
|
-#include <utility>
|
|
-
|
|
#include <fmt/base.h>
|
|
|
|
+#include "sleipnir/util/unreachable.hpp"
|
|
+
|
|
namespace slp {
|
|
|
|
/// Solver exit status. Negative values indicate failure.
|
|
@@ -96,7 +96,7 @@ struct fmt::formatter<slp::ExitStatus> {
|
|
case TIMEOUT:
|
|
return m_underlying.format("timeout", ctx);
|
|
default:
|
|
- std::unreachable();
|
|
+ slp::unreachable();
|
|
}
|
|
}
|
|
|
|
diff --git a/include/sleipnir/util/unreachable.hpp b/include/sleipnir/util/unreachable.hpp
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..2e5ec3e716b36e892476fb3accafacbb1ba1fa7d
|
|
--- /dev/null
|
|
+++ b/include/sleipnir/util/unreachable.hpp
|
|
@@ -0,0 +1,16 @@
|
|
+// Copyright (c) Sleipnir contributors
|
|
+
|
|
+#pragma once
|
|
+
|
|
+namespace slp {
|
|
+
|
|
+[[noreturn]]
|
|
+inline void unreachable() {
|
|
+#if defined(_MSC_VER) && !defined(__clang__)
|
|
+ __assume(false);
|
|
+#else
|
|
+ __builtin_unreachable();
|
|
+#endif
|
|
+}
|
|
+
|
|
+} // namespace slp
|