Skip to content

Commit 3c301ac

Browse files
authored
Turbopack: Remove FileSystemPath::value_to_string in favor of ValueToStringRef::to_string_ref (#92284)
`FileSystemPath::value_to_string` was just calling `ValueToString::to_string`. But: - It's better to call `ValueToStringRef::to_string_ref` - We don't really get much value from this inherent method except for avoiding a few imports? I suspect this is left over from when we used to always wrap `FileSystemPath` in `Vc`.
1 parent 124c400 commit 3c301ac

15 files changed

Lines changed: 46 additions & 45 deletions

File tree

crates/next-core/src/app_structure.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use rustc_hash::FxHashMap;
77
use tracing::Instrument;
88
use turbo_rcstr::{RcStr, rcstr};
99
use turbo_tasks::{
10-
FxIndexMap, FxIndexSet, NonLocalValue, ResolvedVc, TaskInput, TryJoinIterExt, ValueDefault, Vc,
11-
debug::ValueDebugFormat, fxindexmap, trace::TraceRawVcs, turbobail,
10+
FxIndexMap, FxIndexSet, NonLocalValue, ResolvedVc, TaskInput, TryJoinIterExt, ValueDefault,
11+
ValueToStringRef, Vc, debug::ValueDebugFormat, fxindexmap, trace::TraceRawVcs, turbobail,
1212
};
1313
use turbo_tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath};
1414
use turbopack_core::issue::{
@@ -325,7 +325,7 @@ async fn get_directory_tree(
325325
) -> Result<Vc<DirectoryTree>> {
326326
let span = tracing::info_span!(
327327
"read app directory tree",
328-
name = display(dir.value_to_string().await?)
328+
name = display(dir.to_string_ref().await?)
329329
);
330330
get_directory_tree_internal(dir, page_extensions)
331331
.instrument(span)

crates/next-core/src/base_loader_tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use indoc::formatdoc;
33
use turbo_rcstr::RcStr;
4-
use turbo_tasks::{FxIndexMap, ResolvedVc, Vc};
4+
use turbo_tasks::{FxIndexMap, ResolvedVc, ValueToStringRef, Vc};
55
use turbo_tasks_fs::FileSystemPath;
66
use turbopack::{ModuleAssetContext, transition::Transition};
77
use turbopack_core::{
@@ -118,7 +118,7 @@ impl BaseLoaderTreeBuilder {
118118
// Use the original source path, not the transformed module path.
119119
// This is important for MDX files where page.mdx becomes page.mdx.tsx after
120120
// transformation, but the font manifest uses the original source path.
121-
let module_path = path.value_to_string().await?;
121+
let module_path = path.to_string_ref().await?;
122122

123123
Ok(format!(
124124
"[{identifier}, {path}]",

crates/next-core/src/emit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Result;
22
use tracing::Instrument;
3-
use turbo_tasks::{TryFlatJoinIterExt, Vc};
3+
use turbo_tasks::{TryFlatJoinIterExt, ValueToStringRef, Vc};
44
use turbo_tasks_fs::{FileSystemPath, rebase};
55
use turbopack_core::{
66
asset::Asset,
@@ -54,7 +54,7 @@ pub async fn emit_assets(
5454

5555
async move {
5656
let path = asset.path().owned().await?;
57-
let span = tracing::info_span!("emit asset", name = %path.value_to_string().await?);
57+
let span = tracing::info_span!("emit asset", name = %path.to_string_ref().await?);
5858
async move {
5959
Ok(if path.is_inside_ref(&node_root) {
6060
Some(emit(*asset).as_side_effect().await?)

crates/next-core/src/next_app/app_client_references_chunks.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use anyhow::Result;
22
use tracing::Instrument;
33
use turbo_rcstr::rcstr;
4-
use turbo_tasks::{FxIndexMap, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc};
4+
use turbo_tasks::{
5+
FxIndexMap, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, ValueToStringRef, Vc,
6+
};
57
use turbopack_core::{
68
chunk::{ChunkGroupResult, ChunkingContext, availability_info::AvailabilityInfo},
79
module::Module,
@@ -185,7 +187,7 @@ pub async fn get_app_client_references_chunks(
185187

186188
let server_path = server_component.server_path().owned().await?;
187189
let is_layout = server_path.file_stem() == Some("layout");
188-
let server_component_path = server_path.value_to_string().await?;
190+
let server_component_path = server_path.to_string_ref().await?;
189191

190192
let ssr_modules = client_reference_types
191193
.iter()

crates/next-core/src/next_app/app_route_entry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Result;
22
use turbo_rcstr::{RcStr, rcstr};
3-
use turbo_tasks::{ResolvedVc, Vc, fxindexmap};
3+
use turbo_tasks::{ResolvedVc, ValueToStringRef, Vc, fxindexmap};
44
use turbo_tasks_fs::FileSystemPath;
55
use turbopack::ModuleAssetContext;
66
use turbopack_core::{
@@ -80,7 +80,7 @@ pub async fn get_app_route_entry(
8080
("VAR_DEFINITION_FILENAME", path.file_stem().unwrap()),
8181
// TODO(alexkirsz) Is this necessary?
8282
("VAR_DEFINITION_BUNDLE_PATH", ""),
83-
("VAR_RESOLVED_PAGE_PATH", &path.value_to_string().await?),
83+
("VAR_RESOLVED_PAGE_PATH", &path.to_string_ref().await?),
8484
("VAR_USERLAND", &inner),
8585
],
8686
[("nextConfigOutput", output_type)],

crates/next-core/src/next_manifests/client_reference_manifest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use serde::Serialize;
77
use tracing::Instrument;
88
use turbo_rcstr::{RcStr, rcstr};
99
use turbo_tasks::{
10-
FxIndexMap, FxIndexSet, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, ValueToString, Vc,
10+
FxIndexMap, FxIndexSet, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, ValueToString,
11+
ValueToStringRef, Vc,
1112
};
1213
use turbo_tasks_fs::{File, FileContent, FileSystemPath};
1314
use turbopack_core::{
@@ -414,8 +415,7 @@ async fn build_manifest(
414415
.source_path()
415416
.await?
416417
.with_extension("")
417-
.value_to_string()
418-
.owned()
418+
.to_string_ref()
419419
.await?;
420420
let entry_js_files = entry_manifest
421421
.entry_js_files

crates/next-core/src/pages_structure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use tracing::Instrument;
33
use turbo_rcstr::RcStr;
4-
use turbo_tasks::{OptionVcExt, ResolvedVc, TryJoinIterExt, Vc};
4+
use turbo_tasks::{OptionVcExt, ResolvedVc, TryJoinIterExt, ValueToStringRef, Vc};
55
use turbo_tasks_fs::{
66
DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath, FileSystemPathOption,
77
};
@@ -327,7 +327,7 @@ async fn get_pages_structure_for_directory(
327327
) -> Result<Vc<PagesDirectoryStructure>> {
328328
let span = tracing::info_span!(
329329
"analyze pages structure",
330-
name = display(project_path.value_to_string().await?)
330+
name = display(project_path.to_string_ref().await?)
331331
);
332332
async move {
333333
let page_extensions_raw = &*page_extensions.await?;

turbopack/crates/turbo-tasks-fs/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,13 +1406,6 @@ pub struct FileSystemPath {
14061406
pub path: RcStr,
14071407
}
14081408

1409-
impl FileSystemPath {
1410-
/// Mimics `ValueToString::to_string`.
1411-
pub fn value_to_string(&self) -> Vc<RcStr> {
1412-
<FileSystemPath as ValueToString>::to_string(self.clone().cell())
1413-
}
1414-
}
1415-
14161409
impl ValueToStringRef for FileSystemPath {
14171410
async fn to_string_ref(&self) -> Result<RcStr> {
14181411
turbofmt!("[{}]/{}", self.fs, self.path).await

turbopack/crates/turbopack-core/src/ident.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use once_cell::sync::Lazy;
66
use regex::Regex;
77
use turbo_rcstr::RcStr;
88
use turbo_tasks::{
9-
NonLocalValue, ReadRef, ResolvedVc, TaskInput, ValueToString, Vc, trace::TraceRawVcs, turbofmt,
9+
NonLocalValue, ReadRef, ResolvedVc, TaskInput, ValueToString, ValueToStringRef, Vc,
10+
trace::TraceRawVcs, turbofmt,
1011
};
1112
use turbo_tasks_fs::FileSystemPath;
1213
use turbo_tasks_hash::{DeterministicHash, Xxh3Hash64Hasher, encode_base38, hash_xxh3_hash64};
@@ -226,7 +227,7 @@ impl AssetIdent {
226227
let mut name = if let Some(inner) = context_path.get_path_to(path) {
227228
escape_file_path(inner)
228229
} else {
229-
escape_file_path(&self.path.value_to_string().await?)
230+
escape_file_path(&self.path.to_string_ref().await?)
230231
};
231232
let removed_extension = name.ends_with(&*expected_extension);
232233
if removed_extension {

turbopack/crates/turbopack-core/src/resolve/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use turbo_frozenmap::{FrozenMap, FrozenSet};
1818
use turbo_rcstr::{RcStr, rcstr};
1919
use turbo_tasks::{
2020
FxIndexMap, FxIndexSet, NonLocalValue, ReadRef, ResolvedVc, TaskInput, TryFlatJoinIterExt,
21-
TryJoinIterExt, ValueToString, Vc, trace::TraceRawVcs,
21+
TryJoinIterExt, ValueToString, ValueToStringRef, Vc, trace::TraceRawVcs,
2222
};
2323
use turbo_tasks_fs::{FileSystemEntryType, FileSystemPath};
2424
use turbo_unix_path::normalize_request;
@@ -596,7 +596,7 @@ impl ValueToString for ResolveResult {
596596
result,
597597
" ({ty}, {traced}, {:?})",
598598
if let Some(target) = target {
599-
Some(target.value_to_string().await?)
599+
Some(target.to_string_ref().await?)
600600
} else {
601601
None
602602
}
@@ -1624,7 +1624,7 @@ pub async fn resolve_inline(
16241624
) -> Result<Vc<ResolveResult>> {
16251625
let span = tracing::info_span!(
16261626
"resolving",
1627-
lookup_path = display(lookup_path.value_to_string().await?),
1627+
lookup_path = display(lookup_path.to_string_ref().await?),
16281628
name = tracing::field::Empty,
16291629
reference_type = display(&reference_type),
16301630
);
@@ -1873,7 +1873,7 @@ async fn resolve_internal_inline(
18731873
) -> Result<Vc<ResolveResult>> {
18741874
let span = tracing::info_span!(
18751875
"internal resolving",
1876-
lookup_path = display(lookup_path.value_to_string().await?),
1876+
lookup_path = display(lookup_path.to_string_ref().await?),
18771877
name = tracing::field::Empty
18781878
);
18791879
if !span.is_disabled() {

0 commit comments

Comments
 (0)