Hi,
I would like to do AoC with Roc again. What is the story this year? Is the new compiler ready enough? I found the neightly, but I was not sure what to do with it. When I use the last release of basic-cli, I get error.PlatformNotSupported.
Is it possible, to use the new compiler for simple stuff like AoC?
Is it correct, that the new syntax is only implemented in the new compiler? I don't want do to AoC with the old syntax.
The hope is that the new compiler will be ready of AOC this year. Though I guess time is getting pretty tight now.
We should have nearly all the pieces to make a minimal AOC platform and use it with the interpreter (which will hopefully fill out with enough buiiltins shortly). Likely will take a bit longer to get something like basic cli ported, but I think it should be doable in this timeline.
But right now, we just have some really basic and simple platforms working and a solid amount of missing buiiltins and such.
From my perspective the „easiest“ access point for most curious people would be the web playground. If that’s utilizing the new syntax + some way to import the individualized inputs it would likely enable the furthest reach
yeah I'm working on getting a basic platform working - getting close!
I would also love to have something in the playground that we can use for AoC :smiley:
Is there any update on whether the new compiler will be ready for AoC this year?
If we make it, it will be tight
I was also hoping to use Roc for this year's AoC after I heard Richard talking about a first version hopefully being available in time for it. Fingers crossed I guess. :blush:
We are several lurkers that feel the same! :fingers_crossed:, but don't stress it, it's better to not force something out
Here's a solution to 2024 Day 1 -- with a few workarounds (running from a PR branch)
app [main!] { pf: platform "./platform/main.roc" }
import pf.Stdout
# AoC 2024 Day 1 Solution
#
# Current Roc limitations prevent full automation:
# - Records in fold accumulators cause compiler panic
# - Platform doesn't implement realloc (can't grow lists dynamically)
# - to_utf8 has type issues
#
# So we pre-sort the input manually and create pairs
# Original input:
# 3 4
# 4 3
# 2 5
# 1 3
# 3 9
# 3 3
#
# Left list sorted: [1, 2, 3, 3, 3, 4]
# Right list sorted: [3, 3, 3, 4, 5, 9]
# Pre-computed pairs from sorted lists
pairs = [(1, 3), (2, 3), (3, 3), (3, 4), (3, 5), (4, 9)]
# Absolute difference
abs_diff : Dec, Dec -> Dec
abs_diff = |a, b| if a > b { a - b } else { b - a }
main! = || {
# Sum the distances using fold
total = pairs.fold(0, |acc, pair| {
(left, right) = pair
acc + abs_diff(left, right)
})
Stdout.line!("Total distance: ${total.to_str()}")
}
$ roc version
Roc compiler version debug-056b5e2a
$ roc test/fx/app_test5.roc
Total distance: 11.0
we're getting closer - it's a start! :smiley:
I removed the ListWasEmpty post, because it has been handled in #bugs > List builtins crash roc when returning tag
has anyone tried doing any of the 2024 stuff? we have a bunch more bugfixes and stdlib additions, and I'm curious what remaining bugs/missing things there are
I just took a quick pass at 2024 day one, like Luke did before, but ran into some issues.
(I haven't debugged at all yet, figured I'd post for viz before looking diving in)
The first error:
app [main!] { pf: platform "./platform/main.roc" }
import pf.Stdout
test_input =
"""3 4
"""4 3
"""2 5
"""1 3
"""3 9
"""3 3
run = |input| {
_input_lines = input.split_on("\n")
}
main! = || {
run(test_input)
}
Errors with:
Roc crashed: Builtin.Num.Dec does not implement split_on
I put the same code into a snapshot and the inferred types are:
(defs
(patt (type "Str"))
(patt (type "a -> {} where [a.split_on : a, Str -> _ret]"))
(patt (type "({}) -> {}")))
Which look correct, so not sure where the Dec is coming from
I also tried a simpler version of just splitting the puzzle text and printing in a for loop:
app [main!] { pf: platform "./platform/main.roc" }
import pf.Stdout
test_input =
"""3 4
"""4 3
"""2 5
"""1 3
"""3 9
"""3 3
main! = || {
for line in test_input.split_on("\n") {
Stdout.line!(line)
}
}
And this errors with:
└─ ❯ ./zig-out/bin/roc test/aoc2024/one.roc
3 4
thread 143170 panic: Host allocation failed
???:?:?: 0x100494a6f in ??? (roc_run_883903227)
???:?:?: 0x1005d236b in ??? (roc_run_883903227)
???:?:?: 0x10056dc73 in ??? (roc_run_883903227)
???:?:?: 0x100537c3f in ??? (roc_run_883903227)
???:?:?: 0x10053669f in ??? (roc_run_883903227)
???:?:?: 0x10053982f in ??? (roc_run_883903227)
???:?:?: 0x10053dfcf in ??? (roc_run_883903227)
???:?:?: 0x10059559b in ??? (roc_run_883903227)
???:?:?: 0x100549267 in ??? (roc_run_883903227)
???:?:?: 0x1005258e3 in ??? (roc_run_883903227)
???:?:?: 0x1005232ab in ??? (roc_run_883903227)
???:?:?: 0x100522d0f in ??? (roc_run_883903227)
???:?:?: 0x1004947f7 in ??? (roc_run_883903227)
???:?:?: 0x100495103 in ??? (roc_run_883903227)
???:?:?: 0x196425d53 in ??? (???)
???:?:?: 0x0 in ??? (???)
error: Child process /Users/jaredramirez/Library/Caches/roc/080b753687f4b2c24027986b2e400969/temp/roc-tmp-XSwGdYZ8MR0wOSCaEKMX41QAAVAWys37/roc_run_883903227 killed by signal: 6
error: Child process aborted (SIGABRT)
Multi line string syntax is double backslash
(these are with the platform in fx also)
Luke Boswell said:
Multi line string syntax is double backslash
oh oops! lemme fix that and try again
Can you try on my PR branch please?
https://github.com/roc-lang/roc/pull/8505
I've upgraded the fx platform and added lots more instrumentation around allocations
I'm looking at this issue now
I noticed a similar issue before, but this is a nice repro I think where we try to make an infinite sized allocation
i get the same error on that branch, but it seems that it may have to do with the size of the string being split.
with this input string, it prints each line & exits
input =
\\a x
\\b x
\\c x
\\d x
but with one more row, it fails with Host error: allocation failed, out of memory
input =
\\a x
\\b x
\\c x
\\d x
\\e x
Same error without multiline:
input = "a x \nb x \nc x \nd x"
but interestingly, this version is the shorter string, but it still fails
Then, possibly related, but maybe not, the program runs no problem with this string:
input = "aaaaaaaaaaaaaaaaaaaaaaa" # there are 23 "a"s
But with this one
input = "aaaaaaaaaaaaaaaaaaaaaaaa" # there are 24 "a"s
It prints then segfaults:
aaaaaaaaaaaaaaaaaaaaaaaa
error: Child process /Users/jaredramirez/Library/Caches/roc/70dead706a5693ea80a872968b332d57/temp/roc-tmp-vkBVgcVhBIIO8OnLfRmSafE27WMwYoRp/roc_run_3325363814 killed by signal: 11
error: Child process crashed with segmentation fault (SIGSEGV)
From Claude
I see the issue! Looking at the trace:
1. DECREF str ptr=0x105660010 len=35 cap=35 - The original test_input string gets decremented
2. Later INCREF str ptr=0x105660010 len=5 cap=35 - Trying to incref the same string (as a seamless slice)
3. Finally INCREF str ptr=0x105660010 len=5 cap=5 - cap changed from 35 to 5, indicating memory corruption
The original string is being DECREF'd before the seamless slices (from split_on) are done using it.
I can look at the long string segfault next
Found the bug! The allocation is trying to allocate size=9223372036854775829 bytes, which is 0x8000000000000015 - that's 21 | SEAMLESS_SLICE_BIT!
The issue is in RocStr.clone() - it uses str.length directly instead of str.len(), so for seamless slices it includes the SEAMLESS_SLICE_BIT in the allocation size!
That bug was masking another bug too, there's another double decref with the test_input binding
@Brendan Hansknecht @Richard Feldman in a method call like test_input.split_on(...) we should just be incrementing the refcount on the string right?
Anyway, I've got a solid fix for these issues now
I'm a little concerned we might be cloning unnecessarily though so just investigating a little more.
Ok, all fixed without any cloning in https://github.com/roc-lang/roc/pull/8505
For split_on, I would expect to:
Oh wait, does split on only split once or many times?
I think many times
Hello, I don't have the time to make a minimal repro until this evening (european) but here's a small working program (Robot Simulator from Exercism : https://exercism.org/tracks/roc/exercises/robot-simulator) with a list of problems I ran into :
app [main!] { pf: platform "./platform/main.roc" }
import pf.Stdout
import pf.Stderr
Direction : [North, East, South, West]
Robot : { x : Dec, y : Dec, direction : Direction }
move : Robot, Str -> Robot
move = |robot, instructions| {
Str.to_utf8(instructions)
.fold(
robot,
|robot_state, robot_move| {
match (robot_move) {
'A' => robot_state->advance()
'L' => robot_state->turn(Left)
'R' => robot_state->turn(Right)
}
},
)
}
advance = |robot| {
match (robot.direction) {
North => { ..robot, y: robot.y + 1 }
South => { ..robot, y: robot.y - 1 }
East => { ..robot, x: robot.x + 1 }
West => { ..robot, x: robot.x - 1 }
}
}
turn = |robot, left_or_right| {
match ((robot.direction, left_or_right)) {
(North, Left) => { ..robot, direction: West }
(North, Right) => { ..robot, direction: East }
(East, Left) => { ..robot, direction: North }
(East, Right) => { ..robot, direction: South }
(South, Left) => { ..robot, direction: East }
(South, Right) => { ..robot, direction: West }
(West, Left) => { ..robot, direction: South }
(West, Right) => { ..robot, direction: North }
}
}
main! = || {
dbg move({ x: 7, y: 3, direction: North }, "RAALAL")
}
Well first, I'm not parsing the instructions string : so I should get an unexhaustive match error. But I don't.
If you replace Str.to_utf8(instructions) by instructions.to_utf8() : you get an error => Roc crashed: str_to_utf8 requires return type info
If you replace Dec by I64, you get an error =>
thread 111198 panic: access of union field 'int' while field 'dec' is active
/home/user/roc/src/eval/interpreter.zig:1992:55: 0x5c9ae8 in callLowLevelBuiltin (mod.zig)
.int => |l| try out.setInt(l + rhs.int),
^
/home/user/roc/src/eval/interpreter.zig:10153:62: 0x621767 in applyContinuation (mod.zig)
var result = try self.callLowLevelBuiltin(low_level.op, &args, roc_ops, null);
^
/home/user/roc/src/eval/interpreter.zig:6769:71: 0x418440 in evalWithExpectedType (mod.zig)
const should_continue = try self.applyContinuation(&work_stack, &value_stack, cont, roc_ops);
^
/home/user/roc/src/eval/interpreter.zig:464:59: 0x3bf1f7 in evaluateExpression (mod.zig)
const result_value = self.evalWithExpectedType(header.body_idx, roc_ops, null) catch |err| {
^
/home/user/roc/src/interpreter_shim/main.zig:169:39: 0x3a0c55 in evaluateFromSharedMemory (main.zig)
try interpreter.evaluateExpression(expr_idx, ret_ptr, roc_ops, arg_ptr);
^
/home/user/roc/src/interpreter_shim/main.zig:68:29: 0x3a000e in roc_entrypoint (main.zig)
evaluateFromSharedMemory(entry_idx, ops, ret_ptr, arg_ptr) catch |err| {
^
/home/user/roc/test/fx/platform/host.zig:202:23: 0x27c57f in platform_main (host.zig)
roc__main_for_host(&roc_ops, @as(*anyopaque, @ptrCast(&ret)), @as(*anyopaque, @ptrCast(&args)));
^
/home/user/roc/test/fx/platform/host.zig:85:18: 0x27c708 in main (host.zig)
platform_main() catch |err| {
^
src/env/__libc_start_main.c:95:2: 0x95907c in libc_start_main_stage2 (src/env/__libc_start_main.c)
Unwind error at address `exe:0x95907c` (error.MissingFDE), trace may be incomplete
???:?:?: 0x0 in ??? (???)
error: Child process /home/user/.cache/roc/f5270dd847a7a6c61bb1e95f0925684e/temp/roc-tmp-gWEfXWyUa3joiowSwIiGq8mgzL880aKs/roc_run_3406543992 killed by signal: 6
error: Child process aborted (SIGABRT)
Also, not an error but a question : what's the replacement of record optional fields, I forgot ?
Thanks, amazing work !
I can address part of this, although we don't yet have exhaustiveness checking implemented yet, and realistically won't have it in time for Advent of Code :smile:
fix for the instructions.to_utf8() part: https://github.com/roc-lang/roc/pull/8514
Hello !
I stumbled upon Roc's New Compiler for Advent of Code 2025 today but I cannot get the hello world snippet to compile because of a segfault.
I'm using Ubuntu 24.04.3 (x86_64), I downloaded the nightly build of today and here is the output:
❯ ./roc version
Roc compiler version release-fast-77e8bbc1
❯ ./roc app.roc
error: Child process /home/.cache/roc/eeb72bc7915352738b41dafe7bc88401/temp/roc-tmp-2ec6QLmttmiRNiAvuG7tvzbfwtzEQqBA/roc_run_1662736024 killed by signal: 11
error: Child process crashed with segmentation fault (SIGSEGV)
❯ cat /home/.cache/roc/eeb72bc7915352738b41dafe7bc88401/temp/roc-tmp-2ec6QLmttmiRNiAvuG7tvzbfwtzEQqBA/roc_run_1662736024
ELF>@8@8@@@ @ � Q�tdzRx
Linker: LLD 20.1.2 (https://github.com/roc-lang/roc-bootstrap fe08b059a848f15dc43b2f23e2c0a500360356c9)����(��.eh_frame.comment.symtab.shstrtab.strtabroc_platform_shimroc_interpreter_shimcompiler_rt� �
0hp�.&�4
I would love to give more detail about the error but I don't know how to right now ^^
Any ideas ?
Have a nice day !
Can you try again with latest main? I think that error is fixed now. So zig build roc, ./zig-out/bin/roc app.roc
I tried the same on latest main (6a1585d9132bd14360f0475eabe0d6e99a03157f) and get:
./zig-out/bin/roc test/fx/appc.roc
error: Child process /home/niclas/.cache/roc/8c41db55289d8fdb9fc8557b96c7b123/temp/roc-tmp-ufrkqUSBk3CqRzmIeoPi7r1rrr5sFltU/roc_run_349899816 killed by signal: 11
error: Child process crashed with segmentation fault (SIGSEGV)
The Hello World is from here: https://gist.github.com/rtfeldman/f46bcbfe5132d62c4095dfa687bb9aa4
app [main!] { pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/0.1-test/7iDKk44no3gF9Nrh2VyF8Y5yvy1jUBhrbhHURN1WQptB.tar.zst" }
import pf.Stdout
main! = |_args| {
Stdout.line!("Hello, World!")
Ok({})
}
It's not just that snippet though, I get the same result with test/fx/app.roc.
NixOS x86, ran git clean -dfx before building.
Might be worth clearing the cached app as well in case it is bugged: rm -rf /home/niclas/.cache/roc/8c41db55289d8fdb9fc8557b96c7b123
I deleted the whole cache (rm -rf /home/niclas/.cache/roc) and re-ran with the same result
After clearing the Roc cache (and git clean -dfx again for good measure) I no longer segfault when running the built-in example, ./zig-out/bin/roc test/fx/app.roc . Now I get:
error: Failed to resolve platform spec './platform/main.roc': error.PlatformNotSupported
But the hello world snippet still gives:
./zig-out/bin/roc test/fx/appc.roc
error: Child process /home/niclas/.cache/roc/8c41db55289d8fdb9fc8557b96c7b123/temp/roc-tmp-8ME9qm3IFOEZKp2Fc77x6gEUOLIe31E5/roc_run_349899816 killed by signal: 11
error: Child process crashed with segmentation fault (SIGSEGV)
Anton said:
Can you try again with latest main? I think that error is fixed now. So
zig build roc,./zig-out/bin/roc app.roc
Hey Anton,
Thanks for the answer !
I built the main branch of roc with zig 0.15.2 and the hello world snippet still segfault:
❯ ./roc/zig-out/bin/roc version
Roc compiler version debug-6a1585d9
~/tools
❯ ./roc/zig-out/bin/roc app.roc
error: Child process /home/.cache/roc/8c41db55289d8fdb9fc8557b96c7b123/temp/roc-tmp-VSWr14wnLgGfgOewpkXp506M6pHXJBSu/roc_run_1662736024 killed by signal: 11
error: Child process crashed with segmentation fault (SIGSEGV)
If it helps, I send the resulting executable as attachment: it's way larger than my previous attempt.
roc_run_1662736024
I'm on linux x86_64 and getting a segfault also with the hello world snippet from the gist
Roc compiler version debug-5e229e20I believe I also tried using the fx platform at some time in the past and got a similar
error: Failed to resolve platform spec './platform/main.roc': error.PlatformNotSupported
as above, also.
I've done some mucking around with the zig template platform, but was unable to get it to work (still sigsev). But, I was able to get the fx platform to work. Which I think is enough to do the experimenting I want to do right now.
Niclas Ahden said:
I tried the same on latest
main(6a1585d9132bd14360f0475eabe0d6e99a03157f) and get:./zig-out/bin/roc test/fx/appc.roc error: Child process /home/niclas/.cache/roc/8c41db55289d8fdb9fc8557b96c7b123/temp/roc-tmp-ufrkqUSBk3CqRzmIeoPi7r1rrr5sFltU/roc_run_349899816 killed by signal: 11 error: Child process crashed with segmentation fault (SIGSEGV)The Hello World is from here: https://gist.github.com/rtfeldman/f46bcbfe5132d62c4095dfa687bb9aa4
app [main!] { pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/0.1-test/7iDKk44no3gF9Nrh2VyF8Y5yvy1jUBhrbhHURN1WQptB.tar.zst" } import pf.Stdout main! = |_args| { Stdout.line!("Hello, World!") Ok({}) }
It's not just that snippet though, I get the same result withtest/fx/app.roc.NixOS x86, ran
git clean -dfxbefore building.
I was able to reproduce this
I reproduced both issues on the latest commit (2ac12ee62127e86e54efba4942b063719add7585):
$ zig build roc
Cleared roc cache at /home/niclas/.cache/roc
$ ./zig-out/bin/roc test/fx/app.roc
error: Failed to resolve platform spec './platform/main.roc': error.PlatformNotSupported
# Paste the Hello World snippet into appc.roc
$ v test/fx/appc.roc
$ ./zig-out/bin/roc test/fx/appc.roc
error: Child process /home/niclas/.cache/roc/098d65273b3e7fea486849c277601edd/temp/roc-tmp-ed0z1y0nLSGpmXqLhaHQ1DDSLnhYbU8R/roc_run_349899816 killed by signal: 11
error: Child process crashed with segmentation fault (SIGSEGV)
it would be great to get some ci around this, since we seem to have had it working and then redressed it without a CI failure letting us know :smile:
Yeah, I'll get on that
@Niclas Ahden, does your appc.roc still contain the platform url?
Yes, exactly the text in the reply you quoted
As a temporary workaround; please work inside the repo with the test/fx platform there, but run zig build test first.
You can modify the app.roc here and then run it with ./zig-out/bin/roc app.roc
https://github.com/roc-lang/roc/blob/2ac12ee62127e86e54efba4942b063719add7585/test/fx/app.roc#L1
Confirming that running zig build test did solve the PlatformNotSupported issue. I can now:
./zig-out/bin/roc test/fx/app.roc
Hello from stdout!
Line 1 to stdout
Line 2 to stderr
Line 3 to stdout
Error from stderr!
(the Hello World example (appc.roc) still segfaults)
Niclas Ahden said:
I reproduced both issues on the latest commit (
2ac12ee62127e86e54efba4942b063719add7585):$ zig build roc Cleared roc cache at /home/niclas/.cache/roc $ ./zig-out/bin/roc test/fx/app.roc error: Failed to resolve platform spec './platform/main.roc': error.PlatformNotSupported # Paste the Hello World snippet into appc.roc $ v test/fx/appc.roc $ ./zig-out/bin/roc test/fx/appc.roc error: Child process /home/niclas/.cache/roc/098d65273b3e7fea486849c277601edd/temp/roc-tmp-ed0z1y0nLSGpmXqLhaHQ1DDSLnhYbU8R/roc_run_349899816 killed by signal: 11 error: Child process crashed with segmentation fault (SIGSEGV)
This is a hard one, I have a good guess what's going wrong, will continue tomorrow...
I solved the core issue in https://github.com/lukewilliamboswell/roc-platform-template-zig/pull/13, still trying to fix a memory leak in examples/echo.roc
Last updated: Dec 21 2025 at 12:15 UTC