Elm Exactly
Results / elm-core /

CoreIssue1123NestedCmdBatchStackOverflowTest

Tags:elm19-bugelm-unspecced

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 fail

Issue: elm/core#1123

A deeply nested `Cmd.batch` overflows the stack in `_Platform_gatherEffects`.

<https://github.com/elm/core/issues/1123>

Elm 0.19.1 recurses once per nesting level and throws `RangeError: Maximum call stack size
exceeded`. The test nests a `Task.perform` inside `Cmd.batch [ acc, Cmd.none ]` 100000 times. That
is a valid command, and by the book the program runs it and receives the inner task's result, 1.

The issue's own program used the library functions `List.foldl` and `List.range` to build the
nesting; this version reproduces the same bug with a local tail-recursive loop in their place.

A Standard Definition of Elm? places no bound on the resources evaluation uses, and an
implementation that stops for lack of them is outside the definition (Appendix,
Implementation-Dependent Details, Resource Limits). The book's result for this program is the one
the test expects, but a compiler that runs out of stack or memory on it does not contradict the
book, so the test is tagged `elm-unspecced`: it checks an implementation's resources.

<https://elm-test-suite.netlify.app/standard/appendix-implementation#sec-appendix-implementation-limits>

Results

elm-0.19.1

failran in 141 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2116
	switch (bag.$)
	            ^

RangeError: Maximum call stack size exceeded
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2116:14)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)

Node.js v22.23.5

elm-0.19.2

failran in 81 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2116
	switch (bag.$)
	            ^

RangeError: Maximum call stack size exceeded
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2116:14)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)

Node.js v22.23.5

elm-0.19.3

failran in 84 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2116
	switch (bag.$)
	            ^

RangeError: Maximum call stack size exceeded
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2116:14)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2127:5)

Node.js v22.23.5

lamdera-1.5.0

failran in 131 ms
exit code 1, expected 0
--- output ---
/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2448
	switch (bag.$)
	            ^

RangeError: Maximum call stack size exceeded
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2448:14)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2459:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2459:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2459:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2459:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2459:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2459:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2459:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2459:5)
    at _Platform_gatherEffects (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/CoreIssue1123NestedCmdBatchStackOverflowTest.js:2459:5)

Node.js v22.23.5

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-core/CoreIssue1123NestedCmdBatchStackOverflowTest] in its title.

Source

The -- CHECK: lines give the expected output.

module CoreIssue1123NestedCmdBatchStackOverflowTest exposing (main)
{-| A deeply nested `Cmd.batch` overflows the stack in `_Platform_gatherEffects`.
<https://github.com/elm/core/issues/1123>
Elm 0.19.1 recurses once per nesting level and throws `RangeError: Maximum call stack size
exceeded`. The test nests a `Task.perform` inside `Cmd.batch [ acc, Cmd.none ]` 100000 times. That
is a valid command, and by the book the program runs it and receives the inner task's result, 1.
The issue's own program used the library functions `List.foldl` and `List.range` to build the
nesting; this version reproduces the same bug with a local tail-recursive loop in their place.
A Standard Definition of Elm? places no bound on the resources evaluation uses, and an
implementation that stops for lack of them is outside the definition (Appendix,
Implementation-Dependent Details, Resource Limits). The book's result for this program is the one
the test expects, but a compiler that runs out of stack or memory on it does not contradict the
book, so the test is tagged `elm-unspecced`: it checks an implementation's resources.
<https://elm-test-suite.netlify.app/standard/appendix-implementation#sec-appendix-implementation-limits>
-}
-- TAGS: elm19-bug, elm-unspecced
-- CHECK: got: 1
import Task
nest : Int -> Cmd Int -> Cmd Int
nest depth acc =
if depth <= 0 then
acc
else
nest (depth - 1) (Cmd.batch [ acc, Cmd.none ])
nested : Int -> Cmd Int
nested depth =
nest depth (Task.perform identity (Task.succeed 1))
main : Program () () Int
main =
Platform.worker
{ init = \_ -> ( (), nested 100000 )
, update = \msg model -> ( Debug.log "got" msg |> always model, Cmd.none )
, subscriptions = \_ -> Sub.none
}