Clippy fix

This commit is contained in:
microproofs 2024-10-31 15:58:53 -04:00
parent 6b04a78e78
commit 1227a8a7db
No known key found for this signature in database
GPG Key ID: 14F93C84DE6AFD17
3 changed files with 66 additions and 63 deletions

View File

@ -2419,7 +2419,7 @@ impl<'a> CodeGenerator<'a> {
let current_subject_name = if builtins_path.is_empty() { let current_subject_name = if builtins_path.is_empty() {
subject_name.clone() subject_name.clone()
} else { } else {
format!("{}_{}", subject_name, builtins_path.to_string()) format!("{}_{}", subject_name, builtins_path)
}; };
// Transition process from previous to current // Transition process from previous to current
@ -2434,7 +2434,7 @@ impl<'a> CodeGenerator<'a> {
let prev_subject_name = if prev_builtins.is_empty() { let prev_subject_name = if prev_builtins.is_empty() {
subject_name.clone() subject_name.clone()
} else { } else {
format!("{}_{}", subject_name, prev_builtins.to_string()) format!("{}_{}", subject_name, prev_builtins)
}; };
let prev_tipo = prev_builtins let prev_tipo = prev_builtins
.vec .vec
@ -2494,7 +2494,7 @@ impl<'a> CodeGenerator<'a> {
clauses, clauses,
); );
builtins_to_add.to_air( builtins_to_add.produce_air(
// The only reason I pass this in is to ensure I signal // The only reason I pass this in is to ensure I signal
// whether or not constr_fields_exposer was used. I could // whether or not constr_fields_exposer was used. I could
// probably optimize this part out to simplify codegen in // 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() { let current_subject_name = if builtins_path.is_empty() {
subject_name.clone() subject_name.clone()
} else { } else {
format!("{}_{}", subject_name, builtins_path.to_string()) format!("{}_{}", subject_name, builtins_path)
}; };
// Transition process from previous to current // Transition process from previous to current
@ -2532,7 +2532,7 @@ impl<'a> CodeGenerator<'a> {
let prev_subject_name = if prev_builtins.is_empty() { let prev_subject_name = if prev_builtins.is_empty() {
subject_name.clone() subject_name.clone()
} else { } else {
format!("{}_{}", subject_name, prev_builtins.to_string()) format!("{}_{}", subject_name, prev_builtins)
}; };
let prev_tipo = prev_builtins let prev_tipo = prev_builtins
.vec .vec
@ -2603,7 +2603,7 @@ impl<'a> CodeGenerator<'a> {
let tail_name = if builtins_for_pattern.is_empty() { let tail_name = if builtins_for_pattern.is_empty() {
subject_name.clone() subject_name.clone()
} else { } else {
format!("{}_{}", subject_name, builtins_for_pattern.to_string()) format!("{}_{}", subject_name, builtins_for_pattern)
}; };
let then = self.handle_decision_tree( let then = self.handle_decision_tree(
@ -2645,7 +2645,7 @@ impl<'a> CodeGenerator<'a> {
let tail_name = if builtins_for_pattern.is_empty() { let tail_name = if builtins_for_pattern.is_empty() {
subject_name.clone() subject_name.clone()
} else { } 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 // TODO: change this in the future to use the Builtins to_string method
@ -2687,7 +2687,7 @@ impl<'a> CodeGenerator<'a> {
list_clauses.1, 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 // The only reason I pass this in is to ensure I signal
// whether or not constr_fields_exposer was used. I could // whether or not constr_fields_exposer was used. I could
// probably optimize this part out to simplify codegen in // probably optimize this part out to simplify codegen in
@ -2736,10 +2736,7 @@ impl<'a> CodeGenerator<'a> {
AirTree::anon_func( AirTree::anon_func(
assigns assigns
.iter() .iter()
.map(|i| { .map(|i| introduce_name(&mut self.interner, &i.assigned))
let assign = introduce_name(&mut self.interner, &i.assigned);
assign
})
.collect_vec(), .collect_vec(),
// The one reason we have to pass in mutable self // The one reason we have to pass in mutable self
// So we can build the TypedExpr into Air // 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() { let current_subject_name = if builtins_path.is_empty() {
subject_name.clone() subject_name.clone()
} else { } else {
format!("{}_{}", subject_name, builtins_path.to_string()) format!("{}_{}", subject_name, builtins_path)
}; };
// Transition process from previous to current // Transition process from previous to current
@ -2798,7 +2795,7 @@ impl<'a> CodeGenerator<'a> {
let prev_subject_name = if prev_builtins.is_empty() { let prev_subject_name = if prev_builtins.is_empty() {
subject_name.clone() subject_name.clone()
} else { } else {
format!("{}_{}", subject_name, prev_builtins.to_string()) format!("{}_{}", subject_name, prev_builtins)
}; };
let prev_tipo = prev_builtins let prev_tipo = prev_builtins
.vec .vec
@ -2811,14 +2808,12 @@ impl<'a> CodeGenerator<'a> {
self.handle_assigns(subject_name, subject_tipo, rest, stick_set, then), 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, &mut self.special_functions,
prev_subject_name, prev_subject_name,
prev_tipo, prev_tipo,
assignment, assignment,
); )
thing
} }
} }
} }

View File

@ -201,7 +201,7 @@ impl Scope {
} }
pub fn common_ancestor(&mut self, other: &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 self.scope = scope
.into_iter() .into_iter()
@ -263,7 +263,7 @@ impl<'a> DecisionTree<'a> {
.fold(RcDoc::line().append(RcDoc::text("path(")), |acc, p| { .fold(RcDoc::line().append(RcDoc::text("path(")), |acc, p| {
acc.append( acc.append(
RcDoc::line() RcDoc::line()
.append(RcDoc::text(format!("{}", p.to_string())).nest(4)), .append(RcDoc::text(p.to_string()).nest(4)),
) )
}) })
.append(RcDoc::line()) .append(RcDoc::line())
@ -312,7 +312,7 @@ impl<'a> DecisionTree<'a> {
.fold(RcDoc::line().append(RcDoc::text("path(")), |acc, p| { .fold(RcDoc::line().append(RcDoc::text("path(")), |acc, p| {
acc.append( acc.append(
RcDoc::line() RcDoc::line()
.append(RcDoc::text(format!("{}", p.to_string())).nest(4)), .append(RcDoc::text(p.to_string()).nest(4)),
) )
}) })
.append(RcDoc::line()) .append(RcDoc::line())
@ -703,8 +703,7 @@ impl<'a, 'b> TreeGen<'a, 'b> {
matrix.rows.iter().for_each(|item| { matrix.rows.iter().for_each(|item| {
let col = &item.columns[occurrence_col]; let col = &item.columns[occurrence_col];
match col.pattern { if let Pattern::List { elements, tail, .. } = col.pattern {
Pattern::List { elements, tail, .. } => {
has_list_pattern = true; has_list_pattern = true;
if tail.is_none() { if tail.is_none() {
match longest_elems_no_tail { match longest_elems_no_tail {
@ -730,16 +729,13 @@ impl<'a, 'b> TreeGen<'a, 'b> {
} }
} }
} }
_ => (),
}
}); });
// Since occurrence_col is Some it means there is a // Since occurrence_col is Some it means there is a
// pattern to match on so we also must have a path to the object to test // pattern to match on so we also must have a path to the object to test
// for that pattern // for that pattern
let path = matrix let path = matrix
.rows .rows.first()
.get(0)
.unwrap() .unwrap()
.columns .columns
.get(occurrence_col) .get(occurrence_col)
@ -814,7 +810,7 @@ impl<'a, 'b> TreeGen<'a, 'b> {
.. ..
} => { } => {
let data_type = 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 let (constr_index, _) = data_type
.constructors .constructors
@ -1016,7 +1012,7 @@ impl<'a, 'b> TreeGen<'a, 'b> {
) )
}) })
.collect_vec(), .collect_vec(),
default: fallback_option.into(), default: fallback_option,
} }
} }
} }
@ -1210,8 +1206,8 @@ pub fn get_tipo_by_path(mut subject_tipo: Rc<Type>, mut path: &[Path]) -> Rc<Typ
Path::ListTail(_) => subject_tipo, Path::ListTail(_) => subject_tipo,
Path::Constr(tipo, index) => tipo.arg_types().unwrap().swap_remove(*index), Path::Constr(tipo, index) => tipo.arg_types().unwrap().swap_remove(*index),
Path::OpaqueConstr(tipo) => { Path::OpaqueConstr(tipo) => {
let x = tipo.arg_types().unwrap().swap_remove(0);
x tipo.arg_types().unwrap().swap_remove(0)
} }
}; };

