38
38
where
39
39
K :: Value : ut:: UnifyValue < Error = ut:: NoError > ,
40
40
{
41
- if !self . unify_log . get ( vid) . is_empty ( )
42
- || self . reference_counts . get ( vid) . map_or ( false , |c| * c != 0 )
43
- {
41
+ if self . needs_log ( vid) {
42
+ warn ! ( "ModifiedSet {:?} => {:?}" , vid, ty) ;
44
43
self . modified_set . set ( vid) ;
45
44
}
46
45
let vid = vid. into ( ) ;
@@ -60,31 +59,37 @@ where
60
59
value : K :: Value ,
61
60
) -> Result < ( ) , <K :: Value as ut:: UnifyValue >:: Error > {
62
61
let vid = self . find ( vid) . into ( ) ;
63
- if !self . unify_log . get ( vid) . is_empty ( )
64
- || self . reference_counts . get ( vid) . map_or ( false , |c| * c != 0 )
65
- {
62
+ if self . needs_log ( vid) {
66
63
self . modified_set . set ( vid) ;
67
64
}
68
65
self . relations . unify_var_value ( vid, value)
69
66
}
70
67
71
68
pub fn unify_var_var ( & mut self , a : I , b : I ) -> Result < ( ) , <K :: Value as ut:: UnifyValue >:: Error > {
72
- let a_root = self . relations . find ( a) ;
73
- let b_root = self . relations . find ( b) ;
74
- if a_root == b_root {
69
+ let a = self . relations . find ( a) ;
70
+ let b = self . relations . find ( b) ;
71
+ if a == b {
75
72
return Ok ( ( ) ) ;
76
73
}
77
74
78
- self . relations . unify_var_var ( a_root , b_root ) ?;
75
+ self . relations . unify_var_var ( a , b ) ?;
79
76
80
- if a_root == self . relations . find ( a_root) {
81
- self . unify_log . unify ( a_root. into ( ) , b_root. into ( ) ) ;
82
- } else {
83
- self . unify_log . unify ( b_root. into ( ) , a_root. into ( ) ) ;
77
+ if self . needs_log ( a. into ( ) ) || self . needs_log ( b. into ( ) ) {
78
+ warn ! ( "Log: {:?} {:?} => {:?}" , a, b, I :: from( self . relations. find( a) ) ) ;
79
+ if a == self . relations . find ( a) {
80
+ self . unify_log . unify ( a. into ( ) , b. into ( ) ) ;
81
+ } else {
82
+ self . unify_log . unify ( b. into ( ) , a. into ( ) ) ;
83
+ }
84
84
}
85
85
Ok ( ( ) )
86
86
}
87
87
88
+ fn needs_log ( & self , vid : I ) -> bool {
89
+ !self . unify_log . get ( vid) . is_empty ( )
90
+ || self . reference_counts . get ( vid) . map_or ( false , |c| * c != 0 )
91
+ }
92
+
88
93
pub fn union_value ( & mut self , vid : I , value : K :: Value )
89
94
where
90
95
K :: Value : ut:: UnifyValue < Error = ut:: NoError > ,
@@ -145,6 +150,7 @@ where
145
150
}
146
151
147
152
pub fn watch_variable ( & mut self , index : I ) {
153
+ debug_assert ! ( index == self . relations. find( index) . into( ) ) ;
148
154
self . reference_counts . ensure_contains_elem ( index, || 0 ) ;
149
155
self . reference_counts [ index] += 1 ;
150
156
}
0 commit comments