|
|
c44fa3 |
From 21090e6067660e4a22d6227118d5cfc30629d548 Mon Sep 17 00:00:00 2001
|
|
|
c44fa3 |
From: Nicola Sella <nsella@redhat.com>
|
|
|
c44fa3 |
Date: Wed, 7 Dec 2022 16:11:10 +0100
|
|
|
c44fa3 |
Subject: [PATCH 1/3] Revert "Improve choice rule generation"
|
|
|
c44fa3 |
|
|
|
c44fa3 |
This reverts commit 1da9bef88dd269055cbd7eda2f3572963d6d9b64.
|
|
|
c44fa3 |
---
|
|
|
c44fa3 |
src/rules.c | 169 ++++++++++++++++++++++++++++++++++++++-------------
|
|
|
c44fa3 |
src/solver.c | 45 --------------
|
|
|
c44fa3 |
2 files changed, 126 insertions(+), 88 deletions(-)
|
|
|
c44fa3 |
|
|
|
c44fa3 |
diff --git a/src/rules.c b/src/rules.c
|
|
|
c44fa3 |
index 2c56959c..a260c2de 100644
|
|
|
c44fa3 |
--- a/src/rules.c
|
|
|
c44fa3 |
+++ b/src/rules.c
|
|
|
c44fa3 |
@@ -3255,12 +3255,6 @@ solver_rule2rules(Solver *solv, Id rid, Queue *q, int recursive)
|
|
|
c44fa3 |
|
|
|
c44fa3 |
|
|
|
c44fa3 |
/* check if the newest versions of pi still provides the dependency we're looking for */
|
|
|
c44fa3 |
-/* pi: installed package
|
|
|
c44fa3 |
- * r: rule for the dependency
|
|
|
c44fa3 |
- * m: map with all positive elements of r
|
|
|
c44fa3 |
- * return 0: at least one provider
|
|
|
c44fa3 |
- * return 1: the newest versions do not provide the dependency
|
|
|
c44fa3 |
- */
|
|
|
c44fa3 |
static int
|
|
|
c44fa3 |
solver_choicerulecheck(Solver *solv, Id pi, Rule *r, Map *m, Queue *q)
|
|
|
c44fa3 |
{
|
|
|
c44fa3 |
@@ -3309,6 +3303,94 @@ solver_choicerulecheck(Solver *solv, Id pi, Rule *r, Map *m, Queue *q)
|
|
|
c44fa3 |
return 1; /* none of the new packages provided it */
|
|
|
c44fa3 |
}
|
|
|
c44fa3 |
|
|
|
c44fa3 |
+static int
|
|
|
c44fa3 |
+solver_choicerulecheck2(Solver *solv, Id pi, Id pt, Queue *q)
|
|
|
c44fa3 |
+{
|
|
|
c44fa3 |
+ Pool *pool = solv->pool;
|
|
|
c44fa3 |
+ Rule *ur;
|
|
|
c44fa3 |
+ Id p, pp;
|
|
|
c44fa3 |
+ int i;
|
|
|
c44fa3 |
+
|
|
|
c44fa3 |
+ if (!q->count || q->elements[0] != pi)
|
|
|
c44fa3 |
+ {
|
|
|
c44fa3 |
+ if (q->count)
|
|
|
c44fa3 |
+ queue_empty(q);
|
|
|
c44fa3 |
+ ur = solv->rules + solv->updaterules + (pi - pool->installed->start);
|
|
|
c44fa3 |
+ if (!ur->p)
|
|
|
c44fa3 |
+ ur = solv->rules + solv->featurerules + (pi - pool->installed->start);
|
|
|
c44fa3 |
+ if (!ur->p)
|
|
|
c44fa3 |
+ return 1; /* orphaned, thus newest */
|
|
|
c44fa3 |
+ queue_push2(q, pi, 0);
|
|
|
c44fa3 |
+ FOR_RULELITERALS(p, pp, ur)
|
|
|
c44fa3 |
+ if (p > 0 && p != pi)
|
|
|
c44fa3 |
+ queue_push(q, p);
|
|
|
c44fa3 |
+ queue_push(q, pi);
|
|
|
c44fa3 |
+ }
|
|
|
c44fa3 |
+ if (q->count <= 3)
|
|
|
c44fa3 |
+ return q->count == 3 && q->elements[2] == pt ? 1 : 0;
|
|
|
c44fa3 |
+ if (!q->elements[1])
|
|
|
c44fa3 |
+ {
|
|
|
c44fa3 |
+ queue_deleten(q, 0, 2);
|
|
|
c44fa3 |
+ policy_filter_unwanted(solv, q, POLICY_MODE_CHOOSE);
|
|
|
c44fa3 |
+ queue_unshift(q, 1); /* filter mark */
|
|
|
c44fa3 |
+ queue_unshift(q, pi);
|
|
|
c44fa3 |
+ }
|
|
|
c44fa3 |
+ for (i = 2; i < q->count; i++)
|
|
|
c44fa3 |
+ if (q->elements[i] == pt)
|
|
|
c44fa3 |
+ return 1;
|
|
|
c44fa3 |
+ return 0; /* not newest */
|
|
|
c44fa3 |
+}
|
|
|
c44fa3 |
+
|
|
|
c44fa3 |
+static int
|
|
|
c44fa3 |
+solver_choicerulecheck3(Solver *solv, Id pt, Queue *q)
|
|
|
c44fa3 |
+{
|
|
|
c44fa3 |
+ Pool *pool = solv->pool;
|
|
|
c44fa3 |
+ Id p, pp;
|
|
|
c44fa3 |
+ int i;
|
|
|
c44fa3 |
+
|
|
|
c44fa3 |
+ if (!q->count || q->elements[0] != pt)
|
|
|
c44fa3 |
+ {
|
|
|
c44fa3 |
+ Solvable *s = pool->solvables + pt;
|
|
|
c44fa3 |
+ if (q->count)
|
|
|
c44fa3 |
+ queue_empty(q);
|
|
|
c44fa3 |
+ /* no installed package, so check all with same name */
|
|
|
c44fa3 |
+ queue_push2(q, pt, 0);
|
|
|
c44fa3 |
+ FOR_PROVIDES(p, pp, s->name)
|
|
|
c44fa3 |
+ if (pool->solvables[p].name == s->name && p != pt)
|
|
|
c44fa3 |
+ queue_push(q, p);
|
|
|
c44fa3 |
+ queue_push(q, pt);
|
|
|
c44fa3 |
+ }
|
|
|
c44fa3 |
+ if (q->count <= 3)
|
|
|
c44fa3 |
+ return q->count == 3 && q->elements[2] == pt ? 1 : 0;
|
|
|
c44fa3 |
+ if (!q->elements[1])
|
|
|
c44fa3 |
+ {
|
|
|
c44fa3 |
+ queue_deleten(q, 0, 2);
|
|
|
c44fa3 |
+ policy_filter_unwanted(solv, q, POLICY_MODE_CHOOSE);
|
|
|
c44fa3 |
+ queue_unshift(q, 1); /* filter mark */
|
|
|
c44fa3 |
+ queue_unshift(q, pt);
|
|
|
c44fa3 |
+ }
|
|
|
c44fa3 |
+ for (i = 2; i < q->count; i++)
|
|
|
c44fa3 |
+ if (q->elements[i] == pt)
|
|
|
c44fa3 |
+ return 1;
|
|
|
c44fa3 |
+ return 0; /* not newest */
|
|
|
c44fa3 |
+}
|
|
|
c44fa3 |
+
|
|
|
c44fa3 |
+static inline void
|
|
|
c44fa3 |
+queue_removeelement(Queue *q, Id el)
|
|
|
c44fa3 |
+{
|
|
|
c44fa3 |
+ int i, j;
|
|
|
c44fa3 |
+ for (i = 0; i < q->count; i++)
|
|
|
c44fa3 |
+ if (q->elements[i] == el)
|
|
|
c44fa3 |
+ break;
|
|
|
c44fa3 |
+ if (i < q->count)
|
|
|
c44fa3 |
+ {
|
|
|
c44fa3 |
+ for (j = i++; i < q->count; i++)
|
|
|
c44fa3 |
+ if (q->elements[i] != el)
|
|
|
c44fa3 |
+ q->elements[j++] = q->elements[i];
|
|
|
c44fa3 |
+ queue_truncate(q, j);
|
|
|
c44fa3 |
+ }
|
|
|
c44fa3 |
+}
|
|
|
c44fa3 |
+
|
|
|
c44fa3 |
static Id
|
|
|
c44fa3 |
choicerule_find_installed(Pool *pool, Id p)
|
|
|
c44fa3 |
{
|
|
|
c44fa3 |
@@ -3357,14 +3439,14 @@ solver_addchoicerules(Solver *solv)
|
|
|
c44fa3 |
Pool *pool = solv->pool;
|
|
|
c44fa3 |
Map m, mneg;
|
|
|
c44fa3 |
Rule *r;
|
|
|
c44fa3 |
- Queue q, qi, qcheck, infoq;
|
|
|
c44fa3 |
+ Queue q, qi, qcheck, qcheck2, infoq;
|
|
|
c44fa3 |
int i, j, rid, havechoice, negcnt;
|
|
|
c44fa3 |
Id p, d, pp, p2;
|
|
|
c44fa3 |
Solvable *s;
|
|
|
c44fa3 |
Id lastaddedp, lastaddedd;
|
|
|
c44fa3 |
int lastaddedcnt;
|
|
|
c44fa3 |
unsigned int now;
|
|
|
c44fa3 |
- int isinstalled;
|
|
|
c44fa3 |
+ int isnewest = 0;
|
|
|
c44fa3 |
|
|
|
c44fa3 |
solv->choicerules = solv->nrules;
|
|
|
c44fa3 |
if (!pool->installed)
|
|
|
c44fa3 |
@@ -3376,6 +3458,7 @@ solver_addchoicerules(Solver *solv)
|
|
|
c44fa3 |
queue_init(&q);
|
|
|
c44fa3 |
queue_init(&qi);
|
|
|
c44fa3 |
queue_init(&qcheck);
|
|
|
c44fa3 |
+ queue_init(&qcheck2);
|
|
|
c44fa3 |
queue_init(&infoq);
|
|
|
c44fa3 |
map_init(&m, pool->nsolvables);
|
|
|
c44fa3 |
map_init(&mneg, pool->nsolvables);
|
|
|
c44fa3 |
@@ -3395,28 +3478,20 @@ solver_addchoicerules(Solver *solv)
|
|
|
c44fa3 |
if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 <= 0))
|
|
|
c44fa3 |
continue; /* only look at requires rules */
|
|
|
c44fa3 |
/* solver_printrule(solv, SOLV_DEBUG_RESULT, r); */
|
|
|
c44fa3 |
+ queue_empty(&q);
|
|
|
c44fa3 |
queue_empty(&qi);
|
|
|
c44fa3 |
havechoice = 0;
|
|
|
c44fa3 |
- isinstalled = 0;
|
|
|
c44fa3 |
FOR_RULELITERALS(p, pp, r)
|
|
|
c44fa3 |
{
|
|
|
c44fa3 |
if (p < 0)
|
|
|
c44fa3 |
- {
|
|
|
c44fa3 |
- Solvable *s = pool->solvables - p;
|
|
|
c44fa3 |
- p2 = s->repo == pool->installed ? -p : 0;
|
|
|
c44fa3 |
- if (p2)
|
|
|
c44fa3 |
- {
|
|
|
c44fa3 |
- if (!(solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, p2 - solv->installed->start))))
|
|
|
c44fa3 |
- isinstalled = 1;
|
|
|
c44fa3 |
- }
|
|
|
c44fa3 |
- continue;
|
|
|
c44fa3 |
- }
|
|
|
c44fa3 |
+ continue;
|
|
|
c44fa3 |
s = pool->solvables + p;
|
|
|
c44fa3 |
if (!s->repo)
|
|
|
c44fa3 |
continue;
|
|
|
c44fa3 |
if (s->repo == pool->installed)
|
|
|
c44fa3 |
{
|
|
|
c44fa3 |
queue_push2(&qi, p, p);
|
|
|
c44fa3 |
+ queue_push(&q, p);
|
|
|
c44fa3 |
continue;
|
|
|
c44fa3 |
}
|
|
|
c44fa3 |
/* find an installed package p2 that we can update/downgrade to p */
|
|
|
c44fa3 |
@@ -3428,6 +3503,7 @@ solver_addchoicerules(Solver *solv)
|
|
|
c44fa3 |
if (policy_is_illegal(solv, pool->solvables + p2, s, 0))
|
|
|
c44fa3 |
continue;
|
|
|
c44fa3 |
queue_push2(&qi, p2, p);
|
|
|
c44fa3 |
+ queue_push(&q, p);
|
|
|
c44fa3 |
continue;
|
|
|
c44fa3 |
}
|
|
|
c44fa3 |
/* package p is independent of the installed ones */
|
|
|
c44fa3 |
@@ -3436,31 +3512,47 @@ solver_addchoicerules(Solver *solv)
|
|
|
c44fa3 |
#if 0
|
|
|
c44fa3 |
printf("havechoice: %d qcount %d qicount %d\n", havechoice, q.count, qi.count);
|
|
|
c44fa3 |
#endif
|
|
|
c44fa3 |
- if (!havechoice || !qi.count)
|
|
|
c44fa3 |
+ if (!havechoice || !q.count || !qi.count)
|
|
|
c44fa3 |
continue; /* no choice */
|
|
|
c44fa3 |
|
|
|
c44fa3 |
FOR_RULELITERALS(p, pp, r)
|
|
|
c44fa3 |
if (p > 0)
|
|
|
c44fa3 |
MAPSET(&m, p);
|
|
|
c44fa3 |
|
|
|
c44fa3 |
- if (!isinstalled)
|
|
|
c44fa3 |
+ isnewest = 1;
|
|
|
c44fa3 |
+ FOR_RULELITERALS(p, pp, r)
|
|
|
c44fa3 |
{
|
|
|
c44fa3 |
- /* do extra checking for packages related to installed packages */
|
|
|
c44fa3 |
- for (i = j = 0; i < qi.count; i += 2)
|
|
|
c44fa3 |
+ if (p > 0)
|
|
|
c44fa3 |
+ break;
|
|
|
c44fa3 |
+ p2 = choicerule_find_installed(pool, -p);
|
|
|
c44fa3 |
+ if (p2 && !solver_choicerulecheck2(solv, p2, -p, &qcheck2))
|
|
|
c44fa3 |
{
|
|
|
c44fa3 |
- p2 = qi.elements[i];
|
|
|
c44fa3 |
- if (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, p2 - solv->installed->start)))
|
|
|
c44fa3 |
- {
|
|
|
c44fa3 |
- if (solver_choicerulecheck(solv, p2, r, &m, &qcheck))
|
|
|
c44fa3 |
- continue;
|
|
|
c44fa3 |
- }
|
|
|
c44fa3 |
- qi.elements[j++] = p2;
|
|
|
c44fa3 |
- qi.elements[j++] = qi.elements[i + 1];
|
|
|
c44fa3 |
+ isnewest = 0;
|
|
|
c44fa3 |
+ break;
|
|
|
c44fa3 |
+ }
|
|
|
c44fa3 |
+ if (!p2 && !solver_choicerulecheck3(solv, -p, &qcheck2))
|
|
|
c44fa3 |
+ {
|
|
|
c44fa3 |
+ isnewest = 0;
|
|
|
c44fa3 |
+ break;
|
|
|
c44fa3 |
}
|
|
|
c44fa3 |
- queue_truncate(&qi, j);
|
|
|
c44fa3 |
}
|
|
|
c44fa3 |
+ /* do extra checking */
|
|
|
c44fa3 |
+ for (i = j = 0; i < qi.count; i += 2)
|
|
|
c44fa3 |
+ {
|
|
|
c44fa3 |
+ p2 = qi.elements[i];
|
|
|
c44fa3 |
+ if (!p2)
|
|
|
c44fa3 |
+ continue;
|
|
|
c44fa3 |
+ if (isnewest && solver_choicerulecheck(solv, p2, r, &m, &qcheck))
|
|
|
c44fa3 |
+ {
|
|
|
c44fa3 |
+ /* oops, remove element p from q */
|
|
|
c44fa3 |
+ queue_removeelement(&q, qi.elements[i + 1]);
|
|
|
c44fa3 |
+ continue;
|
|
|
c44fa3 |
+ }
|
|
|
c44fa3 |
+ qi.elements[j++] = p2;
|
|
|
c44fa3 |
+ }
|
|
|
c44fa3 |
+ queue_truncate(&qi, j);
|
|
|
c44fa3 |
|
|
|
c44fa3 |
- if (!qi.count)
|
|
|
c44fa3 |
+ if (!q.count || !qi.count)
|
|
|
c44fa3 |
{
|
|
|
c44fa3 |
FOR_RULELITERALS(p, pp, r)
|
|
|
c44fa3 |
if (p > 0)
|
|
|
c44fa3 |
@@ -3468,15 +3560,6 @@ solver_addchoicerules(Solver *solv)
|
|
|
c44fa3 |
continue;
|
|
|
c44fa3 |
}
|
|
|
c44fa3 |
|
|
|
c44fa3 |
- queue_empty(&q);
|
|
|
c44fa3 |
- /* split q from qi */
|
|
|
c44fa3 |
- for (i = j = 0; i < qi.count; i += 2)
|
|
|
c44fa3 |
- {
|
|
|
c44fa3 |
- queue_push(&q, qi.elements[i + 1]);
|
|
|
c44fa3 |
- qi.elements[j++] = qi.elements[i];
|
|
|
c44fa3 |
- }
|
|
|
c44fa3 |
- queue_truncate(&qi, j);
|
|
|
c44fa3 |
-
|
|
|
c44fa3 |
|
|
|
c44fa3 |
/* now check the update rules of the installed package.
|
|
|
c44fa3 |
* if all packages of the update rules are contained in
|
|
|
c44fa3 |
@@ -3496,7 +3579,6 @@ solver_addchoicerules(Solver *solv)
|
|
|
c44fa3 |
break;
|
|
|
c44fa3 |
if (p)
|
|
|
c44fa3 |
break;
|
|
|
c44fa3 |
- /* speed improvement: only check each package once */
|
|
|
c44fa3 |
for (j = i + 1; j < qi.count; j++)
|
|
|
c44fa3 |
if (qi.elements[i] == qi.elements[j])
|
|
|
c44fa3 |
qi.elements[j] = 0;
|
|
|
c44fa3 |
@@ -3554,6 +3636,7 @@ solver_addchoicerules(Solver *solv)
|
|
|
c44fa3 |
queue_free(&q);
|
|
|
c44fa3 |
queue_free(&qi);
|
|
|
c44fa3 |
queue_free(&qcheck);
|
|
|
c44fa3 |
+ queue_free(&qcheck2);
|
|
|
c44fa3 |
queue_free(&infoq);
|
|
|
c44fa3 |
map_free(&m);
|
|
|
c44fa3 |
map_free(&mneg);
|
|
|
c44fa3 |
diff --git a/src/solver.c b/src/solver.c
|
|
|
c44fa3 |
index 28341d6d..23285ff2 100644
|
|
|
c44fa3 |
--- a/src/solver.c
|
|
|
c44fa3 |
+++ b/src/solver.c
|
|
|
c44fa3 |
@@ -2620,43 +2620,6 @@ resolve_orphaned(Solver *solv, int level, int disablerules, Queue *dq, int *reru
|
|
|
c44fa3 |
return level;
|
|
|
c44fa3 |
}
|
|
|
c44fa3 |
|
|
|
c44fa3 |
-int
|
|
|
c44fa3 |
-solver_check_unneeded_choicerules(Solver *solv)
|
|
|
c44fa3 |
-{
|
|
|
c44fa3 |
- Pool *pool = solv->pool;
|
|
|
c44fa3 |
- Rule *r, *or;
|
|
|
c44fa3 |
- Id p, pp, p2, pp2;
|
|
|
c44fa3 |
- int i;
|
|
|
c44fa3 |
- int havedisabled = 0;
|
|
|
c44fa3 |
-
|
|
|
c44fa3 |
- /* check if some choice rules could have been broken */
|
|
|
c44fa3 |
- for (i = solv->choicerules, r = solv->rules + i; i < solv->choicerules_end; i++, r++)
|
|
|
c44fa3 |
- {
|
|
|
c44fa3 |
- if (r->d < 0)
|
|
|
c44fa3 |
- continue;
|
|
|
c44fa3 |
- or = solv->rules + solv->choicerules_info[i - solv->choicerules];
|
|
|
c44fa3 |
- if (or->d < 0)
|
|
|
c44fa3 |
- continue;
|
|
|
c44fa3 |
- FOR_RULELITERALS(p, pp, or)
|
|
|
c44fa3 |
- {
|
|
|
c44fa3 |
- if (p < 0 || solv->decisionmap[p] <= 0)
|
|
|
c44fa3 |
- continue;
|
|
|
c44fa3 |
- FOR_RULELITERALS(p2, pp2, r)
|
|
|
c44fa3 |
- if (p2 == p)
|
|
|
c44fa3 |
- break;
|
|
|
c44fa3 |
- if (!p2)
|
|
|
c44fa3 |
- {
|
|
|
c44fa3 |
- /* did not find p in choice rule, disable it */
|
|
|
c44fa3 |
- POOL_DEBUG(SOLV_DEBUG_SOLVER, "disabling unneeded choice rule #%d\n", i);
|
|
|
c44fa3 |
- solver_disablechoicerules(solv, r);
|
|
|
c44fa3 |
- havedisabled = 1;
|
|
|
c44fa3 |
- break;
|
|
|
c44fa3 |
- }
|
|
|
c44fa3 |
- }
|
|
|
c44fa3 |
- }
|
|
|
c44fa3 |
- return havedisabled;
|
|
|
c44fa3 |
-}
|
|
|
c44fa3 |
-
|
|
|
c44fa3 |
/*-------------------------------------------------------------------
|
|
|
c44fa3 |
*
|
|
|
c44fa3 |
* solver_run_sat
|
|
|
c44fa3 |
@@ -2842,14 +2805,6 @@ solver_run_sat(Solver *solv, int disablerules, int doweak)
|
|
|
c44fa3 |
continue;
|
|
|
c44fa3 |
}
|
|
|
c44fa3 |
|
|
|
c44fa3 |
- if (solv->choicerules != solv->choicerules_end && solver_check_unneeded_choicerules(solv))
|
|
|
c44fa3 |
- {
|
|
|
c44fa3 |
- POOL_DEBUG(SOLV_DEBUG_SOLVER, "did choice rule minimization, rerunning solver\n");
|
|
|
c44fa3 |
- solver_reset(solv);
|
|
|
c44fa3 |
- level = 0; /* restart from scratch */
|
|
|
c44fa3 |
- continue;
|
|
|
c44fa3 |
- }
|
|
|
c44fa3 |
-
|
|
|
c44fa3 |
if (solv->solution_callback)
|
|
|
c44fa3 |
{
|
|
|
c44fa3 |
solv->solution_callback(solv, solv->solution_callback_data);
|
|
|
c44fa3 |
--
|
|
|
c44fa3 |
2.38.1
|
|
|
c44fa3 |
|