@@ -25,6 +25,10 @@ pub struct State<P: Package, V: Version> {
25
25
26
26
incompatibilities : Map < P , Vec < IncompId < P , V > > > ,
27
27
28
+ /// Store the ids of incompatibilities that are already contradicted
29
+ /// and will stay that way until the next conflict and backtrack is operated.
30
+ contradicted_incompatibilities : rustc_hash:: FxHashSet < IncompId < P , V > > ,
31
+
28
32
/// Partial solution.
29
33
/// TODO: remove pub.
30
34
pub partial_solution : PartialSolution < P , V > ,
@@ -52,6 +56,7 @@ impl<P: Package, V: Version> State<P, V> {
52
56
root_package,
53
57
root_version,
54
58
incompatibilities,
59
+ contradicted_incompatibilities : rustc_hash:: FxHashSet :: default ( ) ,
55
60
partial_solution : PartialSolution :: empty ( ) ,
56
61
incompatibility_store,
57
62
unit_propagation_buffer : vec ! [ ] ,
@@ -100,6 +105,9 @@ impl<P: Package, V: Version> State<P, V> {
100
105
let mut conflict_id = None ;
101
106
// We only care about incompatibilities if it contains the current package.
102
107
for & incompat_id in self . incompatibilities [ & current_package] . iter ( ) . rev ( ) {
108
+ if self . contradicted_incompatibilities . contains ( & incompat_id) {
109
+ continue ;
110
+ }
103
111
let current_incompat = & self . incompatibility_store [ incompat_id] ;
104
112
match self . partial_solution . relation ( current_incompat) {
105
113
// If the partial solution satisfies the incompatibility
@@ -116,6 +124,11 @@ impl<P: Package, V: Version> State<P, V> {
116
124
incompat_id,
117
125
& self . incompatibility_store ,
118
126
) ;
127
+ // With the partial solution updated, the incompatibility is now contradicted.
128
+ self . contradicted_incompatibilities . insert ( incompat_id) ;
129
+ }
130
+ Relation :: Contradicted ( _) => {
131
+ self . contradicted_incompatibilities . insert ( incompat_id) ;
119
132
}
120
133
_ => { }
121
134
}
@@ -130,6 +143,9 @@ impl<P: Package, V: Version> State<P, V> {
130
143
root_cause,
131
144
& self . incompatibility_store ,
132
145
) ;
146
+ // After conflict resolution and the partial solution update,
147
+ // the root cause incompatibility is now contradicted.
148
+ self . contradicted_incompatibilities . insert ( root_cause) ;
133
149
}
134
150
}
135
151
// If there are no more changed packages, unit propagation is done.
@@ -200,6 +216,7 @@ impl<P: Package, V: Version> State<P, V> {
200
216
) {
201
217
self . partial_solution
202
218
. backtrack ( decision_level, & self . incompatibility_store ) ;
219
+ self . contradicted_incompatibilities . clear ( ) ;
203
220
if incompat_changed {
204
221
self . merge_incompatibility ( incompat) ;
205
222
}
0 commit comments