View File

@ -1,4 +1,4 @@
use std::rc::Rc; use std::{fmt::Display, rc::Rc};
use itertools::Itertools; use itertools::Itertools;
use uplc::{builder::CONSTR_FIELDS_EXPOSER, builtins::DefaultFunction}; use uplc::{builder::CONSTR_FIELDS_EXPOSER, builtins::DefaultFunction};
@ -38,7 +38,7 @@ impl PartialEq for Builtin {
impl Eq for Builtin {} impl Eq for Builtin {}
impl 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 { match self {
Builtin::HeadList(t) => AirTree::builtin(DefaultFunction::HeadList, t, vec![arg]), Builtin::HeadList(t) => AirTree::builtin(DefaultFunction::HeadList, t, vec![arg]),
Builtin::ExtractField(t) => AirTree::extract_field(t, arg), Builtin::ExtractField(t) => AirTree::extract_field(t, arg),
@ -70,15 +70,15 @@ impl Builtin {
} }
} }
impl ToString for Builtin { impl Display for Builtin {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Builtin::HeadList(_) => "head".to_string(), Builtin::HeadList(_) => write!(f, "head"),
Builtin::ExtractField(_) => "extractfield".to_string(), Builtin::ExtractField(_) => write!(f, "extractfield"),
Builtin::TailList => "tail".to_string(), Builtin::TailList => write!(f, "tail"),
Builtin::UnConstrFields => "unconstrfields".to_string(), Builtin::UnConstrFields => write!(f, "unconstrfields"),
Builtin::FstPair(_) => "fst".to_string(), Builtin::FstPair(_) => write!(f, "fst"),
Builtin::SndPair(_) => "snd".to_string(), Builtin::SndPair(_) => write!(f, "snd"),
} }
} }
} }
@ -88,6 +88,12 @@ pub struct Builtins {
pub vec: Vec<Builtin>, pub vec: Vec<Builtin>,
} }
impl Default for Builtins {
fn default() -> Self {
Self::new()
}
}
impl Builtins { impl Builtins {
pub fn new() -> Self { pub fn new() -> Self {
Builtins { vec: vec![] } Builtins { vec: vec![] }
@ -198,7 +204,7 @@ impl Builtins {
self self
} }
pub fn to_air( pub fn produce_air(
self, self,
special_funcs: &mut CodeGenSpecialFuncs, special_funcs: &mut CodeGenSpecialFuncs,
prev_name: String, prev_name: String,
@ -208,7 +214,7 @@ impl Builtins {
let (_, _, name_builtins) = self.vec.into_iter().fold( let (_, _, name_builtins) = self.vec.into_iter().fold(
(prev_name, subject_tipo, vec![]), (prev_name, subject_tipo, vec![]),
|(prev_name, prev_tipo, mut acc), item| { |(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(); let next_tipo = item.tipo();
acc.push((prev_name, prev_tipo, next_name.clone(), item)); 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)| { .rfold(then, |then, (prev_name, prev_tipo, next_name, builtin)| {
AirTree::let_assignment( AirTree::let_assignment(
next_name, 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, then,
) )
}) })
} }
} }
impl ToString for Builtins { impl Display for Builtins {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.vec.iter().map(|i| i.to_string()).join("_") 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 { impl TreeSet {
pub fn new() -> Self { pub fn new() -> Self {
TreeSet { children: vec![] } TreeSet { children: vec![] }