GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Handle oversized __hash__ results without panicking by Copilot · Pull Request #6561 · RustPython/RustPython Conversation
|
There was an error while loading. Please reload this page.
| RustPython Version | Status | Exit Code |
|---|---|---|
Python 3.13.0alpha (heads/main-dirty:21300f689, Dec 13 2025, 22:16:49) [RustPython 0.4.0 with rustc 1.90.0-nightly (11ad40bb8 2025-06-28)] |
Panic | 1 |
fn hash_wrapper(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyHash> { let hash_obj = vm.call_special_method(zelf, identifier!(vm, __hash__), ())?; let py_int = hash_obj .downcast_ref::<PyInt>() .ok_or_else(|| vm.new_type_error("__hash__ method should return an integer"))?; let big_int = py_int.as_bigint(); let hash: PyHash = big_int .to_i64() .unwrap_or_else(|| (big_int % BigInt::from(u64::MAX)).to_i64().unwrap()); // Bug: u64::MAX should be i64::Max Ok(hash) }
thread 'main' panicked at crates/vm/src/types/slot.rs:369:72:
called `Option::unwrap()` on a `None` value
stack backtrace:
0: __rustc::rust_begin_unwind
at /rustc/11ad40bb839ca16f74784b4ab72596ad85587298/library/std/src/panicking.rs:697:5
1: core::panicking::panic_fmt
at /rustc/11ad40bb839ca16f74784b4ab72596ad85587298/library/core/src/panicking.rs:75:14
2: core::panicking::panic
at /rustc/11ad40bb839ca16f74784b4ab72596ad85587298/library/core/src/panicking.rs:145:5
3: core::option::unwrap_failed
at /rustc/11ad40bb839ca16f74784b4ab72596ad85587298/library/core/src/option.rs:2072:5
4: core::option::Option<T>::unwrap
at /home/jackfromeast/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1005:21
5: rustpython_vm::types::slot::hash_wrapper::{{closure}}
at ./crates/vm/src/types/slot.rs:369:72
6: core::option::Option<T>::unwrap_or_else
at /home/jackfromeast/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1050:21
7: rustpython_vm::types::slot::hash_wrapper
at ./crates/vm/src/types/slot.rs:369:10
8: rustpython_vm::protocol::object::<impl rustpython_vm::object::core::PyObject>::hash
at ./crates/vm/src/protocol/object.rs:663:20
9: rustpython_vm::stdlib::builtins::builtins::hash
at ./crates/vm/src/stdlib/builtins.rs:440:13
10: core::ops::function::Fn::call
at /home/jackfromeast/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:79:5
11: rustpython_vm::function::builtin::<impl rustpython_vm::function::builtin::sealed::PyNativeFnInternal<(rustpython_vm::function::builtin::OwnedParam<T1>,),R,rustpython_vm::vm::VirtualMachine> for F>::call_
at ./crates/vm/src/function/builtin.rs:126:17
12: <F as rustpython_vm::function::builtin::IntoPyNativeFn<(T,R,VM)>>::call
at ./crates/vm/src/function/builtin.rs:92:14
13: rustpython_vm::function::builtin::into_func::{{closure}}
at ./crates/vm/src/function/builtin.rs:50:40
14: <rustpython_vm::builtins::builtin_func::PyNativeFunction as rustpython_vm::types::slot::Callable>::call
at ./crates/vm/src/builtins/builtin_func.rs:73:9
15: rustpython_vm::types::slot::Callable::slot_call
at ./crates/vm/src/types/slot.rs:1028:9
16: rustpython_vm::protocol::callable::PyCallable::invoke
at ./crates/vm/src/protocol/callable.rs:52:22
17: rustpython_vm::protocol::callable::<impl rustpython_vm::object::core::PyObject>::call_with_args
at ./crates/vm/src/protocol/callable.rs:33:18
18: rustpython_vm::protocol::callable::<impl rustpython_vm::object::core::PyObject>::call
at ./crates/vm/src/protocol/callable.rs:22:14
19: rustpython_vm::frame::ExecutingFrame::execute_call
at ./crates/vm/src/frame.rs:1880:30
20: rustpython_vm::frame::ExecutingFrame::execute_instruction
at ./crates/vm/src/frame.rs:667:22
21: rustpython_vm::frame::ExecutingFrame::run
at ./crates/vm/src/frame.rs:372:31
22: rustpython_vm::frame::<impl rustpython_vm::object::core::Py<rustpython_vm::frame::Frame>>::run::{{closure}}
at ./crates/vm/src/frame.r...
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes RustPython/RustPython#6550
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit
* **Tests**
* Added comprehensive test cases for hash function behavior, validating edge cases and handling of built-in types.
* **Refactor**
* Optimized internal hash computation logic.
<sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
📝 WalkthroughWalkthroughThis PR fixes a panic in the hash wrapping logic when Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (2)**/*.rs📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.py📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
🧬 Code graph analysis (2)crates/vm/src/types/slot.rs (1)
extra_tests/snippets/builtin_hash.py (1)
🔇 Additional comments (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: youknowone <[email protected]>
|
Code has been automatically formatted The code in this PR has been formatted using git pull origin copilot/fix-hash-wrapper-panic |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@copilot Investigate the proper behavior of CPython and ensure test_dataclasses work |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: youknowone <[email protected]>
Adjusted the hash wrapper to leave in-range integers unchanged and only normalize on overflow, matching CPython’s conversion; test_dataclasses now passes (commit 7fb03b2). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@coderabbitai review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@youknowone: I'll review the changes in this PR. I'll pay special attention to:
I'll analyze the implementation to ensure that:
✅ Actions performedReview triggered.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.