@@ -1742,36 +1742,60 @@ public Class<? extends TruffleLanguage<?>> getLanguage() {
1742
1742
return PythonLanguage .class ;
1743
1743
}
1744
1744
1745
- @ ExportMessage
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 )) {
1745
+ @ GenerateUncached
1746
+ @ SuppressWarnings ("unused" )
1747
+ public abstract static class ToDisplaySideEffectingNode extends Node {
1748
+
1749
+ public abstract String execute (PythonAbstractObject receiver );
1750
+
1751
+ @ Specialization
1752
+ public String doDefault (PythonAbstractObject receiver ,
1753
+ @ CachedContext (PythonLanguage .class ) PythonContext context ,
1754
+ @ Cached ReadAttributeFromObjectNode readStr ,
1755
+ @ Cached CallNode callNode ,
1756
+ @ Cached CastToJavaStringNode castStr ,
1757
+ @ Cached ConditionProfile toStringUsed ) {
1755
1758
Object toStrAttr ;
1756
1759
String names ;
1757
1760
if (context .getOption (PythonOptions .UseReprForPrintString )) {
1758
1761
names = BuiltinNames .REPR ;
1759
1762
} else {
1760
1763
names = BuiltinNames .STR ;
1761
1764
}
1762
- toStrAttr = readStr .execute (builtins , names );
1763
- result = castStr .execute (callNode .execute (toStrAttr , this ));
1764
- // reusing the same condition profile here as it effectively
1765
- // has the same effect.
1766
- if (conditionProfile .profile (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 )) {
1767
1772
return result ;
1773
+ } else {
1774
+ return receiver .toStringBoundary ();
1768
1775
}
1769
1776
}
1770
- return toStringImpl ();
1777
+
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 );
1788
+ }
1789
+
1790
+ @ Specialization (guards = "!allowSideEffects" )
1791
+ public static String doNonSideEffecting (PythonAbstractObject receiver , boolean allowSideEffects ) {
1792
+ return receiver .toStringBoundary ();
1793
+ }
1794
+
1771
1795
}
1772
1796
1773
1797
@ TruffleBoundary
1774
- private String toStringImpl () {
1798
+ final String toStringBoundary () {
1775
1799
return toString ();
1776
1800
}
1777
1801
0 commit comments