MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / CheckedRecursion

Interface CheckedRecursion

src/ore/src/stack.rs:178–216  ·  view source on GitHub ↗

A trait for types which support bounded recursion to prevent stack overflow. The rather odd design of this trait allows checked recursion to be added to existing mutually recursive functions without threading an explicit `depth: &mut usize` parameter through each function. As long as there is an existing context structure, or if the mutually recursive functions are methods on a context structure,

Source from the content-addressed store, hash-verified

176/// }
177/// ```
178pub trait CheckedRecursion {
179 /// Extracts a reference to the recursion guard embedded within the type.
180 fn recursion_guard(&self) -> &RecursionGuard;
181
182 /// Checks whether it is safe to recur and calls `f` if so.
183 ///
184 /// If the recursion limit for the recursion guard returned by
185 /// [`CheckedRecursion::recursion_guard`] has been reached, returns a
186 /// `RecursionLimitError`. Otherwise, it will call `f`, possibly growing the
187 /// stack if necessary.
188 ///
189 /// Calls to this function must be manually inserted at any point that
190 /// mutual recursion occurs.
191 #[inline(always)]
192 fn checked_recur<F, T, E>(&self, f: F) -> Result<T, E>
193 where
194 F: FnOnce(&Self) -> Result<T, E>,
195 E: From<RecursionLimitError>,
196 {
197 self.recursion_guard().descend()?;
198 let out = maybe_grow(|| f(self));
199 self.recursion_guard().ascend();
200 out
201 }
202
203 /// Like [`CheckedRecursion::checked_recur`], but operates on a mutable
204 /// reference to `Self`.
205 #[inline(always)]
206 fn checked_recur_mut<F, T, E>(&mut self, f: F) -> Result<T, E>
207 where
208 F: FnOnce(&mut Self) -> Result<T, E>,
209 E: From<RecursionLimitError>,
210 {
211 self.recursion_guard().descend()?;
212 let out = maybe_grow(|| f(self));
213 self.recursion_guard().ascend();
214 out
215 }
216}
217
218/// Tracks recursion depth.
219///

Callers 16

apply_recMethod · 0.80
plan_exprFunction · 0.80
typecheckMethod · 0.80
typecheck_scalarMethod · 0.80
typecheck_aggregateMethod · 0.80
actionMethod · 0.80
visit_internalMethod · 0.80
plan_queryFunction · 0.80
plan_nested_queryFunction · 0.80
plan_set_exprFunction · 0.80

Implementers 15

transform_ast.rssrc/sql/src/plan/transform_ast.rs
query.rssrc/sql/src/plan/query.rs
stack.rssrc/ore/src/stack.rs
dataflows.rssrc/adapter/src/optimize/dataflows.rs
parser.rssrc/sql-parser/src/parser.rs
typecheck.rssrc/transform/src/typecheck.rs
redundant_join.rssrc/transform/src/redundant_join.rs
literal_lifting.rssrc/transform/src/literal_lifting.rs
dataflow.rssrc/transform/src/dataflow.rs
non_null_requirements.rssrc/transform/src/non_null_requirement
predicate_pushdown.rssrc/transform/src/predicate_pushdown.r
column_knowledge.rssrc/transform/src/column_knowledge.rs

Calls

no outgoing calls

Tested by

no test coverage detected