From 874688849ef0059be2d46fd4e599f1b5fa0acc3d Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Sat, 31 May 2025 05:06:05 +0000 Subject: [PATCH 1/6] stdarch-gen-arm: Modernization of the coding style It modernizes the coding style of the crate stdarch-gen-arm by fixing Clippy warnings (except clippy::{collapsible_if,obfuscated_if_else} that might make the program look worse as a result of "fixing" warnings). Clippy: rust version 1.89.0-nightly (6f6971078 2025-05-28) Number of Fixed Warnings: 84/84 Note: Rust Analyzer double counts one of the Clippy warnings so it reduces 85 warnings (as reported by the Rust Analyzer). This commit also applies similar technique used to resolve Clippy warnings but also simplifies identifier name formatting and makes reading easier. Confirmed that the exact same code will be generated. --- crates/stdarch-gen-arm/src/big_endian.rs | 29 +--- crates/stdarch-gen-arm/src/context.rs | 5 +- crates/stdarch-gen-arm/src/expression.rs | 15 +- crates/stdarch-gen-arm/src/fn_suffix.rs | 133 ++++-------------- crates/stdarch-gen-arm/src/intrinsic.rs | 37 ++--- .../stdarch-gen-arm/src/load_store_tests.rs | 5 +- crates/stdarch-gen-arm/src/main.rs | 12 +- crates/stdarch-gen-arm/src/typekinds.rs | 8 +- crates/stdarch-gen-arm/src/wildstring.rs | 2 +- 9 files changed, 76 insertions(+), 170 deletions(-) diff --git a/crates/stdarch-gen-arm/src/big_endian.rs b/crates/stdarch-gen-arm/src/big_endian.rs index 171904bbdb..b982ff53ec 100644 --- a/crates/stdarch-gen-arm/src/big_endian.rs +++ b/crates/stdarch-gen-arm/src/big_endian.rs @@ -38,7 +38,7 @@ fn create_array(lanes: u32) -> Option { 4 => Some("[3, 2, 1, 0]".to_string()), 8 => Some("[7, 6, 5, 4, 3, 2, 1, 0]".to_string()), 16 => Some("[15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]".to_string()), - _ => panic!("Incorrect vector number of vector lanes: {}", lanes), + _ => panic!("Incorrect vector number of vector lanes: {lanes}"), } } @@ -78,12 +78,7 @@ pub fn type_has_tuple(type_kind: &TypeKind) -> bool { } pub fn make_variable_mutable(variable_name: &str, type_kind: &TypeKind) -> Expression { - let mut_variable = format!( - "let mut {}: {} = {}", - variable_name, - type_kind.to_string(), - variable_name - ); + let mut_variable = format!("let mut {variable_name}: {type_kind} = {variable_name}"); let identifier_name = create_single_wild_string(&mut_variable); Expression::Identifier(identifier_name, IdentifierType::Symbol) } @@ -114,9 +109,7 @@ fn create_shuffle_internal( }; let lane_count = vector_type.lanes(); - let Some(array_lanes) = create_array(lane_count) else { - return None; - }; + let array_lanes = create_array(lane_count)?; let tuple_count = vector_type.tuple_size().map_or_else(|| 0, |t| t.to_int()); @@ -144,10 +137,7 @@ fn create_assigned_tuple_shuffle_call_fmt( array_lanes: &String, ) -> String { format!( - "{variable_name}.{idx} = unsafe {{ simd_shuffle!({variable_name}.{idx}, {variable_name}.{idx}, {array_lanes}) }};\n", - variable_name = variable_name, - idx = idx, - array_lanes = array_lanes + "{variable_name}.{idx} = unsafe {{ simd_shuffle!({variable_name}.{idx}, {variable_name}.{idx}, {array_lanes}) }};\n" ) } @@ -157,10 +147,7 @@ fn create_assigned_shuffle_call_fmt( array_lanes: &String, ) -> String { format!( - "let {variable_name}: {type_kind} = unsafe {{ simd_shuffle!({variable_name}, {variable_name}, {array_lanes}) }}", - type_kind = type_kind.to_string(), - variable_name = variable_name, - array_lanes = array_lanes + "let {variable_name}: {type_kind} = unsafe {{ simd_shuffle!({variable_name}, {variable_name}, {array_lanes}) }}" ) } @@ -169,11 +156,7 @@ fn create_shuffle_call_fmt( _type_kind: &TypeKind, array_lanes: &String, ) -> String { - format!( - "simd_shuffle!({variable_name}, {variable_name}, {array_lanes})", - variable_name = variable_name, - array_lanes = array_lanes - ) + format!("simd_shuffle!({variable_name}, {variable_name}, {array_lanes})") } /// Create a `simd_shuffle!(<...>, [...])` call, where the output is stored diff --git a/crates/stdarch-gen-arm/src/context.rs b/crates/stdarch-gen-arm/src/context.rs index 751fd9f2a3..9b8eb8e8b9 100644 --- a/crates/stdarch-gen-arm/src/context.rs +++ b/crates/stdarch-gen-arm/src/context.rs @@ -1,6 +1,6 @@ use itertools::Itertools; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, usize}; +use std::collections::HashMap; use crate::{ expression::Expression, @@ -165,11 +165,12 @@ impl LocalContext { .map_or_else(err, |ty| Ok((ty.size().parse::().unwrap()-1).to_string())), Wildcard::SizeInBytesLog2(idx) => self.input.typekind(*idx) .map_or_else(err, |ty| Ok(ty.size_in_bytes_log2())), - Wildcard::NVariant if self.substitutions.get(wildcard).is_none() => Ok(String::new()), + Wildcard::NVariant if !self.substitutions.contains_key(wildcard) => Ok(String::new()), Wildcard::TypeKind(idx, opts) => { self.input.typekind(*idx) .map_or_else(err, |ty| { let literal = if let Some(opts) = opts { + #[allow(clippy::obfuscated_if_else)] opts.contains(ty.base_type().map(|bt| *bt.kind()).ok_or_else(|| { format!("cannot retrieve a type literal out of {ty}") })?) diff --git a/crates/stdarch-gen-arm/src/expression.rs b/crates/stdarch-gen-arm/src/expression.rs index b1db251a14..56c94602ff 100644 --- a/crates/stdarch-gen-arm/src/expression.rs +++ b/crates/stdarch-gen-arm/src/expression.rs @@ -56,7 +56,7 @@ impl FnCall { FnCall(Box::new(fn_ptr), arguments, Vec::new(), true).into() } - pub fn is_llvm_link_call(&self, llvm_link_name: &String) -> bool { + pub fn is_llvm_link_call(&self, llvm_link_name: &str) -> bool { self.is_expected_call(llvm_link_name) } @@ -66,7 +66,7 @@ impl FnCall { pub fn is_expected_call(&self, fn_call_name: &str) -> bool { if let Expression::Identifier(fn_name, IdentifierType::Symbol) = self.0.as_ref() { - &fn_name.to_string() == fn_call_name + fn_name.to_string() == fn_call_name } else { false } @@ -205,6 +205,7 @@ impl Expression { Self::FnCall(fn_call) => { fn_call.build(intrinsic, ctx)?; + #[allow(clippy::collapsible_if)] if let Some(llvm_link_name) = ctx.local.substitutions.get(&Wildcard::LLVMLink) { if fn_call.is_llvm_link_call(llvm_link_name) { *self = intrinsic @@ -357,7 +358,7 @@ impl Expression { false } } - _ => panic!("Badly defined function call: {:?}", fn_call), + _ => panic!("Badly defined function call: {fn_call:?}"), }, _ => false, } @@ -365,11 +366,7 @@ impl Expression { /// Determine if an espression is a LLVM binding pub fn is_llvm_link(&self) -> bool { - if let Expression::LLVMLink(_) = self { - true - } else { - false - } + matches!(self, Expression::LLVMLink(_)) } } @@ -508,7 +505,7 @@ impl ToTokens for Expression { identifier .to_string() .parse::() - .expect(format!("invalid syntax: {:?}", self).as_str()) + .unwrap_or_else(|_| panic!("invalid syntax: {self:?}")) .to_tokens(tokens); } Self::IntConstant(n) => tokens.append(Literal::i32_unsuffixed(*n)), diff --git a/crates/stdarch-gen-arm/src/fn_suffix.rs b/crates/stdarch-gen-arm/src/fn_suffix.rs index 9f7827776e..26c156ae17 100644 --- a/crates/stdarch-gen-arm/src/fn_suffix.rs +++ b/crates/stdarch-gen-arm/src/fn_suffix.rs @@ -61,7 +61,7 @@ fn neon_get_base_and_char(ty: &VectorType) -> (u32, char, bool) { BaseType::Sized(BaseTypeKind::Int, size) => (*size, 's', *size * lanes == 128), BaseType::Sized(BaseTypeKind::UInt, size) => (*size, 'u', *size * lanes == 128), BaseType::Sized(BaseTypeKind::Poly, size) => (*size, 'p', *size * lanes == 128), - _ => panic!("Unhandled {:?}", ty), + _ => panic!("Unhandled {ty:?}"), } } @@ -73,169 +73,92 @@ pub fn make_neon_suffix(type_kind: TypeKind, suffix_kind: SuffixKind) -> String TypeKind::Vector(ty) => { let tuple_size = ty.tuple_size().map_or(0, |t| t.to_int()); let (base_size, prefix_char, requires_q) = neon_get_base_and_char(&ty); + let prefix_q = if requires_q { "q" } else { "" }; let lanes = ty.lanes(); match suffix_kind { SuffixKind::Normal => { - let mut str_suffix: String = String::new(); - if requires_q { - str_suffix.push('q'); - } - str_suffix.push('_'); - str_suffix.push(prefix_char); - str_suffix.push_str(base_size.to_string().as_str()); + let mut str_suffix: String = format!("{prefix_q}_{prefix_char}{base_size}"); if tuple_size > 0 { str_suffix.push_str("_x"); str_suffix.push_str(tuple_size.to_string().as_str()); } - return str_suffix; + str_suffix } SuffixKind::NSuffix => { - let mut str_suffix: String = String::new(); - if requires_q { - str_suffix.push('q'); - } - str_suffix.push_str("_n_"); - str_suffix.push(prefix_char); - str_suffix.push_str(base_size.to_string().as_str()); - return str_suffix; + format!("{prefix_q}_n_{prefix_char}{base_size}") } - SuffixKind::NoQ => format!("_{}{}", prefix_char, base_size), - SuffixKind::NoQNSuffix => format!("_n{}{}", prefix_char, base_size), + SuffixKind::NoQ => format!("_{prefix_char}{base_size}"), + SuffixKind::NoQNSuffix => format!("_n{prefix_char}{base_size}"), SuffixKind::Unsigned => { let t = type_kind.to_string(); if t.starts_with("u") { return t; } - return format!("u{}", t); + format!("u{t}") } SuffixKind::Lane => { if lanes == 0 { - panic!("type {} has no lanes!", type_kind.to_string()) + panic!("type {type_kind} has no lanes!") } else { - format!("{}", lanes) + format!("{lanes}") } } SuffixKind::Tuple => { if tuple_size == 0 { - panic!("type {} has no lanes!", type_kind.to_string()) + panic!("type {type_kind} has no lanes!") } else { - format!("{}", tuple_size) + format!("{tuple_size}") } } SuffixKind::Base => base_size.to_string(), SuffixKind::NoX => { - let mut str_suffix: String = String::new(); - if requires_q { - str_suffix.push('q'); - } - str_suffix.push('_'); - str_suffix.push(prefix_char); - str_suffix.push_str(base_size.to_string().as_str()); - return str_suffix; + format!("{prefix_q}_{prefix_char}{base_size}") } SuffixKind::Dup => { - let mut str_suffix: String = String::new(); - if requires_q { - str_suffix.push('q'); - } - str_suffix.push('_'); - str_suffix.push_str("dup_"); - str_suffix.push(prefix_char); - str_suffix.push_str(base_size.to_string().as_str()); + let mut str_suffix: String = format!("{prefix_q}_dup_{prefix_char}{base_size}"); if tuple_size > 0 { str_suffix.push_str("_x"); str_suffix.push_str(tuple_size.to_string().as_str()); } - return str_suffix; + str_suffix } SuffixKind::DupNox => { - let mut str_suffix: String = String::new(); - if requires_q { - str_suffix.push('q'); - } - str_suffix.push('_'); - str_suffix.push_str("dup_"); - str_suffix.push(prefix_char); - str_suffix.push_str(base_size.to_string().as_str()); - return str_suffix; + format!("{prefix_q}_dup_{prefix_char}{base_size}") } SuffixKind::LaneNoX => { - let mut str_suffix: String = String::new(); - if requires_q { - str_suffix.push('q'); - } - str_suffix.push('_'); - str_suffix.push_str("lane_"); - str_suffix.push(prefix_char); - str_suffix.push_str(base_size.to_string().as_str()); - return str_suffix; + format!("{prefix_q}_lane_{prefix_char}{base_size}") } SuffixKind::LaneQNoX => { - let mut str_suffix: String = String::new(); - if requires_q { - str_suffix.push('q'); - } - str_suffix.push('_'); - str_suffix.push_str("laneq_"); - str_suffix.push(prefix_char); - str_suffix.push_str(base_size.to_string().as_str()); - return str_suffix; + format!("{prefix_q}_laneq_{prefix_char}{base_size}") } SuffixKind::Rot270 => { - if requires_q { - return format!("q_rot270_{}{}", prefix_char, base_size.to_string()); - } - return format!("_rot270_{}{}", prefix_char, base_size.to_string()); + format!("{prefix_q}_rot270_{prefix_char}{base_size}") } SuffixKind::Rot270Lane => { - if requires_q { - return format!("q_rot270_lane_{}{}", prefix_char, base_size.to_string()); - } - return format!("_rot270_lane_{}{}", prefix_char, base_size.to_string()); + format!("{prefix_q}_rot270_lane_{prefix_char}{base_size}") } SuffixKind::Rot270LaneQ => { - if requires_q { - return format!("q_rot270_laneq_{}{}", prefix_char, base_size.to_string()); - } - return format!("_rot270_laneq_{}{}", prefix_char, base_size.to_string()); + format!("{prefix_q}_rot270_laneq_{prefix_char}{base_size}") } SuffixKind::Rot180 => { - if requires_q { - return format!("q_rot180_{}{}", prefix_char, base_size.to_string()); - } - return format!("_rot180_{}{}", prefix_char, base_size.to_string()); + format!("{prefix_q}_rot180_{prefix_char}{base_size}") } SuffixKind::Rot180Lane => { - if requires_q { - return format!("q_rot180_lane_{}{}", prefix_char, base_size.to_string()); - } - return format!("_rot180_lane_{}{}", prefix_char, base_size.to_string()); + format!("{prefix_q}_rot180_lane_{prefix_char}{base_size}") } SuffixKind::Rot180LaneQ => { - if requires_q { - return format!("q_rot180_laneq_{}{}", prefix_char, base_size.to_string()); - } - return format!("_rot180_laneq_{}{}", prefix_char, base_size.to_string()); + format!("{prefix_q}_rot180_laneq_{prefix_char}{base_size}") } SuffixKind::Rot90 => { - if requires_q { - return format!("q_rot90_{}{}", prefix_char, base_size.to_string()); - } - return format!("_rot90_{}{}", prefix_char, base_size.to_string()); + format!("{prefix_q}_rot90_{prefix_char}{base_size}") } SuffixKind::Rot90Lane => { - if requires_q { - return format!("q_rot90_lane_{}{}", prefix_char, base_size.to_string()); - } - return format!("_rot90_lane_{}{}", prefix_char, base_size.to_string()); + format!("{prefix_q}_rot90_lane_{prefix_char}{base_size}") } SuffixKind::Rot90LaneQ => { - if requires_q { - return format!("q_rot90_laneq_{}{}", prefix_char, base_size.to_string()); - } - return format!("_rot90_laneq_{}{}", prefix_char, base_size.to_string()); + format!("{prefix_q}_rot90_laneq_{prefix_char}{base_size}") } SuffixKind::BaseByteSize => format!("{}", base_size / 8), } @@ -272,7 +195,7 @@ impl FromStr for SuffixKind { "base_byte_size" => Ok(SuffixKind::BaseByteSize), "lane_nox" => Ok(SuffixKind::LaneNoX), "laneq_nox" => Ok(SuffixKind::LaneQNoX), - _ => Err(format!("unknown suffix type: {}", s)), + _ => Err(format!("unknown suffix type: {s}")), } } } diff --git a/crates/stdarch-gen-arm/src/intrinsic.rs b/crates/stdarch-gen-arm/src/intrinsic.rs index 822bf74ef0..efaa9e1418 100644 --- a/crates/stdarch-gen-arm/src/intrinsic.rs +++ b/crates/stdarch-gen-arm/src/intrinsic.rs @@ -254,6 +254,7 @@ impl Constraint { } } + #[allow(clippy::collapsible_if)] if let Self::SVEMaxElems { sve_max_elems_type: ty, .. @@ -331,6 +332,7 @@ impl Signature { self.name.build_acle(ctx)?; } + #[allow(clippy::collapsible_if)] if let Some(ref mut return_type) = self.return_type { if let Some(w) = return_type.clone().wildcard() { return_type.populate_wildcard(ctx.provide_type_wildcard(w)?)?; @@ -383,10 +385,7 @@ impl ToTokens for Signature { .clone() .into_iter() .map(|mut arg| { - if arg - .kind - .vector() - .map_or(false, |ty| ty.base_type().is_bool()) + if arg.kind.vector().is_some_and(|ty| ty.base_type().is_bool()) && self.predicate_needs_conversion { arg.kind = TypeKind::Vector(VectorType::make_predicate_from_bitsize(8)) @@ -400,7 +399,7 @@ impl ToTokens for Signature { if let Some(ref return_type) = self.return_type { if return_type .vector() - .map_or(false, |ty| ty.base_type().is_bool()) + .is_some_and(|ty| ty.base_type().is_bool()) && self.predicate_needs_conversion { tokens.append_all(quote! { -> svbool_t }) @@ -475,10 +474,11 @@ pub struct LLVMLink { impl LLVMLink { pub fn resolve(&self, cfg: &ArchitectureSettings) -> String { - self.name - .starts_with("llvm") - .then(|| self.name.to_string()) - .unwrap_or_else(|| format!("{}.{}", cfg.llvm_link_prefix, self.name)) + if self.name.starts_with("llvm") { + self.name.to_string() + } else { + format!("{}.{}", cfg.llvm_link_prefix, self.name) + } } pub fn build_and_save(&mut self, ctx: &mut Context) -> context::Result { @@ -529,7 +529,7 @@ impl LLVMLink { if let Some(ref mut links) = self.links { links.iter_mut().for_each(|ele| { ele.link - .build(&ctx.local, TypeRepr::LLVMMachine) + .build(ctx.local, TypeRepr::LLVMMachine) .expect("Failed to transform to LLVMMachine representation"); }); } else { @@ -1024,15 +1024,14 @@ impl Intrinsic { if variant.attr.is_none() && variant.assert_instr.is_none() { panic!( "Error: {} is missing both 'attr' and 'assert_instr' fields. You must either manually declare the attributes using the 'attr' field or use 'assert_instr'!", - variant.signature.name.to_string() + variant.signature.name ); } if variant.attr.is_some() { let attr: &Vec = &variant.attr.clone().unwrap(); let mut expanded_attr: Vec = Vec::new(); - for idx in 0..attr.len() { - let mut ex = attr[idx].clone(); + for mut ex in attr.iter().cloned() { ex.build(&variant, &mut ctx)?; expanded_attr.push(ex); } @@ -1085,6 +1084,7 @@ impl Intrinsic { /* We do not want to be creating a `mut` variant if the type * has one lane. If it has one lane that means it does not need * shuffling */ + #[allow(clippy::collapsible_if)] if let TypeKind::Vector(vector_type) = &function_parameter.kind { if vector_type.lanes() == 1 { continue; @@ -1172,7 +1172,7 @@ impl Intrinsic { /* Now we shuffle the return value - we are creating a new * return value for the intrinsic. */ - let return_value_variable = if type_has_tuple(&return_type) { + let return_value_variable = if type_has_tuple(return_type) { create_mut_let_variable(&ret_val_name, return_type, return_value.clone()) } else { create_let_variable(&ret_val_name, return_type, return_value.clone()) @@ -1542,7 +1542,7 @@ impl Intrinsic { .get(0) .and_then(|arg| arg.typekind()) .and_then(|ty| ty.base_type()) - .map(BaseType::clone); + .cloned(); // Add global target features self.target_features = ctx @@ -1766,7 +1766,7 @@ fn create_tokens(intrinsic: &Intrinsic, endianness: Endianness, tokens: &mut Tok /* Target feature will get added here */ let attr_expressions = &mut attr.iter().peekable(); - while let Some(ex) = attr_expressions.next() { + for ex in attr_expressions { let mut inner = TokenStream::new(); ex.to_tokens(&mut inner); tokens.append(Punct::new('#', Spacing::Alone)); @@ -1778,9 +1778,10 @@ fn create_tokens(intrinsic: &Intrinsic, endianness: Endianness, tokens: &mut Tok }); } + #[allow(clippy::collapsible_if)] if let Some(assert_instr) = &intrinsic.assert_instr { if !assert_instr.is_empty() { - InstructionAssertionsForBaseType(&assert_instr, &intrinsic.base_type.as_ref()) + InstructionAssertionsForBaseType(assert_instr, &intrinsic.base_type.as_ref()) .to_tokens(tokens) } } @@ -1825,7 +1826,7 @@ fn create_tokens(intrinsic: &Intrinsic, endianness: Endianness, tokens: &mut Tok impl ToTokens for Intrinsic { fn to_tokens(&self, tokens: &mut TokenStream) { - if self.big_endian_compose.len() >= 1 { + if !self.big_endian_compose.is_empty() { for i in 0..2 { match i { 0 => create_tokens(self, Endianness::Little, tokens), diff --git a/crates/stdarch-gen-arm/src/load_store_tests.rs b/crates/stdarch-gen-arm/src/load_store_tests.rs index a238c5fb33..5cf39b2e11 100644 --- a/crates/stdarch-gen-arm/src/load_store_tests.rs +++ b/crates/stdarch-gen-arm/src/load_store_tests.rs @@ -129,6 +129,7 @@ fn generate_single_test( let chars = LdIntrCharacteristics::new(&load)?; let fn_name = load.signature.fn_name().to_string(); + #[allow(clippy::collapsible_if)] if let Some(ty) = &chars.gather_bases_type { if ty.base_type().unwrap().get_size() == Ok(32) && chars.gather_index_type.is_none() @@ -372,7 +373,7 @@ fn generate_single_test( let create = format_ident!("svcreate{tuple_len}_{acle_type}"); quote!(#create(#(#expecteds),*)) }; - let input = store.input.types.get(0).unwrap().get(0).unwrap(); + let input = store.input.types.first().unwrap().get(0).unwrap(); let store_type = input .get(store.test.get_typeset_index().unwrap()) .and_then(InputType::typekind) @@ -579,7 +580,7 @@ struct LdIntrCharacteristics { impl LdIntrCharacteristics { fn new(intr: &Intrinsic) -> Result { - let input = intr.input.types.get(0).unwrap().get(0).unwrap(); + let input = intr.input.types.first().unwrap().get(0).unwrap(); let load_type = input .get(intr.test.get_typeset_index().unwrap()) .and_then(InputType::typekind) diff --git a/crates/stdarch-gen-arm/src/main.rs b/crates/stdarch-gen-arm/src/main.rs index 9ea1917c14..9bf7d0981d 100644 --- a/crates/stdarch-gen-arm/src/main.rs +++ b/crates/stdarch-gen-arm/src/main.rs @@ -164,11 +164,11 @@ use stdarch_test::assert_instr; use super::*;{uses_neon} "#, - uses_neon = generated_input - .ctx - .uses_neon_types - .then_some("\nuse crate::core_arch::arch::aarch64::*;") - .unwrap_or_default(), + uses_neon = if generated_input.ctx.uses_neon_types { + "\nuse crate::core_arch::arch::aarch64::*;" + } else { + "" + }, )?; let intrinsics = generated_input.intrinsics; format_code(out, quote! { #(#intrinsics)* })?; @@ -198,7 +198,7 @@ pub fn format_code( /// Panics if the resulting name is empty, or if file_name() is not UTF-8. fn make_output_filepath(in_filepath: &Path, out_dirpath: &Path) -> PathBuf { make_filepath(in_filepath, out_dirpath, |_name: &str| { - format!("generated.rs") + "generated.rs".to_owned() }) } diff --git a/crates/stdarch-gen-arm/src/typekinds.rs b/crates/stdarch-gen-arm/src/typekinds.rs index bf22501b1d..7c697cb7c0 100644 --- a/crates/stdarch-gen-arm/src/typekinds.rs +++ b/crates/stdarch-gen-arm/src/typekinds.rs @@ -135,7 +135,7 @@ pub enum VectorTupleSize { } impl VectorTupleSize { - pub fn to_int(&self) -> u32 { + pub fn to_int(self) -> u32 { match self { Self::Two => 2, Self::Three => 3, @@ -453,6 +453,7 @@ impl VectorType { is_scalable: bool, tuple_size: Option, ) -> VectorType { + #[allow(clippy::collapsible_if)] if is_scalable { if let BaseType::Sized(BaseTypeKind::Bool, size) = base_ty { return Self::make_predicate_from_bitsize(size); @@ -521,13 +522,12 @@ impl FromStr for VectorType { .transpose() .unwrap(); - let v = Ok(VectorType { + Ok(VectorType { base_type, is_scalable: c.name("sv_ty").is_some(), lanes, tuple_size, - }); - return v; + }) } else { Err(format!("invalid vector type {s:#?} given")) } diff --git a/crates/stdarch-gen-arm/src/wildstring.rs b/crates/stdarch-gen-arm/src/wildstring.rs index 616c1172d4..4f8cc67f5e 100644 --- a/crates/stdarch-gen-arm/src/wildstring.rs +++ b/crates/stdarch-gen-arm/src/wildstring.rs @@ -66,7 +66,7 @@ impl WildString { self.0.is_empty() } - pub fn replace<'a, P>(&'a self, from: P, to: &str) -> WildString + pub fn replace

