Fix enumerate counter overflow #1366
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
davidhewitt
Fixes #1363.
enumerate('a', 2**63 - 1)panics in a checked build because the native counter increments pasti64::MAX, even after the only item has been collected. Keep the counter as a Python integer value and use existing integer addition, which promotes toLongInt. Starting values also use the existing__index__conversion instead of narrowing toi64.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 main59b67be, 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 andgit diff --checkpassed.cargo test -p montyfound three compiler-diagnostic snapshot mismatches:readonly_mutable_projection,smuggle_and_swap_reader, andsmuggle_heap_read. Each produces exactly the same diagnostic on a clean detached worktree at59b67bewith 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.