Sorry to be back so soon with another major problem, but turning --optimize on seems to change the result of a roc program
$ roc run dn08.roc
3
$ roc run --optimize dn08.roc
0
app "dn08"
packages {
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}
imports [
pf.Stdout,
pf.Task,
]
provides [main] to pf
main =
arr = [14, 12, 19, 16, 18, 11, 15, 10, 13, 17]
n = List.len arr
k = 5
r = 3
goal = List.sortAsc arr
List.range { start: At 0, end: At k }
|> List.map
\e -> List.range { start: At 0, end: Before e }
|> List.map \_ -> allSwaps n r
|> List.joinMap product
|> List.map \e -> eval arr e r
|> List.countIf \e -> e == goal
|> Num.toStr
|> Stdout.line
eval = \init, prog, r ->
List.walk prog init \state, elem ->
when elem is
Swap a b ->
List.range { start: At 0, end: Before r }
|> List.walk state \arr, offset ->
List.swap arr (a + offset) (b + offset)
allSwaps = \n, r ->
List.range { start: At 0, end: At (n - r) }
|> List.map \e ->
List.range { start: After e, end: At (n - r) }
|> List.map \e2 -> Swap e e2
|> List.join
|> List.keepIf \e -> e |> isValidSwap r
isValidSwap = \swap, r ->
when swap is
Swap a b ->
a + r <= b
product : List (List a) -> List (List a)
product = \l ->
first = l |> List.first |> Result.withDefault [] |> List.map List.single
l
|> List.dropFirst 1
|> List.walk first \state, elem ->
List.joinMap state \a ->
List.map elem \b ->
List.append a b
Probably another variant of https://github.com/roc-lang/roc/issues/6434
Specifically a variant of https://github.com/roc-lang/roc/issues/6139
Seems likely
Sorry, for not noticing it, tho it was quite jarring to notice a 3 suddenly turn to a 0
Might i also use this moment of attention to ask about why diff <(roc run dn08.roc) <(roc run --optimize dn08.roc)
doesn't work? Does roc change any files on the file system or why would running two compilers at the same time pose a problem?
Both of those commands will generate the same executable file ./dn08
. They also will both download and build from the same platform which could have race conditions.
Definitely should work though.
Brendan Hansknecht said:
They also will both download and build from the same platform which could have race conditions.
I took some steps to make this work (if I remember right, it downloads to a tempdir, then renames the file to its destination and ignores "already exists" errors) but the race condition around the output binary is definitely possible :big_smile:
Oh cool
So just the output binary then (and maybe some surgical linker copied files)
For some reason I thought run
ran directly
closing, as the original issue is already known. Thanks for the help
Adrian has marked this topic as resolved.
For some reason I thought
run
ran directly
It should
Just doesn't currently
Or at a minimum, it should build into a cache/tmp/hidden folder such that you don't get these kinds of collisions
Last updated: Jul 26 2025 at 12:14 UTC