Skip to content

Commit f30cc42

Browse files
committed
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
1 parent a54e51a commit f30cc42

File tree

11 files changed

+90
-94
lines changed

11 files changed

+90
-94
lines changed

crates/intrinsic-test/src/arm/compile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::common::compile_c::CompilationCommandBuilder;
22
use crate::common::gen_c::compile_c_programs;
33

44
pub fn compile_c_arm(
5-
intrinsics_name_list: &Vec<String>,
5+
intrinsics_name_list: &[String],
66
compiler: &str,
77
target: &str,
88
cxx_toolchain_dir: Option<&str>,
@@ -56,7 +56,7 @@ pub fn compile_c_arm(
5656
.clone()
5757
.set_input_name(intrinsic_name)
5858
.set_output_name(intrinsic_name)
59-
.to_string()
59+
.make_string()
6060
})
6161
.collect::<Vec<_>>();
6262

crates/intrinsic-test/src/arm/json_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct JsonIntrinsic {
5454

5555
pub fn get_neon_intrinsics(
5656
filename: &Path,
57-
target: &String,
57+
target: &str,
5858
) -> Result<Vec<Intrinsic<ArmIntrinsicType>>, Box<dyn std::error::Error>> {
5959
let file = std::fs::File::open(filename)?;
6060
let reader = std::io::BufReader::new(file);
@@ -75,7 +75,7 @@ pub fn get_neon_intrinsics(
7575

7676
fn json_to_intrinsic(
7777
mut intr: JsonIntrinsic,
78-
target: &String,
78+
target: &str,
7979
) -> Result<Intrinsic<ArmIntrinsicType>, Box<dyn std::error::Error>> {
8080
let name = intr.name.replace(['[', ']'], "");
8181

crates/intrinsic-test/src/arm/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
4545
intrinsics.dedup();
4646

4747
Box::new(Self {
48-
intrinsics: intrinsics,
49-
cli_options: cli_options,
48+
intrinsics,
49+
cli_options,
5050
})
5151
}
5252

@@ -71,9 +71,12 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
7171

7272
match compiler {
7373
None => true,
74-
Some(compiler) => {
75-
compile_c_arm(&intrinsics_name_list, compiler, target, cxx_toolchain_dir)
76-
}
74+
Some(compiler) => compile_c_arm(
75+
intrinsics_name_list.as_slice(),
76+
compiler,
77+
target,
78+
cxx_toolchain_dir,
79+
),
7780
}
7881
}
7982

crates/intrinsic-test/src/arm/types.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
1212
(self.0.bit_len, self.0.simd_len, self.0.vec_len)
1313
{
1414
match (simd_len, vec_len) {
15-
(None, None) => format!("{}{}{}_t", const_prefix, prefix, bit_len),
16-
(Some(simd), None) => format!("{}{bit_len}x{simd}_t", prefix),
17-
(Some(simd), Some(vec)) => format!("{}{bit_len}x{simd}x{vec}_t", prefix),
15+
(None, None) => format!("{const_prefix}{prefix}{bit_len}_t"),
16+
(Some(simd), None) => format!("{prefix}{bit_len}x{simd}_t"),
17+
(Some(simd), Some(vec)) => format!("{prefix}{bit_len}x{simd}x{vec}_t"),
1818
(None, Some(_)) => todo!("{:#?}", self), // Likely an invalid case
1919
}
2020
} else {
@@ -24,8 +24,10 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
2424

2525
fn c_single_vector_type(&self) -> String {
2626
if let (Some(bit_len), Some(simd_len)) = (self.0.bit_len, self.0.simd_len) {
27-
let prefix = self.0.kind.c_prefix();
28-
format!("{}{bit_len}x{simd_len}_t", prefix)
27+
format!(
28+
"{prefix}{bit_len}x{simd_len}_t",
29+
prefix = self.0.kind.c_prefix()
30+
)
2931
} else {
3032
unreachable!("Shouldn't be called on this type")
3133
}
@@ -40,9 +42,9 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
4042
(self.0.bit_len, self.0.simd_len, self.0.vec_len)
4143
{
4244
match (simd_len, vec_len) {
43-
(None, None) => format!("{}{bit_len}", rust_prefix),
44-
(Some(simd), None) => format!("{}{bit_len}x{simd}_t", c_prefix),
45-
(Some(simd), Some(vec)) => format!("{}{bit_len}x{simd}x{vec}_t", c_prefix),
45+
(None, None) => format!("{rust_prefix}{bit_len}"),
46+
(Some(simd), None) => format!("{c_prefix}{bit_len}x{simd}_t"),
47+
(Some(simd), Some(vec)) => format!("{c_prefix}{bit_len}x{simd}x{vec}_t"),
4648
(None, Some(_)) => todo!("{:#?}", self), // Likely an invalid case
4749
}
4850
} else {
@@ -119,7 +121,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
119121
}
120122
}
121123

122-
fn from_c(s: &str, target: &String) -> Result<Box<Self>, String> {
124+
fn from_c(s: &str, target: &str) -> Result<Box<Self>, String> {
123125
const CONST_STR: &str = "const";
124126
if let Some(s) = s.strip_suffix('*') {
125127
let (s, constant) = match s.trim().strip_suffix(CONST_STR) {
@@ -128,11 +130,11 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
128130
};
129131
let s = s.trim_end();
130132
let temp_return = ArmIntrinsicType::from_c(s, target);
131-
temp_return.and_then(|mut op| {
133+
temp_return.map(|mut op| {
132134
let edited = op.as_mut();
133135
edited.0.ptr = true;
134136
edited.0.ptr_constant = constant;
135-
Ok(op)
137+
op
136138
})
137139
} else {
138140
// [const ]TYPE[{bitlen}[x{simdlen}[x{vec_len}]]][_t]

crates/intrinsic-test/src/common/argument.rs

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ where
3333
}
3434

3535
pub fn has_constraint(&self) -> bool {
36-
!self.constraint.is_some()
36+
self.constraint.is_none()
3737
}
3838

3939
pub fn type_and_name_from_c(arg: &str) -> (&str, &str) {
@@ -65,7 +65,7 @@ where
6565
pub fn from_c(
6666
pos: usize,
6767
arg: &str,
68-
target: &String,
68+
target: &str,
6969
constraint: Option<Constraint>,
7070
) -> Argument<T> {
7171
let (ty, var_name) = Self::type_and_name_from_c(arg);
@@ -127,15 +127,14 @@ where
127127
/// e.g `const int32x2_t a_vals = {0x3effffff, 0x3effffff, 0x3f7fffff}`, if loads=2.
128128
pub fn gen_arglists_c(&self, indentation: Indentation, loads: u32) -> String {
129129
self.iter()
130-
.filter_map(|arg| {
131-
(!arg.has_constraint()).then(|| {
132-
format!(
133-
"{indentation}const {ty} {name}_vals[] = {values};",
134-
ty = arg.ty.c_scalar_type(),
135-
name = arg.name,
136-
values = arg.ty.populate_random(indentation, loads, &Language::C)
137-
)
138-
})
130+
.filter(|&arg| (!arg.has_constraint()))
131+
.map(|arg| {
132+
format!(
133+
"{indentation}const {ty} {name}_vals[] = {values};",
134+
ty = arg.ty.c_scalar_type(),
135+
name = arg.name,
136+
values = arg.ty.populate_random(indentation, loads, &Language::C)
137+
)
139138
})
140139
.collect::<Vec<_>>()
141140
.join("\n")
@@ -145,17 +144,16 @@ where
145144
/// values can be loaded as a sliding window, e.g `const A_VALS: [u32; 20] = [...];`
146145
pub fn gen_arglists_rust(&self, indentation: Indentation, loads: u32) -> String {
147146
self.iter()
148-
.filter_map(|arg| {
149-
(!arg.has_constraint()).then(|| {
150-
format!(
151-
"{indentation}{bind} {name}: [{ty}; {load_size}] = {values};",
152-
bind = arg.rust_vals_array_binding(),
153-
name = arg.rust_vals_array_name(),
154-
ty = arg.ty.rust_scalar_type(),
155-
load_size = arg.ty.num_lanes() * arg.ty.num_vectors() + loads - 1,
156-
values = arg.ty.populate_random(indentation, loads, &Language::Rust)
157-
)
158-
})
147+
.filter(|&arg| (!arg.has_constraint()))
148+
.map(|arg| {
149+
format!(
150+
"{indentation}{bind} {name}: [{ty}; {load_size}] = {values};",
151+
bind = arg.rust_vals_array_binding(),
152+
name = arg.rust_vals_array_name(),
153+
ty = arg.ty.rust_scalar_type(),
154+
load_size = arg.ty.num_lanes() * arg.ty.num_vectors() + loads - 1,
155+
values = arg.ty.populate_random(indentation, loads, &Language::Rust)
156+
)
159157
})
160158
.collect::<Vec<_>>()
161159
.join("\n")
@@ -168,22 +166,18 @@ where
168166
/// ARM-specific
169167
pub fn load_values_c(&self, indentation: Indentation) -> String {
170168
self.iter()
171-
.filter_map(|arg| {
172-
// The ACLE doesn't support 64-bit polynomial loads on Armv7
173-
// This and the cast are a workaround for this
174-
175-
(!arg.has_constraint()).then(|| {
176-
format!(
177-
"{indentation}{ty} {name} = cast<{ty}>({load}(&{name}_vals[i]));\n",
178-
ty = arg.to_c_type(),
179-
name = arg.name,
180-
load = if arg.is_simd() {
181-
arg.ty.get_load_function(Language::C)
182-
} else {
183-
"*".to_string()
184-
}
185-
)
186-
})
169+
.filter(|&arg| (!arg.has_constraint()))
170+
.map(|arg| {
171+
format!(
172+
"{indentation}{ty} {name} = cast<{ty}>({load}(&{name}_vals[i]));\n",
173+
ty = arg.to_c_type(),
174+
name = arg.name,
175+
load = if arg.is_simd() {
176+
arg.ty.get_load_function(Language::C)
177+
} else {
178+
"*".to_string()
179+
}
180+
)
187181
})
188182
.collect()
189183
}
@@ -193,19 +187,18 @@ where
193187
/// e.g `let a = vld1_u8(A_VALS.as_ptr().offset(i));`
194188
pub fn load_values_rust(&self, indentation: Indentation) -> String {
195189
self.iter()
196-
.filter_map(|arg| {
197-
(!arg.has_constraint()).then(|| {
198-
format!(
199-
"{indentation}let {name} = {load}({vals_name}.as_ptr().offset(i));\n",
200-
name = arg.name,
201-
vals_name = arg.rust_vals_array_name(),
202-
load = if arg.is_simd() {
203-
arg.ty.get_load_function(Language::Rust)
204-
} else {
205-
"*".to_string()
206-
},
207-
)
208-
})
190+
.filter(|&arg| (!arg.has_constraint()))
191+
.map(|arg| {
192+
format!(
193+
"{indentation}let {name} = {load}({vals_name}.as_ptr().offset(i));\n",
194+
name = arg.name,
195+
vals_name = arg.rust_vals_array_name(),
196+
load = if arg.is_simd() {
197+
arg.ty.get_load_function(Language::Rust)
198+
} else {
199+
"*".to_string()
200+
},
201+
)
209202
})
210203
.collect()
211204
}

crates/intrinsic-test/src/common/cli.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ impl ProcessedCli {
100100
};
101101

102102
Self {
103-
toolchain: toolchain,
104-
cpp_compiler: cpp_compiler,
105-
c_runner: c_runner,
106-
target: target,
107-
linker: linker,
108-
cxx_toolchain_dir: cxx_toolchain_dir,
109-
skip: skip,
110-
filename: filename,
103+
toolchain,
104+
cpp_compiler,
105+
c_runner,
106+
target,
107+
linker,
108+
cxx_toolchain_dir,
109+
skip,
110+
filename,
111111
}
112112
}
113113
}

crates/intrinsic-test/src/common/compile_c.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ impl CompilationCommandBuilder {
100100
}
101101

102102
impl CompilationCommandBuilder {
103-
pub fn to_string(self) -> String {
103+
pub fn make_string(self) -> String {
104104
let arch_flags = self.arch_flags.join("+");
105105
let flags = std::env::var("CPPFLAGS").unwrap_or("".into());
106-
let project_root = self.project_root.unwrap_or(String::new());
106+
let project_root = self.project_root.unwrap_or_default();
107107
let project_root_str = project_root.as_str();
108108
let mut output = self.output.clone();
109109
if self.linker.is_some() {

crates/intrinsic-test/src/common/gen_c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int main(int argc, char **argv) {{
5858
.map(|header| format!("#include <{header}>"))
5959
.collect::<Vec<_>>()
6060
.join("\n"),
61-
arch_specific_definitions = arch_specific_definitions.into_iter().join("\n"),
61+
arch_specific_definitions = arch_specific_definitions.join("\n"),
6262
)
6363
}
6464

crates/intrinsic-test/src/common/gen_rust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub fn setup_rust_file_paths(identifiers: &Vec<String>) -> BTreeMap<&String, Str
130130
identifiers
131131
.par_iter()
132132
.map(|identifier| {
133-
let rust_dir = format!(r#"rust_programs/{}"#, identifier);
133+
let rust_dir = format!(r#"rust_programs/{identifier}"#);
134134
let _ = std::fs::create_dir_all(&rust_dir);
135135
let rust_filename = format!(r#"{rust_dir}/main.rs"#);
136136

crates/intrinsic-test/src/common/intrinsic_helpers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ impl IntrinsicType {
117117
}
118118

119119
pub fn num_lanes(&self) -> u32 {
120-
if let Some(sl) = self.simd_len { sl } else { 1 }
120+
self.simd_len.unwrap_or(1)
121121
}
122122

123123
pub fn num_vectors(&self) -> u32 {
124-
if let Some(vl) = self.vec_len { vl } else { 1 }
124+
self.vec_len.unwrap_or(1)
125125
}
126126

127127
pub fn is_simd(&self) -> bool {
@@ -266,7 +266,7 @@ impl IntrinsicType {
266266

267267
pub fn as_call_param_c(&self, name: &String) -> String {
268268
if self.ptr {
269-
format!("&{}", name)
269+
format!("&{name}")
270270
} else {
271271
name.clone()
272272
}
@@ -282,7 +282,7 @@ pub trait IntrinsicTypeDefinition: Deref<Target = IntrinsicType> {
282282
fn get_lane_function(&self) -> String;
283283

284284
/// can be implemented in an `impl` block
285-
fn from_c(_s: &str, _target: &String) -> Result<Box<Self>, String>;
285+
fn from_c(_s: &str, _target: &str) -> Result<Box<Self>, String>;
286286

287287
/// Gets a string containing the typename for this type in C format.
288288
/// can be directly defined in `impl` blocks

crates/intrinsic-test/src/common/write_file.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::fs::File;
77
use std::io::Write;
88

99
pub fn write_file(filename: &String, code: String) {
10-
let mut file = File::create(&filename).unwrap();
10+
let mut file = File::create(filename).unwrap();
1111
file.write_all(code.into_bytes().as_slice()).unwrap();
1212
}
1313

@@ -34,9 +34,8 @@ pub fn write_c_testfiles<T: IntrinsicTypeDefinition + Sized>(
3434
notice,
3535
arch_specific_definitions,
3636
);
37-
match filename_mapping.get(&i.name()) {
38-
Some(filename) => write_file(filename, c_code),
39-
None => {}
37+
if let Some(filename) = filename_mapping.get(&i.name()) {
38+
write_file(filename, c_code)
4039
};
4140
});
4241

@@ -58,9 +57,8 @@ pub fn write_rust_testfiles<T: IntrinsicTypeDefinition>(
5857

5958
intrinsics.iter().for_each(|&i| {
6059
let rust_code = create_rust_test_program(i, rust_target, notice, definitions, cfg);
61-
match filename_mapping.get(&i.name()) {
62-
Some(filename) => write_file(filename, rust_code),
63-
None => {}
60+
if let Some(filename) = filename_mapping.get(&i.name()) {
61+
write_file(filename, rust_code)
6462
}
6563
});
6664

0 commit comments

Comments
 (0)