@@ -9,13 +9,11 @@ use crate::{PlanCallbacks, path_env::prepend_path_env};
99
1010#[ derive( Debug , thiserror:: Error ) ]
1111#[ error(
12- "Detected a cycle in task call stack, from the {0}th frame to the end " , cycle_start + 1
12+ "Detected a recursion in task call stack: the last frame calls the {0}th frame" , recursion_point + 1
1313) ]
14- pub struct TaskCycleError {
15- /// The index in `task_call_stack` where the cycle starts
16- ///
17- /// The cycle ends at the end of `task_call_stack`.
18- cycle_start : usize ,
14+ pub struct TaskRecursionError {
15+ /// The index in `task_call_stack` where the last frame recurses to.
16+ recursion_point : usize ,
1917}
2018
2119/// The context for planning an execution from a task.
@@ -93,12 +91,15 @@ impl<'a> PlanContext<'a> {
9391 }
9492 }
9593
96- /// Check if adding the given task node index would create a cycle in the call stack.
97- pub fn check_cycle ( & self , task_node_index : TaskNodeIndex ) -> Result < ( ) , TaskCycleError > {
98- if let Some ( cycle_start) =
94+ /// Check if adding the given task node index would create a recursion in the call stack.
95+ pub fn check_recursion (
96+ & self ,
97+ task_node_index : TaskNodeIndex ,
98+ ) -> Result < ( ) , TaskRecursionError > {
99+ if let Some ( recursion_start) =
99100 self . task_call_stack . iter ( ) . position ( |( idx, _) | * idx == task_node_index)
100101 {
101- return Err ( TaskCycleError { cycle_start } ) ;
102+ return Err ( TaskRecursionError { recursion_point : recursion_start } ) ;
102103 }
103104 Ok ( ( ) )
104105 }
@@ -139,49 +140,3 @@ impl<'a> PlanContext<'a> {
139140 }
140141 }
141142}
142- // pub fn enter_package(&mut self, package_path: Arc<AbsolutePath>) -> Result<PlanContext<'_>, PackageCycleError> {
143- // Ok(PlanContext {
144- // cwd: package_path,
145- // envs: Arc::clone(&self.envs),
146- // callbacks: self.callbacks,
147- // stack: self.stack,
148- // })
149- // }
150-
151- // /// Create a new context with new frame.
152- // ///
153- // /// Returns `None` if the new frame already exists in the stack (to prevent infinite recursion).
154- // pub fn with_new_frame<R>(
155- // &mut self,
156- // new_frame: PlanStackFrame,
157- // envs: impl Iterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>,
158- // cwd: Arc<AbsolutePath>,
159- // f: impl FnOnce(PlanContext<'_>) -> R,
160- // ) -> Option<R> {
161- // // IndexSet::insert returns `false` and doesn't touch the set if the item already exists.
162- // if !self.stack.insert(new_frame) {
163- // return None;
164- // }
165- // // Merge envs
166- // let mut new_envs: Option<HashMap<Arc<OsStr>, Arc<OsStr>>> = None;
167- // for (key, value) in envs {
168- // // Clone on write
169- // new_envs
170- // .get_or_insert_with(|| self.envs.as_ref().clone())
171- // .insert(Arc::from(key.as_ref()), Arc::from(value.as_ref()));
172- // }
173-
174- // let ret = f(PlanContext {
175- // cwd,
176- // envs: if let Some(new_envs) = new_envs {
177- // Arc::new(new_envs)
178- // } else {
179- // Arc::clone(&self.envs)
180- // },
181- // callbacks: self.callbacks,
182- // stack: self.stack,
183- // });
184- // self.stack.pop().expect("stack pop should succeed");
185- // Some(ret)
186- // }
187- // }
0 commit comments