File tree 3 files changed +22
-6
lines changed 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 51
51
#![ feature( negative_impls) ]
52
52
#![ feature( never_type) ]
53
53
#![ feature( ptr_alignment_type) ]
54
+ #![ feature( round_char_boundary) ]
54
55
#![ feature( rustc_attrs) ]
55
56
#![ feature( rustdoc_internals) ]
56
57
#![ feature( trusted_len) ]
Original file line number Diff line number Diff line change
1
+ use std:: borrow:: Cow ;
1
2
use std:: fmt;
2
3
use std:: hash:: Hash ;
3
4
@@ -468,6 +469,20 @@ impl<'tcx> CodegenUnit<'tcx> {
468
469
hash. as_u128 ( ) . to_base_fixed_len ( CASE_INSENSITIVE )
469
470
}
470
471
472
+ pub fn shorten_name ( human_readable_name : & str ) -> Cow < ' _ , str > {
473
+ // Set a limit a somewhat below the common platform limits for file names.
474
+ const MAX_CGU_NAME_LENGTH : usize = 200 ;
475
+ if human_readable_name. len ( ) > MAX_CGU_NAME_LENGTH {
476
+ let mangled_name = Self :: mangle_name ( human_readable_name) ;
477
+ let truncate_to = human_readable_name
478
+ . floor_char_boundary ( MAX_CGU_NAME_LENGTH - mangled_name. len ( ) - 1 ) ;
479
+ format ! ( "{}-{}" , & human_readable_name[ ..truncate_to] , mangled_name) . into ( )
480
+ } else {
481
+ // If the name is short enough, we can just return it as is.
482
+ human_readable_name. into ( )
483
+ }
484
+ }
485
+
471
486
pub fn compute_size_estimate ( & mut self ) {
472
487
// The size of a codegen unit as the sum of the sizes of the items
473
488
// within it.
@@ -604,7 +619,7 @@ impl<'tcx> CodegenUnitNameBuilder<'tcx> {
604
619
let cgu_name = self . build_cgu_name_no_mangle ( cnum, components, special_suffix) ;
605
620
606
621
if self . tcx . sess . opts . unstable_opts . human_readable_cgu_names {
607
- cgu_name
622
+ Symbol :: intern ( & CodegenUnit :: shorten_name ( cgu_name. as_str ( ) ) )
608
623
} else {
609
624
Symbol :: intern ( & CodegenUnit :: mangle_name ( cgu_name. as_str ( ) ) )
610
625
}
Original file line number Diff line number Diff line change @@ -461,15 +461,15 @@ fn merge_codegen_units<'tcx>(
461
461
462
462
for cgu in codegen_units. iter_mut ( ) {
463
463
if let Some ( new_cgu_name) = new_cgu_names. get ( & cgu. name ( ) ) {
464
- if cx. tcx . sess . opts . unstable_opts . human_readable_cgu_names {
465
- cgu . set_name ( Symbol :: intern ( new_cgu_name) ) ;
464
+ let new_cgu_name = if cx. tcx . sess . opts . unstable_opts . human_readable_cgu_names {
465
+ Symbol :: intern ( & CodegenUnit :: shorten_name ( new_cgu_name) )
466
466
} else {
467
467
// If we don't require CGU names to be human-readable,
468
468
// we use a fixed length hash of the composite CGU name
469
469
// instead.
470
- let new_cgu_name = CodegenUnit :: mangle_name ( new_cgu_name) ;
471
- cgu . set_name ( Symbol :: intern ( & new_cgu_name ) ) ;
472
- }
470
+ Symbol :: intern ( & CodegenUnit :: mangle_name ( new_cgu_name) )
471
+ } ;
472
+ cgu . set_name ( new_cgu_name ) ;
473
473
}
474
474
}
475
475
You can’t perform that action at this time.
0 commit comments