forked from M-Labs/nac3
1
0
Fork 0

core: rename to_var_map to into_var_map

This commit is contained in:
lyken 2024-06-13 16:03:32 +08:00
parent aa94e0c8a4
commit fed1361c6a
7 changed files with 30 additions and 30 deletions

View File

@ -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!()

View File

@ -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::<HashMap<_, _>>(),
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 }
})),

View File

@ -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(),

View File

@ -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::<HashMap<_, _>>(),
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();

View File

@ -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::<HashMap<_, _>>(),
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]),
})),
);

View File

@ -61,7 +61,7 @@ pub type VarMap = IndexMapping<TypeVarId>;
/// 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<I>(vars: I) -> VarMap
pub fn into_var_map<I>(vars: I) -> VarMap
where
I: IntoIterator<Item = TypeVar>,
{

View File

@ -116,7 +116,7 @@ impl TestEnvironment {
unifier.add_ty(TypeEnum::TObj {
obj_id: DefinitionId(3),
fields: [("a".into(), (tvar.ty, true))].iter().cloned().collect::<HashMap<_, _>>(),
params: to_var_map([tvar]),
params: into_var_map([tvar]),
}),
);