From 08b717d6402f3df962b1f90dfba134f8ae387993 Mon Sep 17 00:00:00 2001 From: David Mak Date: Wed, 18 Dec 2024 10:43:24 +0800 Subject: [PATCH] [meta] Refactor itertools::{chain,enumerate,repeat_n} with std equiv --- nac3core/src/codegen/expr.rs | 4 ++-- nac3core/src/symbol_resolver.rs | 12 ++++++------ nac3core/src/toplevel/composer.rs | 2 +- nac3core/src/typecheck/typedef/mod.rs | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/nac3core/src/codegen/expr.rs b/nac3core/src/codegen/expr.rs index 0118ca43..8b72bee5 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -11,7 +11,7 @@ use inkwell::{ values::{BasicValueEnum, CallSiteValue, FunctionValue, IntValue, PointerValue, StructValue}, AddressSpace, IntPredicate, OptimizationLevel, }; -use itertools::{chain, izip, Either, Itertools}; +use itertools::{izip, Either, Itertools}; use nac3parser::ast::{ self, Boolop, Cmpop, Comprehension, Constant, Expr, ExprKind, Location, Operator, StrRef, @@ -1965,7 +1965,7 @@ pub fn gen_cmpop_expr_with_values<'ctx, G: CodeGenerator>( } } - let cmp_val = izip!(chain(once(&left), comparators.iter()), comparators.iter(), ops.iter(),) + let cmp_val = izip!(once(&left).chain(comparators.iter()), comparators.iter(), ops.iter(),) .fold(Ok(None), |prev: Result, String>, (lhs, rhs, op)| { let (left_ty, lhs) = lhs; let (right_ty, rhs) = rhs; diff --git a/nac3core/src/symbol_resolver.rs b/nac3core/src/symbol_resolver.rs index bab823c1..2378dd62 100644 --- a/nac3core/src/symbol_resolver.rs +++ b/nac3core/src/symbol_resolver.rs @@ -6,7 +6,7 @@ use std::{ }; use inkwell::values::{BasicValueEnum, FloatValue, IntValue, PointerValue, StructValue}; -use itertools::{chain, izip, Itertools}; +use itertools::{izip, Itertools}; use parking_lot::RwLock; use nac3parser::ast::{Constant, Expr, Location, StrRef}; @@ -452,11 +452,11 @@ pub fn parse_type_annotation( type_vars.len() )])); } - let fields = chain( - fields.iter().map(|(k, v, m)| (*k, (*v, *m))), - methods.iter().map(|(k, v, _)| (*k, (*v, false))), - ) - .collect(); + let fields = fields + .iter() + .map(|(k, v, m)| (*k, (*v, *m))) + .chain(methods.iter().map(|(k, v, _)| (*k, (*v, false)))) + .collect(); Ok(unifier.add_ty(TypeEnum::TObj { obj_id, fields, params: VarMap::default() })) } else { Err(HashSet::from([format!("Cannot use function name as type at {loc}")])) diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index 6040ced1..bd9a9214 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -1052,7 +1052,7 @@ impl TopLevelComposer { } let mut result = Vec::new(); let no_defaults = args.args.len() - args.defaults.len() - 1; - for (idx, x) in itertools::enumerate(args.args.iter().skip(1)) { + for (idx, x) in args.args.iter().skip(1).enumerate() { let type_ann = { let Some(annotation_expr) = x.node.annotation.as_ref() else {return Err(HashSet::from([format!("type annotation needed for `{}` (at {})", x.node.arg, x.location)]));}; parse_ast_to_type_annotation_kinds( diff --git a/nac3core/src/typecheck/typedef/mod.rs b/nac3core/src/typecheck/typedef/mod.rs index 49cea04c..e190c4c4 100644 --- a/nac3core/src/typecheck/typedef/mod.rs +++ b/nac3core/src/typecheck/typedef/mod.rs @@ -3,13 +3,13 @@ use std::{ cell::RefCell, collections::{HashMap, HashSet}, fmt::{self, Display}, - iter::{repeat, zip}, + iter::{repeat, repeat_n, zip}, rc::Rc, sync::{Arc, Mutex}, }; use indexmap::IndexMap; -use itertools::{repeat_n, Itertools}; +use itertools::Itertools; use nac3parser::ast::{Cmpop, Location, StrRef, Unaryop};