[llvm] 4a7b800 - [ORC] Switch ExecutionSession::ErrorReporter to use unique_function.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 7 00:15:57 PDT 2024
Author: Lang Hames
Date: 2024-06-07T16:55:22+10:00
New Revision: 4a7b8003012985028bdf637be0a9c7a71dff65d9
URL: https://github.com/llvm/llvm-project/commit/4a7b8003012985028bdf637be0a9c7a71dff65d9
DIFF: https://github.com/llvm/llvm-project/commit/4a7b8003012985028bdf637be0a9c7a71dff65d9.diff
LOG: [ORC] Switch ExecutionSession::ErrorReporter to use unique_function.
This allows the ReportError functor to hold move-only types.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/Orc/Core.h
llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Core.h b/llvm/include/llvm/ExecutionEngine/Orc/Core.h
index bac923aba02af..6ce6affe38e05 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Core.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Core.h
@@ -1438,7 +1438,7 @@ class ExecutionSession {
public:
/// For reporting errors.
- using ErrorReporter = std::function<void(Error)>;
+ using ErrorReporter = unique_function<void(Error)>;
/// Send a result to the remote.
using SendResultFunction = unique_function<void(shared::WrapperFunctionResult)>;
diff --git a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
index 53a74c833eb31..39a49eb179993 100644
--- a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
@@ -24,6 +24,32 @@ class CoreAPIsStandardTest : public CoreAPIsBasedStandardTest {};
namespace {
+class CustomError : public ErrorInfo<CustomError> {
+public:
+ static char ID;
+ void log(raw_ostream &OS) const override { OS << "CustomError"; }
+ std::error_code convertToErrorCode() const override { return {}; }
+};
+char CustomError::ID = 0;
+
+TEST_F(CoreAPIsStandardTest, ErrorReporter) {
+ // Check that errors reported via ExecutionSession::reportError are sent to
+ // the registered error reporter, and that the error reporter can hold
+ // uniquely owned state.
+
+ Error ReportedError = Error::success();
+
+ ES.setErrorReporter(
+ // Make sure error reporter can capture uniquely-owned state.
+ [&, State = std::make_unique<int>(42)](Error Err) {
+ ReportedError = joinErrors(std::move(Err), std::move(ReportedError));
+ });
+
+ ES.reportError(make_error<CustomError>());
+
+ EXPECT_THAT_ERROR(std::move(ReportedError), Failed<CustomError>());
+}
+
TEST_F(CoreAPIsStandardTest, JITDylibAddToLinkOrder) {
// Check that the JITDylib::addToLinkOrder methods behave as expected.
auto &JD2 = ES.createBareJITDylib("JD2");
More information about the llvm-commits
mailing list