From fed1361c6abd18dae480b3127a8c04719e06a6dc Mon Sep 17 00:00:00 2001 From: lyken Date: Thu, 13 Jun 2024 16:03:32 +0800 Subject: [PATCH] core: rename to_var_map to into_var_map --- nac3artiq/src/symbol_resolver.rs | 6 ++--- nac3core/src/codegen/concrete_type.rs | 6 ++--- nac3core/src/toplevel/builtins.rs | 24 +++++++++---------- nac3core/src/toplevel/helper.rs | 14 +++++------ .../src/typecheck/type_inferencer/test.rs | 6 ++--- nac3core/src/typecheck/typedef/mod.rs | 2 +- nac3core/src/typecheck/typedef/test.rs | 2 +- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/nac3artiq/src/symbol_resolver.rs b/nac3artiq/src/symbol_resolver.rs index 6ef6e95..2bb2751 100644 --- a/nac3artiq/src/symbol_resolver.rs +++ b/nac3artiq/src/symbol_resolver.rs @@ -9,7 +9,7 @@ use nac3core::{ }, typecheck::{ type_inferencer::PrimitiveStore, - typedef::{iter_type_vars, to_var_map, Type, TypeEnum, TypeVar, Unifier, VarMap}, + typedef::{iter_type_vars, into_var_map, Type, TypeEnum, TypeVar, Unifier, VarMap}, }, }; use nac3parser::ast::{self, StrRef}; @@ -719,7 +719,7 @@ impl InnerResolver { unreachable!("must be tobj") }; - let var_map = to_var_map(iter_type_vars(params).map(|tvar| { + let var_map = into_var_map(iter_type_vars(params).map(|tvar| { let TypeEnum::TVar { id, range, name, loc, .. } = &*unifier.get_ty(tvar.ty) else { unreachable!() @@ -746,7 +746,7 @@ impl InnerResolver { } (TypeEnum::TObj { params, fields, .. }, false) => { self.pyid_to_type.write().insert(py_obj_id, extracted_ty); - let var_map = to_var_map(iter_type_vars(params).map(|tvar| { + let var_map = into_var_map(iter_type_vars(params).map(|tvar| { let TypeEnum::TVar { id, range, name, loc, .. } = &*unifier.get_ty(tvar.ty) else { unreachable!() diff --git a/nac3core/src/codegen/concrete_type.rs b/nac3core/src/codegen/concrete_type.rs index 7ac198a..65cbe57 100644 --- a/nac3core/src/codegen/concrete_type.rs +++ b/nac3core/src/codegen/concrete_type.rs @@ -3,7 +3,7 @@ use crate::{ toplevel::DefinitionId, typecheck::{ type_inferencer::PrimitiveStore, - typedef::{to_var_map, FunSignature, FuncArg, Type, TypeEnum, TypeVar, TypeVarId, Unifier}, + typedef::{into_var_map, FunSignature, FuncArg, Type, TypeEnum, TypeVar, TypeVarId, Unifier}, }, }; @@ -272,7 +272,7 @@ impl ConcreteTypeStore { (*name, (self.to_unifier_type(unifier, primitives, cty.0, cache), cty.1)) }) .collect::>(), - params: to_var_map(params.iter().map(|(&id, cty)| { + params: into_var_map(params.iter().map(|(&id, cty)| { let ty = self.to_unifier_type(unifier, primitives, *cty, cache); TypeVar { id, ty } })), @@ -287,7 +287,7 @@ impl ConcreteTypeStore { }) .collect(), ret: self.to_unifier_type(unifier, primitives, *ret, cache), - vars: to_var_map(vars.iter().map(|(&id, cty)| { + vars: into_var_map(vars.iter().map(|(&id, cty)| { let ty = self.to_unifier_type(unifier, primitives, *cty, cache); TypeVar { id, ty } })), diff --git a/nac3core/src/toplevel/builtins.rs b/nac3core/src/toplevel/builtins.rs index bfecd65..e4b3ba0 100644 --- a/nac3core/src/toplevel/builtins.rs +++ b/nac3core/src/toplevel/builtins.rs @@ -25,7 +25,7 @@ use crate::{ }, symbol_resolver::SymbolValue, toplevel::{helper::PrimDef, numpy::make_ndarray_ty}, - typecheck::typedef::{iter_type_vars, to_var_map, TypeVar, VarMap}, + typecheck::typedef::{iter_type_vars, into_var_map, TypeVar, VarMap}, }; use super::*; @@ -373,7 +373,7 @@ impl<'a> BuiltinBuilder<'a> { Some("N".into()), None, ); - let num_var_map = to_var_map([num_ty]); + let num_var_map = into_var_map([num_ty]); let ndarray_float = make_ndarray_ty(unifier, primitives, Some(float), None); let ndarray_float_2d = { @@ -390,11 +390,11 @@ impl<'a> BuiltinBuilder<'a> { let ndarray_num_ty = make_ndarray_ty(unifier, primitives, Some(num_ty.ty), None); let float_or_ndarray_ty = unifier.get_fresh_var_with_range(&[float, ndarray_float], Some("T".into()), None); - let float_or_ndarray_var_map = to_var_map([float_or_ndarray_ty]); + let float_or_ndarray_var_map = into_var_map([float_or_ndarray_ty]); let num_or_ndarray_ty = unifier.get_fresh_var_with_range(&[num_ty.ty, ndarray_num_ty], Some("T".into()), None); - let num_or_ndarray_var_map = to_var_map([num_ty, num_or_ndarray_ty]); + let num_or_ndarray_var_map = into_var_map([num_ty, num_or_ndarray_ty]); let list_int32 = unifier.add_ty(TypeEnum::TList { ty: int32 }); @@ -717,7 +717,7 @@ impl<'a> BuiltinBuilder<'a> { default_value: None, }], ret: self.primitives.option, - vars: to_var_map([self.option_tvar]), + vars: into_var_map([self.option_tvar]), })), var_id: vec![self.option_tvar.id], instance_to_symbol: HashMap::default(), @@ -892,7 +892,7 @@ impl<'a> BuiltinBuilder<'a> { create_fn_by_codegen( self.unifier, - &to_var_map([common_ndim, p0_ty, ret_ty]), + &into_var_map([common_ndim, p0_ty, ret_ty]), prim.name(), ret_ty.ty, &[(p0_ty.ty, "n")], @@ -956,7 +956,7 @@ impl<'a> BuiltinBuilder<'a> { create_fn_by_codegen( self.unifier, - &to_var_map([common_ndim, p0_ty, ret_ty]), + &into_var_map([common_ndim, p0_ty, ret_ty]), prim.name(), ret_ty.ty, &[(p0_ty.ty, "n")], @@ -1034,7 +1034,7 @@ impl<'a> BuiltinBuilder<'a> { }, ], ret: ndarray, - vars: to_var_map([tv]), + vars: into_var_map([tv]), })), var_id: vec![tv.id], instance_to_symbol: HashMap::default(), @@ -1054,7 +1054,7 @@ impl<'a> BuiltinBuilder<'a> { create_fn_by_codegen( self.unifier, - &to_var_map([tv]), + &into_var_map([tv]), prim.name(), self.primitives.ndarray, // We are using List[int32] here, as I don't know a way to specify an n-tuple bound on a @@ -1333,7 +1333,7 @@ impl<'a> BuiltinBuilder<'a> { signature: self.unifier.add_ty(TypeEnum::TFunc(FunSignature { args: vec![FuncArg { name: "ls".into(), ty: arg_ty.ty, default_value: None }], ret: int32, - vars: to_var_map([tvar, arg_ty]), + vars: into_var_map([tvar, arg_ty]), })), var_id: Vec::default(), instance_to_symbol: HashMap::default(), @@ -1516,7 +1516,7 @@ impl<'a> BuiltinBuilder<'a> { .map(|p| FuncArg { name: p.1.into(), ty: p.0, default_value: None }) .collect(), ret: ret_ty.ty, - vars: to_var_map([x1_ty, x2_ty, ret_ty]), + vars: into_var_map([x1_ty, x2_ty, ret_ty]), })), var_id: vec![x1_ty.id, x2_ty.id], instance_to_symbol: HashMap::default(), @@ -1745,7 +1745,7 @@ impl<'a> BuiltinBuilder<'a> { .map(|p| FuncArg { name: p.1.into(), ty: p.0, default_value: None }) .collect(), ret: ret_ty.ty, - vars: to_var_map([x1_ty, x2_ty, ret_ty]), + vars: into_var_map([x1_ty, x2_ty, ret_ty]), })), var_id: vec![ret_ty.id], instance_to_symbol: HashMap::default(), diff --git a/nac3core/src/toplevel/helper.rs b/nac3core/src/toplevel/helper.rs index 8cc77a9..0c37d1e 100644 --- a/nac3core/src/toplevel/helper.rs +++ b/nac3core/src/toplevel/helper.rs @@ -2,7 +2,7 @@ use std::convert::TryInto; use crate::symbol_resolver::SymbolValue; use crate::toplevel::numpy::unpack_ndarray_var_tys; -use crate::typecheck::typedef::{to_var_map, Mapping, TypeVarId, VarMap}; +use crate::typecheck::typedef::{into_var_map, Mapping, TypeVarId, VarMap}; use nac3parser::ast::{Constant, Location}; use strum::IntoEnumIterator; use strum_macros::EnumIter; @@ -377,12 +377,12 @@ impl TopLevelComposer { let is_some_type_fun_ty = unifier.add_ty(TypeEnum::TFunc(FunSignature { args: vec![], ret: bool, - vars: to_var_map([option_type_var]), + vars: into_var_map([option_type_var]), })); let unwrap_fun_ty = unifier.add_ty(TypeEnum::TFunc(FunSignature { args: vec![], ret: option_type_var.ty, - vars: to_var_map([option_type_var]), + vars: into_var_map([option_type_var]), })); let option = unifier.add_ty(TypeEnum::TObj { obj_id: PrimDef::Option.id(), @@ -393,7 +393,7 @@ impl TopLevelComposer { ] .into_iter() .collect::>(), - params: to_var_map([option_type_var]), + params: into_var_map([option_type_var]), }); let size_t_ty = match size_t { @@ -409,7 +409,7 @@ impl TopLevelComposer { let ndarray_copy_fun_ty = unifier.add_ty(TypeEnum::TFunc(FunSignature { args: vec![], ret: ndarray_copy_fun_ret_ty.ty, - vars: to_var_map([ndarray_dtype_tvar, ndarray_ndims_tvar]), + vars: into_var_map([ndarray_dtype_tvar, ndarray_ndims_tvar]), })); let ndarray_fill_fun_ty = unifier.add_ty(TypeEnum::TFunc(FunSignature { args: vec![FuncArg { @@ -418,7 +418,7 @@ impl TopLevelComposer { default_value: None, }], ret: none, - vars: to_var_map([ndarray_dtype_tvar, ndarray_ndims_tvar]), + vars: into_var_map([ndarray_dtype_tvar, ndarray_ndims_tvar]), })); let ndarray = unifier.add_ty(TypeEnum::TObj { obj_id: PrimDef::NDArray.id(), @@ -426,7 +426,7 @@ impl TopLevelComposer { (PrimDef::NDArrayCopy.simple_name().into(), (ndarray_copy_fun_ty, true)), (PrimDef::NDArrayFill.simple_name().into(), (ndarray_fill_fun_ty, true)), ]), - params: to_var_map([ndarray_dtype_tvar, ndarray_ndims_tvar]), + params: into_var_map([ndarray_dtype_tvar, ndarray_ndims_tvar]), }); unifier.unify(ndarray_copy_fun_ret_ty.ty, ndarray).unwrap(); diff --git a/nac3core/src/typecheck/type_inferencer/test.rs b/nac3core/src/typecheck/type_inferencer/test.rs index 45c9788..b5e2b1e 100644 --- a/nac3core/src/typecheck/type_inferencer/test.rs +++ b/nac3core/src/typecheck/type_inferencer/test.rs @@ -143,7 +143,7 @@ impl TestEnvironment { let ndarray = unifier.add_ty(TypeEnum::TObj { obj_id: PrimDef::NDArray.id(), fields: HashMap::new(), - params: to_var_map([ndarray_dtype_tvar, ndarray_ndims_tvar]), + params: into_var_map([ndarray_dtype_tvar, ndarray_ndims_tvar]), }); let primitives = PrimitiveStore { int32, @@ -323,7 +323,7 @@ impl TestEnvironment { let foo_ty = unifier.add_ty(TypeEnum::TObj { obj_id: DefinitionId(defs + 1), fields: [("a".into(), (tvar.ty, true))].iter().cloned().collect::>(), - params: to_var_map([tvar]), + params: into_var_map([tvar]), }); top_level_defs.push( RwLock::new(TopLevelDef::Class { @@ -345,7 +345,7 @@ impl TestEnvironment { unifier.add_ty(TypeEnum::TFunc(FunSignature { args: vec![], ret: foo_ty, - vars: to_var_map([tvar]), + vars: into_var_map([tvar]), })), ); diff --git a/nac3core/src/typecheck/typedef/mod.rs b/nac3core/src/typecheck/typedef/mod.rs index ee06cab..59e1ad4 100644 --- a/nac3core/src/typecheck/typedef/mod.rs +++ b/nac3core/src/typecheck/typedef/mod.rs @@ -61,7 +61,7 @@ pub type VarMap = IndexMapping; /// Build a [`VarMap`] from an iterator of [`TypeVar`] /// /// The resulting [`VarMap`] wil have the same order as the input iterator. -pub fn to_var_map(vars: I) -> VarMap +pub fn into_var_map(vars: I) -> VarMap where I: IntoIterator, { diff --git a/nac3core/src/typecheck/typedef/test.rs b/nac3core/src/typecheck/typedef/test.rs index 6867819..7c5dd47 100644 --- a/nac3core/src/typecheck/typedef/test.rs +++ b/nac3core/src/typecheck/typedef/test.rs @@ -116,7 +116,7 @@ impl TestEnvironment { unifier.add_ty(TypeEnum::TObj { obj_id: DefinitionId(3), fields: [("a".into(), (tvar.ty, true))].iter().cloned().collect::>(), - params: to_var_map([tvar]), + params: into_var_map([tvar]), }), );