core: Apply clippy suggestions

This commit is contained in:
David Mak 2024-04-01 16:22:40 +08:00
parent 623fcf85af
commit 4bb0e60981
4 changed files with 38 additions and 18 deletions

1
.clippy.toml Normal file
View File

@ -0,0 +1 @@
doc-valid-idents = ["NumPy", ".."]

View File

@ -38,10 +38,15 @@ pub enum PrimitiveValue {
Bool(bool), Bool(bool),
} }
/// An entry in the [`DeferredEvaluationStore`], containing the deferred types, a [`PyObject`]
/// representing the `__constraints__` of the type variables, and the name of the type to be
/// instantiated.
type DeferredEvaluationEntry = (Vec<Type>, PyObject, String);
#[derive(Clone)] #[derive(Clone)]
pub struct DeferredEvaluationStore { pub struct DeferredEvaluationStore {
needs_defer: Arc<AtomicBool>, needs_defer: Arc<AtomicBool>,
store: Arc<RwLock<Vec<(Vec<Type>, PyObject, String)>>>, store: Arc<RwLock<Vec<DeferredEvaluationEntry>>>,
} }
impl DeferredEvaluationStore { impl DeferredEvaluationStore {
@ -53,12 +58,18 @@ impl DeferredEvaluationStore {
} }
} }
/// A class field as stored in the [`InnerResolver`], represented by the ID and name of the
/// associated [`PythonValue`].
type ResolverField = (u64, StrRef);
/// A class field as stored in Python, represented by the `id()` and [`PyObject`] of the field.
type PyFieldHandle = (u64, PyObject);
pub struct InnerResolver { pub struct InnerResolver {
pub id_to_type: RwLock<HashMap<StrRef, Type>>, pub id_to_type: RwLock<HashMap<StrRef, Type>>,
pub id_to_def: RwLock<HashMap<StrRef, DefinitionId>>, pub id_to_def: RwLock<HashMap<StrRef, DefinitionId>>,
pub id_to_pyval: RwLock<HashMap<StrRef, (u64, PyObject)>>, pub id_to_pyval: RwLock<HashMap<StrRef, (u64, PyObject)>>,
pub id_to_primitive: RwLock<HashMap<u64, PrimitiveValue>>, pub id_to_primitive: RwLock<HashMap<u64, PrimitiveValue>>,
pub field_to_val: RwLock<HashMap<(u64, StrRef), Option<(u64, PyObject)>>>, pub field_to_val: RwLock<HashMap<ResolverField, Option<PyFieldHandle>>>,
pub global_value_ids: Arc<RwLock<HashMap<u64, PyObject>>>, pub global_value_ids: Arc<RwLock<HashMap<u64, PyObject>>>,
pub class_names: Mutex<HashMap<StrRef, Type>>, pub class_names: Mutex<HashMap<StrRef, Type>>,
pub pyid_to_def: Arc<RwLock<HashMap<u64, DefinitionId>>>, pub pyid_to_def: Arc<RwLock<HashMap<u64, DefinitionId>>>,

View File

@ -697,24 +697,24 @@ pub fn gen_ndarray_eye<'ctx>(
.to_basic_value_enum(context, generator, nrows_ty)?; .to_basic_value_enum(context, generator, nrows_ty)?;
let ncols_ty = fun.0.args[1].ty; let ncols_ty = fun.0.args[1].ty;
let ncols_arg = args.iter() let ncols_arg = if let Some(arg) =
.find(|arg| arg.0.is_some_and(|name| name == fun.0.args[1].name)) args.iter().find(|arg| arg.0.is_some_and(|name| name == fun.0.args[1].name)) {
.map(|arg| arg.1.clone().to_basic_value_enum(context, generator, ncols_ty)) arg.1.clone().to_basic_value_enum(context, generator, ncols_ty)
.unwrap_or_else(|| { } else {
args[0].1.clone().to_basic_value_enum(context, generator, nrows_ty) args[0].1.clone().to_basic_value_enum(context, generator, nrows_ty)
})?; }?;
let offset_ty = fun.0.args[2].ty; let offset_ty = fun.0.args[2].ty;
let offset_arg = args.iter() let offset_arg = if let Some(arg) =
.find(|arg| arg.0.is_some_and(|name| name == fun.0.args[2].name)) args.iter().find(|arg| arg.0.is_some_and(|name| name == fun.0.args[2].name)) {
.map(|arg| arg.1.clone().to_basic_value_enum(context, generator, offset_ty)) arg.1.clone().to_basic_value_enum(context, generator, offset_ty)
.unwrap_or_else(|| { } else {
Ok(context.gen_symbol_val( Ok(context.gen_symbol_val(
generator, generator,
fun.0.args[2].default_value.as_ref().unwrap(), fun.0.args[2].default_value.as_ref().unwrap(),
offset_ty offset_ty
)) ))
})?; }?;
call_ndarray_eye_impl( call_ndarray_eye_impl(
generator, generator,

View File

@ -248,6 +248,14 @@ impl Unifier {
self.primitive_store.replace(*primitives); self.primitive_store.replace(*primitives);
} }
/// Returns the [`UnificationTable`] associated with this `Unifier`.
///
/// # Safety
///
/// The use of this function is discouraged under most circumstances. Only use this function if
/// in-place manipulation of type variables and/or type fields is necessary, otherwise prefer to
/// [add a new type][`Unifier::add_ty`] and [unify the type][`Unifier::unify`] with an existing
/// type.
pub unsafe fn get_unification_table(&mut self) -> &mut UnificationTable<Rc<TypeEnum>> { pub unsafe fn get_unification_table(&mut self) -> &mut UnificationTable<Rc<TypeEnum>> {
&mut self.unification_table &mut self.unification_table
} }