Stream: beginners

Topic: ✔ Question on the Repl embedded in the Website


view this post on Zulip Rolf Kreibaum (Jan 01 2024 at 23:04):

Hi, the website throws an error at me that I don't understand when I try to use the embedded repl:

image.png

Is this a known thing? Is my input even valid Roc?

view this post on Zulip Notification Bot (Jan 01 2024 at 23:05):

A message was moved here from #beginners > Issues related to type annotations by Rolf Kreibaum.

view this post on Zulip Brendan Hansknecht (Jan 01 2024 at 23:09):

Looks like a bug in the dev wasm backend

view this post on Zulip Rolf Kreibaum (Jan 01 2024 at 23:17):

Where would I go to report that? https://github.com/roc-lang/roc/issues or some other place?

view this post on Zulip Rolf Kreibaum (Jan 01 2024 at 23:21):

I found similar reports in the tracker, so I'll report it there.

view this post on Zulip Luke Boswell (Jan 01 2024 at 23:21):

Thank you

view this post on Zulip Rolf Kreibaum (Jan 01 2024 at 23:26):

Moved to https://github.com/roc-lang/roc/issues/6334 and the issue also links back to this chat. Thanks for the quick and friendly replies :-)

view this post on Zulip Notification Bot (Jan 01 2024 at 23:26):

Rolf Kreibaum has marked this topic as resolved.

view this post on Zulip Folkert de Vries (Jan 02 2024 at 12:37):

the problem is not specific to the web repl actually

  The rockin' roc repl
────────────────────────

Enter an expression, or :help, or :q to quit.

»  List.map [0.1,0.2,0.3] (\x -> x*x)
…
thread 'main' panicked at 'not yet implemented: NumMulWrap: layout, Builtin(Decimal)', crates/compiler/gen_dev/src/generic64/mod.rs:1500:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@Brendan Hansknecht what should "mulwrap" for decimals do? just disregard overflow and whatever happens happens?

view this post on Zulip Folkert de Vries (Jan 02 2024 at 12:39):

in practice that would mean that mulWrap is the same as mulSaturated. @Richard Feldman may also have an opinion here: what is the behavior we expect multiplication to have for decimals ?

view this post on Zulip Richard Feldman (Jan 02 2024 at 13:08):

mulWrap and the like only accept integers

view this post on Zulip Richard Feldman (Jan 02 2024 at 13:08):

so the behavior I expect is a type mismatch :big_smile:

view this post on Zulip Folkert de Vries (Jan 02 2024 at 13:51):

no? floats implement mulwrap too

view this post on Zulip Folkert de Vries (Jan 02 2024 at 13:52):

or another way to say this is: what would normal mul do for floats then when they overflow? is that just ignored then?

view this post on Zulip Richard Feldman (Jan 02 2024 at 13:57):

floats overflow to infinity

view this post on Zulip Richard Feldman (Jan 02 2024 at 13:58):

I guess there's an argument for extending it to work with any number type

view this post on Zulip Richard Feldman (Jan 02 2024 at 13:59):

for the sake of Dec performance

view this post on Zulip Richard Feldman (Jan 02 2024 at 13:59):

so I guess the answer for Dec would be that we would do whatever's fastest and gets the correct answer if there's no overflow

view this post on Zulip Richard Feldman (Jan 02 2024 at 13:59):

and then if there is overflow, it does something that's probably undesirable but not UB haha

view this post on Zulip Richard Feldman (Jan 02 2024 at 14:00):

so you'd reach for it for Dec when you want a but more perf and you're really confident it won't overflow

view this post on Zulip Richard Feldman (Jan 02 2024 at 14:01):

and if it does overflow you're ok with it silently getting the wrong answer if it means more perf

view this post on Zulip Folkert de Vries (Jan 02 2024 at 14:47):

for dec, I think saturated is equivalent in performance to any alternative

view this post on Zulip Folkert de Vries (Jan 02 2024 at 15:00):

in any case, NumWrap should not even be used here. That was a shortcut in the dev backend. I've implemented it properly here https://github.com/roc-lang/roc/pull/6337.

view this post on Zulip Folkert de Vries (Jan 02 2024 at 15:01):

and also fixed a bug that made roc_panic not work (crash worked before, I just messed up an argument type somewhere)

view this post on Zulip Folkert de Vries (Jan 02 2024 at 15:02):

btw, I assume @Brendan Hansknecht is there a reason not to use zig's builtin https://ziglang.org/documentation/master/#toc-mulWithOverflow ?

view this post on Zulip Brendan Hansknecht (Jan 02 2024 at 16:05):

mulWithOverflow doesn't work cause we don't know if it is an overflow until the Dec has been divided by 10^18.

view this post on Zulip Brendan Hansknecht (Jan 02 2024 at 16:06):

To multiple 2 decs, we multiply into a i256, then divide by 10^18.

view this post on Zulip Brendan Hansknecht (Jan 02 2024 at 16:07):

So overflow would be if that final result doesn't fit back into an i128


Last updated: Jul 06 2025 at 12:14 UTC