Skip to content

Commit 0c47579

Browse files
committed
TODO (TESTING): intrinsic-test: Modernization of coding styles
It fixes 35 out of 36 Clippy warnings, modernizing the coding styles (as allowed since the bootstrap compiler is new enough). The author is investigating possible issues.
1 parent ffb0456 commit 0c47579

File tree

10 files changed

+87
-89
lines changed

10 files changed

+87
-89
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/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 & 10 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
}
@@ -39,10 +41,11 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
3941
} else if let (Some(bit_len), simd_len, vec_len) =
4042
(self.0.bit_len, self.0.simd_len, self.0.vec_len)
4143
{
44+
// TODO: investigation (c_prefix is created okay?)
4245
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),
46+
(None, None) => format!("{rust_prefix}{bit_len}"),
47+
(Some(simd), None) => format!("{c_prefix}{bit_len}x{simd}_t"),
48+
(Some(simd), Some(vec)) => format!("{c_prefix}{bit_len}x{simd}x{vec}_t"),
4649
(None, Some(_)) => todo!("{:#?}", self), // Likely an invalid case
4750
}
4851
} else {
@@ -128,11 +131,11 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
128131
};
129132
let s = s.trim_end();
130133
let temp_return = ArmIntrinsicType::from_c(s, target);
131-
temp_return.and_then(|mut op| {
134+
temp_return.map(|mut op| {
132135
let edited = op.as_mut();
133136
edited.0.ptr = true;
134137
edited.0.ptr_constant = constant;
135-
Ok(op)
138+
op
136139
})
137140
} else {
138141
// [const ]TYPE[{bitlen}[x{simdlen}[x{vec_len}]]][_t]

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

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

3535
pub fn has_constraint(&self) -> bool {
36-
!self.constraint.is_some()
36+
// TODO: investigation (is_none is okay?)
37+
self.constraint.is_none()
3738
}
3839

3940
pub fn type_and_name_from_c(arg: &str) -> (&str, &str) {
@@ -127,15 +128,14 @@ where
127128
/// e.g `const int32x2_t a_vals = {0x3effffff, 0x3effffff, 0x3f7fffff}`, if loads=2.
128129
pub fn gen_arglists_c(&self, indentation: Indentation, loads: u32) -> String {
129130
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-
})
131+
.filter(|&arg| (!arg.has_constraint()))
132+
.map(|arg| {
133+
format!(
134+
"{indentation}const {ty} {name}_vals[] = {values};",
135+
ty = arg.ty.c_scalar_type(),
136+
name = arg.name,
137+
values = arg.ty.populate_random(indentation, loads, &Language::C)
138+
)
139139
})
140140
.collect::<Vec<_>>()
141141
.join("\n")
@@ -145,17 +145,16 @@ where
145145
/// values can be loaded as a sliding window, e.g `const A_VALS: [u32; 20] = [...];`
146146
pub fn gen_arglists_rust(&self, indentation: Indentation, loads: u32) -> String {
147147
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-
})
148+
.filter(|&arg| (!arg.has_constraint()))
149+
.map(|arg| {
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+
)
159158
})
160159
.collect::<Vec<_>>()
161160
.join("\n")
@@ -168,22 +167,18 @@ where
168167
/// ARM-specific
169168
pub fn load_values_c(&self, indentation: Indentation) -> String {
170169
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-
})
170+
.filter(|&arg| (!arg.has_constraint()))
171+
.map(|arg| {
172+
format!(
173+
"{indentation}{ty} {name} = cast<{ty}>({load}(&{name}_vals[i]));\n",
174+
ty = arg.to_c_type(),
175+
name = arg.name,
176+
load = if arg.is_simd() {
177+
arg.ty.get_load_function(Language::C)
178+
} else {
179+
"*".to_string()
180+
}
181+
)
187182
})
188183
.collect()
189184
}
@@ -193,19 +188,18 @@ where
193188
/// e.g `let a = vld1_u8(A_VALS.as_ptr().offset(i));`
194189
pub fn load_values_rust(&self, indentation: Indentation) -> String {
195190
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-
})
191+
.filter(|&arg| (!arg.has_constraint()))
192+
.map(|arg| {
193+
format!(
194+
"{indentation}let {name} = {load}({vals_name}.as_ptr().offset(i));\n",
195+
name = arg.name,
196+
vals_name = arg.rust_vals_array_name(),
197+
load = if arg.is_simd() {
198+
arg.ty.get_load_function(Language::Rust)
199+
} else {
200+
"*".to_string()
201+
},
202+
)
209203
})
210204
.collect()
211205
}

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: 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
}

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)