From 263121049334fc5af1f6b3c23292831b02ae2369 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 19 Jun 2020 23:47:54 +0200 Subject: [PATCH] Solver: analyze multi conflict rules in conflict resolution correctly --- src/Composer/DependencyResolver/Pool.php | 11 +++++++++++ src/Composer/DependencyResolver/Solver.php | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/Composer/DependencyResolver/Pool.php b/src/Composer/DependencyResolver/Pool.php index b46447f72..c4173a00a 100644 --- a/src/Composer/DependencyResolver/Pool.php +++ b/src/Composer/DependencyResolver/Pool.php @@ -189,4 +189,15 @@ class Pool implements \Countable { return \in_array($package, $this->unacceptableFixedPackages, true); } + + public function __toString() + { + $str = "Pool:\n"; + + foreach ($this->packages as $package) { + $str .= '- '.str_pad($package->id, 6, ' ', STR_PAD_LEFT).': '.$package->getName()."\n"; + } + + return $str; + } } diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index 73e79c819..4ded368ba 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -15,6 +15,7 @@ namespace Composer\DependencyResolver; use Composer\IO\IOInterface; use Composer\Package\PackageInterface; use Composer\Repository\PlatformRepository; +use Composer\Semver\Constraint\MultiConstraint; /** * @author Nils Adermann @@ -385,6 +386,10 @@ class Solver $this->learnedPool[\count($this->learnedPool) - 1][] = $rule; foreach ($rule->getLiterals() as $literal) { + if (!$this->decisions->decided($literal)) { + continue; + } + // skip the one true literal if ($this->decisions->satisfy($literal)) { continue; @@ -412,6 +417,16 @@ class Solver } unset($literal); + $decision = $this->decisions->atOffset($decisionId-1); + if ($rule !== $decision[Decisions::DECISION_REASON] && $decision[Decisions::DECISION_REASON] instanceof MultiConflictRule) { + $num++; + foreach ($decision[Decisions::DECISION_REASON]->getLiterals() as $literal) { + if (!$this->decisions->satisfy($literal)) { + $seen[abs($literal)] = true; + } + } + } + $l1retry = true; while ($l1retry) { $l1retry = false; @@ -459,6 +474,13 @@ class Solver $l1num++; $l1retry = true; } + + $decision = $this->decisions->atOffset($decisionId); + $rule = $decision[Decisions::DECISION_REASON]; + + if ($rule instanceof MultiConflictRule) { + $l1retry = true; + } } $decision = $this->decisions->atOffset($decisionId);