From 055f3a6b7256907376232beb53b2633226530297 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Mon, 6 Jan 2025 15:37:07 -0800 Subject: [PATCH] refactor(turbopack): Remove last known (non-test) usages of unresolved vcs in turbo_tasks::value! --- crates/next-api/src/app.rs | 4 ++-- turbopack/crates/turbopack/src/lib.rs | 10 +++++----- .../module_options/module_options_context.rs | 2 +- .../src/module_options/module_rule.rs | 4 ++-- .../src/module_options/rule_condition.rs | 6 +++--- .../src/module_options/transition_rule.rs | 19 +++++++++++-------- .../crates/turbopack/src/transition/mod.rs | 6 +++--- 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/crates/next-api/src/app.rs b/crates/next-api/src/app.rs index 92ca5b69cd80d..6227e55a1a545 100644 --- a/crates/next-api/src/app.rs +++ b/crates/next-api/src/app.rs @@ -358,7 +358,7 @@ impl AppProject { named_transitions: transitions, transition_rules: vec![TransitionRule::new( styles_rule_condition(), - Vc::upcast(self.client_transition()), + ResolvedVc::upcast(self.client_transition().to_resolved().await?), )], ..Default::default() } @@ -411,7 +411,7 @@ impl AppProject { named_transitions: transitions, transition_rules: vec![TransitionRule::new( styles_rule_condition(), - Vc::upcast(self.client_transition()), + ResolvedVc::upcast(self.client_transition().to_resolved().await?), )], ..Default::default() } diff --git a/turbopack/crates/turbopack/src/lib.rs b/turbopack/crates/turbopack/src/lib.rs index 31272a0f3ec18..786c76d2affc2 100644 --- a/turbopack/crates/turbopack/src/lib.rs +++ b/turbopack/crates/turbopack/src/lib.rs @@ -432,7 +432,7 @@ impl ModuleAssetContext { #[turbo_tasks::function] async fn process_with_transition_rules( self: Vc, - source: Vc>, + source: ResolvedVc>, reference_type: Value, ) -> Result> { let this = self.await?; @@ -443,9 +443,9 @@ impl ModuleAssetContext { .get_by_rules(source, &reference_type) .await? { - transition.process(source, self, reference_type) + transition.process(*source, self, reference_type) } else { - self.process_default(source, reference_type) + self.process_default(*source, reference_type) }, ) } @@ -530,7 +530,7 @@ async fn process_default_internal( if processed_rules.contains(&i) { continue; } - if rule.matches(*source, &path_ref, &reference_type).await? { + if rule.matches(source, &path_ref, &reference_type).await? { for effect in rule.effects() { match effect { ModuleRuleEffect::SourceTransforms(transforms) => { @@ -542,7 +542,7 @@ async fn process_default_internal( .await? .transitions .await? - .get_by_rules(*current_source, &reference_type) + .get_by_rules(current_source, &reference_type) .await? { return Ok(transition.process( diff --git a/turbopack/crates/turbopack/src/module_options/module_options_context.rs b/turbopack/crates/turbopack/src/module_options/module_options_context.rs index d865ee4069380..d0e7e6a72df54 100644 --- a/turbopack/crates/turbopack/src/module_options/module_options_context.rs +++ b/turbopack/crates/turbopack/src/module_options/module_options_context.rs @@ -107,7 +107,7 @@ pub struct JsxTransformOptions { pub runtime: Option, } -#[turbo_tasks::value(shared, local)] +#[turbo_tasks::value(shared)] #[derive(Clone, Default)] #[serde(default)] pub struct ModuleOptionsContext { diff --git a/turbopack/crates/turbopack/src/module_options/module_rule.rs b/turbopack/crates/turbopack/src/module_options/module_rule.rs index 237fa9a01efbe..031c2e4f6bfdb 100644 --- a/turbopack/crates/turbopack/src/module_options/module_rule.rs +++ b/turbopack/crates/turbopack/src/module_options/module_rule.rs @@ -1,6 +1,6 @@ use anyhow::Result; use serde::{Deserialize, Serialize}; -use turbo_tasks::{trace::TraceRawVcs, NonLocalValue, ResolvedVc, Vc}; +use turbo_tasks::{trace::TraceRawVcs, NonLocalValue, ResolvedVc}; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ reference_type::ReferenceType, source::Source, source_transform::SourceTransforms, @@ -52,7 +52,7 @@ impl ModuleRule { pub async fn matches( &self, - source: Vc>, + source: ResolvedVc>, path: &FileSystemPath, reference_type: &ReferenceType, ) -> Result { diff --git a/turbopack/crates/turbopack/src/module_options/rule_condition.rs b/turbopack/crates/turbopack/src/module_options/rule_condition.rs index 0bc997281b2c4..55eaf9440f21a 100644 --- a/turbopack/crates/turbopack/src/module_options/rule_condition.rs +++ b/turbopack/crates/turbopack/src/module_options/rule_condition.rs @@ -1,6 +1,6 @@ use anyhow::Result; use serde::{Deserialize, Serialize}; -use turbo_tasks::{primitives::Regex, trace::TraceRawVcs, NonLocalValue, ReadRef, Vc}; +use turbo_tasks::{primitives::Regex, trace::TraceRawVcs, NonLocalValue, ReadRef, ResolvedVc}; use turbo_tasks_fs::{glob::Glob, FileSystemPath}; use turbopack_core::{ reference_type::ReferenceType, source::Source, virtual_source::VirtualSource, @@ -51,7 +51,7 @@ impl RuleCondition { impl RuleCondition { pub async fn matches( &self, - source: Vc>, + source: ResolvedVc>, path: &FileSystemPath, reference_type: &ReferenceType, ) -> Result { @@ -96,7 +96,7 @@ impl RuleCondition { } RuleCondition::ReferenceType(condition_ty) => condition_ty.includes(reference_type), RuleCondition::ResourceIsVirtualSource => { - Vc::try_resolve_downcast_type::(source) + ResolvedVc::try_downcast_type::(source) .await? .is_some() } diff --git a/turbopack/crates/turbopack/src/module_options/transition_rule.rs b/turbopack/crates/turbopack/src/module_options/transition_rule.rs index 8d4d92b8ceffa..28d5b8371bba4 100644 --- a/turbopack/crates/turbopack/src/module_options/transition_rule.rs +++ b/turbopack/crates/turbopack/src/module_options/transition_rule.rs @@ -1,22 +1,22 @@ use anyhow::Result; use serde::{Deserialize, Serialize}; -use turbo_tasks::{trace::TraceRawVcs, Vc}; +use turbo_tasks::{trace::TraceRawVcs, NonLocalValue, ResolvedVc}; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{reference_type::ReferenceType, source::Source}; use super::{match_mode::MatchMode, RuleCondition}; use crate::transition::Transition; -#[derive(Debug, Clone, Serialize, Deserialize, TraceRawVcs, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, NonLocalValue)] pub struct TransitionRule { condition: RuleCondition, - transition: Vc>, + transition: ResolvedVc>, match_mode: MatchMode, } impl TransitionRule { /// Creates a new transition rule. Will not match internal references. - pub fn new(condition: RuleCondition, transition: Vc>) -> Self { + pub fn new(condition: RuleCondition, transition: ResolvedVc>) -> Self { TransitionRule { condition, transition, @@ -25,7 +25,10 @@ impl TransitionRule { } /// Creates a new transition rule. Will only match internal references. - pub fn new_internal(condition: RuleCondition, transition: Vc>) -> Self { + pub fn new_internal( + condition: RuleCondition, + transition: ResolvedVc>, + ) -> Self { TransitionRule { condition, transition, @@ -34,7 +37,7 @@ impl TransitionRule { } /// Creates a new transition rule. Will match all references. - pub fn new_all(condition: RuleCondition, transition: Vc>) -> Self { + pub fn new_all(condition: RuleCondition, transition: ResolvedVc>) -> Self { TransitionRule { condition, transition, @@ -42,13 +45,13 @@ impl TransitionRule { } } - pub fn transition(&self) -> Vc> { + pub fn transition(&self) -> ResolvedVc> { self.transition } pub async fn matches( &self, - source: Vc>, + source: ResolvedVc>, path: &FileSystemPath, reference_type: &ReferenceType, ) -> Result { diff --git a/turbopack/crates/turbopack/src/transition/mod.rs b/turbopack/crates/turbopack/src/transition/mod.rs index 56d2bfc8e5a00..2f61f6e6a4db7 100644 --- a/turbopack/crates/turbopack/src/transition/mod.rs +++ b/turbopack/crates/turbopack/src/transition/mod.rs @@ -109,7 +109,7 @@ pub trait Transition { } } -#[turbo_tasks::value(shared, local)] +#[turbo_tasks::value(shared)] #[derive(Default)] pub struct TransitionOptions { pub named_transitions: HashMap>>, @@ -132,9 +132,9 @@ impl TransitionOptions { pub async fn get_by_rules( &self, - source: Vc>, + source: ResolvedVc>, reference_type: &ReferenceType, - ) -> Result>>> { + ) -> Result>>> { if self.transition_rules.is_empty() { return Ok(None); }