-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Offload] Use llvm::Error throughout liboffload internals #140879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,48 +69,31 @@ struct ErrPtrHash { | |
using ErrSetT = std::unordered_set<ErrPtrT, ErrPtrHash, ErrPtrEqual>; | ||
ErrSetT &errors(); | ||
|
||
struct ol_impl_result_t { | ||
ol_impl_result_t(std::nullptr_t) : Result(OL_SUCCESS) {} | ||
ol_impl_result_t(ol_errc_t Code) { | ||
if (Code == OL_ERRC_SUCCESS) { | ||
Result = nullptr; | ||
} else { | ||
auto Err = std::unique_ptr<ol_error_struct_t>( | ||
new ol_error_struct_t{Code, nullptr}); | ||
Result = errors().emplace(std::move(Err)).first->get(); | ||
} | ||
} | ||
|
||
ol_impl_result_t(ol_errc_t Code, llvm::StringRef Details) { | ||
assert(Code != OL_ERRC_SUCCESS); | ||
Result = nullptr; | ||
auto DetailsStr = errorStrs().insert(Details).first->getKeyData(); | ||
auto Err = std::unique_ptr<ol_error_struct_t>( | ||
new ol_error_struct_t{Code, DetailsStr}); | ||
Result = errors().emplace(std::move(Err)).first->get(); | ||
} | ||
namespace { | ||
ol_errc_t GetErrorCode(std::error_code Code) { | ||
if (Code.category() == | ||
error::make_error_code(error::ErrorCode::SUCCESS).category()) | ||
return static_cast<ol_errc_t>(Code.value()); | ||
|
||
static ol_impl_result_t fromError(llvm::Error &&Error) { | ||
ol_errc_t ErrCode; | ||
llvm::StringRef Details; | ||
llvm::handleAllErrors(std::move(Error), [&](llvm::StringError &Err) { | ||
ErrCode = GetErrorCode(Err.convertToErrorCode()); | ||
Details = errorStrs().insert(Err.getMessage()).first->getKeyData(); | ||
}); | ||
return OL_ERRC_UNKNOWN; | ||
} | ||
} // namespace | ||
|
||
return ol_impl_result_t{ErrCode, Details}; | ||
inline ol_result_t llvmErrorToOffloadError(llvm::Error &&Err) { | ||
if (!Err) { | ||
// No error | ||
return nullptr; | ||
} | ||
|
||
operator ol_result_t() { return Result; } | ||
ol_errc_t ErrCode; | ||
llvm::StringRef Details; | ||
|
||
private: | ||
static ol_errc_t GetErrorCode(std::error_code Code) { | ||
if (Code.category() == | ||
error::make_error_code(error::ErrorCode::SUCCESS).category()) { | ||
return static_cast<ol_errc_t>(Code.value()); | ||
} | ||
return OL_ERRC_UNKNOWN; | ||
} | ||
llvm::handleAllErrors(std::move(Err), [&](llvm::StringError &Err) { | ||
ErrCode = GetErrorCode(Err.convertToErrorCode()); | ||
Details = errorStrs().insert(Err.getMessage()).first->getKeyData(); | ||
}); | ||
|
||
ol_result_t Result; | ||
}; | ||
auto NewErr = std::unique_ptr<ol_error_struct_t>( | ||
new ol_error_struct_t{ErrCode, Details.data()}); | ||
Comment on lines
+96
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we make a constructor for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, right, forgot about the C API part. Nah, this is fine. |
||
return errors().emplace(std::move(NewErr)).first->get(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we have a success type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Liboffload uses nullptr to mean success. We could change it to be a constant
{OL_ERRC_SUCCESS, "success"}
somewhere in memory, but I think that's out of scope for this mr and worth discussing separately.