Skip to content

Commit e47e574

Browse files
committed
rename cycle to recursion
1 parent 6364036 commit e47e574

File tree

3 files changed

+16
-61
lines changed

3 files changed

+16
-61
lines changed

crates/vite_task_plan/src/context.rs

Lines changed: 11 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
// }

crates/vite_task_plan/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::env::JoinPathsError;
33
use vite_task_graph::display::TaskDisplay;
44

55
use crate::{
6-
context::{PlanContext, TaskCallStackDisplay, TaskCycleError},
6+
context::{PlanContext, TaskCallStackDisplay, TaskRecursionError},
77
envs::ResolveEnvError,
88
};
99

@@ -25,7 +25,7 @@ pub enum TaskPlanErrorKind {
2525
),
2626

2727
#[error(transparent)]
28-
TaskCycleDetected(#[from] TaskCycleError),
28+
TaskRecursionDetected(#[from] TaskRecursionError),
2929

3030
#[error("Invalid vite task command")]
3131
ParsePlanRequestError {

crates/vite_task_plan/src/plan.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ async fn plan_task_as_execution_node(
2424
task_node_index: TaskNodeIndex,
2525
mut context: PlanContext<'_>,
2626
) -> Result<TaskExecution, Error> {
27-
// Check for cycles in the task call stack.
27+
// Check for recursions in the task call stack.
2828
context
29-
.check_cycle(task_node_index)
30-
.map_err(TaskPlanErrorKind::TaskCycleDetected)
29+
.check_recursion(task_node_index)
30+
.map_err(TaskPlanErrorKind::TaskRecursionDetected)
3131
.with_plan_context(&context)?;
3232

3333
// Prepend {package_path}/node_modules/.bin to PATH

0 commit comments

Comments
 (0)