@@ -698,28 +698,49 @@ impl<B: WriteBackendMethods> WorkItem<B> {
698
698
699
699
/// Generate a short description of this work item suitable for use as a thread name.
700
700
fn short_description ( & self ) -> String {
701
- // `pthread_setname()` on *nix is limited to 15 characters and longer names are ignored.
702
- // Use very short descriptions in this case to maximize the space available for the module name.
703
- // Windows does not have that limitation so use slightly more descriptive names there.
701
+ // `pthread_setname()` on *nix ignores anything beyond the first 15
702
+ // bytes. Use short descriptions to maximize the space available for
703
+ // the module name.
704
+ #[ cfg( not( windows) ) ]
705
+ fn desc ( short : & str , _long : & str , name : & str ) -> String {
706
+ // The short label is three bytes, and is followed by a space. That
707
+ // leaves 11 bytes for the CGU name. How we obtain those 11 bytes
708
+ // depends on the the CGU name form.
709
+ //
710
+ // - Non-incremental, e.g. `regex.f10ba03eb5ec7975-cgu.0`: the part
711
+ // before the `-cgu.0` is the same for every CGU, so use the
712
+ // `cgu.0` part. The number suffix will be different for each
713
+ // CGU.
714
+ //
715
+ // - Incremental (normal), e.g. `2i52vvl2hco29us0`: use the whole
716
+ // name because each CGU will have a unique ASCII hash, and the
717
+ // first 11 bytes will be enough to identify it.
718
+ //
719
+ // - Incremental (with `-Zhuman-readable-cgu-names`), e.g.
720
+ // `regex.f10ba03eb5ec7975-re_builder.volatile`: use the whole
721
+ // name. The first 11 bytes won't be enough to uniquely identify
722
+ // it, but no obvious substring will, and this is a rarely used
723
+ // option so it doesn't matter much.
724
+ //
725
+ assert_eq ! ( short. len( ) , 3 ) ;
726
+ let name = if let Some ( index) = name. find ( "-cgu." ) {
727
+ & name[ index + 1 ..] // +1 skips the leading '-'.
728
+ } else {
729
+ name
730
+ } ;
731
+ format ! ( "{short} {name}" )
732
+ }
733
+
734
+ // Windows has no thread name length limit, so use more descriptive names.
735
+ #[ cfg( windows) ]
736
+ fn desc ( _short : & str , long : & str , name : & str ) -> String {
737
+ format ! ( "{long} {name}" )
738
+ }
739
+
704
740
match self {
705
- WorkItem :: Optimize ( m) => {
706
- #[ cfg( windows) ]
707
- return format ! ( "optimize module {}" , m. name) ;
708
- #[ cfg( not( windows) ) ]
709
- return format ! ( "opt {}" , m. name) ;
710
- }
711
- WorkItem :: CopyPostLtoArtifacts ( m) => {
712
- #[ cfg( windows) ]
713
- return format ! ( "copy LTO artifacts for {}" , m. name) ;
714
- #[ cfg( not( windows) ) ]
715
- return format ! ( "copy {}" , m. name) ;
716
- }
717
- WorkItem :: LTO ( m) => {
718
- #[ cfg( windows) ]
719
- return format ! ( "LTO module {}" , m. name( ) ) ;
720
- #[ cfg( not( windows) ) ]
721
- return format ! ( "LTO {}" , m. name( ) ) ;
722
- }
741
+ WorkItem :: Optimize ( m) => desc ( "opt" , "optimize module {}" , & m. name ) ,
742
+ WorkItem :: CopyPostLtoArtifacts ( m) => desc ( "cpy" , "copy LTO artifacts for {}" , & m. name ) ,
743
+ WorkItem :: LTO ( m) => desc ( "lto" , "LTO module {}" , m. name ( ) ) ,
723
744
}
724
745
}
725
746
}
0 commit comments