diff --git a/vm/src/builtins/function.rs b/vm/src/builtins/function.rs index 29ea3d991..44dadf340 100644 --- a/vm/src/builtins/function.rs +++ b/vm/src/builtins/function.rs @@ -242,7 +242,7 @@ impl PyFunction { .filter(|(slot, _)| slot.is_none()) { if let Some(defaults) = &get_defaults!().1 { - if let Some(default) = defaults.get_item_opt(&*kwarg, vm)? { + if let Some(default) = defaults.get_item_opt(&**kwarg, vm)? { *slot = Some(default); continue; } diff --git a/vm/src/builtins/function/jitfunc.rs b/vm/src/builtins/function/jitfunc.rs index 6a5c8a558..6d7f4ddb0 100644 --- a/vm/src/builtins/function/jitfunc.rs +++ b/vm/src/builtins/function/jitfunc.rs @@ -188,7 +188,7 @@ pub(crate) fn get_jit_args<'a>( let arg_idx = i + func.code.arg_count; if !jit_args.is_set(arg_idx) { let default = kw_only_defaults - .get_item(&*name, vm) + .get_item(&**name, vm) .map_err(|_| ArgsError::NotAllArgsPassed) .and_then(|obj| get_jit_value(vm, &obj))?; jit_args.set(arg_idx, default)?; diff --git a/vm/src/dictdatatype.rs b/vm/src/dictdatatype.rs index cd043827d..7fb97de95 100644 --- a/vm/src/dictdatatype.rs +++ b/vm/src/dictdatatype.rs @@ -738,36 +738,6 @@ impl DictKey for Py { } } -impl DictKey for PyStrRef { - type Owned = Self; - #[inline] - fn _to_owned(&self, _vm: &VirtualMachine) -> Self::Owned { - self.clone() - } - - fn key_hash(&self, vm: &VirtualMachine) -> PyResult { - Ok(self.hash(vm)) - } - - fn key_is(&self, other: &PyObject) -> bool { - self.is(other) - } - - fn key_eq(&self, vm: &VirtualMachine, other_key: &PyObject) -> PyResult { - if self.is(other_key) { - Ok(true) - } else if let Some(pystr) = str_exact(other_key, vm) { - Ok(pystr.as_str() == self.as_str()) - } else { - vm.bool_eq(self.as_object(), other_key) - } - } - - fn key_as_isize(&self, vm: &VirtualMachine) -> PyResult { - self.as_object().key_as_isize(vm) - } -} - impl DictKey for PyRefExact { type Owned = Self; #[inline] @@ -793,39 +763,6 @@ impl DictKey for PyRefExact { /// Implement trait for the str type, so that we can use strings /// to index dictionaries. -impl DictKey for &str { - type Owned = String; - #[inline] - fn _to_owned(&self, _vm: &VirtualMachine) -> Self::Owned { - (**self).to_owned() - } - - fn key_hash(&self, vm: &VirtualMachine) -> PyResult { - // follow a similar route as the hashing of PyStrRef - Ok(vm.state.hash_secret.hash_str(*self)) - } - - fn key_is(&self, _other: &PyObject) -> bool { - // No matter who the other pyobject is, we are never the same thing, since - // we are a str, not a pyobject. - false - } - - fn key_eq(&self, vm: &VirtualMachine, other_key: &PyObject) -> PyResult { - if let Some(pystr) = str_exact(other_key, vm) { - Ok(pystr.as_str() == *self) - } else { - // Fall back to PyObjectRef implementation. - let s = vm.ctx.new_str(*self); - s.key_eq(vm, other_key) - } - } - - fn key_as_isize(&self, vm: &VirtualMachine) -> PyResult { - Err(vm.new_type_error("'str' object cannot be interpreted as an integer".to_owned())) - } -} - impl DictKey for str { type Owned = String; #[inline] @@ -964,7 +901,7 @@ mod tests { assert_eq!(true, dict.contains(&vm, &*key1).unwrap()); assert_eq!(true, dict.contains(&vm, "x").unwrap()); - let val = dict.get(&vm, &"x").unwrap().unwrap(); + let val = dict.get(&vm, "x").unwrap().unwrap(); vm.bool_eq(&val, &value2) .expect("retrieved value must be equal to inserted value."); }) diff --git a/vm/src/frame.rs b/vm/src/frame.rs index a35a5e587..54bef39ae 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -572,7 +572,7 @@ impl ExecutingFrame<'_> { } bytecode::Instruction::DeleteGlobal(idx) => { let name = &self.code.names[*idx as usize]; - match self.globals.del_item(&*name, vm) { + match self.globals.del_item(&**name, vm) { Ok(()) => {} Err(e) if e.fast_isinstance(&vm.ctx.exceptions.key_error) => { return Err( diff --git a/vm/src/intern.rs b/vm/src/intern.rs index 8d583fa97..c7109c19a 100644 --- a/vm/src/intern.rs +++ b/vm/src/intern.rs @@ -1,7 +1,7 @@ use crate::{ builtins::{PyStr, PyTypeRef}, common::lock::PyRwLock, - PyRef, PyRefExact, + Py, PyRef, PyRefExact, }; use std::ops::Deref; @@ -88,12 +88,14 @@ mod sealed { } /// A sealed marker trait for `DictKey` types that always become an exact instance of `str` -pub trait Internable: sealed::SealedInternable + crate::dictdatatype::DictKey { +pub trait Internable: sealed::SealedInternable + AsRef { + type Key: crate::dictdatatype::DictKey + ?Sized; fn as_str(&self) -> &str; fn into_pyref(self, str_type: PyTypeRef) -> PyRefExact; } impl Internable for String { + type Key = str; fn as_str(&self) -> &str { String::as_str(self) } @@ -104,6 +106,7 @@ impl Internable for String { } impl Internable for &str { + type Key = str; fn as_str(&self) -> &str { self } @@ -113,6 +116,7 @@ impl Internable for &str { } impl Internable for PyRefExact { + type Key = Py; fn as_str(&self) -> &str { self.deref().as_str() } diff --git a/vm/src/scope.rs b/vm/src/scope.rs index 9594a900d..4cc6e8ccf 100644 --- a/vm/src/scope.rs +++ b/vm/src/scope.rs @@ -1,9 +1,4 @@ -use crate::{ - builtins::{pystr::IntoPyStrRef, PyDictRef, PyStrRef}, - convert::ToPyObject, - function::ArgMapping, - VirtualMachine, -}; +use crate::{builtins::PyDictRef, function::ArgMapping, VirtualMachine}; use std::fmt; #[derive(Clone)] @@ -140,14 +135,14 @@ impl Scope { // } } -mod sealed { - pub trait Sealed {} - impl Sealed for &str {} - impl Sealed for super::PyStrRef {} -} -pub trait PyName: - sealed::Sealed + crate::dictdatatype::DictKey + Clone + ToPyObject + IntoPyStrRef -{ -} -impl PyName for &str {} -impl PyName for PyStrRef {} +// mod sealed { +// pub trait Sealed {} +// impl Sealed for &str {} +// impl Sealed for super::PyStrRef {} +// } +// pub trait PyName: +// sealed::Sealed + crate::dictdatatype::DictKey + Clone + ToPyObject + IntoPyStrRef +// { +// } +// impl PyName for str {} +// impl PyName for Py {} diff --git a/vm/src/stdlib/thread.rs b/vm/src/stdlib/thread.rs index 999dccdc0..8e8fbb612 100644 --- a/vm/src/stdlib/thread.rs +++ b/vm/src/stdlib/thread.rs @@ -371,9 +371,9 @@ pub(crate) mod _thread { } else { let dict = zelf.ldict(vm); if let Some(value) = value { - dict.set_item(&attr, value, vm)?; + dict.set_item(&*attr, value, vm)?; } else { - dict.del_item(&attr, vm)?; + dict.del_item(&*attr, vm)?; } Ok(()) }