Stream: show and tell

Topic: roc-random


view this post on Zulip jan kili (Jan 18 2022 at 17:01):

:gift_heart: New library! Pseudo-random number generators: https://github.com/JanCVanB/roc-random
This is only a v0.1 release, with minimally-usable implementations of 8/16/32-bit PCG-RXS-M-XS. I intend to make its API more ergonomic in v0.2, so I'd love to hear how you think v0.1 feels to use! :smile:

view this post on Zulip Anton (Jan 18 2022 at 19:36):

I put example.roc and Random.roc in examples/cli(commit 2cbac921f), executed cargo run examples/cli/example.rocand got:

thread '<unnamed>' panicked at 'Found unbound type variables {102}
 in type alias `Random.Seed8` [] : [ Global('Seed8') (Alias `Num.U8`[ but actually (Alias `Num.Num` (Alias `Num.Integer` (Alias `Num.Unsigned8`[ but actually [ Private(`Num.@Unsigned8`) ] ])[ but actually [ Private(`Num.@Integer`) (Alias `Num.Unsigned8`[ but actually [ Private(`Num.@Unsigned8`) ] ]) ] ])[ but actually [ Private(`Num.@Num`) (Alias `Num.Integer` (Alias `Num.Unsigned8`[ but actually [ Private(`Num.@Unsigned8`) ] ])[ but actually [ Private(`Num.@Integer`) (Alias `Num.Unsigned8`[ but actually [ Private(`Num.@Unsigned8`) ] ]) ] ]) ] ]) ]) ]<102>', compiler/can/src/scope.rs:192:17

Did you happen to come across this error before @JanCVanB?

view this post on Zulip jan kili (Jan 18 2022 at 19:42):

:thinking: I haven't. That's a lot of but actually lol

view this post on Zulip jan kili (Jan 18 2022 at 20:00):

I just tested cargo run examples/cli/example.roc for the first time (I usually build roc for release and run it with that executable), and I get the same error message that you did. Investigating!

view this post on Zulip jan kili (Jan 18 2022 at 20:31):

Yes, building for release (cargo build --release) and using that executable (./target/release/roc examples/cli/example.roc) seems to work.

view this post on Zulip jan kili (Jan 18 2022 at 20:31):

Does anyone know if there is a difference between roc foo.roc and cargo run foo.roc?

view this post on Zulip jan kili (Jan 18 2022 at 20:32):

Whoa! This might be the culprit, does cargo run use a dev/debug runner by default?

[nix-shell:~/code/clones/roc/examples/cli]$ cargo run example.roc
    Finished dev [unoptimized + debuginfo] target(s) in 0.29s
     Running `/Users/jan/code/clones/roc/target/debug/roc example.roc`
...

view this post on Zulip jan kili (Jan 18 2022 at 20:34):

Okay, I have a solution for you @Anton , just use the release build/runner/option/thing! cargo run --release examples/cli/example.roc :smile:

view this post on Zulip Folkert de Vries (Jan 18 2022 at 20:35):

eh, what?

view this post on Zulip Folkert de Vries (Jan 18 2022 at 20:39):

but really, the presence of the --release flag matters for whether the compiler hits a panic or produces a working executable?

view this post on Zulip jan kili (Jan 18 2022 at 20:40):

It seems yes, is that bad?

[nix-shell:~/code/clones/roc]$ cargo run examples/cli/example.roc
    Finished dev [unoptimized + debuginfo] target(s) in 0.28s
     Running `target/debug/roc examples/cli/example.roc`
thread '<unnamed>' panicked at 'Found unbound type variables {102}
 in type alias `Random.Seed8` [] : [ Global('Seed8') (Alias `Num.U8`[ but actually (Alias `Num.Num` (Alias `Num.Integer` (Alias `Num.Unsigned8`[ but actually [ Private(`Num.@Unsigned8`) ] ])[ but actually [ Private(`Num.@Integer`) (Alias `Num.Unsigned8`[ but actually [ Private(`Num.@Unsigned8`) ] ]) ] ])[ but actually [ Private(`Num.@Num`) (Alias `Num.Integer` (Alias `Num.Unsigned8`[ but actually [ Private(`Num.@Unsigned8`) ] ])[ but actually [ Private(`Num.@Integer`) (Alias `Num.Unsigned8`[ but actually [ Private(`Num.@Unsigned8`) ] ]) ] ]) ] ]) ]) ]<102>', compiler/can/src/scope.rs:192:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
