Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic due to unwrap in crates/compiler/mono/src/ir.rs #7414

Open
a-lavis opened this issue Dec 26, 2024 · 1 comment
Open

panic due to unwrap in crates/compiler/mono/src/ir.rs #7414

a-lavis opened this issue Dec 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@a-lavis
Copy link
Contributor

a-lavis commented Dec 26, 2024

roc --version:

roc nightly pre-release, built from commit 0bf249afcbb on Mon Dec 23 09:14:40 UTC 2024

When running roc 3.roc where 3.roc is the following file:

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.tar.br",
    aoc: "https://github.com/lukewilliamboswell/aoc-template/releases/download/0.2.0/tlS1ZkwSKSB87_3poSOXcwHyySe0WxWOWQbPmp7rxBw.tar.br",
}

import pf.Stdin
import pf.Stdout
import pf.Utc
import aoc.AoC {
    stdin: Stdin.readToEnd,
    stdout: Stdout.write,
    time: \{} -> Utc.now {} |> Task.map Utc.toMillisSinceEpoch,
}

main =
    AoC.solve {
        year: 2024,
        day: 3,
        title: "Historian Hysteria",
        part1,
        part2,
    }

unwrap : Result ok err, Str -> ok
unwrap = \result, crashMsg ->
    when result is
        Ok value -> value
        Err _ -> crash crashMsg

clear = \state -> { state & mode: Nothing, first_operand: [], second_operand: [] }

list_to_num : List U8 -> I32
list_to_num = \list ->
    list |> Str.fromUtf8 |> unwrap "couldn't convert from UTF8" |> Str.toI32 |> unwrap "couldn't convert to int"

parse : Str, Bool -> Result Str _
parse = \input, do_and_dont ->
    Str.walkUtf8
        input
        {
            enabled: Bool.true,
            mode: Nothing,
            first_operand: [],
            second_operand: [],
            result: 0,
        }
        \state, char ->
            { enabled, mode, first_operand, second_operand, result } = state
            when mode is
                Nothing ->
                    when char is
                        'm' if enabled -> { state & mode: M }
                        'd' if do_and_dont -> { state & mode: D }
                        _ -> clear state

                M ->
                    when char is
                        'u' -> { state & mode: U }
                        _ -> clear state

                U ->
                    when char is
                        'l' -> { state & mode: L }
                        _ -> clear state

                L ->
                    when char is
                        '(' -> { state & mode: OpenParen }
                        _ -> clear state

                OpenParen ->
                    when char is
                        '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '0' ->
                            { state &
                                mode: FirstOperand,
                                first_operand: List.append first_operand char,
                            }

                        _ -> clear state

                FirstOperand ->
                    when char is
                        '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '0' ->
                            { state &
                                first_operand: List.append first_operand char,
                            }

                        ',' -> { state & mode: Comma }
                        _ -> clear state

                Comma ->
                    when char is
                        '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '0' ->
                            { state &
                                mode: SecondOperand,
                                second_operand: List.append second_operand char,
                            }

                        _ -> clear state

                SecondOperand ->
                    when char is
                        '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '0' ->
                            { state &
                                second_operand: List.append second_operand char,
                            }

                        ')' ->
                            { state &
                                mode: Nothing,
                                first_operand: [],
                                second_operand: [],
                                result: result + ((list_to_num first_operand) * (list_to_num second_operand)),
                            }

                        _ -> clear state

                D ->
                    when char is
                        'o' -> { state & mode: O }
                        _ -> clear state

                O ->
                    when char is
                        '(' -> { state & mode: DoOpenParen }
                        'n' -> { state & mode: N }
                        _ -> clear state

                DoOpenParen ->
                    when char is
                        ')' -> { state & mode: Nothing, enabled: Bool.true, first_operand: [], second_operand: [] }
                        _ -> clear state

                N ->
                    when char is
                        '\'' -> { state & mode: Apostrophe }
                        _ -> clear state

                Apostrophe ->
                    when char is
                        't' -> { state & mode: T }
                        _ -> clear state

                T ->
                    when char is
                        '(' -> { state & mode: DontOpenParen }
                        _ -> clear state

                DontOpenParen ->
                    when char is
                        ')' -> { state & enabled: Bool.false, first_operand: [], second_operand: [], mode: Nothing }
                        _ -> clear state
    |> .result
    |> Num.toStr
    |> Ok

## Implement your part1 and part2 solutions here
part1 : Str -> Result Str _
part1 = \input -> parse input Bool.false

part2 : Str -> Result Str _
part2 = \input -> parse input Bool.true

I immediately get the following error:

thread '<unnamed>' panicked at crates/compiler/mono/src/ir.rs:6246:56:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

and then it hangs and I have to CTRL+C out.

let spec_symbol_index = iter_lambda_set.next().unwrap().0;

It sounds like there are many known bugs with lambda sets, but just wanted to report this in case its helpful 😄

@a-lavis
Copy link
Contributor Author

a-lavis commented Dec 26, 2024

Ah just saw this:

https://roc.zulipchat.com/#narrow/channel/358903-advent-of-code/topic/2024.20Day.203/near/485763228

so changing partX : Str -> Result Str _ to part2 : Str -> Result Str [] fixes it. nice!

@Anton-4 Anton-4 added the bug Something isn't working label Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants