Skip to content

Commit

Permalink
[Orc][RPC] Add an RPCFunctionNotSupported error type and return it from
Browse files Browse the repository at this point in the history
negotiateFunction where appropriate.

Replacing the old ECError with a custom type allows us to attach the name of
the function that could not be negotiated, enabling better diagnostics for
negotiation failures.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292055 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lhames committed Jan 15, 2017
1 parent 10dd00c commit b1e2ecc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
12 changes: 12 additions & 0 deletions include/llvm/ExecutionEngine/Orc/OrcError.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ enum class OrcErrorCode : int {

Error orcError(OrcErrorCode ErrCode);

class RPCFunctionNotSupported : public ErrorInfo<RPCFunctionNotSupported> {
public:
static char ID;

RPCFunctionNotSupported(std::string RPCFunctionSignature);
std::error_code convertToErrorCode() const override;
void log(raw_ostream &OS) const override;
const std::string &getFunctionSignature() const;
private:
std::string RPCFunctionSignature;
};

} // End namespace orc.
} // End namespace llvm.

Expand Down
4 changes: 2 additions & 2 deletions include/llvm/ExecutionEngine/Orc/RPCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ class MultiThreadedRPCEndpoint
return Error::success();
// If it's invalid and we can't re-attempt negotiation, throw an error.
if (!Retry)
return orcError(OrcErrorCode::UnknownRPCFunction);
return make_error<RPCFunctionNotSupported>(Func::getPrototype());
}

// We don't have a function id for Func yet, call the remote to try to
Expand Down Expand Up @@ -1254,7 +1254,7 @@ class SingleThreadedRPCEndpoint
return Error::success();
// If it's invalid and we can't re-attempt negotiation, throw an error.
if (!Retry)
return orcError(OrcErrorCode::UnknownRPCFunction);
return make_error<RPCFunctionNotSupported>(Func::getPrototype());
}

// We don't have a function id for Func yet, call the remote to try to
Expand Down
20 changes: 20 additions & 0 deletions lib/ExecutionEngine/Orc/OrcError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,30 @@ static ManagedStatic<OrcErrorCategory> OrcErrCat;
namespace llvm {
namespace orc {

char RPCFunctionNotSupported::ID = 0;

Error orcError(OrcErrorCode ErrCode) {
typedef std::underlying_type<OrcErrorCode>::type UT;
return errorCodeToError(
std::error_code(static_cast<UT>(ErrCode), *OrcErrCat));
}

RPCFunctionNotSupported::RPCFunctionNotSupported(std::string RPCFunctionSignature)
: RPCFunctionSignature(std::move(RPCFunctionSignature)) {}

std::error_code RPCFunctionNotSupported::convertToErrorCode() const {
typedef std::underlying_type<OrcErrorCode>::type UT;
return std::error_code(static_cast<UT>(OrcErrorCode::UnknownRPCFunction),
*OrcErrCat);
}

void RPCFunctionNotSupported::log(raw_ostream &OS) const {
OS << "Could not negotiate RPC function '" << RPCFunctionSignature << "'";
}

const std::string &RPCFunctionNotSupported::getFunctionSignature() const {
return RPCFunctionSignature;
}

}
}

0 comments on commit b1e2ecc

Please sign in to comment.