From dd527a4049622202c882a59cc6eec16a82a63245 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sat, 19 May 2012 21:49:48 +0200 Subject: [PATCH] Remove weak rules Since we no longer have suggest/recommend rules and no longer use any update or feature rules so packages are removed by default, we do not need weak rules anymore. --- src/Composer/DependencyResolver/Rule.php | 12 ----- src/Composer/DependencyResolver/Solver.php | 54 +++---------------- .../Test/DependencyResolver/RuleTest.php | 12 ----- 3 files changed, 8 insertions(+), 70 deletions(-) diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index 93d00fc26..f5cb4ed01 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -35,7 +35,6 @@ class Rule protected $literals; protected $type; protected $id; - protected $weak; protected $job; @@ -53,7 +52,6 @@ class Rule $this->reasonData = $reasonData; $this->disabled = false; - $this->weak = false; $this->job = $job; @@ -139,16 +137,6 @@ class Rule return !$this->disabled; } - public function isWeak() - { - return $this->weak; - } - - public function setWeak($weak) - { - $this->weak = $weak; - } - public function getLiterals() { return $this->literals; diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index 45410ada2..2afb01c7d 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -69,7 +69,7 @@ class Solver for ($ruleIndex = 0; $ruleIndex < count($this->rules); $ruleIndex++) { $rule = $this->rules->ruleById($ruleIndex); - if ($rule->isWeak() || !$rule->isAssertion() || $rule->isDisabled()) { + if (!$rule->isAssertion() || $rule->isDisabled()) { continue; } @@ -104,15 +104,15 @@ class Solver continue; } - // conflict with another job or update/feature rule + // conflict with another job $problem = new Problem; $problem->addRule($rule); $problem->addRule($conflict); - // push all of our rules (can only be feature or job rules) + // push all of our rules (can only be job rules) // asserting this literal on the problem stack foreach ($this->rules->getIteratorFor(RuleSet::TYPE_JOB) as $assertRule) { - if ($assertRule->isDisabled() || !$assertRule->isAssertion() || $assertRule->isWeak()) { + if ($assertRule->isDisabled() || !$assertRule->isAssertion()) { continue; } @@ -137,27 +137,6 @@ class Solver } $ruleIndex = -1; } - - foreach ($this->rules as $rule) { - if (!$rule->isWeak() || !$rule->isAssertion() || $rule->isDisabled()) { - continue; - } - - $literals = $rule->getLiterals(); - $literal = $literals[0]; - - if ($this->decisionMap[abs($literal)] == 0) { - $this->decide($literal, 1, $rule); - continue; - } - - if ($this->decisionsSatisfy($literals[0])) { - continue; - } - - // conflict, but this is a weak rule => disable - $this->disableProblem($rule); - } } protected function setupInstalledMap() @@ -553,7 +532,7 @@ class Solver return array($learnedLiterals[0], $ruleLevel, $newRule, $why); } - private function analyzeUnsolvableRule($problem, $conflictRule, &$lastWeakWhy) + private function analyzeUnsolvableRule($problem, $conflictRule) { $why = $conflictRule->getId(); @@ -562,7 +541,7 @@ class Solver $problemRules = $this->learnedPool[$learnedWhy]; foreach ($problemRules as $problemRule) { - $this->analyzeUnsolvableRule($problem, $problemRule, $lastWeakWhy); + $this->analyzeUnsolvableRule($problem, $problemRule); } return; } @@ -572,23 +551,15 @@ class Solver return; } - if ($conflictRule->isWeak()) { - /** TODO why > or < lastWeakWhy? */ - if (!$lastWeakWhy || $why > $lastWeakWhy->getId()) { - $lastWeakWhy = $conflictRule; - } - } - $problem->addRule($conflictRule); } private function analyzeUnsolvable($conflictRule, $disableRules) { - $lastWeakWhy = null; $problem = new Problem; $problem->addRule($conflictRule); - $this->analyzeUnsolvableRule($problem, $conflictRule, $lastWeakWhy); + $this->analyzeUnsolvableRule($problem, $conflictRule); $this->problems[] = $problem; @@ -618,7 +589,7 @@ class Solver $why = $this->decisionQueueWhy[$decisionId]; $problem->addRule($why); - $this->analyzeUnsolvableRule($problem, $why, $lastWeakWhy); + $this->analyzeUnsolvableRule($problem, $why); $literals = $why->getLiterals(); @@ -631,15 +602,6 @@ class Solver } } - if ($lastWeakWhy) { - array_pop($this->problems); - - $this->disableProblem($lastWeakWhy); - $this->resetSolver(); - - return 1; - } - if ($disableRules) { foreach ($this->problems[count($this->problems) - 1] as $reason) { $this->disableProblem($reason['rule']); diff --git a/tests/Composer/Test/DependencyResolver/RuleTest.php b/tests/Composer/Test/DependencyResolver/RuleTest.php index 739dbd7ff..739e275ad 100644 --- a/tests/Composer/Test/DependencyResolver/RuleTest.php +++ b/tests/Composer/Test/DependencyResolver/RuleTest.php @@ -110,18 +110,6 @@ class RuleTest extends TestCase $this->assertFalse($rule->isEnabled()); } - public function testSetWeak() - { - $rule = new Rule($this->pool, array(), 'job1', null); - $rule->setWeak(true); - - $rule2 = new Rule($this->pool, array(), 'job1', null); - $rule2->setWeak(false); - - $this->assertTrue($rule->isWeak()); - $this->assertFalse($rule2->isWeak()); - } - public function testIsAssertions() { $rule = new Rule($this->pool, array(1, 12), 'job1', null);