Skip to content

Commit 0c8420e

Browse files
committed
Docs
1 parent 2979a54 commit 0c8420e

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/function.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,13 @@ where
275275
.unwrap_or(empty_cycle_heads())
276276
}
277277

278-
/// Attempts to claim `key_index`, returning `false` if a cycle occurs.
278+
/// Attempts to claim `key_index` without blocking.
279+
///
280+
/// * [`WaitForResult::Running`] if the `key_index` is running on another thread. It's up to the caller to block on the other thread
281+
/// to wait until the result becomes available.
282+
/// * [`WaitForResult::Available`] It is (or at least was) possible to claim the `key_index`
283+
/// * [`WaitResult::Cycle`] Claiming the `key_index` results in a cycle because it's on the current's thread query stack or
284+
/// running on another thread that is blocked on this thread.
279285
fn wait_for<'me>(&'me self, zalsa: &'me Zalsa, key_index: Id) -> WaitForResult<'me> {
280286
match self.sync_table.try_claim(zalsa, key_index) {
281287
ClaimResult::Running(blocked_on) => WaitForResult::Running(blocked_on),

src/function/memo.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,11 @@ impl<'a> TryClaimCycleHeadsIter<'a> {
366366
}
367367

368368
fn queue_ingredient_heads(&mut self, ingredient: &dyn Ingredient, key: Id) {
369-
// Recursively wait for all cycle heads that this head depends on.
370-
// This is normally not necessary, because cycle heads are transitively added
371-
// as query dependencies (they aggregate). The exception to this are queries
372-
// that depend on a fixpoint initial value. They only depend on the fixpoint initial
373-
// value but not on its dependencies because they aren't known yet. They're only known
374-
// once the cycle completes but the cycle heads of the queries don't get updated.
375-
// Because of that, recurse here to collect all cycle heads.
376-
// This also ensures that if a query added new cycle heads, that they are awaited too.
369+
// Recursively wait for all cycle heads that this head depends on. It's important
370+
// that we fetch those from the updated memo because the cycle heads can change
371+
// between iterations and new cycle heads can be added if a query depeonds on
372+
// some cycle heads depending on a specific condition being met
373+
// (`a` calls `b` and `c` in iteration 0 but `c` and `d` in iteration 1 or later).
377374
// IMPORTANT: It's critical that we get the cycle head from the latest memo
378375
// here, in case the memo has become part of another cycle (we need to block on that too!).
379376
self.queue.extend(

src/ingredient.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,13 @@ pub trait Ingredient: Any + std::fmt::Debug + Send + Sync {
8888
}
8989

9090
/// Invoked when the current thread needs to wait for a result for the given `key_index`.
91+
/// This call doesn't block the current thread. Instead, it's up to the caller to block
92+
/// in case `key_index` is [running](`WaitForResult::Running`) on another thread.
9193
///
92-
/// A return value of `true` indicates that a result is now available. A return value of
93-
/// `false` means that a cycle was encountered; the waited-on query is either already claimed
94+
/// A return value of [`WaitForResult::Available`] indicates that a result is now available.
95+
/// A return value of [`WaitForResult::Running`] indicates that `key_index` is currently running
96+
/// on an other thread, it's up to caller to block until the result becomes available if desired.
97+
/// A return value of [`WaitForResult::Cycle`] means that a cycle was encountered; the waited-on query is either already claimed
9498
/// by the current thread, or by a thread waiting on the current thread.
9599
fn wait_for<'me>(&'me self, zalsa: &'me Zalsa, key_index: Id) -> WaitForResult<'me> {
96100
_ = (zalsa, key_index);

0 commit comments

Comments
 (0)