Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inline format!() args from rustc_middle up to and including rustc_codegen_llvm (3) #114074

Merged
merged 1 commit into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
let mut function_features = function_features
.iter()
.flat_map(|feat| {
llvm_util::to_llvm_features(cx.tcx.sess, feat).into_iter().map(|f| format!("+{}", f))
llvm_util::to_llvm_features(cx.tcx.sess, feat).into_iter().map(|f| format!("+{f}"))
})
.chain(codegen_fn_attrs.instruction_set.iter().map(|x| match x {
InstructionSetAttr::ArmA32 => "-thumb-mode".to_string(),
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_llvm/src/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn llvm_machine_type(cpu: &str) -> LLVMMachineType {
"x86" => LLVMMachineType::I386,
"aarch64" => LLVMMachineType::ARM64,
"arm" => LLVMMachineType::ARM,
_ => panic!("unsupported cpu type {}", cpu),
_ => panic!("unsupported cpu type {cpu}"),
}
}

Expand Down Expand Up @@ -128,7 +128,7 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
let name_suffix = if is_direct_dependency { "_imports" } else { "_imports_indirect" };
let output_path = {
let mut output_path: PathBuf = tmpdir.to_path_buf();
output_path.push(format!("{}{}", lib_name, name_suffix));
output_path.push(format!("{lib_name}{name_suffix}"));
output_path.with_extension("lib")
};

Expand Down Expand Up @@ -156,15 +156,15 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
// functions. Therefore, use binutils to create the import library instead,
// by writing a .DEF file to the temp dir and calling binutils's dlltool.
let def_file_path =
tmpdir.join(format!("{}{}", lib_name, name_suffix)).with_extension("def");
tmpdir.join(format!("{lib_name}{name_suffix}")).with_extension("def");

let def_file_content = format!(
"EXPORTS\n{}",
import_name_and_ordinal_vector
.into_iter()
.map(|(name, ordinal)| {
match ordinal {
Some(n) => format!("{} @{} NONAME", name, n),
Some(n) => format!("{name} @{n} NONAME"),
None => name,
}
})
Expand Down Expand Up @@ -435,7 +435,7 @@ impl<'a> LlvmArchiveBuilder<'a> {
}

fn string_to_io_error(s: String) -> io::Error {
io::Error::new(io::ErrorKind::Other, format!("bad archive: {}", s))
io::Error::new(io::ErrorKind::Other, format!("bad archive: {s}"))
}

fn find_binutils_dlltool(sess: &Session) -> OsString {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ fn fat_lto(
let _timer = cgcx
.prof
.generic_activity_with_arg_recorder("LLVM_fat_lto_link_module", |recorder| {
recorder.record_arg(format!("{:?}", name))
recorder.record_arg(format!("{name:?}"))
});
info!("linking {:?}", name);
let data = bc_decoded.data();
Expand Down Expand Up @@ -787,7 +787,7 @@ impl ThinLTOKeysMap {
let file = File::create(path)?;
let mut writer = io::BufWriter::new(file);
for (module, key) in &self.keys {
writeln!(writer, "{} {}", module, key)?;
writeln!(writer, "{module} {key}")?;
}
Ok(())
}
Expand All @@ -801,7 +801,7 @@ impl ThinLTOKeysMap {
let mut split = line.split(' ');
let module = split.next().unwrap();
let key = split.next().unwrap();
assert_eq!(split.next(), None, "Expected two space-separated values, found {:?}", line);
assert_eq!(split.next(), None, "Expected two space-separated values, found {line:?}");
keys.insert(module.to_string(), key.to_string());
}
Ok(Self { keys })
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ pub(crate) fn save_temp_bitcode(
return;
}
unsafe {
let ext = format!("{}.bc", name);
let ext = format!("{name}.bc");
let cgu = Some(&module.name[..]);
let path = cgcx.output_filenames.temp_path_ext(&ext, cgu);
let cstr = path_to_c_string(&path);
Expand Down Expand Up @@ -713,7 +713,7 @@ pub(crate) unsafe fn codegen(

let Ok(demangled) = rustc_demangle::try_demangle(input) else { return 0 };

if write!(cursor, "{:#}", demangled).is_err() {
if write!(cursor, "{demangled:#}").is_err() {
// Possible only if provided buffer is not big enough
return 0;
}
Expand Down Expand Up @@ -834,7 +834,7 @@ pub(crate) unsafe fn codegen(
}

fn create_section_with_flags_asm(section_name: &str, section_flags: &str, data: &[u8]) -> Vec<u8> {
let mut asm = format!(".section {},\"{}\"\n", section_name, section_flags).into_bytes();
let mut asm = format!(".section {section_name},\"{section_flags}\"\n").into_bytes();
asm.extend_from_slice(b".ascii \"");
asm.reserve(data.len());
for &byte in data {
Expand Down
11 changes: 3 additions & 8 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,9 +1415,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
) -> Cow<'b, [&'ll Value]> {
assert!(
self.cx.type_kind(fn_ty) == TypeKind::Function,
"builder::{} not passed a function, but {:?}",
typ,
fn_ty
"builder::{typ} not passed a function, but {fn_ty:?}"
);

let param_tys = self.cx.func_params_types(fn_ty);
Expand Down Expand Up @@ -1509,12 +1507,9 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {

let instr = if signed { "fptosi" } else { "fptoui" };
let name = if let Some(vector_length) = vector_length {
format!(
"llvm.{}.sat.v{}i{}.v{}f{}",
instr, vector_length, int_width, vector_length, float_width
)
format!("llvm.{instr}.sat.v{vector_length}i{int_width}.v{vector_length}f{float_width}")
} else {
format!("llvm.{}.sat.i{}.f{}", instr, int_width, float_width)
format!("llvm.{instr}.sat.i{int_width}.f{float_width}")
};
let f = self.declare_cfn(&name, llvm::UnnamedAddr::No, self.type_func(&[src_ty], dest_ty));
self.call(self.type_func(&[src_ty], dest_ty), None, None, f, &[val], None)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,10 @@ pub(crate) fn i686_decorated_name(
DllCallingConvention::C => {}
DllCallingConvention::Stdcall(arg_list_size)
| DllCallingConvention::Fastcall(arg_list_size) => {
write!(&mut decorated_name, "@{}", arg_list_size).unwrap();
write!(&mut decorated_name, "@{arg_list_size}").unwrap();
}
DllCallingConvention::Vectorcall(arg_list_size) => {
write!(&mut decorated_name, "@@{}", arg_list_size).unwrap();
write!(&mut decorated_name, "@@{arg_list_size}").unwrap();
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ impl<'ll> CodegenCx<'ll, '_> {
assert!(
!defined_in_current_codegen_unit,
"consts::get_static() should always hit the cache for \
statics defined in the same CGU, but did not for `{:?}`",
def_id
statics defined in the same CGU, but did not for `{def_id:?}`"
);

let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn get_or_insert_gdb_debug_scripts_section_global<'ll>(cx: &CodegenCx<'ll, '
// The initial byte `4` instructs GDB that the following pretty printer
// is defined inline as opposed to in a standalone file.
section_contents.extend_from_slice(b"\x04");
let vis_name = format!("pretty-printer-{}-{}\n", crate_name, index);
let vis_name = format!("pretty-printer-{crate_name}-{index}\n");
section_contents.extend_from_slice(vis_name.as_bytes());
section_contents.extend_from_slice(&visualizer.src);

Expand Down
16 changes: 7 additions & 9 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
debug_assert_eq!(
(data_layout.pointer_size, data_layout.pointer_align.abi),
cx.size_and_align_of(ptr_type),
"ptr_type={}, pointee_type={}",
ptr_type,
pointee_type,
"ptr_type={ptr_type}, pointee_type={pointee_type}",
);

let di_node = unsafe {
Expand Down Expand Up @@ -521,7 +519,7 @@ fn recursion_marker_type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> &'ll D
fn hex_encode(data: &[u8]) -> String {
let mut hex_string = String::with_capacity(data.len() * 2);
for byte in data.iter() {
write!(&mut hex_string, "{:02x}", byte).unwrap();
write!(&mut hex_string, "{byte:02x}").unwrap();
}
hex_string
}
Expand Down Expand Up @@ -766,7 +764,7 @@ fn build_param_type_di_node<'ll, 'tcx>(
t: Ty<'tcx>,
) -> DINodeCreationResult<'ll> {
debug!("build_param_type_di_node: {:?}", t);
let name = format!("{:?}", t);
let name = format!("{t:?}");
DINodeCreationResult {
di_node: unsafe {
llvm::LLVMRustDIBuilderCreateBasicType(
Expand Down Expand Up @@ -814,7 +812,7 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
debug!("build_compile_unit_di_node: {:?}", name_in_debuginfo);
let rustc_producer = format!("rustc version {}", tcx.sess.cfg_version);
// FIXME(#41252) Remove "clang LLVM" if we can get GDB and LLVM to play nice.
let producer = format!("clang LLVM ({})", rustc_producer);
let producer = format!("clang LLVM ({rustc_producer})");

let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
let work_dir = tcx.sess.opts.working_dir.to_string_lossy(FileNameDisplayPreference::Remapped);
Expand Down Expand Up @@ -1331,10 +1329,10 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
// Note: This code does not try to give a proper name to each method
// because their might be multiple methods with the same name
// (coming from different traits).
(format!("__method{}", index), void_pointer_type_di_node)
(format!("__method{index}"), void_pointer_type_di_node)
}
ty::VtblEntry::TraitVPtr(_) => {
(format!("__super_trait_ptr{}", index), void_pointer_type_di_node)
(format!("__super_trait_ptr{index}"), void_pointer_type_di_node)
}
ty::VtblEntry::MetadataAlign => ("align".to_string(), usize_di_node),
ty::VtblEntry::MetadataSize => ("size".to_string(), usize_di_node),
Expand Down Expand Up @@ -1504,5 +1502,5 @@ pub fn tuple_field_name(field_index: usize) -> Cow<'static, str> {
TUPLE_FIELD_NAMES
.get(field_index)
.map(|s| Cow::from(*s))
.unwrap_or_else(|| Cow::from(format!("__{}", field_index)))
.unwrap_or_else(|| Cow::from(format!("__{field_index}")))
}
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_llvm/src/debuginfo/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>(
// For all other pointee types we should already have returned None
// at the beginning of the function.
panic!(
"fat_pointer_kind() - Encountered unexpected `pointee_tail_ty`: {:?}",
pointee_tail_ty
"fat_pointer_kind() - Encountered unexpected `pointee_tail_ty`: {pointee_tail_ty:?}"
)
}
}
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,36 +230,36 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
sym::ctlz | sym::cttz => {
let y = self.const_bool(false);
self.call_intrinsic(
&format!("llvm.{}.i{}", name, width),
&format!("llvm.{name}.i{width}"),
&[args[0].immediate(), y],
)
}
sym::ctlz_nonzero => {
let y = self.const_bool(true);
let llvm_name = &format!("llvm.ctlz.i{}", width);
let llvm_name = &format!("llvm.ctlz.i{width}");
self.call_intrinsic(llvm_name, &[args[0].immediate(), y])
}
sym::cttz_nonzero => {
let y = self.const_bool(true);
let llvm_name = &format!("llvm.cttz.i{}", width);
let llvm_name = &format!("llvm.cttz.i{width}");
self.call_intrinsic(llvm_name, &[args[0].immediate(), y])
}
sym::ctpop => self.call_intrinsic(
&format!("llvm.ctpop.i{}", width),
&format!("llvm.ctpop.i{width}"),
&[args[0].immediate()],
),
sym::bswap => {
if width == 8 {
args[0].immediate() // byte swap a u8/i8 is just a no-op
} else {
self.call_intrinsic(
&format!("llvm.bswap.i{}", width),
&format!("llvm.bswap.i{width}"),
&[args[0].immediate()],
)
}
}
sym::bitreverse => self.call_intrinsic(
&format!("llvm.bitreverse.i{}", width),
&format!("llvm.bitreverse.i{width}"),
&[args[0].immediate()],
),
sym::rotate_left | sym::rotate_right => {
Expand Down Expand Up @@ -1283,7 +1283,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
sym::simd_trunc => ("trunc", bx.type_func(&[vec_ty], vec_ty)),
_ => return_error!(InvalidMonomorphization::UnrecognizedIntrinsic { span, name }),
};
let llvm_name = &format!("llvm.{0}.v{1}{2}", intr_name, in_len, elem_ty_str);
let llvm_name = &format!("llvm.{intr_name}.v{in_len}{elem_ty_str}");
let f = bx.declare_cfn(llvm_name, llvm::UnnamedAddr::No, fn_ty);
let c = bx.call(
fn_ty,
Expand Down Expand Up @@ -1498,7 +1498,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
let llvm_elem_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count - 1, bx);

let llvm_intrinsic =
format!("llvm.masked.gather.{}.{}", llvm_elem_vec_str, llvm_pointer_vec_str);
format!("llvm.masked.gather.{llvm_elem_vec_str}.{llvm_pointer_vec_str}");
let fn_ty = bx.type_func(
&[llvm_pointer_vec_ty, alignment_ty, mask_ty, llvm_elem_vec_ty],
llvm_elem_vec_ty,
Expand Down Expand Up @@ -1642,7 +1642,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
let llvm_elem_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count - 1, bx);

let llvm_intrinsic =
format!("llvm.masked.scatter.{}.{}", llvm_elem_vec_str, llvm_pointer_vec_str);
format!("llvm.masked.scatter.{llvm_elem_vec_str}.{llvm_pointer_vec_str}");
let fn_ty =
bx.type_func(&[llvm_elem_vec_ty, llvm_pointer_vec_ty, alignment_ty, mask_ty], ret_t);
let f = bx.declare_cfn(&llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,21 +298,21 @@ impl CodegenBackend for LlvmCodegenBackend {
"ropi-rwpi",
"default",
] {
writeln!(out, " {}", name);
writeln!(out, " {name}");
}
writeln!(out);
}
PrintKind::CodeModels => {
writeln!(out, "Available code models:");
for name in &["tiny", "small", "kernel", "medium", "large"] {
writeln!(out, " {}", name);
writeln!(out, " {name}");
}
writeln!(out);
}
PrintKind::TlsModels => {
writeln!(out, "Available TLS models:");
for name in &["global-dynamic", "local-dynamic", "initial-exec", "local-exec"] {
writeln!(out, " {}", name);
writeln!(out, " {name}");
}
writeln!(out);
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {

pub fn print_version() {
let (major, minor, patch) = get_version();
println!("LLVM version: {}.{}.{}", major, minor, patch);
println!("LLVM version: {major}.{minor}.{patch}");
}

pub fn get_version() -> (u32, u32, u32) {
Expand Down Expand Up @@ -390,11 +390,11 @@ fn print_target_features(out: &mut dyn PrintBackendInfo, sess: &Session, tm: &ll

writeln!(out, "Features supported by rustc for this target:");
for (feature, desc) in &rustc_target_features {
writeln!(out, " {1:0$} - {2}.", max_feature_len, feature, desc);
writeln!(out, " {feature:max_feature_len$} - {desc}.");
}
writeln!(out, "\nCode-generation features supported by LLVM for this target:");
for (feature, desc) in &llvm_target_features {
writeln!(out, " {1:0$} - {2}.", max_feature_len, feature, desc);
writeln!(out, " {feature:max_feature_len$} - {desc}.");
}
if llvm_target_features.is_empty() {
writeln!(out, " Target features listing is not supported by this LLVM version.");
Expand Down Expand Up @@ -573,7 +573,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
match (enable_disable, feat) {
('-' | '+', TargetFeatureFoldStrength::Both(f))
| ('+', TargetFeatureFoldStrength::EnableOnly(f)) => {
Some(format!("{}{}", enable_disable, f))
Some(format!("{enable_disable}{f}"))
}
_ => None,
}
Expand Down
Loading