Rollup merge of #130458 - nnethercote:rustc_codegen_ssa-cleanups, r=jieyouxu

`rustc_codegen_ssa` cleanups

Just some minor improvements I found while reading through this code.

r? ``@jieyouxu``
This commit is contained in:
Matthias Krüger 2024-09-17 17:28:35 +02:00 committed by GitHub
commit d5a081981d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 299 additions and 318 deletions

View file

@ -30,7 +30,7 @@ use crate::errors;
/// and prevent inspection of linker output in case of errors, which we occasionally do.
/// This should be acceptable because other messages from rustc are in English anyway,
/// and may also be desirable to improve searchability of the linker diagnostics.
pub fn disable_localization(linker: &mut Command) {
pub(crate) fn disable_localization(linker: &mut Command) {
// No harm in setting both env vars simultaneously.
// Unix-style linkers.
linker.env("LC_ALL", "C");
@ -41,7 +41,7 @@ pub fn disable_localization(linker: &mut Command) {
/// The third parameter is for env vars, used on windows to set up the
/// path for MSVC to find its DLLs, and gcc to find its bundled
/// toolchain
pub fn get_linker<'a>(
pub(crate) fn get_linker<'a>(
sess: &'a Session,
linker: &Path,
flavor: LinkerFlavor,
@ -215,28 +215,36 @@ fn link_or_cc_args<L: Linker + ?Sized>(
macro_rules! generate_arg_methods {
($($ty:ty)*) => { $(
impl $ty {
pub fn verbatim_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
#[allow(unused)]
pub(crate) fn verbatim_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
verbatim_args(self, args)
}
pub fn verbatim_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
#[allow(unused)]
pub(crate) fn verbatim_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
verbatim_args(self, iter::once(arg))
}
pub fn link_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>, IntoIter: ExactSizeIterator>) -> &mut Self {
#[allow(unused)]
pub(crate) fn link_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>, IntoIter: ExactSizeIterator>) -> &mut Self {
link_args(self, args)
}
pub fn link_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
#[allow(unused)]
pub(crate) fn link_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
link_args(self, iter::once(arg))
}
pub fn cc_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
#[allow(unused)]
pub(crate) fn cc_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
cc_args(self, args)
}
pub fn cc_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
#[allow(unused)]
pub(crate) fn cc_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
cc_args(self, iter::once(arg))
}
pub fn link_or_cc_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
#[allow(unused)]
pub(crate) fn link_or_cc_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
link_or_cc_args(self, args)
}
pub fn link_or_cc_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
#[allow(unused)]
pub(crate) fn link_or_cc_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
link_or_cc_args(self, iter::once(arg))
}
}
@ -263,7 +271,7 @@ generate_arg_methods! {
/// represents the meaning of each option being passed down. This trait is then
/// used to dispatch on whether a GNU-like linker (generally `ld.exe`) or an
/// MSVC linker (e.g., `link.exe`) is being used.
pub trait Linker {
pub(crate) trait Linker {
fn cmd(&mut self) -> &mut Command;
fn is_cc(&self) -> bool {
false
@ -314,12 +322,12 @@ pub trait Linker {
}
impl dyn Linker + '_ {
pub fn take_cmd(&mut self) -> Command {
pub(crate) fn take_cmd(&mut self) -> Command {
mem::replace(self.cmd(), Command::new(""))
}
}
pub struct GccLinker<'a> {
struct GccLinker<'a> {
cmd: Command,
sess: &'a Session,
target_cpu: &'a str,
@ -849,7 +857,7 @@ impl<'a> Linker for GccLinker<'a> {
}
}
pub struct MsvcLinker<'a> {
struct MsvcLinker<'a> {
cmd: Command,
sess: &'a Session,
}
@ -1103,7 +1111,7 @@ impl<'a> Linker for MsvcLinker<'a> {
}
}
pub struct EmLinker<'a> {
struct EmLinker<'a> {
cmd: Command,
sess: &'a Session,
}
@ -1220,7 +1228,7 @@ impl<'a> Linker for EmLinker<'a> {
}
}
pub struct WasmLd<'a> {
struct WasmLd<'a> {
cmd: Command,
sess: &'a Session,
}
@ -1404,7 +1412,7 @@ impl<'a> WasmLd<'a> {
}
/// Linker shepherd script for L4Re (Fiasco)
pub struct L4Bender<'a> {
struct L4Bender<'a> {
cmd: Command,
sess: &'a Session,
hinted_static: bool,
@ -1510,7 +1518,7 @@ impl<'a> Linker for L4Bender<'a> {
}
impl<'a> L4Bender<'a> {
pub fn new(cmd: Command, sess: &'a Session) -> L4Bender<'a> {
fn new(cmd: Command, sess: &'a Session) -> L4Bender<'a> {
L4Bender { cmd, sess, hinted_static: false }
}
@ -1523,14 +1531,14 @@ impl<'a> L4Bender<'a> {
}
/// Linker for AIX.
pub struct AixLinker<'a> {
struct AixLinker<'a> {
cmd: Command,
sess: &'a Session,
hinted_static: Option<bool>,
}
impl<'a> AixLinker<'a> {
pub fn new(cmd: Command, sess: &'a Session) -> AixLinker<'a> {
fn new(cmd: Command, sess: &'a Session) -> AixLinker<'a> {
AixLinker { cmd, sess, hinted_static: None }
}
@ -1758,7 +1766,7 @@ pub(crate) fn linked_symbols(
/// Much simplified and explicit CLI for the NVPTX linker. The linker operates
/// with bitcode and uses LLVM backend to generate a PTX assembly.
pub struct PtxLinker<'a> {
struct PtxLinker<'a> {
cmd: Command,
sess: &'a Session,
}
@ -1824,7 +1832,7 @@ impl<'a> Linker for PtxLinker<'a> {
}
/// The `self-contained` LLVM bitcode linker
pub struct LlbcLinker<'a> {
struct LlbcLinker<'a> {
cmd: Command,
sess: &'a Session,
}
@ -1895,7 +1903,7 @@ impl<'a> Linker for LlbcLinker<'a> {
fn linker_plugin_lto(&mut self) {}
}
pub struct BpfLinker<'a> {
struct BpfLinker<'a> {
cmd: Command,
sess: &'a Session,
}