@@ -87,13 +87,16 @@ pub struct ModuleIds(Vec<Vc<ModuleId>>);
8787pub 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]
255258pub 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
267270pub 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 > > >
273276where
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
281290pub 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 > > > >
287296where
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
316331async 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
475497const MAX_CHUNK_ITEMS_COUNT : usize = 5000 ;
476498
477499struct 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 ,
0 commit comments