roc-lang / roc

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

Compiler tells me this is definitely a bug #4946

Open storyfeet opened 1 year ago

storyfeet commented 1 year ago

I'm trying to work out how to run a looping await in Roc, (I'm very new to this)

So I tried to put "main" as the callback (I probably did it wrong)

iguanas : U64                                            
iguanas = 2    
 main =         
    _ <- await (Stdout.line "How many birds")            
    birdCount <- await Stdin.line                         
    bn = when Str.toU64 birdCount is             
        Err _ -> 0                               
        Ok b -> b  
    total = Num.toStr ( bn + iguanas)
    _ <- await (Stdout.line "There are \(total) animals")    
    main                                                     

Anyhow, while I'd appreciate help making a looping await. I'm posting this because the compiler asked me to nicely.

I got the following message:

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 (`21.IdentId(27)`, [
    InLayout(
        21,
    ),
]): LambdaSet {
    set: [
        ( 21.27, [InLayout(21), InLayout(35)]),
        ( 21.32, [InLayout(1)]),
    ],
    args: [
        InLayout(
            1,
        ),
    ],
    ret: InLayout(
        1,
    ),
    representation: InLayout(
        36,
    ),
    full_layout: InLayout(
        37,
    ),
}', crates/compiler/mono/src/layout.rs:1500:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The backtrace looked like this:

   0: rust_begin_unwind
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:142:14
   2: roc_mono::layout::LambdaSet::find_lambda_name
   3: roc_mono::ir::find_lambda_name
   4: roc_mono::ir::with_hole
   5: roc_mono::ir::with_hole
   6: roc_mono::ir::from_can
   7: roc_mono::ir::from_can_when
   8: roc_mono::ir::from_can
   9: roc_mono::ir::specialize_variable
  10: roc_mono::ir::specialize_external_help
  11: roc_mono::ir::specialize_all
  12: roc_load_internal::file::run_task
  13: core::ops::function::FnOnce::call_once{{vtable.shim}}
ayazhafiz commented 1 year ago

Thanks for the report! Could you share the whole program this came from? I am seeing the following trace when I try to reproduce:

❯ target/release/roc dev examples/helloWorld.roc
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 (`21.IdentId(27)`, [
    InLayout(
        21,
    ),
    InLayout(
        62,
    ),
]): LambdaSet {
    set: [
        ( 21.27, [InLayout(21), InLayout(35)]),
        ( 21.32, [InLayout(1)]),
    ],
    args: [
        InLayout(
            1,
        ),
    ],
    ret: InLayout(
        1,
    ),
    representation: InLayout(
        36,
    ),
    full_layout: InLayout(
        37,
    ),
}', crates/compiler/mono/src/layout.rs:1500:17

(the is an addition of InLayout(62))

I believe this to be related to https://github.com/roc-lang/roc/issues/4905

storyfeet commented 1 year ago

This is the whole file

app "hello"
    packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.1.3/5SXwdW7rH8QAOnD71IkHcFxCmBEPtFSLAIkclPEgjHQ.tar.br" }
    imports [pf.Stdout, pf.Stdin, pf.Task.{await}]
    provides [main] to pf

iguanas : U64
iguanas = 2

main =
    _ <- await (Stdout.line "How many birds")
    birdCount <- await Stdin.line 
    bn = when Str.toU64 birdCount is
        Err _ -> 0
        Ok b -> b
    total = Num.toStr ( bn + iguanas)
    _ <- await (Stdout.line "There are \(total) animals") 
    main
Anton-4 commented 1 year ago

Anyhow, while I'd appreciate help making a looping await.

I think Task.loop may be useful for your case @storyfeet, you can see an example here.

ayazhafiz commented 1 year ago

Unfortunately, this is blocked on #5223.