^C

[nix-shell:~/code/clones/roc]$ cargo run --release examples/cli/example.roc
    Finished release [optimized] target(s) in 0.29s
     Running `target/release/roc examples/cli/example.roc`
🔨 Rebuilding host... Done!
a: 18
b: 18
c: 15
d: 15
e: 17
f: 17
g: 14
h: 14
i: 12
j: 12
k: 19
l: 19
 :)

[nix-shell:~/code/clones/roc]$

view this post on Zulip jan kili (Jan 18 2022 at 20:42):

Context: This is for roc-random's example module (and the Random.roc library interface) copied (and only modified so that the platform path is correct) into the Roc repo's examples/cli/ dir.

view this post on Zulip Folkert de Vries (Jan 18 2022 at 21:01):

oh, ah, no it's fine given that specific error

view this post on Zulip jan kili (Jan 18 2022 at 21:18):

Can I improve the library to not fail in that way, or is it a temporary problem with the dev/debug runner?

view this post on Zulip Folkert de Vries (Jan 18 2022 at 21:41):

my guess is you're using closures a bunch

view this post on Zulip Folkert de Vries (Jan 18 2022 at 21:41):

and that is hitting this code path

view this post on Zulip Folkert de Vries (Jan 18 2022 at 21:42):

the check that fails is (clearly) not needed for producing programs, but usually when it fails something is wrong

view this post on Zulip Folkert de Vries (Jan 18 2022 at 21:42):

you can safely comment it locally though

view this post on Zulip jan kili (Jan 18 2022 at 22:34):

Thanks, I'd love to know more! What part should I comment(-out?), and which part of the code is a closure? Something related to Seed8?

view this post on Zulip Folkert de Vries (Jan 18 2022 at 22:48):

oh no the assert that makes it fail

view this post on Zulip jan kili (Jan 18 2022 at 22:59):

Ah, I guess what I'm actually asking is this: What can I do as a library author to prevent its users from experiencing this compiler panic when using the library with cargo run without --release?

view this post on Zulip Folkert de Vries (Jan 18 2022 at 23:06):

oh, nothing I think

view this post on Zulip Richard Feldman (Jan 18 2022 at 23:24):

this is one of those "something we believed was true turned out not to be, so crash" assertions

view this post on Zulip Richard Feldman (Jan 18 2022 at 23:25):

we want it to be noisy so we can investigate it and ideally solve the cause rather than the symptom

view this post on Zulip Richard Feldman (Jan 18 2022 at 23:27):

but we skip those checks altogether in release builds, so on the one hand we don't get the feedback but on the other hand it might happen to work anyway (as it seems to here) despite our assumption being broken :big_smile:

view this post on Zulip Folkert de Vries (Jan 18 2022 at 23:31):

oh, no this is something that should be true but we have slipped up

view this post on Zulip Folkert de Vries (Jan 18 2022 at 23:31):

it's just that usually the effect is not noticable

view this post on Zulip jan kili (Jan 18 2022 at 23:32):

Is cargo run designed for compiler debugging, app debugging, or app execution?

view this post on Zulip Folkert de Vries (Jan 18 2022 at 23:34):

mostly speed

view this post on Zulip Folkert de Vries (Jan 18 2022 at 23:34):

it compiles faster

view this post on Zulip Folkert de Vries (Jan 18 2022 at 23:35):

also you get more info if something panics, or if you use a debugger

view this post on Zulip jan kili (Jan 18 2022 at 23:45):

Cool, so then as a library author I'll test to both (release and nonrelease) and report issues with either?

view this post on Zulip Folkert de Vries (Jan 18 2022 at 23:51):

well that should not be necessary

view this post on Zulip Folkert de Vries (Jan 18 2022 at 23:51):

we'll get this sorted out now that we have an example that actually fails the assert

view this post on Zulip jan kili (Jan 18 2022 at 23:56):

High five for the co-discovery, @Anton ! :high_five:

view this post on Zulip jan kili (Jan 19 2022 at 07:00):

One last thing, the roc docs website generator is lovely: https://jancvanb.github.io/roc-random/

view this post on Zulip Lucas Rosa (Jan 19 2022 at 19:52):

that's pretty stuff :D


Last updated: Jul 06 2025 at 12:14 UTC