Skip to content

Commit 06985b2

Browse files
authored
[3/n] no-context: migrate turbopack-core (vercel/turborepo#5661)
This migrates `turbopack-core` to the no-context rule. Notably, this addresses an issue where function names were not caught and renames `Issue`'s `context` method to `file_path`.
1 parent 847914e commit 06985b2

File tree

47 files changed

+282
-236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+282
-236
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use turbopack_core::{
4444
context::AssetContext,
4545
environment::{Environment, ExecutionEnvironment, NodeJsEnvironment},
4646
file_source::FileSource,
47-
issue::{IssueContextExt, IssueReporter, IssueSeverity},
47+
issue::{IssueFilePathExt, IssueReporter, IssueSeverity},
4848
module::{Module, Modules},
4949
output::OutputAsset,
5050
reference::all_modules,
@@ -566,7 +566,7 @@ async fn main_operation(
566566
.await?;
567567
for module in modules.iter() {
568568
let set = all_modules(*module)
569-
.issue_context(module.ident().path(), "gathering list of assets")
569+
.issue_file_path(module.ident().path(), "gathering list of assets")
570570
.await?;
571571
for asset in set.await?.iter() {
572572
let path = asset.ident().path().await?;

crates/turbo-tasks-fetch/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub struct FetchIssue {
134134
#[turbo_tasks::value_impl]
135135
impl Issue for FetchIssue {
136136
#[turbo_tasks::function]
137-
fn context(&self) -> Vc<FileSystemPath> {
137+
fn file_path(&self) -> Vc<FileSystemPath> {
138138
self.issue_context
139139
}
140140

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn format_optional_path(
9797
let mut last_context = None;
9898
for item in path.iter().rev() {
9999
let PlainIssueProcessingPathItem {
100-
ref context,
100+
file_path: ref context,
101101
ref description,
102102
} = **item;
103103
if let Some(context) = context {
@@ -138,7 +138,7 @@ pub fn format_issue(
138138
let severity = plain_issue.severity;
139139
// TODO CLICKABLE PATHS
140140
let context_path = plain_issue
141-
.context
141+
.file_path
142142
.replace("[project]", &current_dir.to_string_lossy())
143143
.replace("/./", "/")
144144
.replace("\\\\?\\", "");
@@ -187,7 +187,7 @@ pub fn format_issue(
187187
"{} - [{}] {}",
188188
severity.style(severity_to_style(severity)),
189189
category,
190-
plain_issue.context
190+
plain_issue.file_path
191191
)
192192
.unwrap();
193193

@@ -392,7 +392,8 @@ impl IssueReporter for ConsoleUi {
392392
has_fatal = true;
393393
}
394394

395-
let context_path = make_relative_to_cwd(&plain_issue.context, project_dir, current_dir);
395+
let context_path =
396+
make_relative_to_cwd(&plain_issue.file_path, project_dir, current_dir);
396397
let category = &plain_issue.category;
397398
let title = &plain_issue.title;
398399
let processing_path = &*plain_issue.processing_path;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub trait EvaluatableAsset: Asset + Module + ChunkableModule {}
2020
pub trait EvaluatableAssetExt {
2121
fn to_evaluatable(
2222
self: Vc<Self>,
23-
context: Vc<Box<dyn AssetContext>>,
23+
asset_context: Vc<Box<dyn AssetContext>>,
2424
) -> Vc<Box<dyn EvaluatableAsset>>;
2525
}
2626

@@ -30,18 +30,18 @@ where
3030
{
3131
fn to_evaluatable(
3232
self: Vc<Self>,
33-
context: Vc<Box<dyn AssetContext>>,
33+
asset_context: Vc<Box<dyn AssetContext>>,
3434
) -> Vc<Box<dyn EvaluatableAsset>> {
35-
to_evaluatable(Vc::upcast(self), context)
35+
to_evaluatable(Vc::upcast(self), asset_context)
3636
}
3737
}
3838

3939
#[turbo_tasks::function]
4040
async fn to_evaluatable(
4141
asset: Vc<Box<dyn Source>>,
42-
context: Vc<Box<dyn AssetContext>>,
42+
asset_context: Vc<Box<dyn AssetContext>>,
4343
) -> Result<Vc<Box<dyn EvaluatableAsset>>> {
44-
let asset = context.process(
44+
let asset = asset_context.process(
4545
asset,
4646
Value::new(ReferenceType::Entry(EntryReferenceSubType::Runtime)),
4747
);

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

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,16 @@ pub struct ModuleIds(Vec<Vc<ModuleId>>);
8787
pub trait ChunkableModule: Module + Asset {
8888
fn as_chunk(
8989
self: Vc<Self>,
90-
context: Vc<Box<dyn ChunkingContext>>,
90+
chunking_context: Vc<Box<dyn ChunkingContext>>,
9191
availability_info: Value<AvailabilityInfo>,
9292
) -> Vc<Box<dyn Chunk>>;
9393

94-
fn as_root_chunk(self: Vc<Self>, context: Vc<Box<dyn ChunkingContext>>) -> Vc<Box<dyn Chunk>> {
94+
fn as_root_chunk(
95+
self: Vc<Self>,
96+
chunking_context: Vc<Box<dyn ChunkingContext>>,
97+
) -> Vc<Box<dyn Chunk>> {
9598
self.as_chunk(
96-
context,
99+
chunking_context,
97100
Value::new(AvailabilityInfo::Root {
98101
current_availability_root: Vc::upcast(self),
99102
}),
@@ -254,41 +257,53 @@ pub struct ChunkContentResult<I> {
254257
#[async_trait::async_trait]
255258
pub trait FromChunkableModule: ChunkItem {
256259
async fn from_asset(
257-
context: Vc<Box<dyn ChunkingContext>>,
260+
chunking_context: Vc<Box<dyn ChunkingContext>>,
258261
asset: Vc<Box<dyn Module>>,
259262
) -> Result<Option<Vc<Self>>>;
260263
async fn from_async_asset(
261-
context: Vc<Box<dyn ChunkingContext>>,
264+
chunking_context: Vc<Box<dyn ChunkingContext>>,
262265
asset: Vc<Box<dyn ChunkableModule>>,
263266
availability_info: Value<AvailabilityInfo>,
264267
) -> Result<Option<Vc<Self>>>;
265268
}
266269

267270
pub async fn chunk_content_split<I>(
268-
context: Vc<Box<dyn ChunkingContext>>,
271+
chunking_context: Vc<Box<dyn ChunkingContext>>,
269272
entry: Vc<Box<dyn Module>>,
270273
additional_entries: Option<Vc<Modules>>,
271274
availability_info: Value<AvailabilityInfo>,
272275
) -> Result<ChunkContentResult<Vc<I>>>
273276
where
274277
I: FromChunkableModule,
275278
{
276-
chunk_content_internal_parallel(context, entry, additional_entries, availability_info, true)
277-
.await
278-
.map(|o| o.unwrap())
279+
chunk_content_internal_parallel(
280+
chunking_context,
281+
entry,
282+
additional_entries,
283+
availability_info,
284+
true,
285+
)
286+
.await
287+
.map(|o| o.unwrap())
279288
}
280289

281290
pub async fn chunk_content<I>(
282-
context: Vc<Box<dyn ChunkingContext>>,
291+
chunking_context: Vc<Box<dyn ChunkingContext>>,
283292
entry: Vc<Box<dyn Module>>,
284293
additional_entries: Option<Vc<Modules>>,
285294
availability_info: Value<AvailabilityInfo>,
286295
) -> Result<Option<ChunkContentResult<Vc<I>>>>
287296
where
288297
I: FromChunkableModule,
289298
{
290-
chunk_content_internal_parallel(context, entry, additional_entries, availability_info, false)
291-
.await
299+
chunk_content_internal_parallel(
300+
chunking_context,
301+
entry,
302+
additional_entries,
303+
availability_info,
304+
false,
305+
)
306+
.await
292307
}
293308

294309
#[derive(Eq, PartialEq, Clone, Hash)]
@@ -314,7 +329,7 @@ struct ChunkContentContext {
314329
}
315330

316331
async fn reference_to_graph_nodes<I>(
317-
context: ChunkContentContext,
332+
chunk_content_context: ChunkContentContext,
318333
reference: Vc<Box<dyn ModuleReference>>,
319334
) -> Result<
320335
Vec<(
@@ -347,7 +362,8 @@ where
347362

348363
for &module in &modules {
349364
let module = module.resolve().await?;
350-
if let Some(available_modules) = context.availability_info.available_modules() {
365+
if let Some(available_modules) = chunk_content_context.availability_info.available_modules()
366+
{
351367
if *available_modules.includes(module).await? {
352368
graph_nodes.push((
353369
Some((module, chunking_type)),
@@ -381,7 +397,9 @@ where
381397

382398
match chunking_type {
383399
ChunkingType::Placed => {
384-
if let Some(chunk_item) = I::from_asset(context.chunking_context, module).await? {
400+
if let Some(chunk_item) =
401+
I::from_asset(chunk_content_context.chunking_context, module).await?
402+
{
385403
graph_nodes.push((
386404
Some((module, chunking_type)),
387405
ChunkContentGraphNode::ChunkItem {
@@ -398,31 +416,33 @@ where
398416
}
399417
}
400418
ChunkingType::Parallel => {
401-
let chunk =
402-
chunkable_module.as_chunk(context.chunking_context, context.availability_info);
419+
let chunk = chunkable_module.as_chunk(
420+
chunk_content_context.chunking_context,
421+
chunk_content_context.availability_info,
422+
);
403423
graph_nodes.push((
404424
Some((module, chunking_type)),
405425
ChunkContentGraphNode::Chunk(chunk),
406426
));
407427
}
408428
ChunkingType::IsolatedParallel => {
409-
let chunk = chunkable_module.as_root_chunk(context.chunking_context);
429+
let chunk = chunkable_module.as_root_chunk(chunk_content_context.chunking_context);
410430
graph_nodes.push((
411431
Some((module, chunking_type)),
412432
ChunkContentGraphNode::Chunk(chunk),
413433
));
414434
}
415435
ChunkingType::PlacedOrParallel => {
416436
// heuristic for being in the same chunk
417-
if !context.split
418-
&& *context
437+
if !chunk_content_context.split
438+
&& *chunk_content_context
419439
.chunking_context
420-
.can_be_in_same_chunk(context.entry, module)
440+
.can_be_in_same_chunk(chunk_content_context.entry, module)
421441
.await?
422442
{
423443
// chunk item, chunk or other asset?
424444
if let Some(chunk_item) =
425-
I::from_asset(context.chunking_context, module).await?
445+
I::from_asset(chunk_content_context.chunking_context, module).await?
426446
{
427447
graph_nodes.push((
428448
Some((module, chunking_type)),
@@ -435,18 +455,20 @@ where
435455
}
436456
}
437457

438-
let chunk =
439-
chunkable_module.as_chunk(context.chunking_context, context.availability_info);
458+
let chunk = chunkable_module.as_chunk(
459+
chunk_content_context.chunking_context,
460+
chunk_content_context.availability_info,
461+
);
440462
graph_nodes.push((
441463
Some((module, chunking_type)),
442464
ChunkContentGraphNode::Chunk(chunk),
443465
));
444466
}
445467
ChunkingType::Async => {
446468
if let Some(manifest_loader_item) = I::from_async_asset(
447-
context.chunking_context,
469+
chunk_content_context.chunking_context,
448470
chunkable_module,
449-
context.availability_info,
471+
chunk_content_context.availability_info,
450472
)
451473
.await?
452474
{
@@ -475,7 +497,7 @@ where
475497
const MAX_CHUNK_ITEMS_COUNT: usize = 5000;
476498

477499
struct ChunkContentVisit<I> {
478-
context: ChunkContentContext,
500+
chunk_content_context: ChunkContentContext,
479501
chunk_items_count: usize,
480502
processed_assets: HashSet<(ChunkingType, Vc<Box<dyn Module>>)>,
481503
_phantom: PhantomData<I>,
@@ -522,7 +544,8 @@ where
522544

523545
// Make sure the chunk doesn't become too large.
524546
// This will hurt performance in many aspects.
525-
if !self.context.split && self.chunk_items_count >= MAX_CHUNK_ITEMS_COUNT {
547+
if !self.chunk_content_context.split && self.chunk_items_count >= MAX_CHUNK_ITEMS_COUNT
548+
{
526549
// Chunk is too large, cancel this algorithm and restart with splitting from the
527550
// start.
528551
return VisitControlFlow::Abort(());
@@ -535,7 +558,7 @@ where
535558
fn edges(&mut self, node: &ChunkContentGraphNode<Vc<I>>) -> Self::EdgesFuture {
536559
let node = node.clone();
537560

538-
let context = self.context;
561+
let chunk_content_context = self.chunk_content_context;
539562

540563
async move {
541564
let references = match node {
@@ -549,7 +572,7 @@ where
549572
Ok(references
550573
.await?
551574
.into_iter()
552-
.map(|reference| reference_to_graph_nodes::<I>(context, *reference))
575+
.map(|reference| reference_to_graph_nodes::<I>(chunk_content_context, *reference))
553576
.try_join()
554577
.await?
555578
.into_iter()
@@ -597,15 +620,15 @@ where
597620
.try_join()
598621
.await?;
599622

600-
let context = ChunkContentContext {
623+
let chunk_content_context = ChunkContentContext {
601624
chunking_context,
602625
entry,
603626
split,
604627
availability_info,
605628
};
606629

607630
let visit = ChunkContentVisit {
608-
context,
631+
chunk_content_context,
609632
chunk_items_count: 0,
610633
processed_assets: Default::default(),
611634
_phantom: PhantomData,

crates/turbopack-core/src/compile_time_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl CompileTimeDefines {
122122
pub enum FreeVarReference {
123123
EcmaScriptModule {
124124
request: String,
125-
context: Option<Vc<FileSystemPath>>,
125+
lookup_path: Option<Vc<FileSystemPath>>,
126126
export: Option<String>,
127127
},
128128
Value(CompileTimeDefineValue),

crates/turbopack-core/src/issue/analyze.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Issue for AnalyzeIssue {
3838
}
3939

4040
#[turbo_tasks::function]
41-
fn context(&self) -> Vc<FileSystemPath> {
41+
fn file_path(&self) -> Vc<FileSystemPath> {
4242
self.source_ident.path()
4343
}
4444

crates/turbopack-core/src/issue/code_gen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Issue for CodeGenerationIssue {
2929
}
3030

3131
#[turbo_tasks::function]
32-
fn context(&self) -> Vc<FileSystemPath> {
32+
fn file_path(&self) -> Vc<FileSystemPath> {
3333
self.path
3434
}
3535

0 commit comments

Comments
 (0)