From 943562a4ed2ddc80b84466d85e821037937f8b5c Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 5 Feb 2025 20:37:12 +0100 Subject: solver3: Only enqueue shared dependencies at the package level Dependencies shared by all versions are enqueued at the package level, so avoid enqueuing duplicates at the version level. This presumably has no meaningful impact on performance, potentially a negative performance impact on some workloads as we now need to find the duplicates again; it can become useful when there is a lot of backtracking. More importantly though this improves error messages, because now we can say that "all versions of foo depend on X", rather than saying "foo=1 depends on X" and you are left wondering why we did not select "foo=2". In this commit though, improved error messages are not implemented, they depend on redesigning the reason tracking to use clauses. Also the rationale tracking includes a lot more dependencies of the form "pkg:arch=version -> pkg:arch" which are annoying. Improved error messages should fold them into one node. --- apt-pkg/solver3.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'apt-pkg/solver3.cc') diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc index 945d912db..f2e4360ff 100644 --- a/apt-pkg/solver3.cc +++ b/apt-pkg/solver3.cc @@ -454,6 +454,10 @@ void APT::Solver::Discover(Var var) var = discoverQ.front(); discoverQ.pop(); + // Package needs to be discovered before the version to be able to dedup shared dependencies + if (auto Ver = var.Ver(cache); not Ver.end() && not(*this)[Ver.ParentPkg()].flags.discovered) + var = Var(Ver.ParentPkg()); + auto &state = (*this)[var]; if (state.flags.discovered) @@ -495,6 +499,12 @@ void APT::Solver::Discover(Var var) pkgCache::DepIterator end; dep.GlobOr(start, end); // advances dep + // This dependency is shared across all versions, skip it. + if (auto &pkgClauses = (*this)[Ver.ParentPkg()].clauses; + std::any_of(pkgClauses.begin(), pkgClauses.end(), [start](auto &c) + { return c->dep && c->dep->DependencyData == start->DependencyData; })) + continue; + auto clause = TranslateOrGroup(start, end, Var(Ver)); RegisterClause(std::move(clause)); -- cgit v1.2.3-70-g09d2