dictmultiobject: keep typed strategy in move_to_end for native-type keys - #959
Conversation
w_dict_move_to_end_checked previously switched every non-Object dict to ObjectDictStrategy before reordering. Int and Bytes dicts now reorder in their native IndexMap<i64> / IndexMap<Vec<u8>> storage when the key is an exact int / bytes (typed_move_to_end), matching AbstractTypedStrategy. move_to_end (dictmultiobject.py:1170). Unicode already shares Object's IndexMap<ObjectKey> representation, so it reorders in place too; only a foreign-type key on a typed store, or the Kwargs/Map/Empty strategies, still convert to Object. Extend the synth check with int- and bytes-keyed move_to_end (both directions) and reversed_dict over an int dict. Assisted-by: Claude
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughThe change adds native ChangesTyped dictionary reordering
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
🤖 Codex parity reviewStatic analysis of this diff vs the local RPython/PyPy sources (commit 0a2df44). Files in the reviewed diff1. Regressions to PyPy parity introduced by this patch
2. Other mismatches introduced by this patchNone. 3. Pre-existing mismatches (already present before this patch)None. 4. Structural adaptations
|
There was a problem hiding this comment.
💡 Codex Review
https://github.com/youknowone/pyre/blob/0a2df445d9f7a2335b9de723a8229409575cdbad/pyre-object/src/dictmultiobject.rs#L3634-L3635
Route foreign Unicode keys through the object strategy
This condition exempts every Unicode-strategy dictionary from conversion, but PyPy's AbstractTypedStrategy.move_to_end preserves the typed strategy only when is_correct_type(w_key) and otherwise calls switch_to_object_strategy. Consequently, a lookup with a foreign key such as a str subclass leaves the dictionary tagged as Unicode, bypassing the expected strategy transition and violating the required line-by-line port; exempt Unicode here only for an exact STR_TYPE key, or dispatch this operation through the strategy implementation.
AGENTS.md reference: AGENTS.md:L194-L196
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Follow-up to #957.
w_dict_move_to_end_checkedpreviously routed every non-Objectdict throughswitch_to_object_strategybefore reordering, de-specializing Int/Bytes/Unicode dicts on anymove_to_end.IndexMap<i64>/IndexMap<Vec<u8>>storage for an exact int / bytes key (typed_move_to_end), matchingAbstractTypedStrategy.move_to_end(dictmultiobject.py:1170). The lookup compares native keys, so it stays callback-free and needs no reentrant fallback.ObjectDictStrategy'sIndexMap<ObjectKey>representation, so it reorders in place.Kwargs/Map/Emptystrategies, still convert toObject.keys_versionis bumped only on a real move (theindex != targetguard), preserving the existing no-op behavior.Verification
Byte-identical across CPython 3.14, PyPy3, and pyre via
bench/synth/pypy_dict_primitives_nonbinding.py, extended (section 7) with int- and bytes-keyedmove_to_end(both directions) andreversed_dictover an int dict.cargo build --releaseclean.Follow-up
move_to_end/delitem_if_value_isstill lack a reentrant fallback (contrived,__pypy__-direct-only; shared limitation, not a regression).🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests