Skip to content

Commit e2dadb1

Browse files
committed
Fix formatting and clippy warnings
1 parent 416c293 commit e2dadb1

10 files changed

Lines changed: 573 additions & 195 deletions

File tree

rust/spirv-tools-opt/src/direct/context.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ impl EgglogContext {
8787
let width = self.type_widths.get(&result_type).copied().unwrap_or(32);
8888
match inst.class.opcode {
8989
Op::Constant | Op::SConvert | Op::UConvert => {
90-
self.additional_facts.push(format!(
91-
"(set (ResultWidth id{}) {})",
92-
result_id, width
93-
));
90+
self.additional_facts
91+
.push(format!("(set (ResultWidth id{}) {})", result_id, width));
9492
}
9593
_ => {}
9694
}
@@ -104,10 +102,8 @@ impl EgglogContext {
104102
if let Some(src_id) = src_id {
105103
if let Some(src_type) = self.id_to_type.get(&src_id) {
106104
if *src_type == result_type {
107-
self.additional_facts.push(format!(
108-
"(SameTypeBitcast id{})",
109-
result_id
110-
));
105+
self.additional_facts
106+
.push(format!("(SameTypeBitcast id{})", result_id));
111107
}
112108
}
113109
}
@@ -178,8 +174,12 @@ impl EgglogContext {
178174
})?;
179175
// Format with decimal point for egglog f64 parsing
180176
let s = format!("{}", float_val);
181-
let literal = if s.contains('.') || s.contains('e') || s.contains('E')
182-
|| s == "inf" || s == "-inf" || s == "NaN"
177+
let literal = if s.contains('.')
178+
|| s.contains('e')
179+
|| s.contains('E')
180+
|| s == "inf"
181+
|| s == "-inf"
182+
|| s == "NaN"
183183
{
184184
s
185185
} else {

rust/spirv-tools-opt/src/direct/mod.rs

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ pub fn optimize_module_direct(module: &Module) -> Result<Module, EgglogOptError>
357357
} else {
358358
format!("(BSym \"id{}\")", sel.condition_id)
359359
};
360-
let branch_type_class = ctx.id_to_type.get(&then_id)
360+
let branch_type_class = ctx
361+
.id_to_type
362+
.get(&then_id)
361363
.and_then(|ty| type_classes.get(ty))
362364
.copied()
363365
.unwrap_or(TypeClass::Other);
@@ -367,10 +369,8 @@ pub fn optimize_module_direct(module: &Module) -> Result<Module, EgglogOptError>
367369
TypeClass::Bool => "GammaB",
368370
TypeClass::Other => "Gamma",
369371
};
370-
let gamma_term = format!(
371-
"({} {} id{} id{})",
372-
gamma_ctor, cond_term, then_id, else_id
373-
);
372+
let gamma_term =
373+
format!("({} {} id{} id{})", gamma_ctor, cond_term, then_id, else_id);
374374
let gamma_binding = format!("(let gamma_{}_{} {})", then_id, else_id, gamma_term);
375375
egraph
376376
.parse_and_run_program(None, &gamma_binding)
@@ -767,9 +767,7 @@ pub fn optimize_module_direct(module: &Module) -> Result<Module, EgglogOptError>
767767
match inst.class.opcode {
768768
Op::Constant => {
769769
// Check if this constant's type is float
770-
let is_float = inst
771-
.result_type
772-
.and_then(|ty| type_classes.get(&ty))
770+
let is_float = inst.result_type.and_then(|ty| type_classes.get(&ty))
773771
== Some(&TypeClass::Float);
774772

775773
if is_float {
@@ -932,9 +930,8 @@ pub fn optimize_module_direct(module: &Module) -> Result<Module, EgglogOptError>
932930
next_id += 1;
933931
// value contains f64 bits packed as i64
934932
let f64_val = f64::from_bits(value as u64);
935-
let operand = rspirv::dr::Operand::LiteralBit32(
936-
(f64_val as f32).to_bits(),
937-
);
933+
let operand =
934+
rspirv::dr::Operand::LiteralBit32((f64_val as f32).to_bits());
938935
synthesized_constants.push(Instruction::new(
939936
Op::Constant,
940937
Some(ty),
@@ -2021,7 +2018,12 @@ fn cleanup_module(
20212018
fn collect_ids_from_term(term: &str, id_map: &HashMap<String, Word>, used_ids: &mut HashSet<Word>) {
20222019
// Find all Sym variants: (Sym "idN"), (ISym "idN"), (FSym "idN"), (BSym "idN")
20232020
let sym_prefixes: &[&[u8]] = &[b"(Sym \"id", b"(ISym \"id", b"(FSym \"id", b"(BSym \"id"];
2024-
let const_prefixes: &[&[u8]] = &[b"(Sym \"const", b"(ISym \"const", b"(FSym \"const", b"(BSym \"const"];
2021+
let const_prefixes: &[&[u8]] = &[
2022+
b"(Sym \"const",
2023+
b"(ISym \"const",
2024+
b"(FSym \"const",
2025+
b"(BSym \"const",
2026+
];
20252027
let mut i = 0;
20262028
let bytes = term.as_bytes();
20272029
while i < bytes.len() {
@@ -2047,15 +2049,20 @@ fn collect_ids_from_term(term: &str, id_map: &HashMap<String, Word>, used_ids: &
20472049
break;
20482050
}
20492051
}
2050-
if matched { continue; }
2052+
if matched {
2053+
continue;
2054+
}
20512055

20522056
// Check for Sym "const..." patterns (constant references)
20532057
for prefix in const_prefixes {
20542058
if i + prefix.len() < bytes.len() && &bytes[i..i + prefix.len()] == *prefix {
20552059
// Find the opening quote position: after "(Sym " or "(ISym " etc.
20562060
// We need to extract the key between the quotes
20572061
// Find the full key between quotes
2058-
let key_start = bytes[i..].iter().position(|&b| b == b'"').map(|p| i + p + 1);
2062+
let key_start = bytes[i..]
2063+
.iter()
2064+
.position(|&b| b == b'"')
2065+
.map(|p| i + p + 1);
20592066
if let Some(ks) = key_start {
20602067
let mut end = ks;
20612068
while end < bytes.len() && bytes[end] != b'"' {
@@ -2074,7 +2081,9 @@ fn collect_ids_from_term(term: &str, id_map: &HashMap<String, Word>, used_ids: &
20742081
break;
20752082
}
20762083
}
2077-
if matched { continue; }
2084+
if matched {
2085+
continue;
2086+
}
20782087

20792088
i += 1;
20802089
}
@@ -2499,7 +2508,10 @@ fn topological_sort_bindings(id_to_term: &HashMap<Word, String>) -> Vec<Word> {
24992508
// Skip Sym variant patterns - these are safe opaque references
25002509
// Handles: (Sym "..."), (ISym "..."), (FSym "..."), (BSym "...")
25012510
let skip_sym = (i + 5 < bytes.len() && &bytes[i..i + 5] == b"(Sym ")
2502-
|| (i + 6 < bytes.len() && (&bytes[i..i + 6] == b"(ISym " || &bytes[i..i + 6] == b"(FSym " || &bytes[i..i + 6] == b"(BSym "));
2511+
|| (i + 6 < bytes.len()
2512+
&& (&bytes[i..i + 6] == b"(ISym "
2513+
|| &bytes[i..i + 6] == b"(FSym "
2514+
|| &bytes[i..i + 6] == b"(BSym "));
25032515
if skip_sym {
25042516
// Skip to closing paren
25052517
if let Some(close) = term[i..].find(')') {
@@ -2614,8 +2626,14 @@ fn parse_effect_result(s: &str) -> Option<ParsedEffect> {
26142626

26152627
// Check for Gamma/Select variants (typed and untyped)
26162628
let gamma_select_prefixes = [
2617-
"(Gamma ", "(GammaI ", "(GammaF ", "(GammaB ",
2618-
"(Select ", "(SelectI ", "(SelectF ", "(SelectB ",
2629+
"(Gamma ",
2630+
"(GammaI ",
2631+
"(GammaF ",
2632+
"(GammaB ",
2633+
"(Select ",
2634+
"(SelectI ",
2635+
"(SelectF ",
2636+
"(SelectB ",
26192637
];
26202638
let matched_prefix = gamma_select_prefixes.iter().find(|p| inner.starts_with(*p));
26212639
if let Some(prefix) = matched_prefix {
@@ -3153,10 +3171,18 @@ fn materialize_term(
31533171

31543172
// Select / Gamma / If (untyped and typed variants) — all map to Op::Select
31553173
for select_prefix in &[
3156-
"(Select ", "(Gamma ", "(If ",
3157-
"(SelectI ", "(GammaI ", "(IfI ",
3158-
"(SelectF ", "(GammaF ", "(IfF ",
3159-
"(SelectB ", "(GammaB ", "(IfB ",
3174+
"(Select ",
3175+
"(Gamma ",
3176+
"(If ",
3177+
"(SelectI ",
3178+
"(GammaI ",
3179+
"(IfI ",
3180+
"(SelectF ",
3181+
"(GammaF ",
3182+
"(IfF ",
3183+
"(SelectB ",
3184+
"(GammaB ",
3185+
"(IfB ",
31603186
] {
31613187
if let Some(rest) = term.strip_prefix(select_prefix) {
31623188
if let Some(rest) = rest.strip_suffix(')') {

rust/spirv-tools-opt/src/direct/parse/arithmetic.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,18 @@ const UNARY_OPS: &[(&str, Op)] = &[
6161

6262
/// All Select/Gamma/If variants (typed and untyped) map to Op::Select.
6363
const SELECT_VARIANTS: &[&str] = &[
64-
"Select", "SelectI", "SelectF", "SelectB",
65-
"Gamma", "GammaI", "GammaF", "GammaB",
66-
"If", "IfI", "IfF", "IfB",
64+
"Select",
65+
"SelectI",
66+
"SelectF",
67+
"SelectB",
68+
"Gamma",
69+
"GammaI",
70+
"GammaF",
71+
"GammaB",
72+
"If",
73+
"IfI",
74+
"IfF",
75+
"IfB",
6776
"VecSelect",
6877
];
6978

rust/spirv-tools-opt/src/direct/parse/image.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ pub fn try_parse_image(
4545
vec![
4646
rspirv::dr::Operand::IdRef(image),
4747
rspirv::dr::Operand::IdRef(coord),
48-
rspirv::dr::Operand::ImageOperands(
49-
rspirv::spirv::ImageOperands::OFFSET,
50-
),
48+
rspirv::dr::Operand::ImageOperands(rspirv::spirv::ImageOperands::OFFSET),
5149
rspirv::dr::Operand::IdRef(offset),
5250
],
5351
));
@@ -64,9 +62,7 @@ pub fn try_parse_image(
6462
vec![
6563
rspirv::dr::Operand::IdRef(image),
6664
rspirv::dr::Operand::IdRef(coord),
67-
rspirv::dr::Operand::ImageOperands(
68-
rspirv::spirv::ImageOperands::CONST_OFFSET,
69-
),
65+
rspirv::dr::Operand::ImageOperands(rspirv::spirv::ImageOperands::CONST_OFFSET),
7066
rspirv::dr::Operand::IdRef(offset),
7167
],
7268
));
@@ -98,9 +94,7 @@ pub fn try_parse_image(
9894
vec![
9995
rspirv::dr::Operand::IdRef(image),
10096
rspirv::dr::Operand::IdRef(coord),
101-
rspirv::dr::Operand::ImageOperands(
102-
rspirv::spirv::ImageOperands::OFFSET,
103-
),
97+
rspirv::dr::Operand::ImageOperands(rspirv::spirv::ImageOperands::OFFSET),
10498
rspirv::dr::Operand::IdRef(offset),
10599
],
106100
));
@@ -117,9 +111,7 @@ pub fn try_parse_image(
117111
vec![
118112
rspirv::dr::Operand::IdRef(image),
119113
rspirv::dr::Operand::IdRef(coord),
120-
rspirv::dr::Operand::ImageOperands(
121-
rspirv::spirv::ImageOperands::CONST_OFFSET,
122-
),
114+
rspirv::dr::Operand::ImageOperands(rspirv::spirv::ImageOperands::CONST_OFFSET),
123115
rspirv::dr::Operand::IdRef(offset),
124116
],
125117
));

rust/spirv-tools-opt/src/direct/parse/util.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ pub fn resolve_term_to_id(term: &str, id_map: &HashMap<String, Word>) -> Option<
9090

9191
// Handle bridge constructors as transparent wrappers
9292
for prefix in &[
93-
"(IntToExpr ", "(FloatToExpr ", "(BoolToExpr ",
94-
"(ExprToInt ", "(ExprToFloat ", "(ExprToBool ",
93+
"(IntToExpr ",
94+
"(FloatToExpr ",
95+
"(BoolToExpr ",
96+
"(ExprToInt ",
97+
"(ExprToFloat ",
98+
"(ExprToBool ",
9599
] {
96100
if let Some(rest) = term.strip_prefix(prefix) {
97101
if let Some(inner) = rest.strip_suffix(')') {

0 commit comments

Comments
 (0)