← Back to Pull requests

Fix enumerate counter overflow #1366

Open
unknown opened this pull request with 331 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 16, 2026 11:16 UTC
Author

Fixes #1363.

enumerate('a', 2**63 - 1) panics in a checked build because the native counter increments past i64::MAX, even after the only item has been collected. Keep the counter as a Python integer value and use existing integer addition, which promotes to LongInt. Starting values also use the existing __index__ conversion instead of narrowing to i64.

The counter has a deferred-drop guard. Each output tuple owns its index, and the previous counter is released after replacement. The existing result guard releases partial output if the source raises. Start conversion now precedes iterator construction, matching CPython. The iterable is guarded if conversion fails, and the converted counter is guarded if iterator construction fails. Argument extraction and eager collection behavior are unchanged.

The existing builtin fixture now covers the one-item maximum, crossing the native boundary, large signed starts, an interned large literal, empty input, Boolean normalization, __index__, invalid float starts and a source error after one heap-backed item. The boundary regression panicked on unchanged main 59b67be, while the CPython control passed.

The initialization-order regression fails on the initial PR implementation (['iter', 'index'] instead of ['index', 'iter']) while its CPython control passes. Added controls cover start-conversion failure, iterator-construction failure with a heap-backed index, and exception precedence when both inputs are invalid. The temporary initialization-order limitation is removed.

Validation on macOS arm64, Rust 1.98.0 and Python 3.14.8:

  • make test-cases: 1,550 fixture checks passed across Monty and CPython.

  • cargo run -p monty-datatest --features memory-model-checks -- builtin__more_iter_funcs: changed fixture passed in Monty, with the CPython control also passing.

  • make format-rs, make lint-rs, make lint-py, scoped Markdown formatting and git diff --check passed.

  • cargo test -p monty found three compiler-diagnostic snapshot mismatches: readonly_mutable_projection, smuggle_and_swap_reader, and smuggle_heap_read. Each produces exactly the same diagnostic on a clean detached worktree at 59b67be with this compiler. The snapshots are unchanged.

  • cargo test -p monty -- --skip readonly_mutable_projection --skip smuggle_and_swap_reader --skip smuggle_heap_read: the remaining 1,100 tests passed, two were ignored, and those three were filtered out.
  • Local builds selected the installed macOS 26.5 SDK per command. Linux, Windows, WASM and full model/agent integrations were not run. No performance or broader sandbox-security claim is made.

    Diff: 331 lines (+248 / -83) across 4 files Reviewer: davidhewitt Review duration: 9192m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.42) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 331 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.347
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1366"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.1% (MEDIUM) · Higher = larger blast radius
    42.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.4% · Safe to merge
    22.4%
    Repository