roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.46k stars 314 forks source link

Stack overflow during compilation #6867

Open r-bar opened 4 months ago

r-bar commented 4 months ago

I was working on implementing a web service and encountered a reproducible stack overflow.

$ roc check

thread '<unknown>' has overflowed its stack
fatal runtime error: stack overflow
zsh: IOT instruction (core dumped)  roc check

The (seemingly) relevant section of the file was:

processRequest : App -> (Request -> Task Response [])
processRequest = \app -> \request ->
    #preprocess = \req, middleware -> Task.await req middleware.preprocessRequest
    postprocess = \resp, middleware -> Task.await resp middleware.postprocessResponse
    handleRequest = \reqTask ->
        Task.await reqTask \req ->
            handler = app.router req
            handler req
    Task.ok request
        #|> \req -> List.walk app.middleware req preprocess
        |> handleRequest
        |> \req -> List.walkBackwards app.middleware req postprocess

Uncommenting the 2 lines and compiling / roc check causes the stack overflow. The full program is a single <200 line file and can be found here

Compiling the program with those 2 lines commented works.