Skip to content

Commit ea7319c

Browse files
authored
codemod(turbopack): Rewrite Vc fields in structs as ResolvedVc (part 4) (#71804)
Generated using a version of https://github.com/vercel/turbopack-resolved-vc-codemod . This uses Anthropic Claude Sonnet 3.5 for more complicated errors we don't have hardcoded logic for. - Part 1: #70927 - Part 2: #71172 - Part 3: #71665 Closes PACK-3336
1 parent 0f43e4e commit ea7319c

File tree

22 files changed

+209
-160
lines changed

22 files changed

+209
-160
lines changed

crates/next-core/src/next_client_reference/ecmascript_client_reference/ecmascript_client_reference_transition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Transition for NextEcmascriptClientReferenceTransition {
6161
let this = self.await?;
6262

6363
let ident = match part {
64-
Some(part) => source.ident().with_part(part),
64+
Some(part) => source.ident().with_part(*part),
6565
None => source.ident(),
6666
};
6767
let ident_ref = ident.await?;

turbopack/crates/node-file-trace/src/lib.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use serde::Deserialize;
2323
use serde::Serialize;
2424
use tokio::sync::mpsc::channel;
2525
use turbo_tasks::{
26-
backend::Backend, util::FormatDuration, RcStr, ReadConsistency, TaskId, TransientInstance,
27-
TransientValue, TurboTasks, UpdateInfo, Value, Vc,
26+
backend::Backend, util::FormatDuration, RcStr, ReadConsistency, ResolvedVc, TaskId,
27+
TransientInstance, TransientValue, TurboTasks, UpdateInfo, Value, Vc,
2828
};
2929
use turbo_tasks_fs::{
3030
glob::Glob, DirectoryEntry, DiskFileSystem, FileSystem, FileSystemPath, ReadGlobResult,
@@ -565,11 +565,11 @@ async fn main_operation(
565565

566566
#[turbo_tasks::function]
567567
async fn create_module_asset(
568-
root: Vc<FileSystemPath>,
568+
root: ResolvedVc<FileSystemPath>,
569569
process_cwd: Option<RcStr>,
570570
module_options: TransientInstance<ModuleOptionsContext>,
571571
resolve_options: TransientInstance<ResolveOptionsContext>,
572-
) -> Vc<ModuleAssetContext> {
572+
) -> Result<Vc<ModuleAssetContext>> {
573573
let env = Environment::new(Value::new(ExecutionEnvironment::NodeJsLambda(
574574
NodeJsEnvironment {
575575
cwd: Vc::cell(process_cwd),
@@ -581,13 +581,17 @@ async fn create_module_asset(
581581
let glob_mappings = vec![
582582
(
583583
root,
584-
Glob::new("**/*/next/dist/server/next.js".into()),
585-
ImportMapping::Ignore.into(),
584+
Glob::new("**/*/next/dist/server/next.js".into())
585+
.to_resolved()
586+
.await?,
587+
ImportMapping::Ignore.resolved_cell(),
586588
),
587589
(
588590
root,
589-
Glob::new("**/*/next/dist/bin/next".into()),
590-
ImportMapping::Ignore.into(),
591+
Glob::new("**/*/next/dist/bin/next".into())
592+
.to_resolved()
593+
.await?,
594+
ImportMapping::Ignore.resolved_cell(),
591595
),
592596
];
593597
let mut resolve_options = ResolveOptionsContext::clone(&*resolve_options);
@@ -603,13 +607,13 @@ async fn create_module_asset(
603607
);
604608
}
605609

606-
ModuleAssetContext::new(
610+
Ok(ModuleAssetContext::new(
607611
Default::default(),
608612
compile_time_info,
609613
ModuleOptionsContext::clone(&*module_options).cell(),
610614
resolve_options.cell(),
611615
Vc::cell("node_file_trace".into()),
612-
)
616+
))
613617
}
614618

615619
fn register() {

turbopack/crates/turbopack-browser/src/chunking_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ impl ChunkingContext for BrowserChunkingContext {
386386

387387
let mut assets: Vec<Vc<Box<dyn OutputAsset>>> = chunks
388388
.iter()
389-
.map(|chunk| self.generate_chunk(*chunk))
389+
.map(|chunk| self.generate_chunk(**chunk))
390390
.collect();
391391

392392
if this.enable_hot_module_replacement {
@@ -455,7 +455,7 @@ impl ChunkingContext for BrowserChunkingContext {
455455

456456
let mut assets: Vec<Vc<Box<dyn OutputAsset>>> = chunks
457457
.iter()
458-
.map(|chunk| self.generate_chunk(*chunk))
458+
.map(|chunk| self.generate_chunk(**chunk))
459459
.collect();
460460

461461
let other_assets = Vc::cell(assets.clone());

turbopack/crates/turbopack-browser/src/ecmascript/merged/update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pub(super) async fn update_ecmascript_merged_chunk(
215215
if merged_module_map.get(&module_id) != Some(module_hash) {
216216
let entry = EcmascriptModuleEntry::from_code(
217217
&module_id,
218-
module_code,
218+
*module_code,
219219
chunk_path,
220220
)
221221
.await?;
@@ -227,7 +227,7 @@ pub(super) async fn update_ecmascript_merged_chunk(
227227

228228
for (module_id, module_code) in chunk_partial.modified {
229229
let entry =
230-
EcmascriptModuleEntry::from_code(&module_id, module_code, chunk_path)
230+
EcmascriptModuleEntry::from_code(&module_id, *module_code, chunk_path)
231231
.await?;
232232
merged_update.entries.insert(module_id, entry);
233233
}

turbopack/crates/turbopack-browser/src/ecmascript/update.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use anyhow::Result;
2-
use turbo_tasks::{FxIndexMap, ReadRef, Vc};
2+
use turbo_tasks::{FxIndexMap, ReadRef, ResolvedVc, Vc};
33
use turbopack_core::{chunk::ModuleId, code_builder::Code};
44

55
use super::{content::EcmascriptDevChunkContent, version::EcmascriptDevChunkVersion};
@@ -11,9 +11,9 @@ pub(super) enum EcmascriptChunkUpdate {
1111
}
1212

1313
pub(super) struct EcmascriptChunkPartialUpdate {
14-
pub added: FxIndexMap<ReadRef<ModuleId>, (u64, Vc<Code>)>,
14+
pub added: FxIndexMap<ReadRef<ModuleId>, (u64, ResolvedVc<Code>)>,
1515
pub deleted: FxIndexMap<ReadRef<ModuleId>, u64>,
16-
pub modified: FxIndexMap<ReadRef<ModuleId>, Vc<Code>>,
16+
pub modified: FxIndexMap<ReadRef<ModuleId>, ResolvedVc<Code>>,
1717
}
1818

1919
pub(super) async fn update_ecmascript_chunk(
@@ -40,7 +40,8 @@ pub(super) async fn update_ecmascript_chunk(
4040
for (id, from_hash) in &from.entries_hashes {
4141
if let Some(entry) = entries.get(id) {
4242
if *entry.hash.await? != *from_hash {
43-
modified.insert(id.clone(), entry.code);
43+
let resolved_code = entry.code.to_resolved().await?;
44+
modified.insert(id.clone(), resolved_code);
4445
}
4546
} else {
4647
deleted.insert(id.clone(), *from_hash);
@@ -50,7 +51,10 @@ pub(super) async fn update_ecmascript_chunk(
5051
// Remaining entries are added
5152
for (id, entry) in entries.iter() {
5253
if !from.entries_hashes.contains_key(id) {
53-
added.insert(id.clone(), (*entry.hash.await?, entry.code));
54+
added.insert(
55+
id.clone(),
56+
(*entry.hash.await?, entry.code.to_resolved().await?),
57+
);
5458
}
5559
}
5660

turbopack/crates/turbopack-cli-utils/src/runtime_entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl RuntimeEntry {
6262
}
6363

6464
#[turbo_tasks::value(transparent)]
65-
pub struct RuntimeEntries(Vec<Vc<RuntimeEntry>>);
65+
pub struct RuntimeEntries(Vec<ResolvedVc<RuntimeEntry>>);
6666

6767
#[turbo_tasks::value_impl]
6868
impl RuntimeEntries {

turbopack/crates/turbopack-cli/src/build/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl TurbopackBuildBuilder {
118118
self.entry_requests
119119
.iter()
120120
.cloned()
121-
.map(EntryRequest::cell)
121+
.map(EntryRequest::resolved_cell)
122122
.collect(),
123123
)
124124
.cell(),

turbopack/crates/turbopack-cli/src/dev/web_entry_source.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub async fn get_client_runtime_entries(
7272
request.to_resolved().await?,
7373
project_path.join("_".into()).to_resolved().await?,
7474
)
75-
.cell(),
75+
.resolved_cell(),
7676
)
7777
};
7878

@@ -82,7 +82,7 @@ pub async fn get_client_runtime_entries(
8282
.to_resolved()
8383
.await?,
8484
))
85-
.cell(),
85+
.resolved_cell(),
8686
);
8787

8888
Ok(Vc::cell(runtime_entries))

turbopack/crates/turbopack-cli/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use std::{env::current_dir, path::PathBuf};
22

33
use anyhow::{Context, Result};
44
use dunce::canonicalize;
5-
use turbo_tasks::{RcStr, Vc};
5+
use turbo_tasks::{RcStr, ResolvedVc, Vc};
66
use turbo_tasks_fs::{DiskFileSystem, FileSystem};
77

88
#[turbo_tasks::value(transparent)]
9-
pub struct EntryRequests(pub Vec<Vc<EntryRequest>>);
9+
pub struct EntryRequests(pub Vec<ResolvedVc<EntryRequest>>);
1010

1111
#[turbo_tasks::value(shared)]
1212
#[derive(Clone)]

turbopack/crates/turbopack-core/src/chunk/available_chunk_items.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ pub struct AvailableChunkItemInfo {
1717
pub struct OptionAvailableChunkItemInfo(Option<AvailableChunkItemInfo>);
1818

1919
#[turbo_tasks::value(transparent)]
20-
pub struct AvailableChunkItemInfoMap(FxIndexMap<Vc<Box<dyn ChunkItem>>, AvailableChunkItemInfo>);
20+
pub struct AvailableChunkItemInfoMap(
21+
FxIndexMap<ResolvedVc<Box<dyn ChunkItem>>, AvailableChunkItemInfo>,
22+
);
2123

2224
/// Allows to gather information about which assets are already available.
2325
/// Adding more roots will form a linked list like structure to allow caching
@@ -41,23 +43,23 @@ impl AvailableChunkItems {
4143

4244
#[turbo_tasks::function]
4345
pub async fn with_chunk_items(
44-
self: Vc<Self>,
46+
self: ResolvedVc<Self>,
4547
chunk_items: Vc<AvailableChunkItemInfoMap>,
4648
) -> Result<Vc<Self>> {
4749
let chunk_items = chunk_items
4850
.await?
4951
.into_iter()
5052
.map(|(&chunk_item, &info)| async move {
5153
Ok(self
52-
.get(chunk_item)
54+
.get(*chunk_item)
5355
.await?
5456
.is_none()
5557
.then_some((chunk_item, info)))
5658
})
5759
.try_flat_join()
5860
.await?;
5961
Ok(AvailableChunkItems {
60-
parent: Some(self.to_resolved().await?),
62+
parent: Some(self),
6163
chunk_items: Vc::cell(chunk_items.into_iter().collect()),
6264
}
6365
.cell())
@@ -87,13 +89,13 @@ impl AvailableChunkItems {
8789
#[turbo_tasks::function]
8890
pub async fn get(
8991
&self,
90-
chunk_item: Vc<Box<dyn ChunkItem>>,
92+
chunk_item: ResolvedVc<Box<dyn ChunkItem>>,
9193
) -> Result<Vc<OptionAvailableChunkItemInfo>> {
9294
if let Some(&info) = self.chunk_items.await?.get(&chunk_item) {
9395
return Ok(Vc::cell(Some(info)));
9496
};
9597
if let Some(parent) = self.parent {
96-
return Ok(parent.get(chunk_item));
98+
return Ok(parent.get(*chunk_item));
9799
}
98100
Ok(Vc::cell(None))
99101
}

0 commit comments

Comments
 (0)