1
+ use crate :: active_query:: CompletedQuery ;
1
2
use crate :: cycle:: { CycleRecoveryStrategy , IterationCount } ;
2
3
use crate :: function:: memo:: Memo ;
3
4
use crate :: function:: { Configuration , IngredientImpl } ;
4
5
use crate :: sync:: atomic:: { AtomicBool , Ordering } ;
5
6
use crate :: zalsa:: { MemoIngredientIndex , Zalsa , ZalsaDatabase } ;
6
- use crate :: zalsa_local:: { ActiveQueryGuard , QueryRevisions } ;
7
+ use crate :: zalsa_local:: ActiveQueryGuard ;
7
8
use crate :: { Event , EventKind , Id } ;
8
9
9
10
impl < C > IngredientImpl < C >
@@ -39,15 +40,15 @@ where
39
40
} ) ;
40
41
let memo_ingredient_index = self . memo_ingredient_index ( zalsa, id) ;
41
42
42
- let ( new_value, mut revisions ) = match C :: CYCLE_STRATEGY {
43
+ let ( new_value, mut completed_query ) = match C :: CYCLE_STRATEGY {
43
44
CycleRecoveryStrategy :: Panic => {
44
45
Self :: execute_query ( db, zalsa, active_query, opt_old_memo, id)
45
46
}
46
47
CycleRecoveryStrategy :: FallbackImmediate => {
47
- let ( mut new_value, mut revisions ) =
48
+ let ( mut new_value, mut completed_query ) =
48
49
Self :: execute_query ( db, zalsa, active_query, opt_old_memo, id) ;
49
50
50
- if let Some ( cycle_heads) = revisions. cycle_heads_mut ( ) {
51
+ if let Some ( cycle_heads) = completed_query . revisions . cycle_heads_mut ( ) {
51
52
// Did the new result we got depend on our own provisional value, in a cycle?
52
53
if cycle_heads. contains ( & database_key_index) {
53
54
// Ignore the computed value, leave the fallback value there.
@@ -73,14 +74,14 @@ where
73
74
. zalsa_local ( )
74
75
. push_query ( database_key_index, IterationCount :: initial ( ) ) ;
75
76
new_value = C :: cycle_initial ( db, C :: id_to_input ( zalsa, id) ) ;
76
- revisions = active_query. pop ( ) ;
77
+ completed_query = active_query. pop ( ) ;
77
78
// We need to set `cycle_heads` and `verified_final` because it needs to propagate to the callers.
78
79
// When verifying this, we will see we have fallback and mark ourselves verified.
79
- revisions. set_cycle_heads ( cycle_heads) ;
80
- revisions. verified_final = AtomicBool :: new ( false ) ;
80
+ completed_query . revisions . set_cycle_heads ( cycle_heads) ;
81
+ completed_query . revisions . verified_final = AtomicBool :: new ( false ) ;
81
82
}
82
83
83
- ( new_value, revisions )
84
+ ( new_value, completed_query )
84
85
}
85
86
CycleRecoveryStrategy :: Fixpoint => self . execute_maybe_iterate (
86
87
db,
@@ -97,16 +98,25 @@ where
97
98
// really change, even if some of its inputs have. So we can
98
99
// "backdate" its `changed_at` revision to be the same as the
99
100
// old value.
100
- self . backdate_if_appropriate ( old_memo, database_key_index, & mut revisions, & new_value) ;
101
+ self . backdate_if_appropriate (
102
+ old_memo,
103
+ database_key_index,
104
+ & mut completed_query. revisions ,
105
+ & new_value,
106
+ ) ;
101
107
102
108
// Diff the new outputs with the old, to discard any no-longer-emitted
103
109
// outputs and update the tracked struct IDs for seeding the next revision.
104
- self . diff_outputs ( zalsa, database_key_index, old_memo, & mut revisions ) ;
110
+ self . diff_outputs ( zalsa, database_key_index, old_memo, & completed_query ) ;
105
111
}
106
112
self . insert_memo (
107
113
zalsa,
108
114
id,
109
- Memo :: new ( Some ( new_value) , zalsa. current_revision ( ) , revisions) ,
115
+ Memo :: new (
116
+ Some ( new_value) ,
117
+ zalsa. current_revision ( ) ,
118
+ completed_query. revisions ,
119
+ ) ,
110
120
memo_ingredient_index,
111
121
)
112
122
}
@@ -120,7 +130,7 @@ where
120
130
zalsa : & ' db Zalsa ,
121
131
id : Id ,
122
132
memo_ingredient_index : MemoIngredientIndex ,
123
- ) -> ( C :: Output < ' db > , QueryRevisions ) {
133
+ ) -> ( C :: Output < ' db > , CompletedQuery ) {
124
134
let database_key_index = active_query. database_key_index ;
125
135
let mut iteration_count = IterationCount :: initial ( ) ;
126
136
let mut fell_back = false ;
@@ -131,11 +141,12 @@ where
131
141
let mut opt_last_provisional: Option < & Memo < ' db , C > > = None ;
132
142
loop {
133
143
let previous_memo = opt_last_provisional. or ( opt_old_memo) ;
134
- let ( mut new_value, mut revisions ) =
144
+ let ( mut new_value, mut completed_query ) =
135
145
Self :: execute_query ( db, zalsa, active_query, previous_memo, id) ;
136
146
137
147
// Did the new result we got depend on our own provisional value, in a cycle?
138
- if let Some ( cycle_heads) = revisions
148
+ if let Some ( cycle_heads) = completed_query
149
+ . revisions
139
150
. cycle_heads_mut ( )
140
151
. filter ( |cycle_heads| cycle_heads. contains ( & database_key_index) )
141
152
{
@@ -211,14 +222,21 @@ where
211
222
} )
212
223
} ) ;
213
224
cycle_heads. update_iteration_count ( database_key_index, iteration_count) ;
214
- revisions. update_iteration_count ( iteration_count) ;
225
+ completed_query
226
+ . revisions
227
+ . update_iteration_count ( iteration_count) ;
215
228
crate :: tracing:: debug!(
216
- "{database_key_index:?}: execute: iterate again, revisions: {revisions:#?}"
229
+ "{database_key_index:?}: execute: iterate again, revisions: {revisions:#?}" ,
230
+ revisions = & completed_query. revisions
217
231
) ;
218
232
opt_last_provisional = Some ( self . insert_memo (
219
233
zalsa,
220
234
id,
221
- Memo :: new ( Some ( new_value) , zalsa. current_revision ( ) , revisions) ,
235
+ Memo :: new (
236
+ Some ( new_value) ,
237
+ zalsa. current_revision ( ) ,
238
+ completed_query. revisions ,
239
+ ) ,
222
240
memo_ingredient_index,
223
241
) ) ;
224
242
@@ -235,15 +253,19 @@ where
235
253
236
254
if cycle_heads. is_empty ( ) {
237
255
// If there are no more cycle heads, we can mark this as verified.
238
- revisions. verified_final . store ( true , Ordering :: Relaxed ) ;
256
+ completed_query
257
+ . revisions
258
+ . verified_final
259
+ . store ( true , Ordering :: Relaxed ) ;
239
260
}
240
261
}
241
262
242
263
crate :: tracing:: debug!(
243
- "{database_key_index:?}: execute: result.revisions = {revisions:#?}"
264
+ "{database_key_index:?}: execute: result.revisions = {revisions:#?}" ,
265
+ revisions = & completed_query. revisions
244
266
) ;
245
267
246
- break ( new_value, revisions ) ;
268
+ break ( new_value, completed_query ) ;
247
269
}
248
270
}
249
271
@@ -254,7 +276,7 @@ where
254
276
active_query : ActiveQueryGuard < ' db > ,
255
277
opt_old_memo : Option < & Memo < ' db , C > > ,
256
278
id : Id ,
257
- ) -> ( C :: Output < ' db > , QueryRevisions ) {
279
+ ) -> ( C :: Output < ' db > , CompletedQuery ) {
258
280
if let Some ( old_memo) = opt_old_memo {
259
281
// If we already executed this query once, then use the tracked-struct ids from the
260
282
// previous execution as the starting point for the new one.
0 commit comments