⚡ Sangsakala Proxy 🏠 Home
Skip to content

Align builtin reduction callback controls - #9718

Draft
youknowdot wants to merge 5 commits into
RustPython:mainfrom
youknowdot:fix/minmax-streaming-controls-20261104
Draft

youknowdot wants to merge 5 commits into
RustPython:mainfrom
youknowdot:fix/minmax-streaming-controls-20261104

Conversation

@youknowdot

@youknowdot youknowdot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Group CPython 3.15 min/max streaming, sum and all/any iteration, argument binding and callback ownership controls in 265 changed lines across three production Rust files.

  • Consume a single iterable one item at a time, interleaving key and comparison callbacks without materialization or length-hint calls. Multiple positional candidates use borrowed caller slots.

  • Keep raw caller arguments alive until internal cleanup finishes. Share one min/max engine with explicit winner/current item and key ownership and correct success/error release order.

  • Reuse ArgSpec through a borrowed keyword-only entry point. Validate arity, keyword count/names and default restrictions before obtaining an iterator.

  • Scope CPython-style typo suggestions and lossless WTF-8 keyword diagnostics to the new entry point. Reuse the existing suggestion algorithm with UTF-8 byte-length thresholds and suppress suggestions for surrogate-bearing names. Existing parser and suggestion consumers retain their behavior.

  • Bind sum inputs before iterability checks, acquire and validate its iterator before rejected-start errors, and retain the original start through all callbacks.

  • Preserve generic sum accumulator-before-item-before-iterator error cleanup without changing compensated arithmetic or numeric fast paths.

  • Share one all/any engine with canonical iterator validation and one cached next slot. Python slot wrappers continue to resolve a replaced/deleted next dynamically, including mutation from truth callbacks and item finalizers.

  • Preserve raw inputs, item-before-next cleanup, short circuiting and length-hint avoidance without changing generic iteration or min/max/sum traversal policy.

Validation

Pinned CPython reference: d220409a13b77de7a6c30abe16ea90db01528edc. The focused oracle passed 22 grouped assertions and recorded 30 outcomes/traces, covering streaming, mutation, length-hint avoidance, binding, defaults, comparisons, exception propagation and internal finalizer order. These are reference/source checks, not RustPython runtime tests.

Independent source review passed, including 344 additional CPython diagnostic assertions over 172 keyword names. The initial compiler run caught a Result-versus-Option guard method mismatch; the corrected final source passed threaded cargo check in 1m05s and all-targets Clippy in 2m58s. All 12 unchanged baseline diagnostics match exactly, without suppression. Ordinary commit hooks passed. No tests, Lib files, expected failures or workflows are changed.

Limits and integration

Native RustPython execution was not performed because the required execution guard has not been verified. Full workspace/C-API suites, runtime differential tests and separate platform/feature graphs remain unrun. Hosted CI is pending.

Caller-frame argument destruction order can depend on the original call syntax, which FuncArgs no longer records. This patch retains raw owners through internal cleanup; it does not impose one universal caller-tail ordering or claim to solve that wider lifetime issue. Duplicate-keyword detection belongs to VM call binding before FuncArgs' unique-key map.

PR #9668 makes ArgSpec fields and parse_with public. Read-only three-way source composition succeeds while retaining those public interfaces and the new shared parser internals; the combined graph was not compiled. #9699 does not implement min/max behavior, and the examined older builtin changes do not duplicate this group. Existing non-opted-in parser consumers' surrogate diagnostics and suggestion behavior remain unchanged.

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

Sum follow-up validation

Independent exact-source review passed 30 pinned CPython oracle cases, 14 additional numeric error controls and the existing arithmetic snippet on CPython. Final threaded cargo check passed in 1m05s and all-targets Clippy in 2m17s; all 12 baseline diagnostics match unchanged. An initial redundant-clone diagnostic was fixed by making the existing iterator-then-raw-start release order explicit, without suppression or removing retention. Normal commit hooks passed. These are reference/source and compilation checks, not native RustPython runtime validation.

The sum wrapper continues to use shared FromArgs binding. Exact total-arity/duplicate-argument diagnostic precedence and keyword typo suggestions are deferred; this does not alter shared binder behavior for other functions.

All/any follow-up validation

Independent exact-source review passed bounded CPython controls for truth and item-finalizer next-slot mutation (eight cases), invalid iterator results, short circuiting, errors and length-hint avoidance. The existing test_all and test_any methods were extracted unchanged and passed on pinned CPython. Final threaded host-env/VM/stdlib cargo check passed in 1m11s, all-targets Clippy in 2m47s, and all 12 baseline diagnostics match unchanged. Normal commit hooks passed. A newly unused adapter import was removed before final validation. No native RustPython runtime test is claimed.

Terminal StopIteration conversion still uses the shared wrapper, which discards the original exception before returning its payload. This follow-up preserves the previous payload-before-iterator release order; full traceback-dependent terminal ownership parity remains deferred. Existing generic binder diagnostic precedence is unchanged.

Preserve callback and internal owner order, retain raw caller arguments, and reuse keyword matching and suggestion machinery without changing existing parser consumers.

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

Validate the iterator before rejecting the start type, retain raw arguments, and release generic accumulator operands in CPython order without changing numeric fast paths.

Assisted-by: OpenAI Codex:model version not exposed
Release the iterator before the original start on generic success, preserving callback lifetime order while making the required retention visible to Clippy.

Assisted-by: OpenAI Codex:model version not exposed
@youknowdot youknowdot changed the title Stream min and max with shared callback controls Align min, max and sum callback controls Nov 4, 2026
Validate iterator acquisition before traversal, cache the next slot while preserving dynamic method dispatch, and retain existing item and terminal cleanup boundaries.

Assisted-by: OpenAI Codex:model version not exposed
All builtin reduction entry points now retain raw objects, leaving this adapter import unused.

Assisted-by: OpenAI Codex:model version not exposed
@youknowdot youknowdot changed the title Align min, max and sum callback controls Align builtin reduction callback controls Nov 4, 2026
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.

1 participant