Skip to content

Commit 7314a30

Browse files
a4lgmadhav-madhusoodanan
authored andcommitted
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 c80661a commit 7314a30

File tree

11 files changed

+87
-91
lines changed

11 files changed

+87
-91
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: 10 additions & 8 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 {

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

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ where
4242
}
4343

4444
pub fn has_constraint(&self) -> bool {
45-
!self.constraint.is_some()
45+
self.constraint.is_none()
4646
}
4747

4848
pub fn type_and_name_from_c(arg: &str) -> (&str, &str) {
@@ -74,7 +74,7 @@ where
7474
pub fn from_c(
7575
pos: usize,
7676
arg: &str,
77-
target: &String,
77+
target: &str,
7878
constraint: Option<Constraint>,
7979
) -> Argument<T> {
8080
let (ty, var_name) = Self::type_and_name_from_c(arg);
@@ -136,15 +136,14 @@ where
136136
/// e.g `const int32x2_t a_vals = {0x3effffff, 0x3effffff, 0x3f7fffff}`, if loads=2.
137137
pub fn gen_arglists_c(&self, indentation: Indentation, loads: u32) -> String {
138138
self.iter()
139-
.filter_map(|arg| {
140-
(!arg.has_constraint()).then(|| {
141-
format!(
142-
"{indentation}const {ty} {name}_vals[] = {values};",
143-
ty = arg.ty.c_scalar_type(),
144-
name = arg.name,
145-
values = arg.ty.populate_random(indentation, loads, &Language::C)
146-
)
147-
})
139+
.filter(|&arg| !arg.has_constraint())
140+
.map(|arg| {
141+
format!(
142+
"{indentation}const {ty} {name}_vals[] = {values};",
143+
ty = arg.ty.c_scalar_type(),
144+
name = arg.name,
145+
values = arg.ty.populate_random(indentation, loads, &Language::C)
146+
)
148147
})
149148
.collect::<Vec<_>>()
150149
.join("\n")
@@ -154,17 +153,16 @@ where
154153
/// values can be loaded as a sliding window, e.g `const A_VALS: [u32; 20] = [...];`
155154
pub fn gen_arglists_rust(&self, indentation: Indentation, loads: u32) -> String {
156155
self.iter()
157-
.filter_map(|arg| {
158-
(!arg.has_constraint()).then(|| {
159-
format!(
160-
"{indentation}{bind} {name}: [{ty}; {load_size}] = {values};",
161-
bind = arg.rust_vals_array_binding(),
162-
name = arg.rust_vals_array_name(),
163-
ty = arg.ty.rust_scalar_type(),
164-
load_size = arg.ty.num_lanes() * arg.ty.num_vectors() + loads - 1,
165-
values = arg.ty.populate_random(indentation, loads, &Language::Rust)
166-
)
167-
})
156+
.filter(|&arg| !arg.has_constraint())
157+
.map(|arg| {
158+
format!(
159+
"{indentation}{bind} {name}: [{ty}; {load_size}] = {values};",
160+
bind = arg.rust_vals_array_binding(),
161+
name = arg.rust_vals_array_name(),
162+
ty = arg.ty.rust_scalar_type(),
163+
load_size = arg.ty.num_lanes() * arg.ty.num_vectors() + loads - 1,
164+
values = arg.ty.populate_random(indentation, loads, &Language::Rust)
165+
)
168166
})
169167
.collect::<Vec<_>>()
170168
.join("\n")
@@ -177,22 +175,18 @@ where
177175
/// ARM-specific
178176
pub fn load_values_c(&self, indentation: Indentation) -> String {
179177
self.iter()
180-
.filter_map(|arg| {
181-
// The ACLE doesn't support 64-bit polynomial loads on Armv7
182-
// This and the cast are a workaround for this
183-
184-
(!arg.has_constraint()).then(|| {
185-
format!(
186-
"{indentation}{ty} {name} = cast<{ty}>({load}(&{name}_vals[i]));\n",
187-
ty = arg.to_c_type(),
188-
name = arg.name,
189-
load = if arg.is_simd() {
190-
arg.ty.get_load_function(Language::C)
191-
} else {
192-
"*".to_string()
193-
}
194-
)
195-
})
178+
.filter(|&arg| !arg.has_constraint())
179+
.map(|arg| {
180+
format!(
181+
"{indentation}{ty} {name} = cast<{ty}>({load}(&{name}_vals[i]));\n",
182+
ty = arg.to_c_type(),
183+
name = arg.name,
184+
load = if arg.is_simd() {
185+
arg.ty.get_load_function(Language::C)
186+
} else {
187+
"*".to_string()
188+
}
189+
)
196190
})
197191
.collect()
198192
}
@@ -202,19 +196,18 @@ where
202196
/// e.g `let a = vld1_u8(A_VALS.as_ptr().offset(i));`
203197
pub fn load_values_rust(&self, indentation: Indentation) -> String {
204198
self.iter()
205-
.filter_map(|arg| {
206-
(!arg.has_constraint()).then(|| {
207-
format!(
208-
"{indentation}let {name} = {load}({vals_name}.as_ptr().offset(i));\n",
209-
name = arg.name,
210-
vals_name = arg.rust_vals_array_name(),
211-
load = if arg.is_simd() {
212-
arg.ty.get_load_function(Language::Rust)
213-
} else {
214-
"*".to_string()
215-
},
216-
)
217-
})
199+
.filter(|&arg| !arg.has_constraint())
200+
.map(|arg| {
201+
format!(
202+
"{indentation}let {name} = {load}({vals_name}.as_ptr().offset(i));\n",
203+
name = arg.name,
204+
vals_name = arg.rust_vals_array_name(),
205+
load = if arg.is_simd() {
206+
arg.ty.get_load_function(Language::Rust)
207+
} else {
208+
"*".to_string()
209+
},
210+
)
218211
})
219212
.collect()
220213
}

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ 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!("rust_programs/{identifier}");
134134
let _ = std::fs::create_dir_all(&rust_dir);
135-
let rust_filename = format!(r#"{rust_dir}/main.rs"#);
135+
let rust_filename = format!("{rust_dir}/main.rs");
136136

137137
(identifier, rust_filename)
138138
})

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

Lines changed: 3 additions & 3 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
}

0 commit comments

Comments
 (0)