From 1227a8a7db3c197b5d85f5b1fc19e1892cdfecc3 Mon Sep 17 00:00:00 2001 From: microproofs Date: Thu, 31 Oct 2024 15:58:53 -0400 Subject: [PATCH] Clippy fix --- crates/aiken-lang/src/gen_uplc.rs | 31 +++++------ .../aiken-lang/src/gen_uplc/decision_tree.rs | 54 +++++++++---------- .../src/gen_uplc/stick_break_set.rs | 44 +++++++++------ 3 files changed, 66 insertions(+), 63 deletions(-) diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index 89c6d099..cf86c0b2 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -2419,7 +2419,7 @@ impl<'a> CodeGenerator<'a> { let current_subject_name = if builtins_path.is_empty() { subject_name.clone() } else { - format!("{}_{}", subject_name, builtins_path.to_string()) + format!("{}_{}", subject_name, builtins_path) }; // Transition process from previous to current @@ -2434,7 +2434,7 @@ impl<'a> CodeGenerator<'a> { let prev_subject_name = if prev_builtins.is_empty() { subject_name.clone() } else { - format!("{}_{}", subject_name, prev_builtins.to_string()) + format!("{}_{}", subject_name, prev_builtins) }; let prev_tipo = prev_builtins .vec @@ -2494,7 +2494,7 @@ impl<'a> CodeGenerator<'a> { clauses, ); - builtins_to_add.to_air( + builtins_to_add.produce_air( // The only reason I pass this in is to ensure I signal // whether or not constr_fields_exposer was used. I could // probably optimize this part out to simplify codegen in @@ -2517,7 +2517,7 @@ impl<'a> CodeGenerator<'a> { let current_subject_name = if builtins_path.is_empty() { subject_name.clone() } else { - format!("{}_{}", subject_name, builtins_path.to_string()) + format!("{}_{}", subject_name, builtins_path) }; // Transition process from previous to current @@ -2532,7 +2532,7 @@ impl<'a> CodeGenerator<'a> { let prev_subject_name = if prev_builtins.is_empty() { subject_name.clone() } else { - format!("{}_{}", subject_name, prev_builtins.to_string()) + format!("{}_{}", subject_name, prev_builtins) }; let prev_tipo = prev_builtins .vec @@ -2603,7 +2603,7 @@ impl<'a> CodeGenerator<'a> { let tail_name = if builtins_for_pattern.is_empty() { subject_name.clone() } else { - format!("{}_{}", subject_name, builtins_for_pattern.to_string()) + format!("{}_{}", subject_name, builtins_for_pattern) }; let then = self.handle_decision_tree( @@ -2645,7 +2645,7 @@ impl<'a> CodeGenerator<'a> { let tail_name = if builtins_for_pattern.is_empty() { subject_name.clone() } else { - format!("{}_{}", subject_name, builtins_for_pattern.to_string()) + format!("{}_{}", subject_name, builtins_for_pattern) }; // TODO: change this in the future to use the Builtins to_string method @@ -2687,7 +2687,7 @@ impl<'a> CodeGenerator<'a> { list_clauses.1, ); - builtins_to_add.to_air( + builtins_to_add.produce_air( // The only reason I pass this in is to ensure I signal // whether or not constr_fields_exposer was used. I could // probably optimize this part out to simplify codegen in @@ -2736,10 +2736,7 @@ impl<'a> CodeGenerator<'a> { AirTree::anon_func( assigns .iter() - .map(|i| { - let assign = introduce_name(&mut self.interner, &i.assigned); - assign - }) + .map(|i| introduce_name(&mut self.interner, &i.assigned)) .collect_vec(), // The one reason we have to pass in mutable self // So we can build the TypedExpr into Air @@ -2783,7 +2780,7 @@ impl<'a> CodeGenerator<'a> { let current_subject_name = if builtins_path.is_empty() { subject_name.clone() } else { - format!("{}_{}", subject_name, builtins_path.to_string()) + format!("{}_{}", subject_name, builtins_path) }; // Transition process from previous to current @@ -2798,7 +2795,7 @@ impl<'a> CodeGenerator<'a> { let prev_subject_name = if prev_builtins.is_empty() { subject_name.clone() } else { - format!("{}_{}", subject_name, prev_builtins.to_string()) + format!("{}_{}", subject_name, prev_builtins) }; let prev_tipo = prev_builtins .vec @@ -2811,14 +2808,12 @@ impl<'a> CodeGenerator<'a> { self.handle_assigns(subject_name, subject_tipo, rest, stick_set, then), ); - let thing = builtins_to_add.to_air( + builtins_to_add.produce_air( &mut self.special_functions, prev_subject_name, prev_tipo, assignment, - ); - - thing + ) } } } diff --git a/crates/aiken-lang/src/gen_uplc/decision_tree.rs b/crates/aiken-lang/src/gen_uplc/decision_tree.rs index d636efd4..74b50dc0 100644 --- a/crates/aiken-lang/src/gen_uplc/decision_tree.rs +++ b/crates/aiken-lang/src/gen_uplc/decision_tree.rs @@ -201,7 +201,7 @@ impl Scope { } pub fn common_ancestor(&mut self, other: &Scope) { - let scope = std::mem::replace(&mut self.scope, vec![]); + let scope = std::mem::take(&mut self.scope); self.scope = scope .into_iter() @@ -263,7 +263,7 @@ impl<'a> DecisionTree<'a> { .fold(RcDoc::line().append(RcDoc::text("path(")), |acc, p| { acc.append( RcDoc::line() - .append(RcDoc::text(format!("{}", p.to_string())).nest(4)), + .append(RcDoc::text(p.to_string()).nest(4)), ) }) .append(RcDoc::line()) @@ -312,7 +312,7 @@ impl<'a> DecisionTree<'a> { .fold(RcDoc::line().append(RcDoc::text("path(")), |acc, p| { acc.append( RcDoc::line() - .append(RcDoc::text(format!("{}", p.to_string())).nest(4)), + .append(RcDoc::text(p.to_string()).nest(4)), ) }) .append(RcDoc::line()) @@ -703,34 +703,31 @@ impl<'a, 'b> TreeGen<'a, 'b> { matrix.rows.iter().for_each(|item| { let col = &item.columns[occurrence_col]; - match col.pattern { - Pattern::List { elements, tail, .. } => { - has_list_pattern = true; - if tail.is_none() { - match longest_elems_no_tail { - Some(elems_count) => { - if elems_count < elements.len() { - longest_elems_no_tail = Some(elements.len()); - } - } - None => { + if let Pattern::List { elements, tail, .. } = col.pattern { + has_list_pattern = true; + if tail.is_none() { + match longest_elems_no_tail { + Some(elems_count) => { + if elems_count < elements.len() { longest_elems_no_tail = Some(elements.len()); } } - } else { - match longest_elems_with_tail { - Some(elems_count) => { - if elems_count < elements.len() { - longest_elems_with_tail = Some(elements.len()); - } - } - None => { + None => { + longest_elems_no_tail = Some(elements.len()); + } + } + } else { + match longest_elems_with_tail { + Some(elems_count) => { + if elems_count < elements.len() { longest_elems_with_tail = Some(elements.len()); } } + None => { + longest_elems_with_tail = Some(elements.len()); + } } } - _ => (), } }); @@ -738,8 +735,7 @@ impl<'a, 'b> TreeGen<'a, 'b> { // pattern to match on so we also must have a path to the object to test // for that pattern let path = matrix - .rows - .get(0) + .rows.first() .unwrap() .columns .get(occurrence_col) @@ -814,7 +810,7 @@ impl<'a, 'b> TreeGen<'a, 'b> { .. } => { let data_type = - lookup_data_type_by_tipo(&self.data_types, &specialized_tipo).unwrap(); + lookup_data_type_by_tipo(self.data_types, &specialized_tipo).unwrap(); let (constr_index, _) = data_type .constructors @@ -1016,7 +1012,7 @@ impl<'a, 'b> TreeGen<'a, 'b> { ) }) .collect_vec(), - default: fallback_option.into(), + default: fallback_option, } } } @@ -1210,8 +1206,8 @@ pub fn get_tipo_by_path(mut subject_tipo: Rc, mut path: &[Path]) -> Rc subject_tipo, Path::Constr(tipo, index) => tipo.arg_types().unwrap().swap_remove(*index), Path::OpaqueConstr(tipo) => { - let x = tipo.arg_types().unwrap().swap_remove(0); - x + + tipo.arg_types().unwrap().swap_remove(0) } }; diff --git a/crates/aiken-lang/src/gen_uplc/stick_break_set.rs b/crates/aiken-lang/src/gen_uplc/stick_break_set.rs index d4c9f0f2..6b8034e8 100644 --- a/crates/aiken-lang/src/gen_uplc/stick_break_set.rs +++ b/crates/aiken-lang/src/gen_uplc/stick_break_set.rs @@ -1,4 +1,4 @@ -use std::rc::Rc; +use std::{fmt::Display, rc::Rc}; use itertools::Itertools; use uplc::{builder::CONSTR_FIELDS_EXPOSER, builtins::DefaultFunction}; @@ -38,7 +38,7 @@ impl PartialEq for Builtin { impl Eq for Builtin {} impl Builtin { - fn to_air_call(self, special_funcs: &mut CodeGenSpecialFuncs, arg: AirTree) -> AirTree { + fn produce_air(self, special_funcs: &mut CodeGenSpecialFuncs, arg: AirTree) -> AirTree { match self { Builtin::HeadList(t) => AirTree::builtin(DefaultFunction::HeadList, t, vec![arg]), Builtin::ExtractField(t) => AirTree::extract_field(t, arg), @@ -70,15 +70,15 @@ impl Builtin { } } -impl ToString for Builtin { - fn to_string(&self) -> String { +impl Display for Builtin { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Builtin::HeadList(_) => "head".to_string(), - Builtin::ExtractField(_) => "extractfield".to_string(), - Builtin::TailList => "tail".to_string(), - Builtin::UnConstrFields => "unconstrfields".to_string(), - Builtin::FstPair(_) => "fst".to_string(), - Builtin::SndPair(_) => "snd".to_string(), + Builtin::HeadList(_) => write!(f, "head"), + Builtin::ExtractField(_) => write!(f, "extractfield"), + Builtin::TailList => write!(f, "tail"), + Builtin::UnConstrFields => write!(f, "unconstrfields"), + Builtin::FstPair(_) => write!(f, "fst"), + Builtin::SndPair(_) => write!(f, "snd"), } } } @@ -88,6 +88,12 @@ pub struct Builtins { pub vec: Vec, } +impl Default for Builtins { + fn default() -> Self { + Self::new() + } +} + impl Builtins { pub fn new() -> Self { Builtins { vec: vec![] } @@ -198,7 +204,7 @@ impl Builtins { self } - pub fn to_air( + pub fn produce_air( self, special_funcs: &mut CodeGenSpecialFuncs, prev_name: String, @@ -208,7 +214,7 @@ impl Builtins { let (_, _, name_builtins) = self.vec.into_iter().fold( (prev_name, subject_tipo, vec![]), |(prev_name, prev_tipo, mut acc), item| { - let next_name = format!("{}_{}", prev_name, item.to_string()); + let next_name = format!("{}_{}", prev_name, item); let next_tipo = item.tipo(); acc.push((prev_name, prev_tipo, next_name.clone(), item)); @@ -222,16 +228,16 @@ impl Builtins { .rfold(then, |then, (prev_name, prev_tipo, next_name, builtin)| { AirTree::let_assignment( next_name, - builtin.to_air_call(special_funcs, AirTree::local_var(prev_name, prev_tipo)), + builtin.produce_air(special_funcs, AirTree::local_var(prev_name, prev_tipo)), then, ) }) } } -impl ToString for Builtins { - fn to_string(&self) -> String { - self.vec.iter().map(|i| i.to_string()).join("_") +impl Display for Builtins { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.vec.iter().map(|i| i.to_string()).join("_")) } } @@ -263,6 +269,12 @@ impl TreeNode { } } +impl Default for TreeSet { + fn default() -> Self { + Self::new() + } +} + impl TreeSet { pub fn new() -> Self { TreeSet { children: vec![] }