Skip to content

Commit 4a7b800

Browse files
committed
[ORC] Switch ExecutionSession::ErrorReporter to use unique_function.
This allows the ReportError functor to hold move-only types.
1 parent b7d976d commit 4a7b800

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

llvm/include/llvm/ExecutionEngine/Orc/Core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ class ExecutionSession {
14381438

14391439
public:
14401440
/// For reporting errors.
1441-
using ErrorReporter = std::function<void(Error)>;
1441+
using ErrorReporter = unique_function<void(Error)>;
14421442

14431443
/// Send a result to the remote.
14441444
using SendResultFunction = unique_function<void(shared::WrapperFunctionResult)>;

llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,32 @@ class CoreAPIsStandardTest : public CoreAPIsBasedStandardTest {};
2424

2525
namespace {
2626

27+
class CustomError : public ErrorInfo<CustomError> {
28+
public:
29+
static char ID;
30+
void log(raw_ostream &OS) const override { OS << "CustomError"; }
31+
std::error_code convertToErrorCode() const override { return {}; }
32+
};
33+
char CustomError::ID = 0;
34+
35+
TEST_F(CoreAPIsStandardTest, ErrorReporter) {
36+
// Check that errors reported via ExecutionSession::reportError are sent to
37+
// the registered error reporter, and that the error reporter can hold
38+
// uniquely owned state.
39+
40+
Error ReportedError = Error::success();
41+
42+
ES.setErrorReporter(
43+
// Make sure error reporter can capture uniquely-owned state.
44+
[&, State = std::make_unique<int>(42)](Error Err) {
45+
ReportedError = joinErrors(std::move(Err), std::move(ReportedError));
46+
});
47+
48+
ES.reportError(make_error<CustomError>());
49+
50+
EXPECT_THAT_ERROR(std::move(ReportedError), Failed<CustomError>());
51+
}
52+
2753
TEST_F(CoreAPIsStandardTest, JITDylibAddToLinkOrder) {
2854
// Check that the JITDylib::addToLinkOrder methods behave as expected.
2955
auto &JD2 = ES.createBareJITDylib("JD2");

0 commit comments

Comments
 (0)