const SymbolStringPtr &DependantName,
MaterializingInfo &EmittedMI);
- Expected<SymbolFlagsMap> defineMaterializing(SymbolFlagsMap SymbolFlags);
+ Expected<SymbolFlagsMap>
+ defineMaterializing(MaterializationResponsibility &FromMR,
+ SymbolFlagsMap SymbolFlags);
Error replace(MaterializationResponsibility &FromMR,
std::unique_ptr<MaterializationUnit> MU);
}
Expected<SymbolFlagsMap>
-JITDylib::defineMaterializing(SymbolFlagsMap SymbolFlags) {
- // TODO: Should we bail out early here if MR is defunct?
+JITDylib::defineMaterializing(MaterializationResponsibility &FromMR,
+ SymbolFlagsMap SymbolFlags) {
return ES.runSessionLocked([&]() -> Expected<SymbolFlagsMap> {
+ if (FromMR.RT->isDefunct())
+ return make_error<ResourceTrackerDefunct>(FromMR.RT);
+
std::vector<NonOwningSymbolStringPtr> AddedSyms;
std::vector<NonOwningSymbolStringPtr> RejectedWeakDefs;
<< NewSymbolFlags << "\n";
});
if (auto AcceptedDefs =
- MR.JD.defineMaterializing(std::move(NewSymbolFlags))) {
+ MR.JD.defineMaterializing(MR, std::move(NewSymbolFlags))) {
// Add all newly accepted symbols to this responsibility object.
for (auto &KV : *AcceptedDefs)
MR.SymbolFlags.insert(KV);
EXPECT_TRUE(QueryHandlerRun) << "Query handler never ran";
}
+TEST_F(CoreAPIsStandardTest, FailDefineMaterializingDueToDefunctTracker) {
+ // Check that a defunct resource tracker causes defineMaterializing to error
+ // immediately.
+
+ std::unique_ptr<MaterializationResponsibility> FooMR;
+ auto MU = std::make_unique<SimpleMaterializationUnit>(
+ SymbolFlagsMap({{Foo, FooSym.getFlags()}}),
+ [&](std::unique_ptr<MaterializationResponsibility> R) {
+ FooMR = std::move(R);
+ });
+
+ auto RT = JD.createResourceTracker();
+ cantFail(JD.define(std::move(MU), RT));
+
+ bool OnCompletionRan = false;
+ auto OnCompletion = [&](Expected<SymbolMap> Result) {
+ EXPECT_THAT_EXPECTED(Result, Failed());
+ OnCompletionRan = true;
+ };
+
+ ES.lookup(LookupKind::Static, makeJITDylibSearchOrder(&JD),
+ SymbolLookupSet(Foo), SymbolState::Ready, OnCompletion,
+ NoDependenciesToRegister);
+
+ cantFail(RT->remove());
+
+ EXPECT_THAT_ERROR(FooMR->defineMaterializing(SymbolFlagsMap()), Failed())
+ << "defineMaterializing should have failed due to a defunct tracker";
+
+ FooMR->failMaterialization();
+
+ EXPECT_TRUE(OnCompletionRan) << "OnCompletion handler did not run.";
+}
+
TEST_F(CoreAPIsStandardTest, TestLookupWithUnthreadedMaterialization) {
auto MU = std::make_unique<SimpleMaterializationUnit>(
SymbolFlagsMap({{Foo, JITSymbolFlags::Exported}}),