Unverified Commit a0eab62e authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

refactor(turbopack-core): Use ResolvedVc in ProcessResult and ModuleResolveResultItem (#74511)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the PR.
- Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to understand the PR)
- When linking to a Slack thread, you might want to share details of the conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
parent 413b357d
...@@ -12,13 +12,13 @@ use crate::{ ...@@ -12,13 +12,13 @@ use crate::{
source::Source, source::Source,
}; };
#[turbo_tasks::value(shared, local)] #[turbo_tasks::value(shared)]
pub enum ProcessResult { pub enum ProcessResult {
/// A module was created. /// A module was created.
Module(ResolvedVc<Box<dyn Module>>), Module(ResolvedVc<Box<dyn Module>>),
/// A module could not be created (according to the rules, e.g. no module type was assigned) /// 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 /// Reference is ignored. This should lead to no module being included by
/// the reference. /// the reference.
...@@ -46,7 +46,7 @@ impl ProcessResult { ...@@ -46,7 +46,7 @@ impl ProcessResult {
Ok(Vc::cell(match self { Ok(Vc::cell(match self {
ProcessResult::Module(module) => Some(*module), ProcessResult::Module(module) => Some(*module),
ProcessResult::Unknown(source) => { ProcessResult::Unknown(source) => {
emit_unknown_module_type_error(*source).await?; emit_unknown_module_type_error(**source).await?;
None None
} }
ProcessResult::Ignore => None, ProcessResult::Ignore => None,
......
...@@ -64,7 +64,7 @@ pub use remap::{ResolveAliasMap, SubpathValue}; ...@@ -64,7 +64,7 @@ pub use remap::{ResolveAliasMap, SubpathValue};
use crate::{error::PrettyPrintError, issue::IssueSeverity}; use crate::{error::PrettyPrintError, issue::IssueSeverity};
#[turbo_tasks::value(shared, local)] #[turbo_tasks::value(shared)]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum ModuleResolveResultItem { pub enum ModuleResolveResultItem {
Module(ResolvedVc<Box<dyn Module>>), Module(ResolvedVc<Box<dyn Module>>),
...@@ -76,7 +76,7 @@ pub enum ModuleResolveResultItem { ...@@ -76,7 +76,7 @@ pub enum ModuleResolveResultItem {
traced: Option<ResolvedVc<ModuleResolveResult>>, traced: Option<ResolvedVc<ModuleResolveResult>>,
}, },
/// A module could not be created (according to the rules, e.g. no module type as assigned) /// 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, Ignore,
Error(ResolvedVc<RcStr>), Error(ResolvedVc<RcStr>),
Empty, Empty,
...@@ -88,7 +88,7 @@ impl ModuleResolveResultItem { ...@@ -88,7 +88,7 @@ impl ModuleResolveResultItem {
Ok(match *self { Ok(match *self {
ModuleResolveResultItem::Module(module) => Some(module), ModuleResolveResultItem::Module(module) => Some(module),
ModuleResolveResultItem::Unknown(source) => { ModuleResolveResultItem::Unknown(source) => {
emit_unknown_module_type_error(source).await?; emit_unknown_module_type_error(*source).await?;
None None
} }
ModuleResolveResultItem::Error(_err) => { ModuleResolveResultItem::Error(_err) => {
......
...@@ -310,7 +310,7 @@ async fn to_single_pattern_mapping( ...@@ -310,7 +310,7 @@ async fn to_single_pattern_mapping(
} }
ModuleResolveResultItem::Ignore => return Ok(SinglePatternMapping::Ignored), ModuleResolveResultItem::Ignore => return Ok(SinglePatternMapping::Ignored),
ModuleResolveResultItem::Unknown(source) => { ModuleResolveResultItem::Unknown(source) => {
emit_unknown_module_type_error(*source).await?; emit_unknown_module_type_error(**source).await?;
return Ok(SinglePatternMapping::Unresolvable( return Ok(SinglePatternMapping::Unresolvable(
"unknown module type".to_string(), "unknown module type".to_string(),
)); ));
......
...@@ -469,7 +469,7 @@ impl ModuleAssetContext { ...@@ -469,7 +469,7 @@ impl ModuleAssetContext {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn process_default( async fn process_default(
module_asset_context: Vc<ModuleAssetContext>, module_asset_context: Vc<ModuleAssetContext>,
source: Vc<Box<dyn Source>>, source: ResolvedVc<Box<dyn Source>>,
reference_type: Value<ReferenceType>, reference_type: Value<ReferenceType>,
processed_rules: Vec<usize>, processed_rules: Vec<usize>,
) -> Result<Vc<ProcessResult>> { ) -> Result<Vc<ProcessResult>> {
...@@ -490,7 +490,7 @@ async fn process_default( ...@@ -490,7 +490,7 @@ async fn process_default(
async fn process_default_internal( async fn process_default_internal(
module_asset_context: Vc<ModuleAssetContext>, module_asset_context: Vc<ModuleAssetContext>,
source: Vc<Box<dyn Source>>, source: ResolvedVc<Box<dyn Source>>,
reference_type: Value<ReferenceType>, reference_type: Value<ReferenceType>,
processed_rules: Vec<usize>, processed_rules: Vec<usize>,
) -> Result<Vc<ProcessResult>> { ) -> Result<Vc<ProcessResult>> {
...@@ -535,22 +535,23 @@ async fn process_default_internal( ...@@ -535,22 +535,23 @@ async fn process_default_internal(
if processed_rules.contains(&i) { if processed_rules.contains(&i) {
continue; continue;
} }
if rule.matches(source, &path_ref, &reference_type).await? { if rule.matches(*source, &path_ref, &reference_type).await? {
for effect in rule.effects() { for effect in rule.effects() {
match effect { match effect {
ModuleRuleEffect::SourceTransforms(transforms) => { 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 { if current_source.ident().resolve().await? != ident {
// The ident has been changed, so we need to apply new rules. // The ident has been changed, so we need to apply new rules.
if let Some(transition) = module_asset_context if let Some(transition) = module_asset_context
.await? .await?
.transitions .transitions
.await? .await?
.get_by_rules(current_source, &reference_type) .get_by_rules(*current_source, &reference_type)
.await? .await?
{ {
return Ok(transition.process( return Ok(transition.process(
current_source, *current_source,
module_asset_context, module_asset_context,
Value::new(reference_type), Value::new(reference_type),
)); ));
...@@ -559,7 +560,7 @@ async fn process_default_internal( ...@@ -559,7 +560,7 @@ async fn process_default_internal(
processed_rules.push(i); processed_rules.push(i);
return Ok(process_default( return Ok(process_default(
module_asset_context, module_asset_context,
current_source, *current_source,
Value::new(reference_type), Value::new(reference_type),
processed_rules, processed_rules,
)); ));
...@@ -641,7 +642,7 @@ async fn process_default_internal( ...@@ -641,7 +642,7 @@ async fn process_default_internal(
}; };
Ok(apply_module_type( Ok(apply_module_type(
current_source, *current_source,
module_asset_context, module_asset_context,
module_type.cell(), module_type.cell(),
Value::new(reference_type.clone()), Value::new(reference_type.clone()),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment