roc-lang / roc

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

stack overflow: lambda set recursion #6890

Open Anton-4 opened 1 month ago

Anton-4 commented 1 month ago

Error on roc build:

thread '<unknown>' has overflowed its stack
fatal runtime error: stack overflow
Aborted (core dumped)

Code:

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
    parser: "https://github.com/lukewilliamboswell/roc-parser/releases/download/0.7.1/MvLlME9RxOBjl0QCxyn3LIaoG9pSlaNxCa-t3BfbPNc.tar.br",
}

import pf.Task

import parser.Core exposing [
    Parser,
    const,
    keep,
    oneOf,
    skip,
]
import parser.String exposing [Utf8, parseUtf8, string]

main =
    input : List U8
    input = []

    parsed = parseUtf8 parser input

    Task.ok {}

parser =
    oneOf [includeP, whiteP]

includeP =
    const \x -> Include x
    |> keep (string "blabla")
    |> skip whiteP # comment this line out to prevent the stack overflow

whitesp = \x -> "\n \r\t" |> Str.toUtf8 |> List.contains x
whiteP : Parser Utf8 [Wsp]_
whiteP = const Wsp |> skip (Core.chompWhile whitesp)

When I look at the call stack with gdb I see this endlessly repeated:

roc_mono::layout::layout_from_flat_type
roc_mono::layout::Layout::from_var
roc_mono::layout::Layout::from_var
roc_mono::layout::LambdaSet::from_var
roc_mono::layout::layout_from_flat_type
roc_mono::layout::Layout::from_var
roc_mono::layout::Layout::from_var
roc_mono::layout::LambdaSet::from_var
roc_mono::layout::layout_from_flat_type

This looks very similar to these solved issues: https://github.com/roc-lang/roc/issues/3444 and https://github.com/roc-lang/roc/issues/3449

adrian4096 commented 1 month ago

From https://roc.zulipchat.com/#narrow/stream/231634-beginners/topic/.E2.9C.94.20Help.20with.20my.20program