inline format!() args up to and including rustc_codegen_llvm
This commit is contained in:
parent
2e0136a131
commit
3ce90b1649
72 changed files with 411 additions and 481 deletions
|
@ -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(),
|
||||
|
|
|
@ -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}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
};
|
||||
|
||||
|
@ -156,7 +156,7 @@ 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{}",
|
||||
|
@ -164,7 +164,7 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
|
|||
.into_iter()
|
||||
.map(|(name, ordinal)| {
|
||||
match ordinal {
|
||||
Some(n) => format!("{} @{} NONAME", name, n),
|
||||
Some(n) => format!("{name} @{n} NONAME"),
|
||||
None => name,
|
||||
}
|
||||
})
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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 })
|
||||
|
|
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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);
|
||||
|
@ -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),
|
||||
|
@ -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}")))
|
||||
}
|
||||
|
|
|
@ -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:?}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -230,22 +230,22 @@ 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 => {
|
||||
|
@ -253,13 +253,13 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
|||
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 => {
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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.");
|
||||
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue