From 20bb05a7eeef529c3908dc1bb04f4157433d8c7e Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 17 Mar 2026 08:49:42 +0100 Subject: [PATCH] Ascii builtin should return a subclass Fixes #686 --- .../src/tests/test_builtin.py | 12 ++ .../builtins/modules/BuiltinFunctions.java | 6 +- .../cext/PythonCextObjectBuiltins.java | 8 +- .../builtins/modules/re/PatternBuiltins.java | 4 +- .../objects/str/TemplateFormatter.java | 10 +- .../python/lib/PyObjectAsciiAsObjectNode.java | 115 ++++++++++++++++++ ... => PyObjectAsciiAsTruffleStringNode.java} | 23 ++-- .../nodes/bytecode/PBytecodeRootNode.java | 12 +- .../bytecode_dsl/PBytecodeDSLRootNode.java | 24 ++-- .../formatting/BytesFormatProcessor.java | 6 +- .../formatting/StringFormatProcessor.java | 6 +- 11 files changed, 172 insertions(+), 54 deletions(-) create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsciiAsObjectNode.java rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PyObjectAsciiNode.java => PyObjectAsciiAsTruffleStringNode.java} (81%) diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_builtin.py b/graalpython/com.oracle.graal.python.test/src/tests/test_builtin.py index 6887631aa6..adcfe09f61 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_builtin.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_builtin.py @@ -54,6 +54,18 @@ def test_ascii(self): self.assertEqual(ascii(1), "1") self.assertEqual(ascii("錦蛇 \t \0 a \x03"), "'\\u9326\\u86c7 \\t \\x00 a \\x03'") + def test_ascii_preserves_str_subclass_for_ascii_repr(self): + class MyStr(str): + pass + + class Foo: + def __repr__(self): + return MyStr("hello") + + result = ascii(Foo()) + self.assertEqual(result, "hello") + self.assertIs(type(result), MyStr) + def test_input(self): import sys class AlwaysLine: diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java index c3e8fda3ed..c923d2bfb3 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java @@ -188,7 +188,7 @@ import com.oracle.graal.python.lib.PyNumberDivmodNode; import com.oracle.graal.python.lib.PyNumberIndexNode; import com.oracle.graal.python.lib.PyNumberPowerNode; -import com.oracle.graal.python.lib.PyObjectAsciiNode; +import com.oracle.graal.python.lib.PyObjectAsciiAsObjectNode; import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs; import com.oracle.graal.python.lib.PyObjectDir; import com.oracle.graal.python.lib.PyObjectGetAttr; @@ -1918,9 +1918,9 @@ public static FormatNode create() { abstract static class AsciiNode extends PythonUnaryBuiltinNode { @Specialization - public static TruffleString ascii(VirtualFrame frame, Object obj, + public static Object ascii(VirtualFrame frame, Object obj, @Bind Node inliningTarget, - @Cached PyObjectAsciiNode asciiNode) { + @Cached PyObjectAsciiAsObjectNode asciiNode) { return asciiNode.execute(frame, inliningTarget, obj); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java index 573f9f4b51..81a4f94c41 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -110,7 +110,7 @@ import com.oracle.graal.python.lib.PyCallableCheckNode; import com.oracle.graal.python.lib.PyLongCheckNode; import com.oracle.graal.python.lib.PyObjectAsFileDescriptor; -import com.oracle.graal.python.lib.PyObjectAsciiNode; +import com.oracle.graal.python.lib.PyObjectAsciiAsObjectNode; import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs; import com.oracle.graal.python.lib.PyObjectDelItem; import com.oracle.graal.python.lib.PyObjectDir; @@ -669,9 +669,9 @@ int doGeneric(Object ptrObject, @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Direct) abstract static class PyObject_ASCII extends CApiUnaryBuiltinNode { @Specialization(guards = "!isNoValue(obj)") - static TruffleString ascii(Object obj, + static Object ascii(Object obj, @Bind Node inliningTarget, - @Cached PyObjectAsciiNode asciiNode) { + @Cached PyObjectAsciiAsObjectNode asciiNode) { return asciiNode.execute(null, inliningTarget, obj); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/re/PatternBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/re/PatternBuiltins.java index 2dc57a4264..2c11b8288f 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/re/PatternBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/re/PatternBuiltins.java @@ -89,7 +89,7 @@ import com.oracle.graal.python.builtins.objects.type.slots.TpSlotHashFun; import com.oracle.graal.python.builtins.objects.type.slots.TpSlotRichCompare; import com.oracle.graal.python.lib.PyCallableCheckNode; -import com.oracle.graal.python.lib.PyObjectAsciiNode; +import com.oracle.graal.python.lib.PyObjectAsciiAsTruffleStringNode; import com.oracle.graal.python.lib.PyObjectGetAttr; import com.oracle.graal.python.lib.PyObjectHashNode; import com.oracle.graal.python.lib.PyObjectReprAsTruffleStringNode; @@ -1408,7 +1408,7 @@ static ParsedReplacement parseReplacement(Node inliningTarget, VirtualFrame fram if (!isIdentifierNode.execute(inliningTarget, name) || binary && !ascii) { errorProfile.enter(inliningTarget); throw raiseRegexErrorNode.executeFormatted(frame, BAD_CHAR_IN_GROUP_NAME, replacement, toCodepointIndex(nameStartPos, binary), - binary ? PyObjectAsciiNode.executeUncached(name) : PyObjectReprAsTruffleStringNode.executeUncached(name)); + binary ? PyObjectAsciiAsTruffleStringNode.executeUncached(name) : PyObjectReprAsTruffleStringNode.executeUncached(name)); } Object namedCaptureGroups = TRegexUtil.TRegexCompiledRegexAccessor.namedCaptureGroups(tregexCompiledRegex, inliningTarget, readNamedGroupsNode); if (!TRegexUtil.TRegexNamedCaptureGroupsAccessor.hasGroup(namedCaptureGroups, name, genericInteropLib)) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/TemplateFormatter.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/TemplateFormatter.java index 644561c894..1f7a6c3246 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/TemplateFormatter.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/TemplateFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -69,11 +69,11 @@ import com.oracle.graal.python.builtins.modules.SysModuleBuiltins; import com.oracle.graal.python.builtins.objects.PNone; import com.oracle.graal.python.builtins.objects.function.PKeyword; -import com.oracle.graal.python.lib.PyObjectAsciiNode; +import com.oracle.graal.python.lib.PyObjectAsciiAsObjectNode; import com.oracle.graal.python.lib.PyObjectGetItem; import com.oracle.graal.python.lib.PyObjectLookupAttr; import com.oracle.graal.python.lib.PyObjectReprAsObjectNode; -import com.oracle.graal.python.lib.PyObjectStrAsTruffleStringNode; +import com.oracle.graal.python.lib.PyObjectStrAsObjectNode; import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.nodes.Node; @@ -458,9 +458,9 @@ private static Object convert(Node node, Object obj, char conversion) { case 'r': return PyObjectReprAsObjectNode.executeUncached(obj); case 's': - return PyObjectStrAsTruffleStringNode.executeUncached(obj); + return PyObjectStrAsObjectNode.executeUncached(obj); case 'a': - return PyObjectAsciiNode.executeUncached(obj); + return PyObjectAsciiAsObjectNode.executeUncached(obj); default: throw PRaiseNode.raiseStatic(node, ValueError, INVALID_CONVERSION); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsciiAsObjectNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsciiAsObjectNode.java new file mode 100644 index 0000000000..bbeb7b6905 --- /dev/null +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsciiAsObjectNode.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both + * + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.oracle.graal.python.lib; + +import static com.oracle.graal.python.builtins.objects.bytes.BytesUtils.unicodeNonAsciiEscape; +import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING; + +import com.oracle.graal.python.nodes.PNodeWithContext; +import com.oracle.graal.python.nodes.util.CastToTruffleStringNode; +import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.GenerateCached; +import com.oracle.truffle.api.dsl.GenerateInline; +import com.oracle.truffle.api.dsl.GenerateUncached; +import com.oracle.truffle.api.dsl.NeverDefault; +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.frame.Frame; +import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.nodes.Node; +import com.oracle.truffle.api.strings.TruffleString; +import com.oracle.truffle.api.strings.TruffleStringIterator; + +/** + * Equivalent of CPython's PyObject_ASCII. + */ +@GenerateUncached +@GenerateInline(inlineByDefault = true) +@GenerateCached +public abstract class PyObjectAsciiAsObjectNode extends PNodeWithContext { + public static Object executeUncached(Object object) { + return PyObjectAsciiAsObjectNodeGen.getUncached().execute(null, null, object); + } + + public final Object executeCached(Frame frame, Object object) { + return execute(frame, this, object); + } + + public abstract Object execute(Frame frame, Node inliningTarget, Object object); + + @Specialization + public static Object ascii(VirtualFrame frame, Node inliningTarget, Object obj, + @Cached PyObjectReprAsObjectNode reprNode, + @Cached CastToTruffleStringNode castToTruffleStringNode, + @Cached TruffleString.GetCodeRangeNode getCodeRangeNode, + @Cached TruffleString.CreateCodePointIteratorNode createCodePointIteratorNode, + @Cached TruffleStringIterator.NextNode nextNode, + @Cached TruffleString.CodePointLengthNode codePointLengthNode, + @Cached TruffleString.FromByteArrayWithCompactionUTF32Node fromByteArrayNode) { + Object reprObj = reprNode.execute(frame, inliningTarget, obj); + TruffleString repr = castToTruffleStringNode.castKnownString(inliningTarget, reprObj); + if (getCodeRangeNode.execute(repr, TS_ENCODING) == TruffleString.CodeRange.ASCII) { + return reprObj; + } + return convertToAscii(repr, createCodePointIteratorNode, nextNode, codePointLengthNode, fromByteArrayNode); + } + + public static TruffleString convertToAscii(TruffleString repr, TruffleString.CreateCodePointIteratorNode createCodePointIteratorNode, TruffleStringIterator.NextNode nextNode, + TruffleString.CodePointLengthNode codePointLengthNode, TruffleString.FromByteArrayWithCompactionUTF32Node fromByteArrayNode) { + // TODO GR-37220: rewrite using TruffleStringBuilder? + byte[] bytes = new byte[codePointLengthNode.execute(repr, TS_ENCODING) * 10]; + TruffleStringIterator it = createCodePointIteratorNode.execute(repr, TS_ENCODING); + int j = 0; + while (it.hasNext()) { + int ch = nextNode.execute(it, TS_ENCODING); + j = unicodeNonAsciiEscape(ch, j, bytes); + } + return fromByteArrayNode.execute(bytes, 0, j, TruffleString.CompactionLevel.S1, true); + } + + @NeverDefault + public static PyObjectAsciiAsObjectNode create() { + return PyObjectAsciiAsObjectNodeGen.create(); + } + + public static PyObjectAsciiAsObjectNode getUncached() { + return PyObjectAsciiAsObjectNodeGen.getUncached(); + } +} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsciiNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsciiAsTruffleStringNode.java similarity index 81% rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsciiNode.java rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsciiAsTruffleStringNode.java index ced7a5f676..75e9f51df4 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsciiNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsciiAsTruffleStringNode.java @@ -40,7 +40,6 @@ */ package com.oracle.graal.python.lib; -import static com.oracle.graal.python.builtins.objects.bytes.BytesUtils.unicodeNonAsciiEscape; import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING; import com.oracle.graal.python.nodes.PNodeWithContext; @@ -62,9 +61,9 @@ @GenerateUncached @GenerateInline(inlineByDefault = true) @GenerateCached -public abstract class PyObjectAsciiNode extends PNodeWithContext { +public abstract class PyObjectAsciiAsTruffleStringNode extends PNodeWithContext { public static TruffleString executeUncached(Object object) { - return PyObjectAsciiNodeGen.getUncached().execute(null, null, object); + return PyObjectAsciiAsTruffleStringNodeGen.getUncached().execute(null, null, object); } public final TruffleString executeCached(Frame frame, Object object) { @@ -81,27 +80,19 @@ public static TruffleString ascii(VirtualFrame frame, Node inliningTarget, Objec @Cached TruffleStringIterator.NextNode nextNode, @Cached TruffleString.CodePointLengthNode codePointLengthNode, @Cached TruffleString.FromByteArrayWithCompactionUTF32Node fromByteArrayNode) { - // TODO GR-37220: rewrite using TruffleStringBuilder? TruffleString repr = reprNode.execute(frame, inliningTarget, obj); if (getCodeRangeNode.execute(repr, TS_ENCODING) == TruffleString.CodeRange.ASCII) { return repr; } - byte[] bytes = new byte[codePointLengthNode.execute(repr, TS_ENCODING) * 10]; - TruffleStringIterator it = createCodePointIteratorNode.execute(repr, TS_ENCODING); - int j = 0; - while (it.hasNext()) { - int ch = nextNode.execute(it, TS_ENCODING); - j = unicodeNonAsciiEscape(ch, j, bytes); - } - return fromByteArrayNode.execute(bytes, 0, j, TruffleString.CompactionLevel.S1, true); + return PyObjectAsciiAsObjectNode.convertToAscii(repr, createCodePointIteratorNode, nextNode, codePointLengthNode, fromByteArrayNode); } @NeverDefault - public static PyObjectAsciiNode create() { - return PyObjectAsciiNodeGen.create(); + public static PyObjectAsciiAsTruffleStringNode create() { + return PyObjectAsciiAsTruffleStringNodeGen.create(); } - public static PyObjectAsciiNode getUncached() { - return PyObjectAsciiNodeGen.getUncached(); + public static PyObjectAsciiAsTruffleStringNode getUncached() { + return PyObjectAsciiAsTruffleStringNodeGen.getUncached(); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java index e86ab84f0c..bf3aca2f85 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java @@ -62,8 +62,8 @@ import com.oracle.graal.python.PythonLanguage; import com.oracle.graal.python.builtins.PythonBuiltinClassType; import com.oracle.graal.python.builtins.modules.BuiltinFunctions.FormatNode; -import com.oracle.graal.python.builtins.modules.BuiltinFunctionsFactory.FormatNodeFactory.FormatNodeGen; import com.oracle.graal.python.builtins.modules.MarshalModuleBuiltins; +import com.oracle.graal.python.builtins.modules.BuiltinFunctionsFactory.FormatNodeFactory.FormatNodeGen; import com.oracle.graal.python.builtins.objects.PNone; import com.oracle.graal.python.builtins.objects.asyncio.GetAwaitableNode; import com.oracle.graal.python.builtins.objects.asyncio.GetAwaitableNodeGen; @@ -143,8 +143,8 @@ import com.oracle.graal.python.lib.PyNumberSubtractNode; import com.oracle.graal.python.lib.PyNumberTrueDivideNode; import com.oracle.graal.python.lib.PyNumberXorNode; -import com.oracle.graal.python.lib.PyObjectAsciiNode; -import com.oracle.graal.python.lib.PyObjectAsciiNodeGen; +import com.oracle.graal.python.lib.PyObjectAsciiAsObjectNode; +import com.oracle.graal.python.lib.PyObjectAsciiAsObjectNodeGen; import com.oracle.graal.python.lib.PyObjectDelItem; import com.oracle.graal.python.lib.PyObjectDelItemNodeGen; import com.oracle.graal.python.lib.PyObjectGetAttr; @@ -401,8 +401,8 @@ public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNod private static final NodeSupplier NODE_STR = PyObjectStrAsObjectNode::create; private static final PyObjectReprAsObjectNode UNCACHED_REPR = PyObjectReprAsObjectNode.getUncached(); private static final NodeSupplier NODE_REPR = PyObjectReprAsObjectNode::create; - private static final PyObjectAsciiNode UNCACHED_ASCII = PyObjectAsciiNode.getUncached(); - private static final NodeSupplier NODE_ASCII = PyObjectAsciiNode::create; + private static final PyObjectAsciiAsObjectNode UNCACHED_ASCII = PyObjectAsciiAsObjectNode.getUncached(); + private static final NodeSupplier NODE_ASCII = PyObjectAsciiAsObjectNode::create; private static final NodeSupplier NODE_FORMAT = FormatNode::create; private static final NodeSupplier NODE_SEND = SendNode::create; private static final NodeSupplier NODE_THROW = ThrowNode::create; @@ -4989,7 +4989,7 @@ private int bytecodeFormatValue(VirtualFrame virtualFrame, int initialStackTop, value = insertChildNode(localNodes, bci, UNCACHED_REPR, PyObjectReprAsObjectNodeGen.class, NODE_REPR, useCachedNodes).executeCached(virtualFrame, value); break; case FormatOptions.FVC_ASCII: - value = insertChildNode(localNodes, bci, UNCACHED_ASCII, PyObjectAsciiNodeGen.class, NODE_ASCII, useCachedNodes).executeCached(virtualFrame, value); + value = insertChildNode(localNodes, bci, UNCACHED_ASCII, PyObjectAsciiAsObjectNodeGen.class, NODE_ASCII, useCachedNodes).executeCached(virtualFrame, value); break; default: assert type == FormatOptions.FVC_NONE; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java index 610555aed2..80d11ef3da 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java @@ -146,7 +146,7 @@ import com.oracle.graal.python.lib.PyNumberSubtractNode; import com.oracle.graal.python.lib.PyNumberTrueDivideNode; import com.oracle.graal.python.lib.PyNumberXorNode; -import com.oracle.graal.python.lib.PyObjectAsciiNode; +import com.oracle.graal.python.lib.PyObjectAsciiAsObjectNode; import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs; import com.oracle.graal.python.lib.PyObjectDelItem; import com.oracle.graal.python.lib.PyObjectFunctionStr; @@ -159,13 +159,13 @@ import com.oracle.graal.python.lib.PyObjectIsNotTrueNode; import com.oracle.graal.python.lib.PyObjectIsTrueNode; import com.oracle.graal.python.lib.PyObjectLookupAttr; -import com.oracle.graal.python.lib.PyObjectReprAsTruffleStringNode; +import com.oracle.graal.python.lib.PyObjectReprAsObjectNode; import com.oracle.graal.python.lib.PyObjectRichCompare.GenericRichCompare; import com.oracle.graal.python.lib.PyObjectSetAttr; import com.oracle.graal.python.lib.PyObjectSetAttrO; import com.oracle.graal.python.lib.PyObjectSetItem; import com.oracle.graal.python.lib.PyObjectSizeNode; -import com.oracle.graal.python.lib.PyObjectStrAsTruffleStringNode; +import com.oracle.graal.python.lib.PyObjectStrAsObjectNode; import com.oracle.graal.python.lib.PySequenceContainsNode; import com.oracle.graal.python.lib.RichCmpOp; import com.oracle.graal.python.nodes.BuiltinNames; @@ -1401,30 +1401,30 @@ public static Object perform(VirtualFrame frame, Object receiver, @Operation(storeBytecodeIndex = true) public static final class FormatStr { @Specialization - public static TruffleString perform(VirtualFrame frame, Object object, + public static Object perform(VirtualFrame frame, Object object, @Bind Node inliningTarget, - @Cached PyObjectStrAsTruffleStringNode asTruffleStringNode) { - return asTruffleStringNode.execute(frame, inliningTarget, object); + @Cached PyObjectStrAsObjectNode strNode) { + return strNode.execute(frame, inliningTarget, object); } } @Operation(storeBytecodeIndex = true) public static final class FormatRepr { @Specialization - public static TruffleString perform(VirtualFrame frame, Object object, + public static Object perform(VirtualFrame frame, Object object, @Bind Node inliningTarget, - @Cached PyObjectReprAsTruffleStringNode asTruffleStringNode) { - return asTruffleStringNode.execute(frame, inliningTarget, object); + @Cached PyObjectReprAsObjectNode reprNode) { + return reprNode.execute(frame, inliningTarget, object); } } @Operation(storeBytecodeIndex = true) public static final class FormatAscii { @Specialization - public static TruffleString perform(VirtualFrame frame, Object object, + public static Object perform(VirtualFrame frame, Object object, @Bind Node inliningTarget, - @Cached PyObjectAsciiNode asTruffleStringNode) { - return asTruffleStringNode.execute(frame, inliningTarget, object); + @Cached PyObjectAsciiAsObjectNode asciiNode) { + return asciiNode.execute(frame, inliningTarget, object); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/BytesFormatProcessor.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/BytesFormatProcessor.java index ea46c4ebc9..ac8d0b4579 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/BytesFormatProcessor.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/BytesFormatProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -62,7 +62,7 @@ import com.oracle.graal.python.builtins.objects.str.PString; import com.oracle.graal.python.builtins.objects.tuple.PTuple; import com.oracle.graal.python.lib.PyMappingCheckNode; -import com.oracle.graal.python.lib.PyObjectAsciiNode; +import com.oracle.graal.python.lib.PyObjectAsciiAsTruffleStringNode; import com.oracle.graal.python.nodes.ErrorMessages; import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.graal.python.runtime.exception.PException; @@ -208,7 +208,7 @@ protected InternalFormat.Formatter handleRemainingFormats(InternalFormat.Spec sp case 'r': case 'a': // ascii - String result = PyObjectAsciiNode.executeUncached(getArg()).toJavaStringUncached(); + String result = PyObjectAsciiAsTruffleStringNode.executeUncached(getArg()).toJavaStringUncached(); fb = new BytesFormatter(buffer, spec, raisingNode); fb.formatAsciiString(result); return fb; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/StringFormatProcessor.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/StringFormatProcessor.java index 6d4cb10703..9ec500f1a5 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/StringFormatProcessor.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/StringFormatProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. * Copyright (c) -2016 Jython Developers * * Licensed under PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 @@ -16,7 +16,7 @@ import com.oracle.graal.python.builtins.objects.str.PString; import com.oracle.graal.python.builtins.objects.tuple.PTuple; import com.oracle.graal.python.lib.PyMappingCheckNode; -import com.oracle.graal.python.lib.PyObjectAsciiNode; +import com.oracle.graal.python.lib.PyObjectAsciiAsTruffleStringNode; import com.oracle.graal.python.lib.PyObjectReprAsTruffleStringNode; import com.oracle.graal.python.lib.PyObjectStrAsTruffleStringNode; import com.oracle.graal.python.nodes.ErrorMessages; @@ -102,7 +102,7 @@ protected InternalFormat.Formatter handleRemainingFormats(InternalFormat.Spec sp TruffleString result; switch (spec.type) { case 'a': // repr as ascii - result = PyObjectAsciiNode.executeUncached(arg); + result = PyObjectAsciiAsTruffleStringNode.executeUncached(arg); break; case 's': // String: converts any object using __str__(), __unicode__() ... result = PyObjectStrAsTruffleStringNode.executeUncached(arg);