(&self, from: P, to: &str) -> WildString where P: Pattern + Copy, { From 9b1d8c9572fbfa95599f4e0319e06586c2d7453d Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Sat, 31 May 2025 05:06:05 +0000 Subject: [PATCH 2/6] stdarch-gen-loongarch: Modernization of the coding style It modernizes the coding style of the crate stdarch-gen-loongarch by fixing Clippy warnings. Clippy: rust version 1.89.0-nightly (6f6971078 2025-05-28) Number of Fixed Warnings: 1/1 Confirmed that the exact same code will be generated (note that, generated.rs in the repository is *not* an exact output but some spaces removed). --- crates/stdarch-gen-loongarch/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/stdarch-gen-loongarch/src/main.rs b/crates/stdarch-gen-loongarch/src/main.rs index ea67682b56..aa9990b6cc 100644 --- a/crates/stdarch-gen-loongarch/src/main.rs +++ b/crates/stdarch-gen-loongarch/src/main.rs @@ -74,7 +74,7 @@ impl TargetFeature { } /// Generate a target_feature attribute - fn to_target_feature_attr(&self, ins: &str) -> Lines { + fn to_target_feature_attr(self, ins: &str) -> Lines { Lines::single(Self::attr( "target_feature", self.as_target_feature_arg(ins), From fda663d59a1e66c1e6b3673f9e5b7e47f3f08dde Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Sat, 31 May 2025 05:06:05 +0000 Subject: [PATCH 3/6] stdarch-test: Modernization of the coding style It modernizes the coding style of the crate stdarch-test by fixing Clippy warnings. Clippy: rust version 1.89.0-nightly (6f6971078 2025-05-28) Number of Fixed Warnings: 1/1 --- crates/stdarch-test/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/stdarch-test/src/lib.rs b/crates/stdarch-test/src/lib.rs index 977b4b46ad..f6614f6d51 100644 --- a/crates/stdarch-test/src/lib.rs +++ b/crates/stdarch-test/src/lib.rs @@ -71,7 +71,7 @@ pub fn assert(shim_addr: usize, fnname: &str, expected: &str) { //eprintln!(" function: {:?}", function); let mut instrs = &function.instrs[..]; - while instrs.last().map_or(false, |s| s == "nop" || s == "int3") { + while instrs.last().is_some_and(|s| s == "nop" || s == "int3") { instrs = &instrs[..instrs.len() - 1]; } From d862fb04673abeceb6611440a4b332c6a3821375 Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Sat, 31 May 2025 05:06:05 +0000 Subject: [PATCH 4/6] stdarch-verify: Modernization of the coding style It modernizes the coding style of the crate stdarch-verify by dealing with Clippy warnings (allows clippy::collapsible_if but review may be required for later changes). Clippy: rust version 1.89.0-nightly (6f6971078 2025-05-28) Number of Fixed Warnings: 4/4 --- crates/stdarch-verify/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/stdarch-verify/src/lib.rs b/crates/stdarch-verify/src/lib.rs index 38ac9864b5..c81f5f45bc 100644 --- a/crates/stdarch-verify/src/lib.rs +++ b/crates/stdarch-verify/src/lib.rs @@ -498,6 +498,7 @@ fn find_target_feature(attrs: &[syn::Attribute]) -> Option { attrs .iter() .flat_map(|a| { + #[allow(clippy::collapsible_if)] if let syn::Meta::List(ref l) = a.meta { if l.path.is_ident("target_feature") { if let Ok(l) = @@ -526,6 +527,7 @@ fn find_doc(attrs: &[syn::Attribute]) -> String { attrs .iter() .filter_map(|a| { + #[allow(clippy::collapsible_if)] if let syn::Meta::NameValue(ref l) = a.meta { if l.path.is_ident("doc") { if let syn::Expr::Lit(syn::ExprLit { From bff8f8528f4edd2403664196ab8b2b54bde5db93 Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Sat, 31 May 2025 05:06:05 +0000 Subject: [PATCH 5/6] stdarch_examples: Modernization of the coding style It modernizes the coding style of the crate stdarch_examples (an example "connect5") by fixing Clippy warnings (except clippy::manual_range_contains in which "fixing" the warning will complicate the code). Clippy: rust version 1.89.0-nightly (6f6971078 2025-05-28) Number of Fixed Warnings: 6/6 --- examples/connect5.rs | 48 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/connect5.rs b/examples/connect5.rs index 2e049cc9bd..8b8ee106c7 100644 --- a/examples/connect5.rs +++ b/examples/connect5.rs @@ -229,8 +229,7 @@ const MAPMOVEIDX: [[i32; 239]; 4] = [ [// Direction 0 /// The first dimension is color: Black, White and Empty.\ /// The second and third one are 2 x 512-bit. Direction 0 and 2 use the first 512-bit. Direction 1 and /// 3 use the second 512-bit.\ -/// Each 512-bit is a 32-bit x 16 array. Direction 0 and 1 store at bit 31-16 and Direction 2 and 3 store at bit 15-0. - +/// Each 512-bit is a 32-bit x 16 array. Direction 0 and 1 store at bit 31-16 and Direction 2 and 3 store at bit 15-0. pub struct Pos { // position state: [Color; SQUARE_SIZE as usize], @@ -473,6 +472,7 @@ fn gen_moves(list: &mut List, pos: &Pos) { } /// AI: use Minimax search with alpha-beta pruning +#[allow(clippy::manual_range_contains)] fn search(pos: &Pos, alpha: i32, beta: i32, depth: i32, _ply: i32) -> i32 { assert!(-EVAL_INF <= alpha && alpha < beta && beta <= EVAL_INF); // leaf? @@ -724,12 +724,12 @@ fn check_pattern5(pos: &Pos, sd: Side) -> bool { for fl in 0..FILE_SIZE { let sq: Square = square_make(fl, rk); - for pat in 0..4 { + for direction in &DIRECTION { let idx0 = sq; - let idx1 = sq + DIRECTION[pat][0]; - let idx2 = sq + DIRECTION[pat][1]; - let idx3 = sq + DIRECTION[pat][2]; - let idx4 = sq + DIRECTION[pat][3]; + let idx1 = sq + direction[0]; + let idx2 = sq + direction[1]; + let idx3 = sq + direction[2]; + let idx4 = sq + direction[3]; let val0 = pos.state[idx0 as usize]; let val1 = pos.state[idx1 as usize]; @@ -754,13 +754,13 @@ fn check_patternlive4(pos: &Pos, sd: Side) -> bool { for fl in 0..FILE_SIZE { let sq: Square = square_make(fl, rk); - for pat in 0..4 { + for direction in &DIRECTION { let idx0 = sq; - let idx1 = sq + DIRECTION[pat][0]; - let idx2 = sq + DIRECTION[pat][1]; - let idx3 = sq + DIRECTION[pat][2]; - let idx4 = sq + DIRECTION[pat][3]; - let idx5 = sq + DIRECTION[pat][4]; + let idx1 = sq + direction[0]; + let idx2 = sq + direction[1]; + let idx3 = sq + direction[2]; + let idx4 = sq + direction[3]; + let idx5 = sq + direction[4]; let val0 = pos.state[idx0 as usize]; let val1 = pos.state[idx1 as usize]; @@ -786,12 +786,12 @@ fn check_patterndead4(pos: &Pos, sd: Side) -> i32 { for fl in 0..FILE_SIZE { let sq: Square = square_make(fl, rk); - for dir in 0..4 { + for direction in &DIRECTION { let idx0 = sq; - let idx1 = sq + DIRECTION[dir][0]; - let idx2 = sq + DIRECTION[dir][1]; - let idx3 = sq + DIRECTION[dir][2]; - let idx4 = sq + DIRECTION[dir][3]; + let idx1 = sq + direction[0]; + let idx2 = sq + direction[1]; + let idx3 = sq + direction[2]; + let idx4 = sq + direction[3]; let val0 = pos.state[idx0 as usize]; let val1 = pos.state[idx1 as usize]; @@ -824,13 +824,13 @@ fn check_patternlive3(pos: &Pos, sd: Side) -> i32 { for fl in 0..FILE_SIZE { let sq: Square = square_make(fl, rk); - for dir in 0..4 { + for direction in &DIRECTION { let idx0 = sq; - let idx1 = sq + DIRECTION[dir][0]; - let idx2 = sq + DIRECTION[dir][1]; - let idx3 = sq + DIRECTION[dir][2]; - let idx4 = sq + DIRECTION[dir][3]; - let idx5 = sq + DIRECTION[dir][4]; + let idx1 = sq + direction[0]; + let idx2 = sq + direction[1]; + let idx3 = sq + direction[2]; + let idx4 = sq + direction[3]; + let idx5 = sq + direction[4]; let val0 = pos.state[idx0 as usize]; let val1 = pos.state[idx1 as usize]; From 87961c5b0e66160f2b1f7e9680eb67bf044b7452 Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Sat, 31 May 2025 05:06:05 +0000 Subject: [PATCH 6/6] intrinsic-test: Modernization of the coding style It modernizes the coding style of the crate intrinsic-test by fixing Clippy warnings. Clippy: rust version 1.89.0-nightly (6f6971078 2025-05-28) Number of Fixed Warnings: 36/36 --- crates/intrinsic-test/src/arm/compile.rs | 4 +- crates/intrinsic-test/src/arm/json_parser.rs | 4 +- crates/intrinsic-test/src/arm/mod.rs | 13 ++- crates/intrinsic-test/src/arm/types.rs | 24 ++--- crates/intrinsic-test/src/common/argument.rs | 95 +++++++++---------- crates/intrinsic-test/src/common/cli.rs | 16 ++-- crates/intrinsic-test/src/common/compile_c.rs | 4 +- crates/intrinsic-test/src/common/gen_c.rs | 2 +- crates/intrinsic-test/src/common/gen_rust.rs | 4 +- .../src/common/intrinsic_helpers.rs | 8 +- .../intrinsic-test/src/common/write_file.rs | 12 +-- 11 files changed, 91 insertions(+), 95 deletions(-) diff --git a/crates/intrinsic-test/src/arm/compile.rs b/crates/intrinsic-test/src/arm/compile.rs index b76dcc79fa..8276cd87c1 100644 --- a/crates/intrinsic-test/src/arm/compile.rs +++ b/crates/intrinsic-test/src/arm/compile.rs @@ -2,7 +2,7 @@ use crate::common::compile_c::CompilationCommandBuilder; use crate::common::gen_c::compile_c_programs; pub fn compile_c_arm( - intrinsics_name_list: &Vec, + intrinsics_name_list: &[String], compiler: &str, target: &str, cxx_toolchain_dir: Option<&str>, @@ -56,7 +56,7 @@ pub fn compile_c_arm( .clone() .set_input_name(intrinsic_name) .set_output_name(intrinsic_name) - .to_string() + .make_string() }) .collect::>(); diff --git a/crates/intrinsic-test/src/arm/json_parser.rs b/crates/intrinsic-test/src/arm/json_parser.rs index 0d46116030..0ac47484b0 100644 --- a/crates/intrinsic-test/src/arm/json_parser.rs +++ b/crates/intrinsic-test/src/arm/json_parser.rs @@ -54,7 +54,7 @@ struct JsonIntrinsic { pub fn get_neon_intrinsics( filename: &Path, - target: &String, + target: &str, ) -> Result>, Box> { let file = std::fs::File::open(filename)?; let reader = std::io::BufReader::new(file); @@ -75,7 +75,7 @@ pub fn get_neon_intrinsics( fn json_to_intrinsic( mut intr: JsonIntrinsic, - target: &String, + target: &str, ) -> Result, Box> { let name = intr.name.replace(['[', ']'], ""); diff --git a/crates/intrinsic-test/src/arm/mod.rs b/crates/intrinsic-test/src/arm/mod.rs index 24d7ab2579..6aaa49ff97 100644 --- a/crates/intrinsic-test/src/arm/mod.rs +++ b/crates/intrinsic-test/src/arm/mod.rs @@ -45,8 +45,8 @@ impl SupportedArchitectureTest for ArmArchitectureTest { intrinsics.dedup(); Box::new(Self { - intrinsics: intrinsics, - cli_options: cli_options, + intrinsics, + cli_options, }) } @@ -71,9 +71,12 @@ impl SupportedArchitectureTest for ArmArchitectureTest { match compiler { None => true, - Some(compiler) => { - compile_c_arm(&intrinsics_name_list, compiler, target, cxx_toolchain_dir) - } + Some(compiler) => compile_c_arm( + intrinsics_name_list.as_slice(), + compiler, + target, + cxx_toolchain_dir, + ), } } diff --git a/crates/intrinsic-test/src/arm/types.rs b/crates/intrinsic-test/src/arm/types.rs index 231fa181ad..68510658b3 100644 --- a/crates/intrinsic-test/src/arm/types.rs +++ b/crates/intrinsic-test/src/arm/types.rs @@ -12,9 +12,9 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType { (self.0.bit_len, self.0.simd_len, self.0.vec_len) { match (simd_len, vec_len) { - (None, None) => format!("{}{}{}_t", const_prefix, prefix, bit_len), - (Some(simd), None) => format!("{}{bit_len}x{simd}_t", prefix), - (Some(simd), Some(vec)) => format!("{}{bit_len}x{simd}x{vec}_t", prefix), + (None, None) => format!("{const_prefix}{prefix}{bit_len}_t"), + (Some(simd), None) => format!("{prefix}{bit_len}x{simd}_t"), + (Some(simd), Some(vec)) => format!("{prefix}{bit_len}x{simd}x{vec}_t"), (None, Some(_)) => todo!("{:#?}", self), // Likely an invalid case } } else { @@ -24,8 +24,10 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType { fn c_single_vector_type(&self) -> String { if let (Some(bit_len), Some(simd_len)) = (self.0.bit_len, self.0.simd_len) { - let prefix = self.0.kind.c_prefix(); - format!("{}{bit_len}x{simd_len}_t", prefix) + format!( + "{prefix}{bit_len}x{simd_len}_t", + prefix = self.0.kind.c_prefix() + ) } else { unreachable!("Shouldn't be called on this type") } @@ -40,9 +42,9 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType { (self.0.bit_len, self.0.simd_len, self.0.vec_len) { match (simd_len, vec_len) { - (None, None) => format!("{}{bit_len}", rust_prefix), - (Some(simd), None) => format!("{}{bit_len}x{simd}_t", c_prefix), - (Some(simd), Some(vec)) => format!("{}{bit_len}x{simd}x{vec}_t", c_prefix), + (None, None) => format!("{rust_prefix}{bit_len}"), + (Some(simd), None) => format!("{c_prefix}{bit_len}x{simd}_t"), + (Some(simd), Some(vec)) => format!("{c_prefix}{bit_len}x{simd}x{vec}_t"), (None, Some(_)) => todo!("{:#?}", self), // Likely an invalid case } } else { @@ -119,7 +121,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType { } } - fn from_c(s: &str, target: &String) -> Result, String> { + fn from_c(s: &str, target: &str) -> Result, String> { const CONST_STR: &str = "const"; if let Some(s) = s.strip_suffix('*') { let (s, constant) = match s.trim().strip_suffix(CONST_STR) { @@ -128,11 +130,11 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType { }; let s = s.trim_end(); let temp_return = ArmIntrinsicType::from_c(s, target); - temp_return.and_then(|mut op| { + temp_return.map(|mut op| { let edited = op.as_mut(); edited.0.ptr = true; edited.0.ptr_constant = constant; - Ok(op) + op }) } else { // [const ]TYPE[{bitlen}[x{simdlen}[x{vec_len}]]][_t] diff --git a/crates/intrinsic-test/src/common/argument.rs b/crates/intrinsic-test/src/common/argument.rs index ce592c584c..8f1573f17d 100644 --- a/crates/intrinsic-test/src/common/argument.rs +++ b/crates/intrinsic-test/src/common/argument.rs @@ -33,7 +33,7 @@ where } pub fn has_constraint(&self) -> bool { - !self.constraint.is_some() + self.constraint.is_none() } pub fn type_and_name_from_c(arg: &str) -> (&str, &str) { @@ -65,7 +65,7 @@ where pub fn from_c( pos: usize, arg: &str, - target: &String, + target: &str, constraint: Option, ) -> Argument { let (ty, var_name) = Self::type_and_name_from_c(arg); @@ -127,15 +127,14 @@ where /// e.g `const int32x2_t a_vals = {0x3effffff, 0x3effffff, 0x3f7fffff}`, if loads=2. pub fn gen_arglists_c(&self, indentation: Indentation, loads: u32) -> String { self.iter() - .filter_map(|arg| { - (!arg.has_constraint()).then(|| { - format!( - "{indentation}const {ty} {name}_vals[] = {values};", - ty = arg.ty.c_scalar_type(), - name = arg.name, - values = arg.ty.populate_random(indentation, loads, &Language::C) - ) - }) + .filter(|&arg| !arg.has_constraint()) + .map(|arg| { + format!( + "{indentation}const {ty} {name}_vals[] = {values};", + ty = arg.ty.c_scalar_type(), + name = arg.name, + values = arg.ty.populate_random(indentation, loads, &Language::C) + ) }) .collect::>() .join("\n") @@ -145,17 +144,16 @@ where /// values can be loaded as a sliding window, e.g `const A_VALS: [u32; 20] = [...];` pub fn gen_arglists_rust(&self, indentation: Indentation, loads: u32) -> String { self.iter() - .filter_map(|arg| { - (!arg.has_constraint()).then(|| { - format!( - "{indentation}{bind} {name}: [{ty}; {load_size}] = {values};", - bind = arg.rust_vals_array_binding(), - name = arg.rust_vals_array_name(), - ty = arg.ty.rust_scalar_type(), - load_size = arg.ty.num_lanes() * arg.ty.num_vectors() + loads - 1, - values = arg.ty.populate_random(indentation, loads, &Language::Rust) - ) - }) + .filter(|&arg| !arg.has_constraint()) + .map(|arg| { + format!( + "{indentation}{bind} {name}: [{ty}; {load_size}] = {values};", + bind = arg.rust_vals_array_binding(), + name = arg.rust_vals_array_name(), + ty = arg.ty.rust_scalar_type(), + load_size = arg.ty.num_lanes() * arg.ty.num_vectors() + loads - 1, + values = arg.ty.populate_random(indentation, loads, &Language::Rust) + ) }) .collect::>() .join("\n") @@ -168,22 +166,18 @@ where /// ARM-specific pub fn load_values_c(&self, indentation: Indentation) -> String { self.iter() - .filter_map(|arg| { - // The ACLE doesn't support 64-bit polynomial loads on Armv7 - // This and the cast are a workaround for this - - (!arg.has_constraint()).then(|| { - format!( - "{indentation}{ty} {name} = cast<{ty}>({load}(&{name}_vals[i]));\n", - ty = arg.to_c_type(), - name = arg.name, - load = if arg.is_simd() { - arg.ty.get_load_function(Language::C) - } else { - "*".to_string() - } - ) - }) + .filter(|&arg| !arg.has_constraint()) + .map(|arg| { + format!( + "{indentation}{ty} {name} = cast<{ty}>({load}(&{name}_vals[i]));\n", + ty = arg.to_c_type(), + name = arg.name, + load = if arg.is_simd() { + arg.ty.get_load_function(Language::C) + } else { + "*".to_string() + } + ) }) .collect() } @@ -193,19 +187,18 @@ where /// e.g `let a = vld1_u8(A_VALS.as_ptr().offset(i));` pub fn load_values_rust(&self, indentation: Indentation) -> String { self.iter() - .filter_map(|arg| { - (!arg.has_constraint()).then(|| { - format!( - "{indentation}let {name} = {load}({vals_name}.as_ptr().offset(i));\n", - name = arg.name, - vals_name = arg.rust_vals_array_name(), - load = if arg.is_simd() { - arg.ty.get_load_function(Language::Rust) - } else { - "*".to_string() - }, - ) - }) + .filter(|&arg| !arg.has_constraint()) + .map(|arg| { + format!( + "{indentation}let {name} = {load}({vals_name}.as_ptr().offset(i));\n", + name = arg.name, + vals_name = arg.rust_vals_array_name(), + load = if arg.is_simd() { + arg.ty.get_load_function(Language::Rust) + } else { + "*".to_string() + }, + ) }) .collect() } diff --git a/crates/intrinsic-test/src/common/cli.rs b/crates/intrinsic-test/src/common/cli.rs index 9345761cf1..1d57272300 100644 --- a/crates/intrinsic-test/src/common/cli.rs +++ b/crates/intrinsic-test/src/common/cli.rs @@ -100,14 +100,14 @@ impl ProcessedCli { }; Self { - toolchain: toolchain, - cpp_compiler: cpp_compiler, - c_runner: c_runner, - target: target, - linker: linker, - cxx_toolchain_dir: cxx_toolchain_dir, - skip: skip, - filename: filename, + toolchain, + cpp_compiler, + c_runner, + target, + linker, + cxx_toolchain_dir, + skip, + filename, } } } diff --git a/crates/intrinsic-test/src/common/compile_c.rs b/crates/intrinsic-test/src/common/compile_c.rs index 5fe700695b..aebb7b111e 100644 --- a/crates/intrinsic-test/src/common/compile_c.rs +++ b/crates/intrinsic-test/src/common/compile_c.rs @@ -100,10 +100,10 @@ impl CompilationCommandBuilder { } impl CompilationCommandBuilder { - pub fn to_string(self) -> String { + pub fn make_string(self) -> String { let arch_flags = self.arch_flags.join("+"); let flags = std::env::var("CPPFLAGS").unwrap_or("".into()); - let project_root = self.project_root.unwrap_or(String::new()); + let project_root = self.project_root.unwrap_or_default(); let project_root_str = project_root.as_str(); let mut output = self.output.clone(); if self.linker.is_some() { diff --git a/crates/intrinsic-test/src/common/gen_c.rs b/crates/intrinsic-test/src/common/gen_c.rs index d84afb9fa3..84c28cc4bf 100644 --- a/crates/intrinsic-test/src/common/gen_c.rs +++ b/crates/intrinsic-test/src/common/gen_c.rs @@ -58,7 +58,7 @@ int main(int argc, char **argv) {{ .map(|header| format!("#include <{header}>")) .collect::>() .join("\n"), - arch_specific_definitions = arch_specific_definitions.into_iter().join("\n"), + arch_specific_definitions = arch_specific_definitions.join("\n"), ) } diff --git a/crates/intrinsic-test/src/common/gen_rust.rs b/crates/intrinsic-test/src/common/gen_rust.rs index 67255fadc6..a2878502ac 100644 --- a/crates/intrinsic-test/src/common/gen_rust.rs +++ b/crates/intrinsic-test/src/common/gen_rust.rs @@ -130,9 +130,9 @@ pub fn setup_rust_file_paths(identifiers: &Vec) -> BTreeMap<&String, Str identifiers .par_iter() .map(|identifier| { - let rust_dir = format!(r#"rust_programs/{}"#, identifier); + let rust_dir = format!("rust_programs/{identifier}"); let _ = std::fs::create_dir_all(&rust_dir); - let rust_filename = format!(r#"{rust_dir}/main.rs"#); + let rust_filename = format!("{rust_dir}/main.rs"); (identifier, rust_filename) }) diff --git a/crates/intrinsic-test/src/common/intrinsic_helpers.rs b/crates/intrinsic-test/src/common/intrinsic_helpers.rs index d96e0429fc..3d200b1946 100644 --- a/crates/intrinsic-test/src/common/intrinsic_helpers.rs +++ b/crates/intrinsic-test/src/common/intrinsic_helpers.rs @@ -117,11 +117,11 @@ impl IntrinsicType { } pub fn num_lanes(&self) -> u32 { - if let Some(sl) = self.simd_len { sl } else { 1 } + self.simd_len.unwrap_or(1) } pub fn num_vectors(&self) -> u32 { - if let Some(vl) = self.vec_len { vl } else { 1 } + self.vec_len.unwrap_or(1) } pub fn is_simd(&self) -> bool { @@ -266,7 +266,7 @@ impl IntrinsicType { pub fn as_call_param_c(&self, name: &String) -> String { if self.ptr { - format!("&{}", name) + format!("&{name}") } else { name.clone() } @@ -282,7 +282,7 @@ pub trait IntrinsicTypeDefinition: Deref { fn get_lane_function(&self) -> String; /// can be implemented in an `impl` block - fn from_c(_s: &str, _target: &String) -> Result, String>; + fn from_c(_s: &str, _target: &str) -> Result, String>; /// Gets a string containing the typename for this type in C format. /// can be directly defined in `impl` blocks diff --git a/crates/intrinsic-test/src/common/write_file.rs b/crates/intrinsic-test/src/common/write_file.rs index abd6ab23b7..0ba3e829a6 100644 --- a/crates/intrinsic-test/src/common/write_file.rs +++ b/crates/intrinsic-test/src/common/write_file.rs @@ -7,7 +7,7 @@ use std::fs::File; use std::io::Write; pub fn write_file(filename: &String, code: String) { - let mut file = File::create(&filename).unwrap(); + let mut file = File::create(filename).unwrap(); file.write_all(code.into_bytes().as_slice()).unwrap(); } @@ -34,9 +34,8 @@ pub fn write_c_testfiles( notice, arch_specific_definitions, ); - match filename_mapping.get(&i.name()) { - Some(filename) => write_file(filename, c_code), - None => {} + if let Some(filename) = filename_mapping.get(&i.name()) { + write_file(filename, c_code) }; }); @@ -58,9 +57,8 @@ pub fn write_rust_testfiles( intrinsics.iter().for_each(|&i| { let rust_code = create_rust_test_program(i, rust_target, notice, definitions, cfg); - match filename_mapping.get(&i.name()) { - Some(filename) => write_file(filename, rust_code), - None => {} + if let Some(filename) = filename_mapping.get(&i.name()) { + write_file(filename, rust_code) } });