Skip to content

Commit

Permalink
refactor(turbopack-core): Use ResolvedVc in ProcessResult and ModuleR…
Browse files Browse the repository at this point in the history
…esolveResultItem
  • Loading branch information
bgw committed Jan 9, 2025
1 parent 413b357 commit 7124286
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions turbopack/crates/turbopack-core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ use crate::{
source::Source,
};

#[turbo_tasks::value(shared, local)]
#[turbo_tasks::value(shared)]
pub enum ProcessResult {
/// A module was created.
Module(ResolvedVc<Box<dyn Module>>),

/// A module could not be created (according to the rules, e.g. no module type was assigned)
Unknown(Vc<Box<dyn Source>>),
Unknown(ResolvedVc<Box<dyn Source>>),

/// Reference is ignored. This should lead to no module being included by
/// the reference.
Expand Down Expand Up @@ -46,7 +46,7 @@ impl ProcessResult {
Ok(Vc::cell(match self {
ProcessResult::Module(module) => Some(*module),
ProcessResult::Unknown(source) => {
emit_unknown_module_type_error(*source).await?;
emit_unknown_module_type_error(**source).await?;
None
}
ProcessResult::Ignore => None,
Expand Down
6 changes: 3 additions & 3 deletions turbopack/crates/turbopack-core/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub use remap::{ResolveAliasMap, SubpathValue};

use crate::{error::PrettyPrintError, issue::IssueSeverity};

#[turbo_tasks::value(shared, local)]
#[turbo_tasks::value(shared)]
#[derive(Clone, Debug)]
pub enum ModuleResolveResultItem {
Module(ResolvedVc<Box<dyn Module>>),
Expand All @@ -76,7 +76,7 @@ pub enum ModuleResolveResultItem {
traced: Option<ResolvedVc<ModuleResolveResult>>,
},
/// A module could not be created (according to the rules, e.g. no module type as assigned)
Unknown(Vc<Box<dyn Source>>),
Unknown(ResolvedVc<Box<dyn Source>>),
Ignore,
Error(ResolvedVc<RcStr>),
Empty,
Expand All @@ -88,7 +88,7 @@ impl ModuleResolveResultItem {
Ok(match *self {
ModuleResolveResultItem::Module(module) => Some(module),
ModuleResolveResultItem::Unknown(source) => {
emit_unknown_module_type_error(source).await?;
emit_unknown_module_type_error(*source).await?;
None
}
ModuleResolveResultItem::Error(_err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ async fn to_single_pattern_mapping(
}
ModuleResolveResultItem::Ignore => return Ok(SinglePatternMapping::Ignored),
ModuleResolveResultItem::Unknown(source) => {
emit_unknown_module_type_error(*source).await?;
emit_unknown_module_type_error(**source).await?;
return Ok(SinglePatternMapping::Unresolvable(
"unknown module type".to_string(),
));
Expand Down
17 changes: 9 additions & 8 deletions turbopack/crates/turbopack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ impl ModuleAssetContext {
#[turbo_tasks::function]
async fn process_default(
module_asset_context: Vc<ModuleAssetContext>,
source: Vc<Box<dyn Source>>,
source: ResolvedVc<Box<dyn Source>>,
reference_type: Value<ReferenceType>,
processed_rules: Vec<usize>,
) -> Result<Vc<ProcessResult>> {
Expand All @@ -490,7 +490,7 @@ async fn process_default(

async fn process_default_internal(
module_asset_context: Vc<ModuleAssetContext>,
source: Vc<Box<dyn Source>>,
source: ResolvedVc<Box<dyn Source>>,
reference_type: Value<ReferenceType>,
processed_rules: Vec<usize>,
) -> Result<Vc<ProcessResult>> {
Expand Down Expand Up @@ -535,22 +535,23 @@ 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) => {
current_source = transforms.transform(current_source);
current_source =
transforms.transform(*current_source).to_resolved().await?;
if current_source.ident().resolve().await? != ident {
// The ident has been changed, so we need to apply new rules.
if let Some(transition) = module_asset_context
.await?
.transitions
.await?
.get_by_rules(current_source, &reference_type)
.get_by_rules(*current_source, &reference_type)
.await?
{
return Ok(transition.process(
current_source,
*current_source,
module_asset_context,
Value::new(reference_type),
));
Expand All @@ -559,7 +560,7 @@ async fn process_default_internal(
processed_rules.push(i);
return Ok(process_default(
module_asset_context,
current_source,
*current_source,
Value::new(reference_type),
processed_rules,
));
Expand Down Expand Up @@ -641,7 +642,7 @@ async fn process_default_internal(
};

Ok(apply_module_type(
current_source,
*current_source,
module_asset_context,
module_type.cell(),
Value::new(reference_type.clone()),
Expand Down

0 comments on commit 7124286

Please sign in to comment.