Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(turbopack): Remove last known (non-test) usages of unresolved vcs in turbo_tasks::value (!!!) #74713

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down
10 changes: 5 additions & 5 deletions turbopack/crates/turbopack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl ModuleAssetContext {
#[turbo_tasks::function]
async fn process_with_transition_rules(
self: Vc<Self>,
source: Vc<Box<dyn Source>>,
source: ResolvedVc<Box<dyn Source>>,
reference_type: Value<ReferenceType>,
) -> Result<Vc<ProcessResult>> {
let this = self.await?;
Expand All @@ -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)
},
)
}
Expand Down Expand Up @@ -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) => {
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub struct JsxTransformOptions {
pub runtime: Option<RcStr>,
}

#[turbo_tasks::value(shared, local)]
#[turbo_tasks::value(shared)]
#[derive(Clone, Default)]
#[serde(default)]
pub struct ModuleOptionsContext {
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbopack/src/module_options/module_rule.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -52,7 +52,7 @@ impl ModuleRule {

pub async fn matches(
&self,
source: Vc<Box<dyn Source>>,
source: ResolvedVc<Box<dyn Source>>,
path: &FileSystemPath,
reference_type: &ReferenceType,
) -> Result<bool> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -51,7 +51,7 @@ impl RuleCondition {
impl RuleCondition {
pub async fn matches(
&self,
source: Vc<Box<dyn Source>>,
source: ResolvedVc<Box<dyn Source>>,
path: &FileSystemPath,
reference_type: &ReferenceType,
) -> Result<bool> {
Expand Down Expand Up @@ -96,7 +96,7 @@ impl RuleCondition {
}
RuleCondition::ReferenceType(condition_ty) => condition_ty.includes(reference_type),
RuleCondition::ResourceIsVirtualSource => {
Vc::try_resolve_downcast_type::<VirtualSource>(source)
ResolvedVc::try_downcast_type::<VirtualSource>(source)
.await?
.is_some()
}
Expand Down
19 changes: 11 additions & 8 deletions turbopack/crates/turbopack/src/module_options/transition_rule.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Transition>>,
transition: ResolvedVc<Box<dyn Transition>>,
match_mode: MatchMode,
}

impl TransitionRule {
/// Creates a new transition rule. Will not match internal references.
pub fn new(condition: RuleCondition, transition: Vc<Box<dyn Transition>>) -> Self {
pub fn new(condition: RuleCondition, transition: ResolvedVc<Box<dyn Transition>>) -> Self {
TransitionRule {
condition,
transition,
Expand All @@ -25,7 +25,10 @@ impl TransitionRule {
}

/// Creates a new transition rule. Will only match internal references.
pub fn new_internal(condition: RuleCondition, transition: Vc<Box<dyn Transition>>) -> Self {
pub fn new_internal(
condition: RuleCondition,
transition: ResolvedVc<Box<dyn Transition>>,
) -> Self {
TransitionRule {
condition,
transition,
Expand All @@ -34,21 +37,21 @@ impl TransitionRule {
}

/// Creates a new transition rule. Will match all references.
pub fn new_all(condition: RuleCondition, transition: Vc<Box<dyn Transition>>) -> Self {
pub fn new_all(condition: RuleCondition, transition: ResolvedVc<Box<dyn Transition>>) -> Self {
TransitionRule {
condition,
transition,
match_mode: MatchMode::All,
}
}

pub fn transition(&self) -> Vc<Box<dyn Transition>> {
pub fn transition(&self) -> ResolvedVc<Box<dyn Transition>> {
self.transition
}

pub async fn matches(
&self,
source: Vc<Box<dyn Source>>,
source: ResolvedVc<Box<dyn Source>>,
path: &FileSystemPath,
reference_type: &ReferenceType,
) -> Result<bool> {
Expand Down
6 changes: 3 additions & 3 deletions turbopack/crates/turbopack/src/transition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RcStr, ResolvedVc<Box<dyn Transition>>>,
Expand All @@ -132,9 +132,9 @@ impl TransitionOptions {

pub async fn get_by_rules(
&self,
source: Vc<Box<dyn Source>>,
source: ResolvedVc<Box<dyn Source>>,
reference_type: &ReferenceType,
) -> Result<Option<Vc<Box<dyn Transition>>>> {
) -> Result<Option<ResolvedVc<Box<dyn Transition>>>> {
if self.transition_rules.is_empty() {
return Ok(None);
}
Expand Down
Loading