@@ -167,6 +167,7 @@ struct Context {
167
167
/// The map used to ensure all generated 'id=' attributes are unique.
168
168
id_map : Rc < RefCell < IdMap > > ,
169
169
pub shared : Arc < SharedContext > ,
170
+ pub cache : Arc < Cache > ,
170
171
}
171
172
172
173
crate struct SharedContext {
@@ -477,31 +478,31 @@ pub fn run(mut krate: clean::Crate,
477
478
let dst = output;
478
479
scx. ensure_dir ( & dst) ?;
479
480
krate = sources:: render ( & dst, & mut scx, krate) ?;
481
+ let ( new_crate, index, cache) = Cache :: from_krate (
482
+ renderinfo,
483
+ & extern_html_root_urls,
484
+ & dst,
485
+ krate,
486
+ ) ;
487
+ krate = new_crate;
488
+ let cache = Arc :: new ( cache) ;
480
489
let mut cx = Context {
481
490
current : Vec :: new ( ) ,
482
491
dst,
483
492
render_redirect_pages : false ,
484
493
id_map : Rc :: new ( RefCell :: new ( id_map) ) ,
485
494
shared : Arc :: new ( scx) ,
495
+ cache : cache. clone ( ) ,
486
496
} ;
487
497
488
- let ( new_crate, index, cache) = Cache :: from_krate (
489
- renderinfo,
490
- & extern_html_root_urls,
491
- & cx. dst ,
492
- krate,
493
- ) ;
494
- krate = new_crate;
495
-
496
498
// Freeze the cache now that the index has been built. Put an Arc into TLS
497
499
// for future parallelization opportunities
498
- let cache = Arc :: new ( cache) ;
499
500
CACHE_KEY . with ( |v| * v. borrow_mut ( ) = cache. clone ( ) ) ;
500
501
CURRENT_DEPTH . with ( |s| s. set ( 0 ) ) ;
501
502
502
503
// Write shared runs within a flock; disable thread dispatching of IO temporarily.
503
504
Arc :: get_mut ( & mut cx. shared ) . unwrap ( ) . fs . set_sync_only ( true ) ;
504
- write_shared ( & cx, & krate, & * cache , index, & md_opts, diag) ?;
505
+ write_shared ( & cx, & krate, index, & md_opts, diag) ?;
505
506
Arc :: get_mut ( & mut cx. shared ) . unwrap ( ) . fs . set_sync_only ( false ) ;
506
507
507
508
// And finally render the whole crate's documentation
@@ -519,7 +520,6 @@ pub fn run(mut krate: clean::Crate,
519
520
fn write_shared (
520
521
cx : & Context ,
521
522
krate : & clean:: Crate ,
522
- cache : & Cache ,
523
523
search_index : String ,
524
524
options : & RenderOptions ,
525
525
diag : & errors:: Handler ,
@@ -750,7 +750,7 @@ themePicker.onblur = handleThemeButtonsBlur;
750
750
{
751
751
let ( mut all_aliases, _, _) = try_err ! ( collect( & dst, & krate. name, "ALIASES" , false ) , & dst) ;
752
752
let mut output = String :: with_capacity ( 100 ) ;
753
- for ( alias, items) in & cache. aliases {
753
+ for ( alias, items) in & cx . cache . aliases {
754
754
if items. is_empty ( ) {
755
755
continue
756
756
}
@@ -920,17 +920,17 @@ themePicker.onblur = handleThemeButtonsBlur;
920
920
921
921
// Update the list of all implementors for traits
922
922
let dst = cx. dst . join ( "implementors" ) ;
923
- for ( & did, imps) in & cache. implementors {
923
+ for ( & did, imps) in & cx . cache . implementors {
924
924
// Private modules can leak through to this phase of rustdoc, which
925
925
// could contain implementations for otherwise private types. In some
926
926
// rare cases we could find an implementation for an item which wasn't
927
927
// indexed, so we just skip this step in that case.
928
928
//
929
929
// FIXME: this is a vague explanation for why this can't be a `get`, in
930
930
// theory it should be...
931
- let & ( ref remote_path, remote_item_type) = match cache. paths . get ( & did) {
931
+ let & ( ref remote_path, remote_item_type) = match cx . cache . paths . get ( & did) {
932
932
Some ( p) => p,
933
- None => match cache. external_paths . get ( & did) {
933
+ None => match cx . cache . external_paths . get ( & did) {
934
934
Some ( p) => p,
935
935
None => continue ,
936
936
}
@@ -958,7 +958,7 @@ themePicker.onblur = handleThemeButtonsBlur;
958
958
// Only create a js file if we have impls to add to it. If the trait is
959
959
// documented locally though we always create the file to avoid dead
960
960
// links.
961
- if !have_impls && !cache. paths . contains_key ( & did) {
961
+ if !have_impls && !cx . cache . paths . contains_key ( & did) {
962
962
continue ;
963
963
}
964
964
@@ -1309,7 +1309,7 @@ impl Context {
1309
1309
extra_scripts : & [ ] ,
1310
1310
static_extra_scripts : & [ ] ,
1311
1311
} ;
1312
- let sidebar = if let Some ( ref version) = cache ( ) . crate_version {
1312
+ let sidebar = if let Some ( ref version) = self . cache . crate_version {
1313
1313
format ! ( "<p class='location'>Crate {}</p>\
1314
1314
<div class='block version'>\
1315
1315
<p>Version {}</p>\
@@ -1399,7 +1399,7 @@ impl Context {
1399
1399
& self . shared . themes )
1400
1400
} else {
1401
1401
let mut url = self . root_path ( ) ;
1402
- if let Some ( & ( ref names, ty) ) = cache ( ) . paths . get ( & it. def_id ) {
1402
+ if let Some ( & ( ref names, ty) ) = self . cache . paths . get ( & it. def_id ) {
1403
1403
for name in & names[ ..names. len ( ) - 1 ] {
1404
1404
url. push_str ( name) ;
1405
1405
url. push_str ( "/" ) ;
@@ -1549,7 +1549,6 @@ impl Context {
1549
1549
fn src_href ( & self , item : & clean:: Item ) -> Option < String > {
1550
1550
let mut root = self . root_path ( ) ;
1551
1551
1552
- let cache = cache ( ) ;
1553
1552
let mut path = String :: new ( ) ;
1554
1553
1555
1554
// We can safely ignore macros from other libraries
@@ -1565,7 +1564,7 @@ impl Context {
1565
1564
return None ;
1566
1565
}
1567
1566
} else {
1568
- let ( krate, src_root) = match * cache. extern_locations . get ( & item. def_id . krate ) ? {
1567
+ let ( krate, src_root) = match * self . cache . extern_locations . get ( & item. def_id . krate ) ? {
1569
1568
( ref name, ref src, Local ) => ( name, src) ,
1570
1569
( ref name, ref src, Remote ( ref s) ) => {
1571
1570
root = s. to_string ( ) ;
@@ -2475,11 +2474,9 @@ fn item_trait(
2475
2474
// If there are methods directly on this trait object, render them here.
2476
2475
render_assoc_items ( w, cx, it, it. def_id , AssocItemRender :: All ) ;
2477
2476
2478
- let cache = cache ( ) ;
2479
-
2480
2477
let mut synthetic_types = Vec :: new ( ) ;
2481
2478
2482
- if let Some ( implementors) = cache. implementors . get ( & it. def_id ) {
2479
+ if let Some ( implementors) = cx . cache . implementors . get ( & it. def_id ) {
2483
2480
// The DefId is for the first Type found with that name. The bool is
2484
2481
// if any Types with the same name but different DefId have been found.
2485
2482
let mut implementor_dups: FxHashMap < & str , ( DefId , bool ) > = FxHashMap :: default ( ) ;
@@ -2502,7 +2499,7 @@ fn item_trait(
2502
2499
2503
2500
let ( local, foreign) = implementors. iter ( )
2504
2501
. partition :: < Vec < _ > , _ > ( |i| i. inner_impl ( ) . for_ . def_id ( )
2505
- . map_or ( true , |d| cache. paths . contains_key ( & d) ) ) ;
2502
+ . map_or ( true , |d| cx . cache . paths . contains_key ( & d) ) ) ;
2506
2503
2507
2504
2508
2505
let ( mut synthetic, mut concrete) : ( Vec < & & Impl > , Vec < & & Impl > ) = local. iter ( )
@@ -2567,7 +2564,7 @@ fn item_trait(
2567
2564
path = if it. def_id. is_local( ) {
2568
2565
cx. current. join( "/" )
2569
2566
} else {
2570
- let ( ref path, _) = cache. external_paths[ & it. def_id] ;
2567
+ let ( ref path, _) = cx . cache. external_paths[ & it. def_id] ;
2571
2568
path[ ..path. len( ) - 1 ] . join( "/" )
2572
2569
} ,
2573
2570
ty = it. type_( ) ,
@@ -3144,7 +3141,7 @@ fn render_assoc_items(w: &mut Buffer,
3144
3141
containing_item : & clean:: Item ,
3145
3142
it : DefId ,
3146
3143
what : AssocItemRender < ' _ > ) {
3147
- let c = cache ( ) ;
3144
+ let c = & cx . cache ;
3148
3145
let v = match c. impls . get ( & it) {
3149
3146
Some ( v) => v,
3150
3147
None => return ,
@@ -3250,7 +3247,7 @@ fn render_deref_methods(w: &mut Buffer, cx: &Context, impl_: &Impl,
3250
3247
render_assoc_items ( w, cx, container_item, did, what)
3251
3248
} else {
3252
3249
if let Some ( prim) = target. primitive_type ( ) {
3253
- if let Some ( & did) = cache ( ) . primitive_locations . get ( & prim) {
3250
+ if let Some ( & did) = cx . cache . primitive_locations . get ( & prim) {
3254
3251
render_assoc_items ( w, cx, container_item, did, what) ;
3255
3252
}
3256
3253
}
@@ -3500,7 +3497,7 @@ fn render_impl(w: &mut Buffer, cx: &Context, i: &Impl, link: AssocItemLink<'_>,
3500
3497
}
3501
3498
}
3502
3499
3503
- let traits = & cache ( ) . traits ;
3500
+ let traits = & cx . cache . traits ;
3504
3501
let trait_ = i. trait_did ( ) . map ( |did| & traits[ & did] ) ;
3505
3502
3506
3503
write ! ( w, "<div class='impl-items'>" ) ;
@@ -3642,7 +3639,7 @@ fn print_sidebar(cx: &Context, it: &clean::Item, buffer: &mut Buffer) {
3642
3639
}
3643
3640
3644
3641
if it. is_crate ( ) {
3645
- if let Some ( ref version) = cache ( ) . crate_version {
3642
+ if let Some ( ref version) = cx . cache . crate_version {
3646
3643
write ! ( buffer,
3647
3644
"<div class='block version'>\
3648
3645
<p>Version {}</p>\
0 commit comments