Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vm/src/builtins/genericalias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn make_parameters(args: &PyTupleRef, vm: &VirtualMachine) -> PyTupleRef {
impl Hashable for PyGenericAlias {
#[inline]
fn hash(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<hash::PyHash> {
Ok(vm._hash(zelf.origin.as_object())? ^ vm._hash(zelf.args.as_object())?)
Ok(zelf.origin.as_object().hash(vm)? ^ zelf.args.as_object().hash(vm)?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion vm/src/builtins/weakref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Hashable for PyWeak {
let obj = zelf
.upgrade()
.ok_or_else(|| vm.new_type_error("weak object has gone away".to_owned()))?;
let hash = vm._hash(&obj)?;
let hash = obj.hash(vm)?;
zelf.hash.store(Some(hash));
Ok(hash)
}
Expand Down
2 changes: 1 addition & 1 deletion vm/src/dictdatatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ pub trait DictKey: IntoPyObject {
/// to index dictionaries.
impl DictKey for PyObjectRef {
fn key_hash(&self, vm: &VirtualMachine) -> PyResult<HashValue> {
vm._hash(self)
self.hash(vm)
}

fn key_is(&self, other: &PyObjectRef) -> bool {
Expand Down
6 changes: 5 additions & 1 deletion vm/src/protocol/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ impl PyObjectRef {
}

pub fn hash(&self, vm: &VirtualMachine) -> PyResult<PyHash> {
vm._hash(self)
let hash = self
.class()
.mro_find_map(|cls| cls.slots.hash.load())
.unwrap(); // hash always exist
hash(self, vm)
}

// const hash_not_implemented: fn(&PyObjectRef, &VirtualMachine) ->PyResult<PyHash> = crate::types::Unhashable::slot_hash;
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ mod builtins {

#[pyfunction]
fn hash(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyHash> {
vm._hash(&obj)
obj.hash(vm)
}

// builtin_help
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/sre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ mod _sre {

impl Hashable for Pattern {
fn hash(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<PyHash> {
let hash = vm._hash(&zelf.pattern)?;
let hash = zelf.pattern.hash(vm)?;
let (_, code, _) = unsafe { zelf.code.align_to::<u8>() };
let hash = hash ^ vm.state.hash_secret.hash_bytes(code);
let hash = hash ^ (zelf.flags.bits() as PyHash);
Expand Down
4 changes: 2 additions & 2 deletions vm/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ pub fn hash_iter<'a, I: IntoIterator<Item = &'a PyObjectRef>>(
iter: I,
vm: &VirtualMachine,
) -> PyResult<rustpython_common::hash::PyHash> {
vm.state.hash_secret.hash_iter(iter, |obj| vm._hash(obj))
vm.state.hash_secret.hash_iter(iter, |obj| obj.hash(vm))
}

pub fn hash_iter_unordered<'a, I: IntoIterator<Item = &'a PyObjectRef>>(
iter: I,
vm: &VirtualMachine,
) -> PyResult<rustpython_common::hash::PyHash> {
rustpython_common::hash::hash_iter_unordered(iter, |obj| vm._hash(obj))
rustpython_common::hash::hash_iter_unordered(iter, |obj| obj.hash(vm))
}

// TODO: find a better place to put this impl
Expand Down
8 changes: 0 additions & 8 deletions vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1885,14 +1885,6 @@ impl VirtualMachine {
self._cmp(&a, &b, op).map(|res| res.into_pyobject(self))
}

pub fn _hash(&self, obj: &PyObjectRef) -> PyResult<rustpython_common::hash::PyHash> {
let hash = obj
.class()
.mro_find_map(|cls| cls.slots.hash.load())
.unwrap(); // hash always exist
hash(obj, self)
}

pub fn obj_len_opt(&self, obj: &PyObjectRef) -> Option<PyResult<usize>> {
self.get_special_method(obj.clone(), "__len__")
.map(Result::ok)
Expand Down