From a779e0266fae5dcf64acfba0e165e2f0ac12a745 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 21 May 2018 21:11:21 +0000 Subject: [PATCH] [ORC] Lookup now returns an error if any symbols are not found. Also tightens the behavior of ExecutionSession::failQuery. Queries can usually only be failed by marking a symbol as failed-to-materialize, but ExecutionSession::failQuery provides a second route, and both routes may be executed from different threads. In the case that a query has already been failed due to a materialization error, ExecutionSession::failQuery will direct the error to ExecutionSession::reportError instead. llvm-svn: 332898 --- include/llvm/ExecutionEngine/Orc/Core.h | 16 +++++++++++ lib/ExecutionEngine/Orc/Core.cpp | 35 +++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/include/llvm/ExecutionEngine/Orc/Core.h b/include/llvm/ExecutionEngine/Orc/Core.h index d06e5bf9430..06e6a0f3469 100644 --- a/include/llvm/ExecutionEngine/Orc/Core.h +++ b/include/llvm/ExecutionEngine/Orc/Core.h @@ -79,6 +79,20 @@ private: SymbolNameSet Symbols; }; +/// Used to notify clients when symbols can not be found during a lookup. +class SymbolsNotFound : public ErrorInfo { +public: + static char ID; + + SymbolsNotFound(SymbolNameSet Symbols); + std::error_code convertToErrorCode() const override; + void log(raw_ostream &OS) const override; + const SymbolNameSet &getSymbols() const { return Symbols; } + +private: + SymbolNameSet Symbols; +}; + /// Tracks responsibility for materialization, and mediates interactions between /// MaterializationUnits and VSOs. /// @@ -366,6 +380,8 @@ private: void removeQueryDependence(VSO &V, const SymbolStringPtr &Name); + bool canStillFail(); + void handleFailed(Error Err); void detach(); diff --git a/lib/ExecutionEngine/Orc/Core.cpp b/lib/ExecutionEngine/Orc/Core.cpp index ded8bddb468..760e2561ba6 100644 --- a/lib/ExecutionEngine/Orc/Core.cpp +++ b/lib/ExecutionEngine/Orc/Core.cpp @@ -20,6 +20,7 @@ namespace llvm { namespace orc { char FailedToMaterialize::ID = 0; +char SymbolsNotFound::ID = 0; void MaterializationUnit::anchor() {} void SymbolResolver::anchor() {} @@ -110,11 +111,31 @@ void FailedToMaterialize::log(raw_ostream &OS) const { OS << "Failed to materialize symbols: " << Symbols; } +SymbolsNotFound::SymbolsNotFound(SymbolNameSet Symbols) + : Symbols(std::move(Symbols)) { + assert(!this->Symbols.empty() && "Can not fail to resolve an empty set"); +} + +std::error_code SymbolsNotFound::convertToErrorCode() const { + return orcError(OrcErrorCode::UnknownORCError); +} + +void SymbolsNotFound::log(raw_ostream &OS) const { + OS << "Symbols not found: " << Symbols; +} + void ExecutionSessionBase::failQuery(AsynchronousSymbolQuery &Q, Error Err) { + bool DeliveredError = true; runSessionLocked([&]() -> void { Q.detach(); - Q.handleFailed(std::move(Err)); + if (Q.canStillFail()) + Q.handleFailed(std::move(Err)); + else + DeliveredError = false; }); + + if (!DeliveredError) + reportError(std::move(Err)); } AsynchronousSymbolQuery::AsynchronousSymbolQuery( @@ -160,6 +181,10 @@ void AsynchronousSymbolQuery::handleFullyReady() { NotifySymbolsReady = SymbolsReadyCallback(); } +bool AsynchronousSymbolQuery::canStillFail() { + return (NotifySymbolsResolved || NotifySymbolsReady); +} + void AsynchronousSymbolQuery::handleFailed(Error Err) { assert(QueryRegistrations.empty() && ResolvedSymbols.empty() && NotYetResolvedCount == 0 && NotYetReadyCount == 0 && @@ -902,7 +927,13 @@ Expected lookup(const std::vector &VSOs, SymbolNameSet Names) UnresolvedSymbols = V->lookup(Query, UnresolvedSymbols); } - // FIXME: Error out if there are remaining unresolved symbols. + if (!UnresolvedSymbols.empty()) { + // If there are unresolved symbols then the query will never return. + // Fail it with ES.failQuery. + auto &ES = (*VSOs.begin())->getExecutionSession(); + ES.failQuery(*Query, + make_error(std::move(UnresolvedSymbols))); + } #if LLVM_ENABLE_THREADS auto ResultFuture = PromisedResult.get_future();