From b6c7a27c121d47d463af124d11a6338ddc409eae Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Sat, 13 Dec 2025 16:45:31 +1100 Subject: [PATCH] [orc-rt] Refactor ErrorHandlerTraits to use CallableTraitsHelper. (#172126) Using CallableTraitsHelper simplifies the expression of ErrorHandlerTraits, which is responsible for running handlers based on their argument and return types. --- orc-rt/include/orc-rt/Error.h | 63 +++++++++-------------------------- 1 file changed, 16 insertions(+), 47 deletions(-) diff --git a/orc-rt/include/orc-rt/Error.h b/orc-rt/include/orc-rt/Error.h index a316e1934f67..a8f411e93022 100644 --- a/orc-rt/include/orc-rt/Error.h +++ b/orc-rt/include/orc-rt/Error.h @@ -9,6 +9,7 @@ #ifndef ORC_RT_ERROR_H #define ORC_RT_ERROR_H +#include "orc-rt/CallableTraitsHelper.h" #include "orc-rt/Compiler.h" #include "orc-rt/RTTI.h" @@ -137,18 +138,15 @@ template Error make_error(ArgTs &&...Args) { return make_error(std::make_unique(std::forward(Args)...)); } -/// Traits class for selecting and applying error handlers. -template -struct ErrorHandlerTraits - : public ErrorHandlerTraits< - decltype(&std::remove_reference_t::operator())> {}; +namespace detail { -// Specialization functions of the form 'Error (const ErrT&)'. -template struct ErrorHandlerTraits { +template struct ErrorHandlerTraitsImpl; + +// Specialization for Error(ErrT&). +template struct ErrorHandlerTraitsImpl { static bool appliesTo(const ErrorInfoBase &E) { return E.template isA(); } - template static Error apply(HandlerT &&H, std::unique_ptr E) { assert(appliesTo(*E) && "Applying incorrect handler"); @@ -156,12 +154,11 @@ template struct ErrorHandlerTraits { } }; -// Specialization functions of the form 'void (const ErrT&)'. -template struct ErrorHandlerTraits { +// Specialization for void(ErrT&). +template struct ErrorHandlerTraitsImpl { static bool appliesTo(const ErrorInfoBase &E) { return E.template isA(); } - template static Error apply(HandlerT &&H, std::unique_ptr E) { assert(appliesTo(*E) && "Applying incorrect handler"); @@ -170,13 +167,12 @@ template struct ErrorHandlerTraits { } }; -/// Specialization for functions of the form 'Error (std::unique_ptr)'. +// Specialization for Error(std::unique_ptr). template -struct ErrorHandlerTraits)> { +struct ErrorHandlerTraitsImpl> { static bool appliesTo(const ErrorInfoBase &E) { return E.template isA(); } - template static Error apply(HandlerT &&H, std::unique_ptr E) { assert(appliesTo(*E) && "Applying incorrect handler"); @@ -185,13 +181,12 @@ struct ErrorHandlerTraits)> { } }; -/// Specialization for functions of the form 'void (std::unique_ptr)'. +// Specialization for void(std::unique_ptr). template -struct ErrorHandlerTraits)> { +struct ErrorHandlerTraitsImpl> { static bool appliesTo(const ErrorInfoBase &E) { return E.template isA(); } - template static Error apply(HandlerT &&H, std::unique_ptr E) { assert(appliesTo(*E) && "Applying incorrect handler"); @@ -201,37 +196,11 @@ struct ErrorHandlerTraits)> { } }; -// Specialization for member functions of the form 'RetT (const ErrT&)'. -template -class ErrorHandlerTraits - : public ErrorHandlerTraits {}; +} // namespace detail. -// Specialization for member functions of the form 'RetT (const ErrT&) const'. -template -class ErrorHandlerTraits - : public ErrorHandlerTraits {}; - -// Specialization for member functions of the form 'RetT (const ErrT&)'. -template -class ErrorHandlerTraits - : public ErrorHandlerTraits {}; - -// Specialization for member functions of the form 'RetT (const ErrT&) const'. -template -class ErrorHandlerTraits - : public ErrorHandlerTraits {}; - -/// Specialization for member functions of the form -/// 'RetT (std::unique_ptr)'. -template -class ErrorHandlerTraits)> - : public ErrorHandlerTraits)> {}; - -/// Specialization for member functions of the form -/// 'RetT (std::unique_ptr) const'. -template -class ErrorHandlerTraits) const> - : public ErrorHandlerTraits)> {}; +template +struct ErrorHandlerTraits + : public CallableTraitsHelper {}; inline Error handleErrorsImpl(std::unique_ptr Payload) { return make_error(std::move(Payload));