Skip to content

Commit

Permalink
refactor(turbopack-core): Remove remaining "local" value type opt-out…
Browse files Browse the repository at this point in the history
…s in turbopack-core
  • Loading branch information
bgw committed Jan 11, 2025
1 parent 7fd7ee7 commit c269526
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 43 deletions.
2 changes: 1 addition & 1 deletion crates/next-core/src/next_font/local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl BeforeResolvePlugin for NextFontLocalResolvePlugin {
.emit();

return Ok(ResolveResultOption::some(
ResolveResult::primary(ResolveResultItem::Error(Vc::cell(
ResolveResult::primary(ResolveResultItem::Error(ResolvedVc::cell(
format!("Font file not found: Can't resolve {}'", font_path)
.into(),
)))
Expand Down
2 changes: 1 addition & 1 deletion crates/next-core/src/next_shared/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl BeforeResolvePlugin for InvalidImportResolvePlugin {
.emit();

ResolveResultOption::some(
ResolveResult::primary(ResolveResultItem::Error(Vc::cell(
ResolveResult::primary(ResolveResultItem::Error(ResolvedVc::cell(
self.message.join("\n").into(),
)))
.cell(),
Expand Down
32 changes: 17 additions & 15 deletions turbopack/crates/turbopack-core/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl ModuleResolveResultItem {
}
}

#[turbo_tasks::value(shared, local)]
#[turbo_tasks::value(shared)]
#[derive(Clone, Debug)]
pub struct ModuleResolveResult {
pub primary: FxIndexMap<RequestKey, ModuleResolveResultItem>,
Expand Down Expand Up @@ -414,7 +414,7 @@ impl Display for ExternalType {
}
}

#[turbo_tasks::value(shared, local)]
#[turbo_tasks::value(shared)]
#[derive(Clone)]
pub enum ResolveResultItem {
Source(ResolvedVc<Box<dyn Source>>),
Expand All @@ -425,7 +425,7 @@ pub enum ResolveResultItem {
traced: ExternalTraced,
},
Ignore,
Error(Vc<RcStr>),
Error(ResolvedVc<RcStr>),
Empty,
Custom(u8),
}
Expand Down Expand Up @@ -473,7 +473,7 @@ impl RequestKey {
}
}

#[turbo_tasks::value(shared, local)]
#[turbo_tasks::value(shared)]
#[derive(Clone)]
pub struct ResolveResult {
pub primary: FxIndexMap<RequestKey, ResolveResultItem>,
Expand Down Expand Up @@ -721,9 +721,7 @@ impl ResolveResult {
}
ResolveResultItem::Ignore => ModuleResolveResultItem::Ignore,
ResolveResultItem::Empty => ModuleResolveResultItem::Empty,
ResolveResultItem::Error(e) => {
ModuleResolveResultItem::Error(e.to_resolved().await?)
}
ResolveResultItem::Error(e) => ModuleResolveResultItem::Error(e),
ResolveResultItem::Custom(u8) => {
ModuleResolveResultItem::Custom(u8)
}
Expand Down Expand Up @@ -1418,7 +1416,10 @@ pub async fn resolve_raw(
path: Vc<Pattern>,
force_in_lookup_dir: bool,
) -> Result<Vc<ResolveResult>> {
async fn to_result(request: &str, path: Vc<FileSystemPath>) -> Result<Vc<ResolveResult>> {
async fn to_result(
request: &str,
path: ResolvedVc<FileSystemPath>,
) -> Result<Vc<ResolveResult>> {
let RealPathResult { path, symlinks } = &*path.realpath_with_links().await?;
Ok(ResolveResult::source_with_affecting_sources(
RequestKey::new(request.into()),
Expand Down Expand Up @@ -1771,7 +1772,7 @@ async fn resolve_internal_inline(
results.push(
resolved(
RequestKey::new(matched_pattern.clone()),
*path,
**path,
lookup_path,
request,
options_value,
Expand All @@ -1784,7 +1785,7 @@ async fn resolve_internal_inline(
}
PatternMatch::Directory(matched_pattern, path) => {
results.push(
resolve_into_folder(*path, options)
resolve_into_folder(**path, options)
.with_request(matched_pattern.clone()),
);
}
Expand Down Expand Up @@ -2186,7 +2187,7 @@ async fn resolve_relative_request(
results.push(
resolved(
RequestKey::new(matched_pattern.into()),
*path,
**path,
lookup_path,
request,
options_value,
Expand All @@ -2203,7 +2204,7 @@ async fn resolve_relative_request(
results.push(
resolved(
RequestKey::new(matched_pattern.into()),
*path,
**path,
lookup_path,
request,
options_value,
Expand All @@ -2226,7 +2227,7 @@ async fn resolve_relative_request(
results.push(
resolved(
RequestKey::new(matched_pattern.into()),
*path,
**path,
lookup_path,
request,
options_value,
Expand All @@ -2244,7 +2245,7 @@ async fn resolve_relative_request(
results.push(
resolved(
RequestKey::new(matched_pattern.clone()),
*path,
**path,
lookup_path,
request,
options_value,
Expand All @@ -2260,7 +2261,8 @@ async fn resolve_relative_request(
// Directory matches must be resolved AFTER file matches
for m in matches.iter() {
if let PatternMatch::Directory(matched_pattern, path) = m {
results.push(resolve_into_folder(*path, options).with_request(matched_pattern.clone()));
results
.push(resolve_into_folder(**path, options).with_request(matched_pattern.clone()));
}
}

Expand Down
60 changes: 37 additions & 23 deletions turbopack/crates/turbopack-core/src/resolve/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_rcstr::RcStr;
use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, ResolvedVc, Value, ValueToString, Vc,
debug::ValueDebugFormat, trace::TraceRawVcs, NonLocalValue, ResolvedVc, Value, ValueToString,
Vc,
};
use turbo_tasks_fs::{
util::normalize_path, DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath,
Expand Down Expand Up @@ -1300,14 +1301,24 @@ impl ValueToString for Pattern {
}
}

#[derive(Debug, PartialEq, Eq, Clone, TraceRawVcs, Serialize, Deserialize, ValueDebugFormat)]
#[derive(
Debug,
PartialEq,
Eq,
Clone,
TraceRawVcs,
Serialize,
Deserialize,
ValueDebugFormat,
NonLocalValue,
)]
pub enum PatternMatch {
File(RcStr, Vc<FileSystemPath>),
Directory(RcStr, Vc<FileSystemPath>),
File(RcStr, ResolvedVc<FileSystemPath>),
Directory(RcStr, ResolvedVc<FileSystemPath>),
}

impl PatternMatch {
pub fn path(&self) -> Vc<FileSystemPath> {
pub fn path(&self) -> ResolvedVc<FileSystemPath> {
match *self {
PatternMatch::File(_, path) | PatternMatch::Directory(_, path) => path,
}
Expand All @@ -1322,7 +1333,7 @@ impl PatternMatch {

// TODO this isn't super efficient
// avoid storing a large list of matches
#[turbo_tasks::value(transparent, local)]
#[turbo_tasks::value(transparent)]
pub struct PatternMatches(Vec<PatternMatch>);

/// Find all files or directories that match the provided `pattern` with the
Expand Down Expand Up @@ -1356,12 +1367,12 @@ pub async fn read_matches(
for (index, (str, until_end)) in constants.into_iter().enumerate() {
if until_end {
if handled.insert(str) {
if let Some(fs_path) = &*if force_in_lookup_dir {
let fs_path = *if force_in_lookup_dir {
lookup_dir.try_join_inside(str.into()).await?
} else {
lookup_dir.try_join(str.into()).await?
} {
let fs_path = fs_path.resolve().await?;
};
if let Some(fs_path) = fs_path {
// This explicit deref of `context` is necessary
#[allow(clippy::explicit_auto_deref)]
let should_match = !force_in_lookup_dir
Expand Down Expand Up @@ -1453,7 +1464,10 @@ pub async fn read_matches(
if let Some(pos) = pat.match_position(&prefix) {
results.push((
pos,
PatternMatch::Directory(prefix.clone().into(), lookup_dir.parent()),
PatternMatch::Directory(
prefix.clone().into(),
lookup_dir.parent().to_resolved().await?,
),
));
}

Expand All @@ -1462,7 +1476,10 @@ pub async fn read_matches(
if let Some(pos) = pat.match_position(&prefix) {
results.push((
pos,
PatternMatch::Directory(prefix.clone().into(), lookup_dir.parent()),
PatternMatch::Directory(
prefix.clone().into(),
lookup_dir.parent().to_resolved().await?,
),
));
}
if let Some(pos) = pat.could_match_position(&prefix) {
Expand All @@ -1481,14 +1498,14 @@ pub async fn read_matches(
if let Some(pos) = pat.match_position(&prefix) {
results.push((
pos,
PatternMatch::Directory(prefix.clone().into(), *lookup_dir),
PatternMatch::Directory(prefix.clone().into(), lookup_dir),
));
}
prefix.pop();
}
if prefix.is_empty() {
if let Some(pos) = pat.match_position("./") {
results.push((pos, PatternMatch::Directory("./".into(), *lookup_dir)));
results.push((pos, PatternMatch::Directory("./".into(), lookup_dir)));
}
if let Some(pos) = pat.could_match_position("./") {
nested.push((pos, read_matches(*lookup_dir, "./".into(), false, pattern)));
Expand Down Expand Up @@ -1525,7 +1542,7 @@ pub async fn read_matches(
if let Some(pos) = pat.match_position(&prefix) {
results.push((
pos,
PatternMatch::File(prefix.clone().into(), **path),
PatternMatch::File(prefix.clone().into(), *path),
));
}
prefix.truncate(len)
Expand All @@ -1540,15 +1557,15 @@ pub async fn read_matches(
if let Some(pos) = pat.match_position(&prefix) {
results.push((
pos,
PatternMatch::Directory(prefix.clone().into(), **path),
PatternMatch::Directory(prefix.clone().into(), *path),
));
}
prefix.push('/');
// {prefix}{key}/
if let Some(pos) = pat.match_position(&prefix) {
results.push((
pos,
PatternMatch::Directory(prefix.clone().into(), **path),
PatternMatch::Directory(prefix.clone().into(), *path),
));
}
if let Some(pos) = pat.could_match_position(&prefix) {
Expand All @@ -1575,16 +1592,13 @@ pub async fn read_matches(
pos,
PatternMatch::Directory(
prefix.clone().into(),
**fs_path,
*fs_path,
),
));
} else {
results.push((
pos,
PatternMatch::File(
prefix.clone().into(),
**fs_path,
),
PatternMatch::File(prefix.clone().into(), *fs_path),
));
}
}
Expand All @@ -1599,7 +1613,7 @@ pub async fn read_matches(
pos,
PatternMatch::Directory(
prefix.clone().into(),
**fs_path,
*fs_path,
),
));
}
Expand All @@ -1614,7 +1628,7 @@ pub async fn read_matches(
pos,
PatternMatch::Directory(
prefix.clone().into(),
**fs_path,
*fs_path,
),
));
}
Expand Down
4 changes: 1 addition & 3 deletions turbopack/crates/turbopack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,7 @@ impl AssetContext for ModuleAssetContext {
}
ResolveResultItem::Ignore => ModuleResolveResultItem::Ignore,
ResolveResultItem::Empty => ModuleResolveResultItem::Empty,
ResolveResultItem::Error(e) => {
ModuleResolveResultItem::Error(e.to_resolved().await?)
}
ResolveResultItem::Error(e) => ModuleResolveResultItem::Error(e),
ResolveResultItem::Custom(u8) => ModuleResolveResultItem::Custom(u8),
})
}
Expand Down

0 comments on commit c269526

Please sign in to comment.