⚡ Sangsakala Proxy 🏠 Home
Skip to content

Align list, tuple and slice controls - #9696

Draft
youknowdot wants to merge 6 commits into
RustPython:mainfrom
youknowdot:fix/list-tuple-controls-20261104
Draft

youknowdot wants to merge 6 commits into
RustPython:mainfrom
youknowdot:fix/list-tuple-controls-20261104

Conversation

@youknowdot

@youknowdot youknowdot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Group related CPython 3.15 list/tuple/slice search and comparison fixes in 534 changed lines across eight production Rust files:

  • Reuse the shared slice-index conversion for list/tuple index bounds, saturate oversized integers, convert both bounds before reading the current list length, and allow searches to reach elements appended by callbacks.

  • Retain raw bounds through conversion/search and release them in argument order through one shared owner, rather than writing method-specific argument parsers.

  • Use CPython's constant list.index/list.remove missing-value errors without invoking user formatting callbacks.

  • Preserve raw ordering results and exact comparison operators for lists, tuples and structseqs; compare tuple prefixes even when lengths differ.

  • Reuse the same raw-result comparison helper for slice components, preserve the same-slice shortcut, and retain the raw length through indices conversions and cleanup. Correct slice-specific conversion diagnostics and constructor keyword priority.

  • Release list element roots before observing callback mutations, then reload the first unequal pair for ordering. Preserve the existing constant-time identical-object equality shortcut.

  • Release detached list children in reverse and clear slice fields in step/start/stop order before freelisting, without retaining the old stop owner in a cached husk.

  • Preserve list.sort cleanup on key or comparison failure: reverse partial-key destruction, restore the current value permutation, restore the live list before reverse-releasing callback-added items, and preserve the original error over a mutation error.

  • Use initial/final reversal around the existing stable forward sort for reverse=True, releasing keys before the final value reversal even on failure.

  • Release each temporary repr result before the next callback. Slice repr reuses the corrected collection formatter also used by tuple/set/deque.

Reference and validation

Compared against CPython source commit d220409a13b77de7a6c30abe16ea90db01528edc and a verified CPython 3.15 oracle. 10,438 reference/model assertions and 82 additional independent oracle assertions passed, including mutation, finalizer order, argument conversion, descriptors, oversized bounds, and nonboolean comparison results. These are CPython/source-model checks, not execution of the Rust implementation.

Independent source review passed for the original six-file composition and the subsequent slice extension. Ordinary commit hooks passed. Focused host-env/VM/stdlib threading cargo check and normal all-targets Clippy passed on the final source. The final slice composition also exposes eight unchanged host_env/socket diagnostics in addition to the earlier four baseline diagnostics (one POSIX needless-collect and three ElementTree lints); no candidate-file warnings remain. Strict -D warnings is not clean because of that baseline; no warnings were suppressed. The compiler caught an owning-versus-borrowed method-resolution error before publication; the one-line explicit borrowed call was independently re-reviewed, normally committed, and rechecked.

The slice extension additionally passed 6,884 CPython/source-model assertions and 109 independent CPython assertions. These reference checks do not claim RustPython runtime coverage.

No Python, Lib, tests, markers or workflows are changed. This does not remove existing expected failures or claim they have passed.

The lifecycle extension additionally passed 59 focused CPython assertions, 40 teardown/structseq controls and 90 independent reference assertions. These include explicit negative controls for deferred behavior, not claims that every probed behavior is fixed. Independent source review passed on the final three-file extension. The first check caught a missing formatter import; it was corrected before the final validation rerun. The final lifecycle source passed threaded cargo check in 1m00s and all-targets Clippy in 2m17s. That exact branch produced the four unchanged POSIX/ElementTree diagnostics, matching the recorded four-warning baseline; the later-main socket diagnostics are absent on this branch. No warnings were suppressed.

Limits and integration

Native RustPython execution was not performed because the required execution guard has not been verified. Full workspace/C-API tests and cross-platform runtime checks remain unrun; hosted CI is pending. Separately locked cross-thread snapshots and malformed-call cleanup before shared bound binding remain inherited limitations. slice.indices retains its inherited shared-binder arity/keyword wording and precedence; typed raw arguments preserve signature metadata and prevent conversion before binding without adding a method-specific parser.

Old infrastructure PRs #8966, #8944, #8939 and #8848, plus metadata PR #9551, touch some of these files but do not implement these behavior fixes. Their eventual composition may require textual reconciliation. The changed public Rust helper/trait interfaces may also affect out-of-tree consumers; all in-tree consumers were checked.

Generic tuple child teardown remains unchanged: structseq shares the Rust tuple payload but CPython destroys its fields forward, unlike ordinary tuples. Tuple-construction allocation-boundary cleanup, subclass dictionary/slot-before-payload teardown, sort mutation-counter false positives for no-op mutations, and algorithm-specific comparison traces or exact failure permutations remain outside this patch. The existing sorting algorithm is not replaced. Old algorithm PR #6096 must preserve these driver/lifecycle controls when composed. The GC designs in #8939/#8944 retain clear-return, edge destruction, then freelist insertion; no core GC rewrite is included.

AI-assisted contribution by OpenAI Codex; assistance is disclosed in the commit trailer.

Reuse shared bounds conversion, retain callback results and argument lifetimes, and preserve constant-time identity comparisons.

Assisted-by: OpenAI Codex:model version not exposed
Avoid the consuming PyObjectRef overload so existing element roots remain alive until explicit left-to-right cleanup.

Assisted-by: OpenAI Codex:model version not exposed
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Retain raw indices length through all component conversions, preserve raw comparison results, and match slice conversion diagnostics.

Assisted-by: OpenAI Codex:model version not exposed
@youknowdot youknowdot changed the title Align list and tuple search and comparison controls Align list, tuple and slice controls Nov 4, 2026
Release detached list and slice owners in CPython order, preserve sort cleanup and reverse-driver semantics, and share immediate repr-result disposal.

Assisted-by: OpenAI Codex:model version not exposed
Comment thread crates/vm/src/builtins/list.rs Outdated
)]
impl Py<PyList> {
#[pyslot]
fn slot_richcompare(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why Comparable is replaced to this one? any reason?

Override the existing rich comparison slot through Comparable while retaining its bool-valued cmp adapter. Preserve arbitrary Python ordering results without duplicating sequence comparison logic.

Assisted-by: OpenAI Codex:model version not exposed
Follow the trait implementation lint after moving sequence rich comparison slots.

Assisted-by: OpenAI Codex:model version not exposed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants