[ORC] Update symbol lookup to use a single callback with a required symbol state
rather than two callbacks.
The asynchronous lookup API (which the synchronous lookup API wraps for
convenience) used to take two callbacks: OnResolved (called once all requested
symbols had an address assigned) and OnReady to be called once all requested
symbols were safe to access). This patch updates the asynchronous lookup API to
take a single 'OnComplete' callback and a required state (SymbolState) to
determine when the callback should be made. This simplifies the common use case
(where the client is interested in a specific state) and will generalize neatly
as new states are introduced to track runtime initialization of symbols.
Clients who were making use of both callbacks in a single query will now need to
issue two queries (one for SymbolState::Resolved and another for
SymbolState::Ready). Synchronous lookup API clients who were explicitly passing
the WaitOnReady argument will now need neeed to pass a SymbolState instead (for
'WaitOnReady == true' use SymbolState::Ready, for 'WaitOnReady == false' use
SymbolState::Resolved). Synchronous lookup API clients who were using default
arugment values should see no change.
llvm-svn: 362832
diff --git a/llvm/unittests/ExecutionEngine/Orc/LegacyAPIInteropTest.cpp b/llvm/unittests/ExecutionEngine/Orc/LegacyAPIInteropTest.cpp
index dca3eeb..f79d721 100644
--- a/llvm/unittests/ExecutionEngine/Orc/LegacyAPIInteropTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/LegacyAPIInteropTest.cpp
@@ -42,10 +42,10 @@
EXPECT_EQ(RS.count(Bar), 1U)
<< "getResponsibilitySet result incorrect. Should be {'bar'}";
- bool OnResolvedRun = false;
+ bool OnCompletionRun = false;
- auto OnResolved = [&](Expected<SymbolMap> Result) {
- OnResolvedRun = true;
+ auto OnCompletion = [&](Expected<SymbolMap> Result) {
+ OnCompletionRun = true;
EXPECT_TRUE(!!Result) << "Unexpected error";
EXPECT_EQ(Result->size(), 2U) << "Unexpected number of resolved symbols";
EXPECT_EQ(Result->count(Foo), 1U) << "Missing lookup result for foo";
@@ -55,18 +55,15 @@
EXPECT_EQ((*Result)[Bar].getAddress(), BarSym.getAddress())
<< "Incorrect address for bar";
};
- auto OnReady = [&](Error Err) {
- EXPECT_FALSE(!!Err) << "Finalization should never fail in this test";
- };
- auto Q = std::make_shared<AsynchronousSymbolQuery>(SymbolNameSet({Foo, Bar}),
- OnResolved, OnReady);
+ auto Q = std::make_shared<AsynchronousSymbolQuery>(
+ SymbolNameSet({Foo, Bar}), SymbolState::Resolved, OnCompletion);
auto Unresolved =
Resolver->lookup(std::move(Q), SymbolNameSet({Foo, Bar, Baz}));
EXPECT_EQ(Unresolved.size(), 1U) << "Expected one unresolved symbol";
EXPECT_EQ(Unresolved.count(Baz), 1U) << "Expected baz to not be resolved";
- EXPECT_TRUE(OnResolvedRun) << "OnResolved was never run";
+ EXPECT_TRUE(OnCompletionRun) << "OnCompletion was never run";
}
TEST_F(LegacyAPIsStandardTest, LegacyLookupHelpersFn) {
@@ -98,10 +95,9 @@
EXPECT_FALSE(BarMaterialized)
<< "lookupFlags should not have materialized bar";
- bool OnResolvedRun = false;
- bool OnReadyRun = false;
- auto OnResolved = [&](Expected<SymbolMap> Result) {
- OnResolvedRun = true;
+ bool OnCompletionRun = false;
+ auto OnCompletion = [&](Expected<SymbolMap> Result) {
+ OnCompletionRun = true;
EXPECT_TRUE(!!Result) << "lookuWithLegacy failed to resolve";
EXPECT_EQ(Result->size(), 2U) << "Wrong number of symbols resolved";
@@ -114,17 +110,12 @@
EXPECT_EQ((*Result)[Bar].getFlags(), BarSym.getFlags())
<< "Wrong flags for bar";
};
- auto OnReady = [&](Error Err) {
- EXPECT_FALSE(!!Err) << "Finalization unexpectedly failed";
- OnReadyRun = true;
- };
- AsynchronousSymbolQuery Q({Foo, Bar}, OnResolved, OnReady);
+ AsynchronousSymbolQuery Q({Foo, Bar}, SymbolState::Resolved, OnCompletion);
auto Unresolved =
lookupWithLegacyFn(ES, Q, SymbolNameSet({Foo, Bar, Baz}), LegacyLookup);
- EXPECT_TRUE(OnResolvedRun) << "OnResolved was not run";
- EXPECT_TRUE(OnReadyRun) << "OnReady was not run";
+ EXPECT_TRUE(OnCompletionRun) << "OnCompletion was not run";
EXPECT_EQ(Unresolved.size(), 1U) << "Expected one unresolved symbol";
EXPECT_EQ(Unresolved.count(Baz), 1U) << "Expected baz to be unresolved";
}