Stream: beginners

Topic: Compiler panic encoding list of lists?


view this post on Zulip Juliano (Dec 03 2022 at 15:01):

The code:

app "day1"
    packages { pf: "basic-cli/src/main.roc" }
    imports [pf.Stdout, pf.File, pf.Task, pf.Path, Json]
    provides [main] to pf

main =
    content <- "./aoc22/day1.txt"
        |> Path.fromStr
        |> File.readUtf8
        |> Task.onFail (\err ->
            when err is
                FileReadUtf8Err _path _fileErr -> crash "FileReadUtf8Err"
                FileReadErr _ _ -> crash "FileReadErr: asd"
        )
        |> Task.await

    split = content
        |> Str.split "\n"
        |> List.split ""

    split
        |> Encode.toBytes Json.toUtf8
        |> Str.fromUtf8
        |> Result.withDefault "err"
        |> Stdout.line

The error:

thread 'main' panicked at 'internal error: entered unreachable code: symbol/layout `pf.InternalTask.fromEffect` ProcLayout {
    arguments: [
        LambdaSet(
            LambdaSet {
                set: [
                    ( pf.Effect.30, [LambdaSet(LambdaSet { set: [( pf.Effect.76, [Union(NonRecursive([]))])], representation: Interned(12, PhantomData) }), LambdaSet(LambdaSet { set: [( pf.Stdout.3, [])], representation: Interned(3, PhantomData) })]),
                    ( pf.Effect.32, [Struct { field_order_hash: FieldOrderHash(0), field_layouts: [] }]),
                ],
                representation: Interned(
                    13,
                    PhantomData,
                ),
            },
        ),
    ],
    result: LambdaSet(
        LambdaSet {
            set: [
                ( pf.Effect.30, [LambdaSet(LambdaSet { set: [( pf.Effect.76, [Union(NonRecursive([]))])], representation: Interned(12, PhantomData) }), LambdaSet(LambdaSet { set: [( pf.Stdout.3, [])], representation: Interned(3, PhantomData) })]),
                ( pf.Effect.32, [Struct { field_order_hash: FieldOrderHash(0), field_layouts: [] }]),
            ],
            representation: Interned(
                13,
                PhantomData,
            ),
        },
    ),
    captures_niche: CapturesNiche(
        [],
    ),
} combo must be in DeclarationToIndex', crates/compiler/mono/src/borrow.rs:165:9

stack backtrace:
   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::borrow::DeclarationToIndex::get_param_offset
             at ./crates/compiler/mono/src/borrow.rs:165:9
   3: roc_mono::borrow::ParamMap::get_param_offset
             at ./crates/compiler/mono/src/borrow.rs:188:9
   4: roc_mono::borrow::ParamMap::get_symbol
             at ./crates/compiler/mono/src/borrow.rs:193:28
   5: roc_mono::borrow::BorrowInfState::collect_call
             at ./crates/compiler/mono/src/borrow.rs:509:26
   6: roc_mono::borrow::BorrowInfState::collect_expr
             at ./crates/compiler/mono/src/borrow.rs:679:27
   7: roc_mono::borrow::BorrowInfState::collect_stmt
             at ./crates/compiler/mono/src/borrow.rs:792:17
   8: roc_mono::borrow::BorrowInfState::collect_proc
             at ./crates/compiler/mono/src/borrow.rs:856:9
   9: roc_mono::borrow::infer_borrow
             at ./crates/compiler/mono/src/borrow.rs:83:17
  10: roc_mono::ir::Proc::insert_refcount_operations
             at ./crates/compiler/mono/src/ir.rs:398:41
  11: roc_load_internal::file::update
             at ./crates/compiler/load_internal/src/file.rs:2912:21
  12: roc_load_internal::file::state_thread_step
             at ./crates/compiler/load_internal/src/file.rs:1749:37
  13: roc_load_internal::file::load_multi_threaded::{{closure}}
             at ./crates/compiler/load_internal/src/file.rs:1970:23
  14: crossbeam_utils::thread::scope::{{closure}}
             at /home/juliano/.cargo/registry/src/github.com-1ecc6299db9ec823/crossbeam-utils-0.8.10/src/thread.rs:161:65
  15: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panic/unwind_safe.rs:271:9
  16: std::panicking::try::do_call
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:492:40
  17: __rust_try
  18: std::panicking::try
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:456:19
  19: std::panic::catch_unwind
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panic.rs:137:14
  20: crossbeam_utils::thread::scope
             at /home/juliano/.cargo/registry/src/github.com-1ecc6299db9ec823/crossbeam-utils-0.8.10/src/thread.rs:161:18
  21: roc_load_internal::file::load_multi_threaded
             at ./crates/compiler/load_internal/src/file.rs:1908:9
  22: roc_load_internal::file::load
             at ./crates/compiler/load_internal/src/file.rs:1543:35
  23: roc_load::load
             at ./crates/compiler/load/src/lib.rs:35:5
  24: roc_load::load_and_monomorphize
             at ./crates/compiler/load/src/lib.rs:132:11
  25: roc_cli::build::build_file
             at ./crates/cli/src/build.rs:95:23
  26: roc_cli::build
             at ./crates/cli/src/lib.rs:655:27
  27: roc::main
             at ./crates/cli/src/main.rs:52:17
  28: core::ops::function::FnOnce::call_once
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/ops/function.rs:248:5

