File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 5151#![ feature( negative_impls) ]
5252#![ feature( never_type) ]
5353#![ feature( ptr_alignment_type) ]
54+ #![ feature( round_char_boundary) ]
5455#![ feature( rustc_attrs) ]
5556#![ feature( rustdoc_internals) ]
5657#![ feature( trusted_len) ]
Original file line number Diff line number Diff line change 1+ use std:: borrow:: Cow ;
12use std:: fmt;
23use std:: hash:: Hash ;
34
@@ -468,6 +469,20 @@ impl<'tcx> CodegenUnit<'tcx> {
468469 hash. as_u128 ( ) . to_base_fixed_len ( CASE_INSENSITIVE )
469470 }
470471
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+
471486 pub fn compute_size_estimate ( & mut self ) {
472487 // The size of a codegen unit as the sum of the sizes of the items
473488 // within it.
@@ -604,7 +619,7 @@ impl<'tcx> CodegenUnitNameBuilder<'tcx> {
604619 let cgu_name = self . build_cgu_name_no_mangle ( cnum, components, special_suffix) ;
605620
606621 if self . tcx . sess . opts . unstable_opts . human_readable_cgu_names {
607- cgu_name
622+ Symbol :: intern ( & CodegenUnit :: shorten_name ( cgu_name. as_str ( ) ) )
608623 } else {
609624 Symbol :: intern ( & CodegenUnit :: mangle_name ( cgu_name. as_str ( ) ) )
610625 }
Original file line number Diff line number Diff line change @@ -461,15 +461,15 @@ fn merge_codegen_units<'tcx>(
461461
462462 for cgu in codegen_units. iter_mut ( ) {
463463 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) )
466466 } else {
467467 // If we don't require CGU names to be human-readable,
468468 // we use a fixed length hash of the composite CGU name
469469 // 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 ) ;
473473 }
474474 }
475475
You can’t perform that action at this time.
0 commit comments