roc icon indicating copy to clipboard operation
roc copied to clipboard

unexpected circular definition error with lazy parser - follow up

Open travisstaloch opened this issue 3 years ago • 0 comments

follow up to #4246

This file reproduces different panics and a stack overflow discovered by a json parser with roc version 2022-10-10-07ceabc

There are actually 6 separate reproduction blocks which can be uncommented one at a time. Each starts with a description + the observed error message. I think the first is actually a proper circular dep error + message.

discussion: https://roc.zulipchat.com/#narrow/stream/231634-beginners/topic/json.20parser/near/303305683

# create this file at <roc-repo-root>/examples/parser/repro.roc
# run
# $ cd <roc-repo-root> && roc examples/parser/repro.roc
#

app "parser-repro"
    packages { pf: "platform/main.roc" }
    imports [
        Parser.Core.{ Parser, oneOf, lazy, map, },
        Parser.Str.{ parseStr, RawStr, },
    ]
    provides [main] to pf

# dummy - just silence warnings
dummy = lazy \{} -> oneOf [] |> map \_ -> ""


# # no lazy or oneOf
# # proper error: ── CIRCULAR DEFINITION ───────────────────────────── examples/parser/repro.roc ─ 
# # ...
# a = b
# b = a


# lazy
# thread '<unnamed>' panicked at 'not yet implemented: recursive closures', crates/compiler/mono/src/layout.rs:1524:61
a = b
b = lazy (\{} -> a)


# # oneOf
# # thread '<unknown>' has overflowed its stack
# a = b
# b = oneOf [a]


# # lazy + oneOf - maybe duplicate
# # thread '<unnamed>' panicked at 'not yet implemented: recursive closures', crates/compiler/mono/src/layout.rs:1524:61
# a = b
# b = lazy (\{} -> oneOf [a])


# # annotations + lazy
# # thread 'main' panicked at 'Error in alias analysis: error in module ModName("UserApp"), function definition FuncName("\x02\x00\x00\x00\x10\x00\x00\x00\x99\x99\x05\xf3]s\xc8\xee"), definition of value binding ValueId(2): could not find func in module ModName("UserApp") with name FuncName("\x03\x00\x00\x00\x10\x00\x00\x00\x99\x99\x05\xf3]s\xc8\xee")', crates/compiler/gen_llvm/src/llvm/build.rs:4504:23
# a: Parser RawStr Str
# a = b
# b: Parser RawStr Str
# b = lazy (\{} -> a)


# # annotations + map + lazy
# # thread 'main' panicked at 'internal error: entered unreachable code: symbol/layout `16.IdentId(3)` ProcLayout {
# a: Parser RawStr Str
# a = b |> map (\_ -> "")
# b: Parser RawStr Str
# b = lazy (\{} -> a)


main: Str
main = 
    # dummy - just silence warnings
    s = parseStr dummy "" |> (Result.withDefault  "err")
    t = parseStr a "" |> (Result.withDefault  "err")
    Str.concat s t

travisstaloch avatar Oct 10 '22 20:10 travisstaloch