Skip to content

Commit 2bb393d

Browse files
committed
make all Cycle fields private and provide public accessor methods
1 parent f0a0087 commit 2bb393d

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

benches/dataflow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn def_cycle_recover(
8181
value: Type,
8282
_def: Definition,
8383
) -> Type {
84-
cycle_recover(value, cycle.iteration)
84+
cycle_recover(value, cycle.iteration())
8585
}
8686

8787
fn use_cycle_initial(_db: &dyn Db, _id: salsa::Id, _use: Use) -> Type {
@@ -95,7 +95,7 @@ fn use_cycle_recover(
9595
value: Type,
9696
_use: Use,
9797
) -> Type {
98-
cycle_recover(value, cycle.iteration)
98+
cycle_recover(value, cycle.iteration())
9999
}
100100

101101
fn cycle_recover(value: Type, count: u32) -> Type {

src/cycle.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,16 +469,34 @@ impl Iterator for CycleHeadIdsIterator<'_> {
469469
}
470470

471471
/// The context that the cycle recovery function receives when a query cycle occurs.
472-
#[derive(Clone)]
473472
pub struct Cycle<'a> {
474473
/// An iterator that outputs the [`Id`]s of the current cycle heads.
475-
/// This will always contain the [`Id`] of the query being processed by the current cycle recovery function,
476-
/// but its position will depend on the query execution order.
477-
pub head_ids: CycleHeadIdsIterator<'a>,
474+
/// This always contains the [`Id`] of the current query but it can contain additional cycle head [`Id`]s
475+
/// if this query is nested in an outer cycle or if it has nested cycles.
476+
pub(crate) head_ids: CycleHeadIdsIterator<'a>,
478477
/// The [`Id`] of the query that the current cycle recovery function is processing.
479-
pub id: Id,
478+
pub(crate) id: Id,
480479
/// The counter of the current fixed point iteration.
481-
pub iteration: u32,
480+
pub(crate) iteration: u32,
481+
}
482+
483+
impl Cycle<'_> {
484+
/// An iterator that outputs the [`Id`]s of the current cycle heads.
485+
/// This always contains the [`Id`] of the current query but it can contain additional cycle head [`Id`]s
486+
/// if this query is nested in an outer cycle or if it has nested cycles.
487+
pub fn head_ids(&self) -> CycleHeadIdsIterator<'_> {
488+
self.head_ids.clone()
489+
}
490+
491+
/// The [`Id`] of the query that the current cycle recovery function is processing.
492+
pub fn id(&self) -> Id {
493+
self.id
494+
}
495+
496+
/// The counter of the current fixed point iteration.
497+
pub fn iteration(&self) -> u32 {
498+
self.iteration
499+
}
482500
}
483501

484502
#[derive(Debug)]

tests/cycle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn cycle_recover(
137137
.is_some_and(|val| val <= MIN_VALUE || val >= MAX_VALUE)
138138
{
139139
Value::OutOfBounds
140-
} else if cycle.iteration > MAX_ITERATIONS {
140+
} else if cycle.iteration() > MAX_ITERATIONS {
141141
Value::TooManyIterations
142142
} else {
143143
value

tests/dataflow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn def_cycle_recover(
8585
if &value == last_provisional_value {
8686
value
8787
} else {
88-
cycle_recover(value, cycle.iteration)
88+
cycle_recover(value, cycle.iteration())
8989
}
9090
}
9191

@@ -103,7 +103,7 @@ fn use_cycle_recover(
103103
if &value == last_provisional_value {
104104
value
105105
} else {
106-
cycle_recover(value, cycle.iteration)
106+
cycle_recover(value, cycle.iteration())
107107
}
108108
}
109109

0 commit comments

Comments
 (0)