diff --git a/turbopack/crates/turbo-tasks-memory/src/task.rs b/turbopack/crates/turbo-tasks-memory/src/task.rs index 5d2024dfbef37a..3689b75a872f8f 100644 --- a/turbopack/crates/turbo-tasks-memory/src/task.rs +++ b/turbopack/crates/turbo-tasks-memory/src/task.rs @@ -598,39 +598,7 @@ impl Task { match ty { TaskTypeForDescription::Root => format!("[{}] root", id), TaskTypeForDescription::Once => format!("[{}] once", id), - TaskTypeForDescription::Persistent(ty) => match &***ty { - CachedTaskType::Native { - fn_type: native_fn, - this: _, - arg: _, - } => { - format!("[{}] {}", id, registry::get_function(*native_fn).name) - } - CachedTaskType::ResolveNative { - fn_type: native_fn, - this: _, - arg: _, - } => { - format!( - "[{}] [resolve] {}", - id, - registry::get_function(*native_fn).name - ) - } - CachedTaskType::ResolveTrait { - trait_type, - method_name: fn_name, - this: _, - arg: _, - } => { - format!( - "[{}] [resolve trait] {} in trait {}", - id, - fn_name, - registry::get_trait(*trait_type).name - ) - } - }, + TaskTypeForDescription::Persistent(ty) => format!("[{id}] {ty}"), } } diff --git a/turbopack/crates/turbo-tasks/src/backend.rs b/turbopack/crates/turbo-tasks/src/backend.rs index a272bbad83572e..0da142efca47d5 100644 --- a/turbopack/crates/turbo-tasks/src/backend.rs +++ b/turbopack/crates/turbo-tasks/src/backend.rs @@ -85,8 +85,50 @@ pub enum CachedTaskType { }, } +impl CachedTaskType { + /// Returns the name of the function in the code. Trait methods are + /// formatted as `TraitName::method_name`. + pub fn get_name(&self) -> Cow<'static, str> { + match self { + Self::Native { + fn_type: native_fn, + this: _, + arg: _, + } + | Self::ResolveNative { + fn_type: native_fn, + this: _, + arg: _, + } => Cow::Borrowed(®istry::get_function(*native_fn).name), + Self::ResolveTrait { + trait_type: trait_id, + method_name: fn_name, + this: _, + arg: _, + } => format!("{}::{}", registry::get_trait(*trait_id).name, fn_name).into(), + } + } + + pub fn try_get_function_id(&self) -> Option { + match self { + Self::Native { fn_type, .. } | Self::ResolveNative { fn_type, .. } => Some(*fn_type), + Self::ResolveTrait { .. } => None, + } + } +} + +/// Provides a description of the task, including the function name. impl Display for CachedTaskType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + CachedTaskType::Native { .. } => {} + CachedTaskType::ResolveNative { .. } => { + f.write_str("[resolve] ")?; + } + CachedTaskType::ResolveTrait { .. } => { + f.write_str("[resolve trait] ")?; + } + } f.write_str(&self.get_name()) } } @@ -284,41 +326,6 @@ mod ser { } } -impl CachedTaskType { - /// Returns the name of the function in the code. Trait methods are - /// formatted as `TraitName::method_name`. - /// - /// Equivalent to [`ToString::to_string`], but potentially more efficient as - /// it can return a `&'static str` in many cases. - pub fn get_name(&self) -> Cow<'static, str> { - match self { - Self::Native { - fn_type: native_fn, - this: _, - arg: _, - } - | Self::ResolveNative { - fn_type: native_fn, - this: _, - arg: _, - } => Cow::Borrowed(®istry::get_function(*native_fn).name), - Self::ResolveTrait { - trait_type: trait_id, - method_name: fn_name, - this: _, - arg: _, - } => format!("{}::{}", registry::get_trait(*trait_id).name, fn_name).into(), - } - } - - pub fn try_get_function_id(&self) -> Option { - match self { - Self::Native { fn_type, .. } | Self::ResolveNative { fn_type, .. } => Some(*fn_type), - Self::ResolveTrait { .. } => None, - } - } -} - pub struct TaskExecutionSpec<'a> { pub future: Pin> + Send + 'a>>, pub span: Span,