Fix slice repr leaking the internal storage representation. - #1073
Open
jseop-lim wants to merge 1 commit into
Open
Fix slice repr leaking the internal storage representation.#1073jseop-lim wants to merge 1 commit into
slice repr leaking the internal storage representation.#1073jseop-lim wants to merge 1 commit into
Conversation
The tp_repr slot delegated to the Java debug toString() of PSlice, which appends each member with String.valueOf. CPython's slice_repr formats all three with %R, so a non-integer member leaked its internal representation: slice(()) printed slice(None, tuple(EmptySequenceStorage[]), None). Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1071
slice.__repr__formatted its three members with Java'sString.valueOfinstead of Pythonrepr(), so any member whose debugtoString()differs from its repr leaked the internal representation.intandNonemembers were unaffected, which is why the common case looked correct.AS-IS
slice(()),slice([]),slice(""),slice(True, 2):TO-BE
(matching CPython)
Changes
SliceBuiltins.ReprNodeto applyPyObjectReprAsTruffleStringNodetogetStart()/getStop()/getStep()and assemble the result withSimpleTruffleStringFormatNode, matching CPython'sslice(%R, %R, %R).RangeBuiltins.ReprNodealready uses this shape forrange, whose CPython repr formats its three members with%Rin the same way. The specialization no longer needs@TruffleBoundary. Unlikerange, whose members are always integers, a slice member can be an arbitrary object with a user-defined__repr__, so the repr node is called with the frame rather thannull.test_reprtotest_slice.py, covering the member types whose JavatoString()diverges from their repr, and an object with a user-defined__repr__to pin that the member is formatted by Pythonrepr().Testing
mx python-jvmon linux-aarch64, thenmx graalpytest test_slice.py test_list.py test_tuple.py test_bytes.py test_memoryview.py test_range.py— 224 tests, all pass.repr()of 15 slice forms (one-, two- and three-argument, withint/None/bool/float/str/bytes/tuple/list/dictmembers and an object with a user-defined__repr__) was compared against CPython 3.13.5 and matches on every one.