roc
roc copied to clipboard
[WIP] Add some basic file I/O to CLI example
(this was blocked on https://github.com/rtfeldman/roc/issues/2365, but now that that's fixed, this is unblocked! I'll probably get back to it in mid-May, but have 3 talks and other things that are likely higher priority between now and then.)
Using File.readBytes
causes a segfault on my system (macOS 12/ARM):
Read this list of bytes: RocList { storage: Some(Refcounted(-9223372036854775808)), elements: [49, 56, 56, 49, 57, 10] }
[1] 94454 segmentation fault ./roc code.roc
Here's a minimal program that fails:
main =
task = File.readBytes inputPath # This path should exist.
Task.attempt task \result ->
when result is
Ok _ -> Stdout.line "Read file."
Err _ -> Stdout.line "Failed to read input."
I threw a few debug statements into the platform code:
readBytes = \path ->
x = await (Stdout.line "Here") \a -> Stdout.line "oo"
Effect.map (Effect.readAllBytes path) \answer ->
z = await (Stdout.line "Here, again.") \a -> Stdout.line ""
# ...
This prints Here and the output from the rust code, but segfaults before the Here, again.
The issue seems to be in converting the tuple returned by roc_fx_readAllBytes
((RocList<u8>, i32)
) to the record Roc expects in the File module ({ bytes : List U8, errno : I32 }
). Changing the declaration to just be a RocList<u8>
and (List U8)
works:
main =
_ <- await (Stdout.line "Trying to read file...")
task = File.readBytes inputPath
Task.attempt task \result ->
when result is
Ok _ -> Stdout.line "Read the file!"
Err _ -> Stdout.line "Failed to read input."
Outputs:
Trying to read file...
Read this list of bytes: RocList { storage: Some(Refcounted(-9223372036854775808)), elements: [49, 56, 56, 49, 57, 10] }
Read the file!
Yeah, that's a known problem without a known fix yet! 😄
@rtfeldman Is this superceded by #3597?
I'm gonna clean all of these up and get things merged this week!
#4030 is merged, so this is now outdated!