@@ -2,7 +2,7 @@ use rustc_hash::FxHashMap;
2
2
use tracing:: debug;
3
3
4
4
use crate :: accumulator:: accumulated_map:: { AccumulatedMap , InputAccumulatedValues } ;
5
- use crate :: active_query:: ActiveQuery ;
5
+ use crate :: active_query:: QueryStack ;
6
6
use crate :: durability:: Durability ;
7
7
use crate :: key:: DatabaseKeyIndex ;
8
8
use crate :: key:: DependencyIndex ;
@@ -36,7 +36,7 @@ pub struct ZalsaLocal {
36
36
///
37
37
/// Unwinding note: pushes onto this vector must be popped -- even
38
38
/// during unwinding.
39
- query_stack : RefCell < Vec < ActiveQuery > > ,
39
+ query_stack : RefCell < QueryStack > ,
40
40
41
41
/// Stores the most recent page for a given ingredient.
42
42
/// This is thread-local to avoid contention.
@@ -46,7 +46,7 @@ pub struct ZalsaLocal {
46
46
impl ZalsaLocal {
47
47
pub ( crate ) fn new ( ) -> Self {
48
48
ZalsaLocal {
49
- query_stack : RefCell :: new ( vec ! [ ] ) ,
49
+ query_stack : RefCell :: new ( QueryStack :: default ( ) ) ,
50
50
most_recent_pages : RefCell :: new ( FxHashMap :: default ( ) ) ,
51
51
}
52
52
}
@@ -87,7 +87,7 @@ impl ZalsaLocal {
87
87
#[ inline]
88
88
pub ( crate ) fn push_query ( & self , database_key_index : DatabaseKeyIndex ) -> ActiveQueryGuard < ' _ > {
89
89
let mut query_stack = self . query_stack . borrow_mut ( ) ;
90
- query_stack. push ( ActiveQuery :: new ( database_key_index) ) ;
90
+ query_stack. push_new_query ( database_key_index) ;
91
91
ActiveQueryGuard {
92
92
local_state : self ,
93
93
database_key_index,
@@ -96,8 +96,8 @@ impl ZalsaLocal {
96
96
}
97
97
98
98
/// Executes a closure within the context of the current active query stacks.
99
- pub ( crate ) fn with_query_stack < R > ( & self , c : impl FnOnce ( & mut Vec < ActiveQuery > ) -> R ) -> R {
100
- c ( self . query_stack . borrow_mut ( ) . as_mut ( ) )
99
+ pub ( crate ) fn with_query_stack < R > ( & self , c : impl FnOnce ( & mut QueryStack ) -> R ) -> R {
100
+ c ( & mut self . query_stack . borrow_mut ( ) )
101
101
}
102
102
103
103
fn query_in_progress ( & self ) -> bool {
@@ -496,15 +496,15 @@ pub(crate) struct ActiveQueryGuard<'me> {
496
496
}
497
497
498
498
impl ActiveQueryGuard < ' _ > {
499
- fn pop_helper ( & self ) -> ActiveQuery {
499
+ fn pop_impl ( & self ) -> QueryRevisions {
500
500
self . local_state . with_query_stack ( |stack| {
501
501
// Sanity check: pushes and pops should be balanced.
502
502
assert_eq ! ( stack. len( ) , self . push_len) ;
503
503
debug_assert_eq ! (
504
504
stack. last( ) . unwrap( ) . database_key_index,
505
505
self . database_key_index
506
506
) ;
507
- stack. pop ( ) . unwrap ( )
507
+ stack. pop_into_revisions ( ) . unwrap ( )
508
508
} )
509
509
}
510
510
@@ -519,8 +519,8 @@ impl ActiveQueryGuard<'_> {
519
519
}
520
520
521
521
/// Invoked when the query has successfully completed execution.
522
- pub ( crate ) fn complete ( self ) -> ActiveQuery {
523
- let query = self . pop_helper ( ) ;
522
+ fn complete ( self ) -> QueryRevisions {
523
+ let query = self . pop_impl ( ) ;
524
524
std:: mem:: forget ( self ) ;
525
525
query
526
526
}
@@ -530,13 +530,7 @@ impl ActiveQueryGuard<'_> {
530
530
/// query's execution.
531
531
#[ inline]
532
532
pub ( crate ) fn pop ( self ) -> QueryRevisions {
533
- // Extract accumulated inputs.
534
- let popped_query = self . complete ( ) ;
535
-
536
- // If this frame were a cycle participant, it would have unwound.
537
- assert ! ( popped_query. cycle. is_none( ) ) ;
538
-
539
- popped_query. into_revisions ( )
533
+ self . complete ( )
540
534
}
541
535
542
536
/// If the active query is registered as a cycle participant, remove and
@@ -549,6 +543,6 @@ impl ActiveQueryGuard<'_> {
549
543
550
544
impl Drop for ActiveQueryGuard < ' _ > {
551
545
fn drop ( & mut self ) {
552
- self . pop_helper ( ) ;
546
+ self . pop_impl ( ) ;
553
547
}
554
548
}
0 commit comments