__length_hint__ - #6636
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesSequence iterator length hints
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: ✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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 |
f022e3a to
e4fe051
Compare
|
Code has been automatically formatted The code in this PR has been formatted using:
git pull origin __length_hint__ |
566aefd to
f1be6e9
Compare
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
f4b68ba to
d22855e
Compare
There was a problem hiding this comment.
Pull request overview
Fixes the deadlock described in #6590 by ensuring iterator.__length_hint__ does not hold the iterator’s internal PyMutex across user callbacks (like __len__). While addressing that, it also corrects the hint calculation to account for the iterator’s current position (so the hint decreases after next()), and adds a regression test to cover the deadlock scenario.
Changes:
- Refactors
PySequenceIterator::__length_hint__to drop the internal lock before invoking__len__, preventing re-entrant deadlocks. - Updates
__length_hint__behavior to returnlen - position(saturating at 0) and returnNotImplementedwhen a length slot is unavailable. - Adds a snippet regression test that would previously hang, and verifies correct
__length_hint__behavior for sequences with/without__len__.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| extra_tests/snippets/builtin_iter.py | Adds regression coverage for the deadlock PoC and verifies correct __length_hint__ semantics. |
| crates/vm/src/builtins/iter.rs | Releases the iterator lock before calling into user __len__ and computes hint as remaining items (len - position). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fix #6590
Summary by CodeRabbit
NotImplementedwhen sequence length is unavailable.