Skip to content

Commit 6c41328

Browse files
committed
Test for nested mutable tracking
1 parent 017b4d6 commit 6c41328

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/tests.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,34 @@ impl Emitter {
407407
}
408408
}
409409

410+
/// Ensures that mutabled tracked calls in a nested function are properly
411+
/// replayed when there is a cache hit for a top-level function.
412+
#[test]
413+
#[serial]
414+
fn test_mutable_nested() {
415+
#[comemo::memoize]
416+
fn a(counter: TrackedMut<Counter>, _k: usize) {
417+
b(counter);
418+
}
419+
420+
#[comemo::memoize]
421+
fn b(mut counter: TrackedMut<Counter>) {
422+
counter.add(3);
423+
}
424+
425+
let mut c1 = Counter(0);
426+
a(c1.track_mut(), 0);
427+
assert_eq!(c1.0, 3);
428+
429+
let mut c2 = Counter(0);
430+
a(c2.track_mut(), 1);
431+
assert_eq!(c2.0, 3);
432+
433+
let mut c3 = Counter(0);
434+
a(c3.track_mut(), 1);
435+
assert_eq!(c3.0, 3);
436+
}
437+
410438
/// Ensures that we don't run into quadratic runtime during cache validation of
411439
/// many cache entries with the same key hash.
412440
#[test]

0 commit comments

Comments
 (0)