|
271 | 271 | @ShortCircuitOperation(name = "PrimitiveBoolOr", booleanConverter = PBytecodeDSLRootNode.BooleanIdentity.class, operator = Operator.OR_RETURN_CONVERTED) |
272 | 272 | @SuppressWarnings("unused") |
273 | 273 | public abstract class PBytecodeDSLRootNode extends PRootNode implements BytecodeRootNode { |
274 | | - private static final int EXPLODE_LOOP_THRESHOLD = 32; |
| 274 | + public static final int EXPLODE_LOOP_THRESHOLD = 32; |
275 | 275 | private static final BytecodeConfig TRACE_AND_PROFILE_CONFIG = PBytecodeDSLRootNodeGen.newConfigBuilder() // |
276 | 276 | .addInstrumentation(TraceOrProfileCall.class) // |
277 | 277 | .addInstrumentation(TraceLine.class) // |
@@ -379,7 +379,7 @@ public static void doExit(VirtualFrame frame, AbstractTruffleException ate, |
379 | 379 | @Bind("$root") PBytecodeDSLRootNode root, |
380 | 380 | @Bind("this") Node location) { |
381 | 381 | if (ate instanceof PException pe) { |
382 | | - pe.notifyAddedTracebackFrame(!root.isPythonInternal()); |
| 382 | + pe.notifyAddedTracebackFrame(!root.isInternal()); |
383 | 383 | } |
384 | 384 |
|
385 | 385 | if (root.needsTraceAndProfileInstrumentation()) { |
@@ -1904,37 +1904,34 @@ public static PList perform(Object[] elements, |
1904 | 1904 | } |
1905 | 1905 |
|
1906 | 1906 | @Operation |
| 1907 | + @ImportStatic({PBytecodeDSLRootNode.class}) |
1907 | 1908 | public static final class MakeSet { |
1908 | | - @Specialization |
1909 | | - public static PSet perform(VirtualFrame frame, Object[] elements, |
| 1909 | + @Specialization(guards = {"elements.length == length", "length <= EXPLODE_LOOP_THRESHOLD"}, limit = "1") |
| 1910 | + @ExplodeLoop |
| 1911 | + public static PSet performExploded(VirtualFrame frame, Object[] elements, |
1910 | 1912 | @Bind("$root") PBytecodeDSLRootNode rootNode, |
1911 | 1913 | @Bind("this") Node node, |
1912 | | - @Cached(value = "elements.length", neverDefault = false) int length, |
1913 | | - @Cached SetNodes.AddNode addNode, |
1914 | | - @Cached HashingCollectionNodes.SetItemNode setItemNode) { |
1915 | | - assert elements.length == length; |
1916 | | - |
| 1914 | + @Cached(value = "elements.length") int length, |
| 1915 | + @Shared @Cached SetNodes.AddNode addNode, |
| 1916 | + @Shared @Cached HashingCollectionNodes.SetItemNode setItemNode) { |
1917 | 1917 | PSet set = rootNode.factory.createSet(); |
1918 | | - if (length <= EXPLODE_LOOP_THRESHOLD) { |
1919 | | - doExploded(frame, set, elements, length, addNode, setItemNode); |
1920 | | - } else { |
1921 | | - doRegular(frame, set, elements, length, addNode, setItemNode); |
1922 | | - } |
1923 | | - return set; |
1924 | | - } |
1925 | | - |
1926 | | - @ExplodeLoop |
1927 | | - private static void doExploded(VirtualFrame frame, PSet set, Object[] elements, int length, SetNodes.AddNode addNode, HashingCollectionNodes.SetItemNode setItemNode) { |
1928 | | - CompilerAsserts.partialEvaluationConstant(length); |
1929 | 1918 | for (int i = 0; i < length; i++) { |
1930 | 1919 | SetNodes.AddNode.add(frame, set, elements[i], addNode, setItemNode); |
1931 | 1920 | } |
| 1921 | + return set; |
1932 | 1922 | } |
1933 | 1923 |
|
1934 | | - private static void doRegular(VirtualFrame frame, PSet set, Object[] elements, int length, SetNodes.AddNode addNode, HashingCollectionNodes.SetItemNode setItemNode) { |
1935 | | - for (int i = 0; i < length; i++) { |
| 1924 | + @Specialization |
| 1925 | + public static PSet performRegular(VirtualFrame frame, Object[] elements, |
| 1926 | + @Bind("$root") PBytecodeDSLRootNode rootNode, |
| 1927 | + @Bind("this") Node node, |
| 1928 | + @Shared @Cached SetNodes.AddNode addNode, |
| 1929 | + @Shared @Cached HashingCollectionNodes.SetItemNode setItemNode) { |
| 1930 | + PSet set = rootNode.factory.createSet(); |
| 1931 | + for (int i = 0; i < elements.length; i++) { |
1936 | 1932 | SetNodes.AddNode.add(frame, set, elements[i], addNode, setItemNode); |
1937 | 1933 | } |
| 1934 | + return set; |
1938 | 1935 | } |
1939 | 1936 | } |
1940 | 1937 |
|
@@ -1999,54 +1996,9 @@ public static PList perform(@Bind("$root") PBytecodeDSLRootNode rootNode) { |
1999 | 1996 | @Operation |
2000 | 1997 | public static final class MakeTuple { |
2001 | 1998 | @Specialization |
2002 | | - public static Object perform(@Variadic Object[] elements, |
2003 | | - @Cached(value = "elements.length", neverDefault = false) int length, |
| 1999 | + public static Object perform(Object[] elements, |
2004 | 2000 | @Bind("$root") PBytecodeDSLRootNode rootNode) { |
2005 | | - assert elements.length == length; |
2006 | | - |
2007 | | - Object[] elts; |
2008 | | - if (length <= EXPLODE_LOOP_THRESHOLD) { |
2009 | | - elts = doExploded(elements, length); |
2010 | | - } else { |
2011 | | - elts = doRegular(elements, length); |
2012 | | - } |
2013 | | - return rootNode.factory.createTuple(elts); |
2014 | | - } |
2015 | | - |
2016 | | - @ExplodeLoop |
2017 | | - private static Object[] doExploded(Object[] elements, int length) { |
2018 | | - CompilerAsserts.partialEvaluationConstant(length); |
2019 | | - int totalLength = 0; |
2020 | | - for (int i = 0; i < length; i++) { |
2021 | | - totalLength += ((Object[]) elements[i]).length; |
2022 | | - } |
2023 | | - |
2024 | | - Object[] elts = new Object[totalLength]; |
2025 | | - int idx = 0; |
2026 | | - for (int i = 0; i < length; i++) { |
2027 | | - Object[] arr = (Object[]) elements[i]; |
2028 | | - int len = arr.length; |
2029 | | - System.arraycopy(arr, 0, elts, idx, len); |
2030 | | - idx += len; |
2031 | | - } |
2032 | | - return elts; |
2033 | | - } |
2034 | | - |
2035 | | - private static Object[] doRegular(Object[] elements, int length) { |
2036 | | - int totalLength = 0; |
2037 | | - for (int i = 0; i < length; i++) { |
2038 | | - totalLength += ((Object[]) elements[i]).length; |
2039 | | - } |
2040 | | - |
2041 | | - Object[] elts = new Object[totalLength]; |
2042 | | - int idx = 0; |
2043 | | - for (int i = 0; i < length; i++) { |
2044 | | - Object[] arr = (Object[]) elements[i]; |
2045 | | - int len = arr.length; |
2046 | | - System.arraycopy(arr, 0, elts, idx, len); |
2047 | | - idx += len; |
2048 | | - } |
2049 | | - return elts; |
| 2001 | + return rootNode.factory.createTuple(elements); |
2050 | 2002 | } |
2051 | 2003 | } |
2052 | 2004 |
|
@@ -3621,7 +3573,7 @@ public static void doExceptional(VirtualFrame frame, |
3621 | 3573 | Object result = callExit.execute(frame, exit, contextManager, excType, pythonException, excTraceback); |
3622 | 3574 | if (!isTrue.execute(frame, inliningTarget, result)) { |
3623 | 3575 | if (exception instanceof PException pException) { |
3624 | | - throw pException.getExceptionForReraise(rootNode.isPythonInternal()); |
| 3576 | + throw pException.getExceptionForReraise(!rootNode.isInternal()); |
3625 | 3577 | } else if (exception instanceof AbstractTruffleException ate) { |
3626 | 3578 | throw ate; |
3627 | 3579 | } else { |
@@ -3723,7 +3675,7 @@ public static void doExceptional(VirtualFrame frame, |
3723 | 3675 | @Cached PRaiseNode.Lazy raiseNode) { |
3724 | 3676 | if (!isTrue.execute(frame, inliningTarget, result)) { |
3725 | 3677 | if (exception instanceof PException) { |
3726 | | - throw ((PException) exception).getExceptionForReraise(rootNode.isPythonInternal()); |
| 3678 | + throw ((PException) exception).getExceptionForReraise(!rootNode.isInternal()); |
3727 | 3679 | } else if (exception instanceof AbstractTruffleException) { |
3728 | 3680 | throw (AbstractTruffleException) exception; |
3729 | 3681 | } else { |
|
0 commit comments