Concat on array with 2791 subarrays causes stack overflow
I have an array with 2791 subarrays.
[[DotEdge("io_stratego2abox_0_0","io_wrap_1_0")],[DotEdge("stratego2abox_0_0","topdown_1_0"), ..., [],[],[],[]]
Trying to concat this into a single array causes a stack overflow.
Fatal error at io_wrap_custom_6_0 option_wrap_5_0 io_input_2_0 io_output_2_0 analyze_callgraph_0_0 concat_0_0 at_end_1_0 at_end_1_0 ...truncated... at_end_1_0 at_end_1_0 at_end_1_0 Stack overflow (use java -ss4m to increase the stack size) Exception in thread "main" java.lang.StackOverflowError at org.strategoxt.lang.SRTS_EXT_at_end_1_0.invoke(SRTS_EXT_at_end_1_0.java:28) at org.strategoxt.lang.compat.override.performance_tweaks.at_end_1_0_override.invoke(at_end_1_0_override.java:21) at org.strategoxt.stratego_lib.g_1317.invoke(g_1317.java:46) at org.strategoxt.stratego_lib.lifted2006.invoke(lifted2006.java:24) at org.strategoxt.lang.SRTS_EXT_at_end_1_0.invoke(SRTS_EXT_at_end_1_0.java:44) at org.strategoxt.lang.compat.override.performance_tweaks.at_end_1_0_override.invoke(at_end_1_0_override.java:21) at org.strategoxt.stratego_lib.g_1317.invoke(g_1317.java:46) at org.strategoxt.stratego_lib.lifted2006.invoke(lifted2006.java:24) ...truncated... at org.strategoxt.lang.SRTS_EXT_at_end_1_0.invoke(SRTS_EXT_at_end_1_0.java:44) at org.strategoxt.lang.compat.override.performance_tweaks.at_end_1_0_override.invoke(at_end_1_0_override.java:21) at org.strategoxt.stratego_lib.g_1317.invoke(g_1317.java:46) at org.strategoxt.stratego_lib.lifted2006.invoke(lifted2006.java:24)
This, of course, is to be expected since the definition of both
Submitted by D. Pelsmaeker on 25 November 2014 at 16:20concat
(and theat_end
strategy it uses) are recursive. However, firstly, ideally this shouldn’t cause a Java exception/crash. Secondly, such a basic strategy might be better implemented in an iterative way (perhaps as a primitive?), or Stratego should support tail call optimization?
Issue Log
If concat does not have a performance override, that seems like a major oversight. There is a way to add performance overrides in: https://github.com/metaborg/strategoxt/blob/java-bootstrap/strategoxt/stratego-libraries/java-backend/java/runtime/org/strategoxt/lang/compat/override/performance-tweaks.str. You could add an override to an external strategy that is implemented in Java, similar to how at-end is overridden to: https://github.com/metaborg/strategoxt/blob/java-bootstrap/strategoxt/stratego-libraries/java-backend/java/runtime/org/strategoxt/lang/SRTS_EXT_at_end_1_0.java.
There’s now a performance override for
concat
(see strategoxt pull request #12).
Log in to post comments