view this post on Zulip Juliano (Dec 03 2022 at 15:04):

Oh, 'List.split' doesn't do what I expect, nvm.

I tried to write my own split by character, and I got another panic.

The code

app "day1"
    packages { pf: "basic-cli/src/main.roc" }
    imports [pf.Stdout, pf.File, pf.Task, pf.Path, Json]
    provides [main] to pf

splitListOn : List a, a -> List (List a)
splitListOn = \list, delim ->
    {cur, acc} = List.walk list {cur: [], acc: []} (\{cur, acc}, elem ->
        if elem == delim then
            {cur: [], acc: List.append acc cur}
        else
            {cur: List.append cur elem, acc: acc}
    )
    acc

main =
    content <- "./aoc22/day1.txt"
        |> Path.fromStr
        |> File.readUtf8
        |> Task.onFail (\err ->
            when err is
                FileReadUtf8Err _path _fileErr -> crash "FileReadUtf8Err"
                FileReadErr _ _ -> crash "FileReadErr: asd"
        )
        |> Task.await

    split = content
        |> Str.split "\n"
        |> splitListOn ""

    split
        |> Encode.toBytes Json.toUtf8
        |> Str.fromUtf8
        |> Result.withDefault "err"
        |> Stdout.line

The error:

thread 'main' panicked at 'internal error: entered unreachable code: symbol/layout `pf.InternalTask.fromEffect` ProcLayout {
    arguments: [
        LambdaSet(
            LambdaSet {
                set: [
                    ( pf.Effect.30, [LambdaSet(LambdaSet { set: [( pf.Effect.76, [Union(NonRecursive([]))])], representation: Interned(12, PhantomData) }), LambdaSet(LambdaSet { set: [( pf.Stdout.3, [])], representation: Interned(3, PhantomData) })]),
                    ( pf.Effect.32, [Struct { field_order_hash: FieldOrderHash(0), field_layouts: [] }]),
                ],
                representation: Interned(
                    13,
                    PhantomData,
                ),
            },
        ),
    ],
    result: LambdaSet(
        LambdaSet {
            set: [
                ( pf.Effect.30, [LambdaSet(LambdaSet { set: [( pf.Effect.76, [Union(NonRecursive([]))])], representation: Interned(12, PhantomData) }), LambdaSet(LambdaSet { set: [( pf.Stdout.3, [])], representation: Interned(3, PhantomData) })]),
                ( pf.Effect.32, [Struct { field_order_hash: FieldOrderHash(0), field_layouts: [] }]),
            ],
            representation: Interned(
                13,
                PhantomData,
            ),
        },
    ),
    captures_niche: CapturesNiche(
        [],
    ),
} combo must be in DeclarationToIndex', crates/compiler/mono/src/borrow.rs:165:9
stack backtrace:
   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::borrow::DeclarationToIndex::get_param_offset
             at ./crates/compiler/mono/src/borrow.rs:165:9
   3: roc_mono::borrow::ParamMap::get_param_offset
             at ./crates/compiler/mono/src/borrow.rs:188:9
   4: roc_mono::borrow::ParamMap::get_symbol
             at ./crates/compiler/mono/src/borrow.rs:193:28
   5: roc_mono::borrow::BorrowInfState::collect_call
             at ./crates/compiler/mono/src/borrow.rs:509:26
   6: roc_mono::borrow::BorrowInfState::collect_expr
             at ./crates/compiler/mono/src/borrow.rs:679:27
   7: roc_mono::borrow::BorrowInfState::collect_stmt
             at ./crates/compiler/mono/src/borrow.rs:792:17
   8: roc_mono::borrow::BorrowInfState::collect_proc
             at ./crates/compiler/mono/src/borrow.rs:856:9
   9: roc_mono::borrow::infer_borrow
             at ./crates/compiler/mono/src/borrow.rs:83:17
  10: roc_mono::ir::Proc::insert_refcount_operations
             at ./crates/compiler/mono/src/ir.rs:398:41
  11: roc_load_internal::file::update
             at ./crates/compiler/load_internal/src/file.rs:2912:21
  12: roc_load_internal::file::state_thread_step
             at ./crates/compiler/load_internal/src/file.rs:1749:37
  13: roc_load_internal::file::load_multi_threaded::{{closure}}
             at ./crates/compiler/load_internal/src/file.rs:1970:23
  14: crossbeam_utils::thread::scope::{{closure}}
             at /home/juliano/.cargo/registry/src/github.com-1ecc6299db9ec823/crossbeam-utils-0.8.10/src/thread.rs:161:65
  15: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panic/unwind_safe.rs:271:9
  16: std::panicking::try::do_call
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:492:40
  17: __rust_try
  18: std::panicking::try
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:456:19
  19: std::panic::catch_unwind
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panic.rs:137:14
  20: crossbeam_utils::thread::scope
             at /home/juliano/.cargo/registry/src/github.com-1ecc6299db9ec823/crossbeam-utils-0.8.10/src/thread.rs:161:18
  21: roc_load_internal::file::load_multi_threaded
             at ./crates/compiler/load_internal/src/file.rs:1908:9
  22: roc_load_internal::file::load
             at ./crates/compiler/load_internal/src/file.rs:1543:35
  23: roc_load::load
             at ./crates/compiler/load/src/lib.rs:35:5
  24: roc_load::load_and_monomorphize
             at ./crates/compiler/load/src/lib.rs:132:11
  25: roc_cli::build::build_file
             at ./crates/cli/src/build.rs:95:23
  26: roc_cli::build
             at ./crates/cli/src/lib.rs:655:27
  27: roc::main
             at ./crates/cli/src/main.rs:52:17
  28: core::ops::function::FnOnce::call_once
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/ops/function.rs:248:5

