roc-lang / roc

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

roc build panic using roc-parser #6310

Open balhoff opened 10 months ago

balhoff commented 10 months ago

Using MacOS 14.2.1 with Apple Silicon CPU, roc_nightly-macos_apple_silicon-2023-12-23-6710b371a43:

roc check passes this code:

app "bug"
    packages {
        pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.0/bkGby8jb0tmZYsy2hg1E_B2QrCgcSTxdUlHtETwm5m4.tar.br",
        parser: "https://github.com/lukewilliamboswell/roc-parser/releases/download/0.3.0/-e3ebWWmlFPfe9fYrr2z1urfslzygbtQQsl69iH1qzQ.tar.br",
    }
    imports [
        pf.Stdout,
        parser.Core.{ oneOf, map, Parser, const, chompWhile, chompUntil, skip, keep },
        parser.String.{ string, codeunit, strFromUtf8, parseStr },
    ]
    provides [main] to pf

Concept : [
    AtomicConcept Str,
    Conjunction { left : Concept, right : Concept },
]

iri =
    const (\d -> d)
    |> skip (codeunit '<')
    |> keep (chompUntil '>')
    |> skip (codeunit '>')
    |> map strFromUtf8

atomicConcept : Parser _ Concept
atomicConcept =
    const AtomicConcept
    |> skip (string "AtomicConcept(")
    |> keep iri
    |> skip (codeunit ')')

conjunction : Parser _ Concept
conjunction =
    const (\left -> \right -> Conjunction { left, right })
    |> skip (string "Conjunction(")
    |> keep concept
    |> skip (chompWhile \c -> c == ' ')
    |> keep concept
    |> skip (codeunit ')')

concept : Parser _ Concept
concept = oneOf [atomicConcept, conjunction]

main =
    Stdout.line (parseStr concept "AtomicConcept(<http://example.org/A>)" |> Inspect.toStr)

but roc build outputs:

An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: https://github.com/roc-lang/roc/issues/new/choose
thread '<unnamed>' panicked at 'no lambda set found for (`19.IdentId(57)`, [
    InLayout(
        132,
    ),
    InLayout(
        113,
    ),
]): LambdaSet {
    set: [
        ( 19.48, [InLayout(STR)]),
        ( 19.57, [InLayout(122), InLayout(114)]),
    ],
    args: [
        InLayout(LIST_U8),
    ],
    ret: InLayout(
        40,
    ),
    representation: InLayout(
        103,
    ),
    full_layout: InLayout(
        113,
    ),
}', crates/compiler/mono/src/layout.rs:1597:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
balhoff commented 10 months ago

@lukewilliamboswell have you run into this issue? (maybe something to do with parsing a recursive type) Do you know of any workaround? (thanks for the library, by the way!)

lukewilliamboswell commented 10 months ago

Yes, I think this is the same as https://github.com/roc-lang/roc/issues/5749 but unfortunately is not a quick fix.

I don't have a good workaround for you. Maybe if you remove the type annotations altogether if might help?

balhoff commented 10 months ago

Yes, I think this is the same as https://github.com/roc-lang/roc/issues/5749 but unfortunately is not a quick fix.

Oh, that's too bad, looks like I may need to wait a while.

Maybe if you remove the type annotations altogether if might help?

Weirdly if I remove the type annotations it no longer type checks:

── TYPE MISMATCH ──────────────────────────────────────────────────── main.roc ─

This expression is used in an unexpected way:

43│  concept = oneOf [atomicConcept, conjunction]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This Core.oneOf call produces:

    Parser (List U8) [
        AtomicConcept Str,
        Conjunction {
            left : Str,
            right : Str,
        },
    ]

But you are trying to use it as:

    Parser (List U8) Str
balhoff commented 10 months ago

@lukewilliamboswell I did find a workaround; I noticed your lazy function. I redefined conjunction as:

conjunction = lazy \_ ->
    const (\left -> \right -> Conjunction { left, right })
    |> skip (string "Conjunction(")
    |> keep concept
    |> skip (chompWhile \c -> c == ' ')
    |> keep concept
    |> skip (codeunit ')')

This works! I guess there is still a compiler bug though.

balhoff commented 10 months ago

Well... it works for two concept expression types but not for three.