|
48 | 48 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__ENTER__;
|
49 | 49 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
|
50 | 50 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__EXIT__;
|
| 51 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__FSPATH__; |
51 | 52 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTRIBUTE__;
|
52 | 53 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTR__;
|
53 | 54 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETITEM__;
|
|
98 | 99 | import com.oracle.graal.python.nodes.PGuards;
|
99 | 100 | import com.oracle.graal.python.nodes.PRaiseNode;
|
100 | 101 | import com.oracle.graal.python.nodes.SpecialMethodNames;
|
101 |
| -import static com.oracle.graal.python.nodes.SpecialMethodNames.__FSPATH__; |
102 | 102 | import com.oracle.graal.python.nodes.attributes.HasInheritedAttributeNode;
|
103 | 103 | import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
|
104 | 104 | import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
|
|
131 | 131 | import com.oracle.truffle.api.dsl.Cached.Shared;
|
132 | 132 | import com.oracle.truffle.api.dsl.CachedContext;
|
133 | 133 | import com.oracle.truffle.api.dsl.GenerateUncached;
|
134 |
| -import com.oracle.truffle.api.dsl.ImportStatic; |
135 | 134 | import com.oracle.truffle.api.dsl.ReportPolymorphism;
|
136 | 135 | import com.oracle.truffle.api.dsl.Specialization;
|
137 | 136 | import com.oracle.truffle.api.interop.ArityException;
|
@@ -1743,48 +1742,61 @@ public Class<? extends TruffleLanguage<?>> getLanguage() {
|
1743 | 1742 | return PythonLanguage.class;
|
1744 | 1743 | }
|
1745 | 1744 |
|
1746 |
| - @ExportMessage |
1747 |
| - @ImportStatic(PythonOptions.class) |
1748 |
| - public static class ToDisplayString { |
1749 |
| - public static boolean useReprForPrintString(PythonContext context) { |
1750 |
| - return context.getOption(PythonOptions.UseReprForPrintString); |
1751 |
| - } |
| 1745 | + @GenerateUncached |
| 1746 | + @SuppressWarnings("unused") |
| 1747 | + public abstract static class ToDisplaySideEffectingNode extends Node { |
1752 | 1748 |
|
1753 |
| - @Specialization(guards = {"allowSideEffects", "builtins != null"}) // may be null during |
1754 |
| - // initialization |
1755 |
| - public static String builtin(PythonAbstractObject self, boolean allowSideEffects, |
1756 |
| - @SuppressWarnings("unused") @CachedContext(PythonLanguage.class) PythonContext context, |
1757 |
| - @Cached(value = "context.getBuiltins()", allowUncached = true) PythonModule builtins, |
| 1749 | + public abstract String execute(PythonAbstractObject receiver); |
| 1750 | + |
| 1751 | + @Specialization |
| 1752 | + public String doDefault(PythonAbstractObject receiver, |
| 1753 | + @CachedContext(PythonLanguage.class) PythonContext context, |
1758 | 1754 | @Cached ReadAttributeFromObjectNode readStr,
|
1759 | 1755 | @Cached CallNode callNode,
|
1760 | 1756 | @Cached CastToJavaStringNode castStr,
|
1761 |
| - @Cached(value = "useReprForPrintString(context)", allowUncached = true) boolean useRepr) { |
| 1757 | + @Cached ConditionProfile toStringUsed) { |
1762 | 1758 | Object toStrAttr;
|
1763 |
| - if (useRepr) { |
1764 |
| - toStrAttr = readStr.execute(builtins, BuiltinNames.REPR); |
| 1759 | + String names; |
| 1760 | + if (context.getOption(PythonOptions.UseReprForPrintString)) { |
| 1761 | + names = BuiltinNames.REPR; |
1765 | 1762 | } else {
|
1766 |
| - toStrAttr = readStr.execute(builtins, BuiltinNames.STR); |
| 1763 | + names = BuiltinNames.STR; |
1767 | 1764 | }
|
1768 |
| - String result = castStr.execute(callNode.execute(toStrAttr, self)); |
1769 |
| - if (result != null) { |
| 1765 | + String result = null; |
| 1766 | + PythonModule builtins = context.getBuiltins(); |
| 1767 | + if (toStringUsed.profile(builtins != null)) { |
| 1768 | + toStrAttr = readStr.execute(builtins, names); |
| 1769 | + result = castStr.execute(callNode.execute(toStrAttr, receiver)); |
| 1770 | + } |
| 1771 | + if (toStringUsed.profile(result != null)) { |
1770 | 1772 | return result;
|
1771 | 1773 | } else {
|
1772 |
| - return fallback(self, allowSideEffects, context, builtins); |
| 1774 | + return receiver.toStringBoundary(); |
1773 | 1775 | }
|
1774 | 1776 | }
|
1775 | 1777 |
|
1776 |
| - public static final PythonModule none() { |
1777 |
| - return null; |
| 1778 | + } |
| 1779 | + |
| 1780 | + @ExportMessage |
| 1781 | + @SuppressWarnings("unused") |
| 1782 | + public static class ToDisplayString { |
| 1783 | + |
| 1784 | + @Specialization(guards = "allowSideEffects") |
| 1785 | + public static String doSideEffecting(PythonAbstractObject receiver, boolean allowSideEffects, |
| 1786 | + @Cached ToDisplaySideEffectingNode toDisplayCallnode) { |
| 1787 | + return toDisplayCallnode.execute(receiver); |
1778 | 1788 | }
|
1779 | 1789 |
|
1780 |
| - @TruffleBoundary |
1781 |
| - @SuppressWarnings("unused") |
1782 |
| - @Specialization(guards = "!allowSideEffects || builtins == null") |
1783 |
| - public static String fallback(PythonAbstractObject self, boolean allowSideEffects, |
1784 |
| - @CachedContext(PythonLanguage.class) PythonContext context, |
1785 |
| - @Cached(value = "context.getBuiltins()", uncached = "none()") PythonModule builtins) { |
1786 |
| - return self.toString(); |
| 1790 | + @Specialization(guards = "!allowSideEffects") |
| 1791 | + public static String doNonSideEffecting(PythonAbstractObject receiver, boolean allowSideEffects) { |
| 1792 | + return receiver.toStringBoundary(); |
1787 | 1793 | }
|
| 1794 | + |
| 1795 | + } |
| 1796 | + |
| 1797 | + @TruffleBoundary |
| 1798 | + final String toStringBoundary() { |
| 1799 | + return toString(); |
1788 | 1800 | }
|
1789 | 1801 |
|
1790 | 1802 | @ExportMessage
|
|
0 commit comments