Skip to content

Commit b1d5922

Browse files
committed
Move desc out of WorkItem::short_description to allow reusing in a future commit
1 parent f524236 commit b1d5922

File tree

1 file changed

+39
-39
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+39
-39
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -714,48 +714,48 @@ pub(crate) enum WorkItem<B: WriteBackendMethods> {
714714
ThinLto(lto::ThinModule<B>),
715715
}
716716

717+
// `pthread_setname()` on *nix ignores anything beyond the first 15
718+
// bytes. Use short descriptions to maximize the space available for
719+
// the module name.
720+
#[cfg(not(windows))]
721+
fn desc(short: &str, _long: &str, name: &str) -> String {
722+
// The short label is three bytes, and is followed by a space. That
723+
// leaves 11 bytes for the CGU name. How we obtain those 11 bytes
724+
// depends on the CGU name form.
725+
//
726+
// - Non-incremental, e.g. `regex.f10ba03eb5ec7975-cgu.0`: the part
727+
// before the `-cgu.0` is the same for every CGU, so use the
728+
// `cgu.0` part. The number suffix will be different for each
729+
// CGU.
730+
//
731+
// - Incremental (normal), e.g. `2i52vvl2hco29us0`: use the whole
732+
// name because each CGU will have a unique ASCII hash, and the
733+
// first 11 bytes will be enough to identify it.
734+
//
735+
// - Incremental (with `-Zhuman-readable-cgu-names`), e.g.
736+
// `regex.f10ba03eb5ec7975-re_builder.volatile`: use the whole
737+
// name. The first 11 bytes won't be enough to uniquely identify
738+
// it, but no obvious substring will, and this is a rarely used
739+
// option so it doesn't matter much.
740+
//
741+
assert_eq!(short.len(), 3);
742+
let name = if let Some(index) = name.find("-cgu.") {
743+
&name[index + 1..] // +1 skips the leading '-'.
744+
} else {
745+
name
746+
};
747+
format!("{short} {name}")
748+
}
749+
750+
// Windows has no thread name length limit, so use more descriptive names.
751+
#[cfg(windows)]
752+
fn desc(_short: &str, long: &str, name: &str) -> String {
753+
format!("{long} {name}")
754+
}
755+
717756
impl<B: WriteBackendMethods> WorkItem<B> {
718757
/// Generate a short description of this work item suitable for use as a thread name.
719758
fn short_description(&self) -> String {
720-
// `pthread_setname()` on *nix ignores anything beyond the first 15
721-
// bytes. Use short descriptions to maximize the space available for
722-
// the module name.
723-
#[cfg(not(windows))]
724-
fn desc(short: &str, _long: &str, name: &str) -> String {
725-
// The short label is three bytes, and is followed by a space. That
726-
// leaves 11 bytes for the CGU name. How we obtain those 11 bytes
727-
// depends on the CGU name form.
728-
//
729-
// - Non-incremental, e.g. `regex.f10ba03eb5ec7975-cgu.0`: the part
730-
// before the `-cgu.0` is the same for every CGU, so use the
731-
// `cgu.0` part. The number suffix will be different for each
732-
// CGU.
733-
//
734-
// - Incremental (normal), e.g. `2i52vvl2hco29us0`: use the whole
735-
// name because each CGU will have a unique ASCII hash, and the
736-
// first 11 bytes will be enough to identify it.
737-
//
738-
// - Incremental (with `-Zhuman-readable-cgu-names`), e.g.
739-
// `regex.f10ba03eb5ec7975-re_builder.volatile`: use the whole
740-
// name. The first 11 bytes won't be enough to uniquely identify
741-
// it, but no obvious substring will, and this is a rarely used
742-
// option so it doesn't matter much.
743-
//
744-
assert_eq!(short.len(), 3);
745-
let name = if let Some(index) = name.find("-cgu.") {
746-
&name[index + 1..] // +1 skips the leading '-'.
747-
} else {
748-
name
749-
};
750-
format!("{short} {name}")
751-
}
752-
753-
// Windows has no thread name length limit, so use more descriptive names.
754-
#[cfg(windows)]
755-
fn desc(_short: &str, long: &str, name: &str) -> String {
756-
format!("{long} {name}")
757-
}
758-
759759
match self {
760760
WorkItem::Optimize(m) => desc("opt", "optimize module", &m.name),
761761
WorkItem::CopyPostLtoArtifacts(m) => desc("cpy", "copy LTO artifacts for", &m.name),

0 commit comments

Comments
 (0)