|
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;
|
@@ -1744,47 +1743,33 @@ public Class<? extends TruffleLanguage<?>> getLanguage() {
|
1744 | 1743 | }
|
1745 | 1744 |
|
1746 | 1745 | @ExportMessage
|
1747 |
| - @ImportStatic(PythonOptions.class) |
1748 |
| - public static class ToDisplayString { |
1749 |
| - public static boolean useReprForPrintString(PythonContext context) { |
1750 |
| - return context.getOption(PythonOptions.UseReprForPrintString); |
1751 |
| - } |
1752 |
| - |
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, |
1758 |
| - @Cached ReadAttributeFromObjectNode readStr, |
1759 |
| - @Cached CallNode callNode, |
1760 |
| - @Cached CastToJavaStringNode castStr, |
1761 |
| - @Cached(value = "useReprForPrintString(context)", allowUncached = true) boolean useRepr) { |
| 1746 | + public String toDisplayString(boolean allowSideEffects, |
| 1747 | + @SuppressWarnings("unused") @CachedContext(PythonLanguage.class) PythonContext context, |
| 1748 | + @Exclusive @Cached ReadAttributeFromObjectNode readStr, |
| 1749 | + @Exclusive @Cached CallNode callNode, |
| 1750 | + @Cached CastToJavaStringNode castStr, |
| 1751 | + @Cached ConditionProfile conditionProfile) { |
| 1752 | + PythonModule builtins = context.getBuiltins(); |
| 1753 | + String result = null; |
| 1754 | + if (conditionProfile.profile(builtins != null && allowSideEffects)) { |
1762 | 1755 | Object toStrAttr;
|
1763 |
| - if (useRepr) { |
1764 |
| - toStrAttr = readStr.execute(builtins, BuiltinNames.REPR); |
1765 |
| - } else { |
1766 |
| - toStrAttr = readStr.execute(builtins, BuiltinNames.STR); |
1767 |
| - } |
1768 |
| - String result = castStr.execute(callNode.execute(toStrAttr, self)); |
1769 |
| - if (result != null) { |
1770 |
| - return result; |
| 1756 | + String names; |
| 1757 | + if (context.getOption(PythonOptions.UseReprForPrintString)) { |
| 1758 | + names = BuiltinNames.REPR; |
1771 | 1759 | } else {
|
1772 |
| - return fallback(self, allowSideEffects, context, builtins); |
| 1760 | + names = BuiltinNames.STR; |
1773 | 1761 | }
|
| 1762 | + toStrAttr = readStr.execute(builtins, names); |
| 1763 | + result = castStr.execute(callNode.execute(toStrAttr, this)); |
| 1764 | + return result; |
| 1765 | + } else { |
| 1766 | + return toStringImpl(); |
1774 | 1767 | }
|
| 1768 | + } |
1775 | 1769 |
|
1776 |
| - public static final PythonModule none() { |
1777 |
| - return null; |
1778 |
| - } |
1779 |
| - |
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(); |
1787 |
| - } |
| 1770 | + @TruffleBoundary |
| 1771 | + private String toStringImpl() { |
| 1772 | + return toString(); |
1788 | 1773 | }
|
1789 | 1774 |
|
1790 | 1775 | @ExportMessage
|
|
0 commit comments