view this post on Zulip Juliano (Dec 03 2022 at 15:22):

removing |> splitListOn "" made the panic go away and showed me other compilation errors.

some were weird, some were good:

── DUPLICATE NAME ───────────────────────────────────────────── aoc22/day1.roc ─

The cur name is first defined here:

8│      {cur, acc} = List.walk list {cur: [], acc: []} (\{cur, acc}, elem ->
        ^^^^^^^^^^

But then it's defined a second time here:

8│      {cur, acc} = List.walk list {cur: [], acc: []} (\{cur, acc}, elem ->
                                                         ^^^^^^^^^^

Since these variables have the same name, it's easy to use the wrong
one on accident. Give one of them a new name.


── DUPLICATE NAME ───────────────────────────────────────────── aoc22/day1.roc ─

The acc name is first defined here:

8│      {cur, acc} = List.walk list {cur: [], acc: []} (\{cur, acc}, elem ->
        ^^^^^^^^^^

But then it's defined a second time here:

8│      {cur, acc} = List.walk list {cur: [], acc: []} (\{cur, acc}, elem ->
                                                         ^^^^^^^^^^

Since these variables have the same name, it's easy to use the wrong
one on accident. Give one of them a new name.


── TYPE MISMATCH ────────────────────────────────────────────── aoc22/day1.roc ─

This 2nd argument to isEq has an unexpected type:

9│          if elem == delim then
                       ^^^^^

This delim value is a:

    a

But isEq needs its 2nd argument to be:

    a | a has Eq

Tip: The type annotation uses the type variable a to say that this
definition can produce any type of value. But in the body I see that
it will only produce an instance of the ability Eq of a single
specific type. Maybe change the type annotation to be more specific?
Maybe change the code to be more general?


── CIRCULAR DEFINITION ──────────────────────────────────────── aoc22/day1.roc ─

The cur definition is causing a very tricky infinite loop:

8│      {cur, acc} = List.walk list {cur: [], acc: []} (\{cur, acc}, elem ->
         ^^^

The cur value depends on itself through the following chain of
definitions:

    ┌─────┐
    │     cur
    │     ↓
    │     acc
    └─────┘

────────────────────────────────────────────────────────────────────────────────

4 errors and 1 warning found in 2987 ms.

view this post on Zulip Juliano (Dec 03 2022 at 15:26):

the Eq restriction on a was :thumbs_up:

the duplicate names were silly, i think? i don't think there's a problem with:

x = List.map [1] (\x -> x+1)
# or closer to what i did
{a} = {a: 1} |> (\{a} -> {a: a+1})

and with record destructuring we _have_ to use the same name

the circular dependency, i've no idea how the compiler got there

view this post on Zulip Juliano (Dec 03 2022 at 15:27):

after working around compilation errors, re-adding |> splitListOn "" didn't panic anymore

view this post on Zulip Brendan Hansknecht (Dec 03 2022 at 16:46):

Maybe not helpful here, but definitely try running roc check ... when you hit errors like this. It is a lot less likely to crash and will hopefully show the issue that is causing the crash.

view this post on Zulip Brendan Hansknecht (Dec 03 2022 at 16:48):

Also, roc doesn't allow shadowing so the circular definition is probably from naming the returned value cur and having cur as an argument to the lambda. Roc is trying to make them the same thing. Which is why it is getting such a messy error, i think.

(At least that is my guess)

view this post on Zulip Brendan Hansknecht (Dec 03 2022 at 16:50):

Also, you can change name with record destructoring: \{a: newNameA} -> #use newNameA

view this post on Zulip OliverHR (Dec 03 2022 at 18:05):

Hi everyone a Roc newbie here. I'm trying to follow the tutorial but I get stuck on the "Building an Application" section.

$ roc dev
── FILE NOT FOUND ──────────────────────────────────────────────── UNKNOWN.roc ─

I am looking for this file, but it's not there:

    https://github.com/roc-lang/basic-cli/releases/download/0.1.1/zAoiC9xtQPHywYk350_b7ust04BmWLW00sjb9ZPtSQk.tar.br

Is the file supposed to be there? Maybe there is a typo in the file
name?%

view this post on Zulip Anton (Dec 03 2022 at 18:20):

Hi Oliver, do you happen to be on a macos x86_64 device?

view this post on Zulip OliverHR (Dec 03 2022 at 18:22):

Hi Anton, yep I'm using an intel macbook running macOS Monterey 12.6.1

view this post on Zulip Anton (Dec 03 2022 at 18:29):

A workaround is mentioned in this issue, I hope to resolve the issue next week. I also have a PR in the oven that adds some warnings in the docs for this issue.

view this post on Zulip OliverHR (Dec 03 2022 at 18:36):

@Anton before I read your comment I've tried decompressing the file tar-brotli and used in the packages section but it didn't work.

But I tried what you suggested on the github issue and it worked!, thank you very much!

app "cli-tutorial"
    packages { pf: "basic-cli/src/main.roc" }
    imports [pf.Stdout]
    provides [main] to pf

main =
    Stdout.line "Hello, World!"

view this post on Zulip Anton (Dec 03 2022 at 18:44):

Happy to help :)

view this post on Zulip OliverHR (Dec 03 2022 at 18:58):

Anton said:

A workaround is mentioned in this issue, I hope to resolve the issue next week. I also have a PR in the oven that adds some warnings in the docs for this issue.

@Anton now that you mention I think is also worth to mention that in this document: "Roc installation guide for x86_64 macOS systems"

You can't select the zig version

# Install the Zig compiler, for apps with Zig-based platforms:

brew install zig@0.9.1         #   <--- this versioned packages are no longer available

We need to install just the "zig" package:

brew install zig

Current zig version (at the moment of the comment is 0.10.0) so I don't know if this affects.

view this post on Zulip Anton (Dec 03 2022 at 18:59):

Yes, that is a problem, zig 0.10.0 will not work. I'll take a look.

view this post on Zulip Anton (Dec 03 2022 at 19:29):

A workaround:

I'll update the documentation tomorrow.

view this post on Zulip Anton (Dec 03 2022 at 19:29):

Thanks for bringing this to my attention @OliverHR :)

view this post on Zulip Brian Carroll (Dec 03 2022 at 19:41):

If you are also using Zig for other projects too, you can set the environment variable ROC_ZIG to a specific path for Roc to use.

view this post on Zulip Luke Boswell (Dec 03 2022 at 19:58):

I didnt know you can change name with destructuring... thats cool!

view this post on Zulip OliverHR (Dec 03 2022 at 20:09):

@Anton /@Brian Carroll thank for the suggestions, I've installed manually zig 0.9.1 It was pretty straightforward, and to don't mess with my zsh/bash config I use direnv, so in this way with a .envrc file I set the environment vars I need.

view this post on Zulip Juliano (Dec 03 2022 at 22:06):

that roc check tip was pure gold @Brendan Hansknecht


Last updated: Jul 05 2025 at 12:14 UTC