Skip to content

Commit

Permalink
Remove MSolver::m_jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Jan 25, 2024
1 parent b9e1203 commit 9d91413
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
3 changes: 0 additions & 3 deletions libmamba/include/mamba/core/solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
#include "mamba/core/pool.hpp"
#include "mamba/core/satisfiability_error.hpp"
#include "mamba/solver/request.hpp"
#include "mamba/specs/match_spec.hpp"
#include "mamba/specs/package_info.hpp"

namespace mamba::solv
{
class ObjQueue;
class ObjSolver;
}

Expand Down Expand Up @@ -104,7 +102,6 @@ namespace mamba
MPool m_pool;
// Temporary Pimpl all libsolv to keep it private
std::unique_ptr<solv::ObjSolver> m_solver;
std::unique_ptr<solv::ObjQueue> m_jobs;
Flags m_flags = {};
bool m_is_solved;

Expand Down
72 changes: 37 additions & 35 deletions libmamba/src/core/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace mamba
: m_libsolv_flags(std::move(flags))
, m_pool(std::move(pool))
, m_solver(nullptr)
, m_jobs(std::make_unique<solv::ObjQueue>())
, m_is_solved(false)
{
}
Expand Down Expand Up @@ -208,39 +207,6 @@ namespace mamba

void MSolver::set_request(Request request)
{
const auto& chan_params = m_pool.channel_context().params();
for (const auto& item : request.items)
{
std::visit(
[&](const auto& r)
{
if constexpr (std::is_same_v<std::decay_t<decltype(r)>, Request::Pin>)
{
add_job_impl(r, *m_jobs, m_pool.pool(), chan_params, m_flags.force_reinstall)
.or_else([](mamba_error&& error) { throw std::move(error); });
}
},
item
);
}
// Fragile: Pins add solvables to Pol and hence require a call to create_whatprovides.
// Channel specific MatchSpec write to whatprovides and hence require it is not modified
// afterwards.
m_pool.create_whatprovides();
for (const auto& item : request.items)
{
std::visit(
[&](const auto& r)
{
if constexpr (!std::is_same_v<std::decay_t<decltype(r)>, Request::Pin>)
{
add_job_impl(r, *m_jobs, m_pool.pool(), chan_params, m_flags.force_reinstall)
.or_else([](mamba_error&& error) { throw std::move(error); });
}
},
item
);
}
m_request = std::move(request);
}

Expand Down Expand Up @@ -295,10 +261,46 @@ namespace mamba

bool MSolver::try_solve()
{
auto solv_jobs = solv::ObjQueue();

const auto& chan_params = m_pool.channel_context().params();
for (const auto& item : m_request.items)
{
std::visit(
[&](const auto& r)
{
if constexpr (std::is_same_v<std::decay_t<decltype(r)>, Request::Pin>)
{
add_job_impl(r, solv_jobs, m_pool.pool(), chan_params, m_flags.force_reinstall)
.or_else([](mamba_error&& error) { throw std::move(error); });
}
},
item
);
}
// Fragile: Pins add solvables to Pol and hence require a call to create_whatprovides.
// Channel specific MatchSpec write to whatprovides and hence require it is not modified
// afterwards.
m_pool.create_whatprovides();
for (const auto& item : m_request.items)
{
std::visit(
[&](const auto& r)
{
if constexpr (!std::is_same_v<std::decay_t<decltype(r)>, Request::Pin>)
{
add_job_impl(r, solv_jobs, m_pool.pool(), chan_params, m_flags.force_reinstall)
.or_else([](mamba_error&& error) { throw std::move(error); });
}
},
item
);
}

m_solver = std::make_unique<solv::ObjSolver>(m_pool.pool());
apply_libsolv_flags();

const bool success = solver().solve(m_pool.pool(), *m_jobs);
const bool success = solver().solve(m_pool.pool(), solv_jobs);
m_is_solved = true;
LOG_INFO << "Problem count: " << solver().problem_count();
Console::instance().json_write({ { "success", success } });
Expand Down

0 comments on commit 9d91413

Please sign in to comment.