Are there some ambitions (or maybe even examples) to allow writing single page web apps in Roc? I suppose since it aims at the low-level platforms, this would require compiling to WASM and some JS-based interop to manipulate the DOM.
There is an example WIP virtual dom implementation at examples/virtual-dom-wip
but that @Brian Carroll was working on. That work was blocked due to some type analysis issues in the compiler. Roc has evolved a lot since then, and maybe this project could continue now I'm not sure.
I think it would definitely be feasible to do client side SPAs using roc.
Perfect! Thanks, I'll take a look at that and prospectively help.
Antonin Komenda has marked this topic as resolved.
Antonin Komenda has marked this topic as unresolved.
I've tried to compile https://github.com/lukewilliamboswell/roc-experiment-js-dom. The example with writing to the console works nicely. The inner_html example, however, throws a pretty cryptic error during compilation:
$ RUST_BACKTRACE=full roc build --target wasm32 --no-link --output app.o examples/inner_html.roc
thread 'main' panicked at crates/compiler/gen_llvm/src/llvm/build.rs:5748:19:
Error in alias analysis: error in module ModName("UserApp"), function definition FuncName("\x11\x00\x00\x00\x00\x00\x00\x80\\\x85\xd0w0\xa31\x8e"), definition of value binding ValueId(16): expected type 'union { (((), (heap_cell,)),), ((),) }', found type '()'
stack backtrace:
0: 0x57c016b90c2b - <unknown>
1: 0x57c015e13980 - <unknown>
2: 0x57c016b8c493 - <unknown>
3: 0x57c016b909c4 - <unknown>
4: 0x57c016b92520 - <unknown>
5: 0x57c016b9223f - <unknown>
6: 0x57c016b92a3e - <unknown>
7: 0x57c016b92942 - <unknown>
8: 0x57c016b91126 - <unknown>
9: 0x57c016b926a4 - <unknown>
10: 0x57c015d08e75 - <unknown>
11: 0x57c016370646 - <unknown>
12: 0x57c01636a438 - <unknown>
13: 0x57c01601bffd - <unknown>
14: 0x57c01601fddf - <unknown>
15: 0x57c01601ef85 - <unknown>
16: 0x57c016143952 - <unknown>
17: 0x57c015fe3769 - <unknown>
18: 0x57c015fd6073 - <unknown>
19: 0x57c015fd6093 - <unknown>
20: 0x57c016b821aa - <unknown>
21: 0x57c015fe99a5 - <unknown>
22: 0x70e672e34e08 - <unknown>
23: 0x70e672e34ecc - __libc_start_main
24: 0x57c015da6e6e - <unknown>
25: 0x0 - <unknown>
Are you using the latest nightly?
I suspect that's the issue Sam recently fixed with try. Otherwise I may have pushed it in a broken state. I can check later.
Hmm, I thought that yes, but maybe not:
$ yay -S roc-nightly-bin
[...]
loading packages...
resolving dependencies...
looking for conflicting packages...
Package (2) Old Version New Version Net Change
roc-nightly-bin 20241120-6 20241126-6 0,00 MiB
roc-nightly-bin-debug 20241120-6 20241126-6 0,00 MiB
Total Installed Size: 93,29 MiB
Net Upgrade Size: 0,00 MiB
:: Proceed with installation? [Y/n]
(2/2) checking keys in keyring [---------------------------------------------------------------------------------------] 100%
(2/2) checking package integrity [---------------------------------------------------------------------------------------] 100%
(2/2) loading package files [---------------------------------------------------------------------------------------] 100%
(2/2) checking for file conflicts [---------------------------------------------------------------------------------------] 100%
:: Processing package changes...
(1/2) upgrading roc-nightly-bin [---------------------------------------------------------------------------------------] 100%
(2/2) upgrading roc-nightly-bin-debug [---------------------------------------------------------------------------------------] 100%
:: Running post-transaction hooks...
(1/3) Arming ConditionNeedsUpdate...
(2/3) Refreshing PackageKit...
(3/3) Checking which packages need to be rebuilt
$ roc version
roc nightly pre-release, built from commit 8dbc909 on Fr 15 Nov 2024 09:02:07 UTC
There has been a breaking change so nightlies will be on hold for a couple more days until everything is updated but you can download a TESTING release from the assets here to get the latest updates.
With the TESTING release the inner_html
example works nicely!
image.png
Thanks :ok:
A related question, how to debug a platform. I am also playing with the roc-htmx-playground
(I am still deciding whether to go elm+roc, htmx+roc or WASM+roc)... and I am getting:
$ DB_PATH=test.db roc run --linker=legacy src/main.roc
Listening on <http://127.0.0.1:8000>
2024-11-27T11:24:25Z Get /
2024-11-27T11:24:25Z Get /bootstrap.min.css
2024-11-27T11:24:25Z Get /styles.css
2024-11-27T11:24:25Z Get /bootstrap.bundle.min.js
2024-11-27T11:24:25Z Get /htmx.min.js
2024-11-27T11:24:25Z Get /site.js
2024-11-27T11:24:27Z Get /treeview
2024-11-27T11:24:27Z Get /bigTask
2024-11-27T11:24:29Z Get /bigTask?page=2&items=25
2024-11-27T11:24:31Z Get /bigTask?page=3&items=25
2024-11-27T11:24:33Z Get /bigTask?page=4&items=25
2024-11-27T11:24:34Z Get /bigTask?page=2&items=25
malloc(): unaligned tcache chunk detected
I've updated the playground to current Roc (I've tested the TESTING version as well, but the problem is still there): https://github.com/lukewilliamboswell/roc-htmx-playground/pull/9
I also debugged it to the platform (the Roc part of the playground works fine)... But in the platform I would appreciate some help how to efficiently debug such thing in Rust. Maybe priting all malloc()s... or strace
or something similar?
Can you run it with Valgrind? That may help.
I was not able to crash it, but I found these:
$ DB_PATH=test.db valgrind src/main
==3385473== Memcheck, a memory error detector
==3385473== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==3385473== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==3385473== Command: src/main
==3385473==
==3385473== posix_memalign() invalid size value: 0
==3385473== at 0x484CA38: posix_memalign (vg_replace_malloc.c:2226)
==3385473== by 0x273990: rust_main (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x48D5E07: (below main) (libc_start_call_main.h:58)
==3385473==
Listening on <http://127.0.0.1:8000>
2024-11-28T09:40:05Z Get /
2024-11-28T09:40:06Z Get /bootstrap.min.css
2024-11-28T09:40:06Z Get /bootstrap.bundle.min.js
2024-11-28T09:40:06Z Get /styles.css
2024-11-28T09:40:06Z Get /htmx.min.js
2024-11-28T09:40:06Z Get /site.js
2024-11-28T09:40:06Z Get /favicon.ico
404 NotFound /favicon.ico
2024-11-28T09:40:07Z Get /bigTask
2024-11-28T09:40:10Z Get /bigTask?page=2&items=25
==3385473== Thread 20 tokio-runtime-w:
==3385473== Invalid read of size 8
==3385473== at 0x222789: decrement_refcounted_ptr_8 (roc_app:0)
==3385473== by 0x22277D: ??? (roc_app:0)
==3385473== by 0x229287: ??? (roc_app:0)
==3385473== by 0x1C0D18: Task_53_b7f067e6f5939fbe06dd68ed4b36fad898cbfd8ef8d993964d5cd10b12ac3ec (roc_app:0)
==3385473== by 0x1ECAD1: Task_96_38ac12d038fd8df52070eb8edb3aab96b2fa7b50fc7a9367255428634fa0264e (roc_app:0)
==3385473== by 0x218289: Task_46_5e6d2773e4caec97557de41edef7addcc8c8bc472f779d224a7d61166dbaabe (roc_app:0)
==3385473== by 0x1E7D02: _158_3fe74881edf546beefa6734056b1899c37505b1c34fcce49bbd7b44b157595 (roc_app:0)
==3385473== by 0x22C6CD: roc__forHost_2_caller (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x29A7ED: tokio::runtime::task::raw::poll (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x2E762D: std::sys_common::backtrace::__rust_begin_short_backtrace (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x2E736E: core::ops::function::FnOnce::call_once{{vtable.shim}} (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x2E3ADA: call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> (boxed.rs:2022)
==3385473== by 0x2E3ADA: call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> (boxed.rs:2022)
==3385473== by 0x2E3ADA: std::sys::pal::unix::thread::Thread::new::thread_start (thread.rs:108)
==3385473== Address 0x77720a0 is 0 bytes inside a block of size 32 free'd
==3385473== at 0x48478EF: free (vg_replace_malloc.c:989)
==3385473== by 0x2227CA: decrement_refcounted_ptr_8 (roc_app:0)
==3385473== by 0x22277D: ??? (roc_app:0)
==3385473== by 0x1A20BA: Controllers.BigTask_15_36cf1b423d96d0d1f556ed298e83394497cd597c20b08eba5512c2685cd67751 (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x1C46BD: Task_46_c436285c5b59d7df49ab96ad8476bdb7c10421fe2225ff48721cb48682ff451 (roc_app:0)
==3385473== by 0x1CCDFE: Task_46_28ea24f1682fb667c3fb23a9dbc02f29e624f88b5aca38a345144704a3139a (roc_app:0)
==3385473== by 0x1FF9B2: Task_46_ee6d8d949dc3617ea48fd44bd0c8f21be51d3676b1b3bdfdfcf8f559e4e0272f (roc_app:0)
==3385473== by 0x222172: Task_46_1f3cd98ac177094c9632f9c81aa71556d2feacfd911d3d139427ec94325c8 (roc_app:0)
==3385473== by 0x1C0D04: Task_53_b7f067e6f5939fbe06dd68ed4b36fad898cbfd8ef8d993964d5cd10b12ac3ec (roc_app:0)
==3385473== by 0x1ECAD1: Task_96_38ac12d038fd8df52070eb8edb3aab96b2fa7b50fc7a9367255428634fa0264e (roc_app:0)
==3385473== by 0x218289: Task_46_5e6d2773e4caec97557de41edef7addcc8c8bc472f779d224a7d61166dbaabe (roc_app:0)
==3385473== by 0x1E7D02: _158_3fe74881edf546beefa6734056b1899c37505b1c34fcce49bbd7b44b157595 (roc_app:0)
==3385473== Block was alloc'd at
==3385473== at 0x48447A8: malloc (vg_replace_malloc.c:446)
==3385473== by 0x2B074D: <roc_std::roc_str::RocStr as core::convert::From<&str>>::from (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x29A5CA: tokio::runtime::task::raw::poll (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x2E762D: std::sys_common::backtrace::__rust_begin_short_backtrace (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x2E736E: core::ops::function::FnOnce::call_once{{vtable.shim}} (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x2E3ADA: call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> (boxed.rs:2022)
==3385473== by 0x2E3ADA: call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> (boxed.rs:2022)
==3385473== by 0x2E3ADA: std::sys::pal::unix::thread::Thread::new::thread_start (thread.rs:108)
==3385473== by 0x494439C: start_thread (pthread_create.c:447)
==3385473== by 0x49C92A3: clone (clone.S:100)
==3385473==
==3385473== Invalid write of size 8
==3385473== at 0x2227AA: decrement_refcounted_ptr_8 (roc_app:0)
==3385473== by 0x22277D: ??? (roc_app:0)
==3385473== by 0x229287: ??? (roc_app:0)
==3385473== by 0x1C0D18: Task_53_b7f067e6f5939fbe06dd68ed4b36fad898cbfd8ef8d993964d5cd10b12ac3ec (roc_app:0)
==3385473== by 0x1ECAD1: Task_96_38ac12d038fd8df52070eb8edb3aab96b2fa7b50fc7a9367255428634fa0264e (roc_app:0)
==3385473== by 0x218289: Task_46_5e6d2773e4caec97557de41edef7addcc8c8bc472f779d224a7d61166dbaabe (roc_app:0)
==3385473== by 0x1E7D02: _158_3fe74881edf546beefa6734056b1899c37505b1c34fcce49bbd7b44b157595 (roc_app:0)
==3385473== by 0x22C6CD: roc__forHost_2_caller (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x29A7ED: tokio::runtime::task::raw::poll (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x2E762D: std::sys_common::backtrace::__rust_begin_short_backtrace (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x2E736E: core::ops::function::FnOnce::call_once{{vtable.shim}} (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x2E3ADA: call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> (boxed.rs:2022)
==3385473== by 0x2E3ADA: call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> (boxed.rs:2022)
==3385473== by 0x2E3ADA: std::sys::pal::unix::thread::Thread::new::thread_start (thread.rs:108)
==3385473== Address 0x77720a0 is 0 bytes inside a block of size 32 free'd
==3385473== at 0x48478EF: free (vg_replace_malloc.c:989)
==3385473== by 0x2227CA: decrement_refcounted_ptr_8 (roc_app:0)
==3385473== by 0x22277D: ??? (roc_app:0)
==3385473== by 0x1A20BA: Controllers.BigTask_15_36cf1b423d96d0d1f556ed298e83394497cd597c20b08eba5512c2685cd67751 (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x1C46BD: Task_46_c436285c5b59d7df49ab96ad8476bdb7c10421fe2225ff48721cb48682ff451 (roc_app:0)
==3385473== by 0x1CCDFE: Task_46_28ea24f1682fb667c3fb23a9dbc02f29e624f88b5aca38a345144704a3139a (roc_app:0)
==3385473== by 0x1FF9B2: Task_46_ee6d8d949dc3617ea48fd44bd0c8f21be51d3676b1b3bdfdfcf8f559e4e0272f (roc_app:0)
==3385473== by 0x222172: Task_46_1f3cd98ac177094c9632f9c81aa71556d2feacfd911d3d139427ec94325c8 (roc_app:0)
==3385473== by 0x1C0D04: Task_53_b7f067e6f5939fbe06dd68ed4b36fad898cbfd8ef8d993964d5cd10b12ac3ec (roc_app:0)
==3385473== by 0x1ECAD1: Task_96_38ac12d038fd8df52070eb8edb3aab96b2fa7b50fc7a9367255428634fa0264e (roc_app:0)
==3385473== by 0x218289: Task_46_5e6d2773e4caec97557de41edef7addcc8c8bc472f779d224a7d61166dbaabe (roc_app:0)
==3385473== by 0x1E7D02: _158_3fe74881edf546beefa6734056b1899c37505b1c34fcce49bbd7b44b157595 (roc_app:0)
==3385473== Block was alloc'd at
==3385473== at 0x48447A8: malloc (vg_replace_malloc.c:446)
==3385473== by 0x2B074D: <roc_std::roc_str::RocStr as core::convert::From<&str>>::from (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x29A5CA: tokio::runtime::task::raw::poll (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x2E762D: std::sys_common::backtrace::__rust_begin_short_backtrace (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x2E736E: core::ops::function::FnOnce::call_once{{vtable.shim}} (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473== by 0x2E3ADA: call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> (boxed.rs:2022)
==3385473== by 0x2E3ADA: call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> (boxed.rs:2022)
==3385473== by 0x2E3ADA: std::sys::pal::unix::thread::Thread::new::thread_start (thread.rs:108)
==3385473== by 0x494439C: start_thread (pthread_create.c:447)
==3385473== by 0x49C92A3: clone (clone.S:100)
==3385473==
Looks like a premature free()
?
Could you make an issue for this (with the valgrind output) @Antonin Komenda?
Sure, and is it problem of the basic-webserver platform or Roc?
I've never seen the posix_memalign
on Roc, let's put it on basic-webserver for now
I have my suspicions... we might fix it in the upgrade to purity inference by coincidence. Also I think were using glue that probably needs to be updated/rolled by hand.
It'd be nice to find the issues and resolve them with basic-cli though. So I've held off launching into that upgrade.
Yeah, this suggests that we are allocating something with the wrong size. Allocate something with no size, attempt to read a refcount from it (invalid read cause didn't allocate space for a recount), attempt to write refcount to it (invalid write).
Also, posix_memalign is just fancy aligned malloc
My first guess is allocating a Box {}
is not adding on the refcount.
If we run Valgrind in a debug build of the platform and make sure to use the legacy linker, should pinpoint a lot more
How to do an appropriate debug build? I've tried roc build --profiling --linker=legacy src/main.roc
, but the Valgrind output looks the same.
Looks like roc-htmx-playground is using an old version of basic-webserver. I recommend trying to upgrade that to the latest main of basic-webserver (in combination with roc TESTING), to do a local platform import use { pf: platform "path-to-basic-ws/platform/main.roc" }
.
As build command you'll want to use:
roc --build-host --suppress-build-host-warning build --linker=legacy src/main.roc
I've already ported the roc-htmx-playground to new Roc and platform: https://github.com/lukewilliamboswell/roc-htmx-playground/pull/9
In that case, I recommend using a local version of basic-webserver 0.9.0. So:
git clone https://github.com/roc-lang/basic-webserver.git
cd basic-webserver
In that folder modify build.roc
by removing --release
here.
Then:
# use latest nightly roc, not TESTING
roc build.roc
Then you'll want to use that built platform by modifying this url to a path; like { pf: platform "some_path/basic-webserver/platform/main.roc" }
.
that should hopefully improve your valgrind output
Do we need to pass a flag with roc build.roc to get a debug build of the platform? Worth checking it's not building a release build by default.
It is building a release build by default which is why I said:
In that folder modify
build.roc
by removing--release
here.
Can you clarify if you mean something else?
Do we need to pass a flag with roc build.roc
That flag got removed, perhaps because it did not work without --release at the time
Nw, i missed that you said that.
Should optimize be removed for buildStubAppLib to get better valgrind output or will it not matter?
|> Cmd.exec ["build", "--lib", "platform/libapp.roc", "--output", stubLibPath, "--optimize"]
That's just for the roc part, and I dont think it will change much much for this debugging.
Anton said:
In that case, I recommend using a local version of basic-webserver 0.9.0. So:
git clone https://github.com/roc-lang/basic-webserver.git cd basic-webserver
In that folder modify
build.roc
by removing--release
here.Then:
# use latest nightly roc, not TESTING roc build.roc
Then you'll want to use that built platform by modifying this url to a path; like
{ pf: platform "some_path/basic-webserver/platform/main.roc" }
.that should hopefully improve your valgrind output
I was able to build the platform, but the build does not contain a .o
so the playground compains:
roc build --build-host --suppress-build-host-warning --linker=legacy src/main.roc
๐จ Building host ...
ld: cannot find src/../../basic-webserver/platform/linux-x64.o: No such file or directory
thread 'main' panicked at crates/compiler/build/src/program.rs:1058:17:
not yet implemented: linker failed with exit code Some(1)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I've got there only libapp.so
and linux-x64.a
.
Did I mess up something in the platform build?
I also experienced the same on macOS on Apple Silicon.
Hmm, can you share the output of ar -t linux-x64.a
in the platform folder?
Here:
ar -t linux-x64.a > ~/desktop/ar.output
Thanks, can you share the output of roc version
?
roc nightly pre-release, built from commit 8dbc909 on Fr 15 Nov 2024 09:02:07 UTC
It should be searching for the .a file, this could be the problematic line, it may just need to use the prebuilt_static_library
function instead. @Luke Boswell may have some useful input as well.
Can you file an issue for this?
If you're up for it you can try that function change yourself, build roc with cargo build --release --bin roc
, the binary will then be in ./target/release/roc
. To use that version of roc with your project you'll also need to switch to basic-webserver 0.10.0
Reported here: https://github.com/roc-lang/roc/issues/7271
I'll try to hotfix it in Roc later.
You shouldn't be using the --build-host
flag, that is only intended for internal tests now. I think I've found the issue with the above, and it's caused by using that flag. Specifically at this point if you are interested.
So you've built the platform correctly, you know this because you can see the linux-x64.a
etc files in platform/
.
So now in your app, you should be able to build it using roc build linker=legacy
src/main.roc``
Hmm, I am getting:
$ roc build --linker=legacy src/main.roc
ld: /tmp/roc_app43ZQ1f.o: in function `roc_fx_sqliteExecute_fastcc_wrapper':
builtins-host:(.text+0xfef2c): undefined reference to `roc_fx_sqliteExecute'
thread 'main' panicked at crates/compiler/build/src/program.rs:1058:17:
not yet implemented: linker failed with exit code Some(1)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I can try to reproduce this later
Thanks a lot (not critical on my side :]). Do I at least get the error correctly: does it mean the built platform is not compatible with the Roc part of the platform?
With respect to the sqlite effects?
does it mean the built platform is not compatible with the Roc part of the platform?
Good catch, yes, this may just be a function name that changed from one version to another
roc_fx_sqliteExecute
is in the linux-x64.a of basic-webserver (0.10.0).
Can you share your code @Antonin Komenda?
This is my basic-webserver
:
$ git st
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: build.roc
modified: examples/todos.roc
modified: platform/Url.roc
no changes added to commit (use "git add" and/or "git commit -a")
$ git diff
diff --git a/build.roc b/build.roc
index 3b63032..4746c49 100644
--- a/build.roc
+++ b/build.roc
@@ -1,5 +1,6 @@
app [main] {
- cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.tar.br",
+ #cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.tar.br",
+ cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.16.0/O00IPk-Krg_diNS2dVWlI0ZQP794Vctxzv0ha96mK0E.tar.br",
}
import cli.Cmd
@@ -100,7 +101,7 @@ cargoBuildHost =
info! "Building rust host ..."
"cargo"
- |> Cmd.exec ["build", "--release"]
+ |> Cmd.exec ["build"]
|> Task.mapErr! ErrBuildingHostBinaries
copyHostLib : OSAndArch, Str -> Task {} _
diff --git a/examples/todos.roc b/examples/todos.roc
index bbf9bd4..73bf2df 100644
--- a/examples/todos.roc
+++ b/examples/todos.roc
@@ -32,7 +32,7 @@ respond = \req, _ ->
req.url
|> Url.fromStr
|> Url.path
- |> Str.splitOn "/"
+ |> Str.split "/"
# Route to handler based on url path
when splitUrl is
diff --git a/platform/Url.roc b/platform/Url.roc
index 817bd31..16c9865 100644
--- a/platform/Url.roc
+++ b/platform/Url.roc
@@ -439,7 +439,7 @@ query = \@Url urlStr ->
queryParams : Url -> Dict Str Str
queryParams = \url ->
query url
- |> Str.splitOn "&"
+ |> Str.split "&"
|> List.walk (Dict.empty {}) \dict, pair ->
when Str.splitFirst pair "=" is
Ok { before, after } -> Dict.insert dict before after
And this the playground:
$ git st
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: src/Helpers.roc
modified: src/Models/BigTask.roc
modified: src/Sql/Session.roc
modified: src/main.roc
no changes added to commit (use "git add" and/or "git commit -a")
$ git diff
diff --git a/src/Helpers.roc b/src/Helpers.roc
index ed6ebee..f30a50e 100644
--- a/src/Helpers.roc
+++ b/src/Helpers.roc
@@ -39,7 +39,7 @@ decodeFormValues = \body ->
parseQueryParams : Str -> Result (Dict Str Str) _
parseQueryParams = \url ->
- when Str.splitOn url "?" is
+ when Str.split url "?" is
[_, queryPart] -> queryPart |> Str.toUtf8 |> Http.parseFormUrlEncoded
parts -> Err (InvalidQuery (Inspect.toStr parts))
diff --git a/src/Models/BigTask.roc b/src/Models/BigTask.roc
index 336472b..15e6e52 100644
--- a/src/Models/BigTask.roc
+++ b/src/Models/BigTask.roc
@@ -41,7 +41,7 @@ parseDate = \date ->
isTwoChars = \str -> List.len (Str.toUtf8 str) == 2
# Format: yyyy-mm-dd
- when Str.splitOn date "-" is
+ when Str.split date "-" is
[""] -> Ok NotSet
[yyyy, mm, dd] if isFourChars yyyy && isTwoChars mm && isTwoChars dd ->
when (Str.toI64 yyyy, Str.toI64 mm, Str.toI64 dd) is
diff --git a/src/Sql/Session.roc b/src/Sql/Session.roc
index 608a495..ce8df9b 100644
--- a/src/Sql/Session.roc
+++ b/src/Sql/Session.roc
@@ -32,7 +32,7 @@ parse = \req ->
when req.headers |> List.keepIf \reqHeader -> reqHeader.name == "cookie" is
[reqHeader] ->
reqHeader.value
- |> Str.splitOn "="
+ |> Str.split "="
|> List.get 1
|> Result.try Str.toI64
|> Result.mapErr \_ -> InvalidSessionCookie
diff --git a/src/main.roc b/src/main.roc
index bb91e83..0c810f5 100644
--- a/src/main.roc
+++ b/src/main.roc
@@ -1,5 +1,6 @@
app [Model, server] {
- pf: platform "https://github.com/roc-lang/basic-webserver/releases/download/0.10.0/BgDDIykwcg51W8HA58FE_BjdzgXVk--ucv6pVb_Adik.tar.br",
+ # pf: platform "https://github.com/roc-lang/basic-webserver/releases/download/0.10.0/BgDDIykwcg51W8HA58FE_BjdzgXVk--ucv6pVb_Adik.tar.br",
+ pf: platform "../../basic-webserver/platform/main.roc",
html: "https://github.com/Hasnep/roc-html/releases/download/v0.6.0/IOyNfA4U_bCVBihrs95US9Tf5PGAWh3qvrBN4DRbK5c.tar.br",
}
@@ -75,7 +76,7 @@ handleReq = \req ->
req.url
|> Url.fromStr
|> Url.path
- |> Str.splitOn "/"
+ |> Str.split "/"
|> List.dropFirst 1
when (req.method, urlSegments) is
I.e. both are main
s with the changes to build the platform and then use the locally built platform (and the splitOn
/split
"backport")
If I try to build the basic-webserver
with the cli 0.17.0, I get:
$ roc build.roc
โโ NOT EXPOSED in .../lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE/Arg/Help.roc โ
The Str module does not expose `splitOn`:
342โ |> Str.splitOn "\n"
^^^^^^^^^^^
Did you mean one of these?
Str.split
Str.splitLast
Str.splitFirst
Str.isEmpty
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1 error and 0 warnings found in 87 ms
.
You can run the program anyway with roc run build.roc
as I am using the non-TESTING Roc, as you suggested before.
You must be using an older nightly, splitOn is a newer API.
Aah, even older... okok, I'll try. Sorry, I didn't get that, I though only non-TESTING.
or could I use the nightly Roc from yesterday maybe?
yes, that one has the new Str.splitOn API
Hmm, still the problem with the sqliteExecure fx:
$ roc build --linker=legacy src/main.roc
ld: /tmp/roc_appLCFstE.o: in function `roc_fx_sqliteExecute_fastcc_wrapper':
builtins-host:(.text+0xfe40c): undefined reference to `roc_fx_sqliteExecute'
thread 'main' panicked at crates/compiler/build/src/program.rs:1058:17:
not yet implemented: linker failed with exit code Some(1)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I've updated Roc, the basic-webserver and the playground, the split/splitOn
is ok now.
I'll try to check the intermediate .o files whether/why not the function is really there
I've extracted the linux-x64.a
to object files and grepped out the fx_sqlite
functions and got only:
host-6d734d3ba16fa1e3.host.6db8a1e53cb1cd2b-cgu.0.rcgu.o
0000000000000000 T roc_fx_sqliteBind
0000000000000000 T roc_fx_sqliteColumns
0000000000000000 T roc_fx_sqliteColumnValue
0000000000000000 T roc_fx_sqlitePrepare
0000000000000000 T roc_fx_sqliteReset
0000000000000000 T roc_fx_sqliteStep
So I really do not have the ...Execute
there. Any suggestions? Or maybe a pointer where is the host object built?
:thinking: this what I get after extracting the linux-x64.a for BgDDIykwcg51W8HA58FE_BjdzgXVk--ucv6pVb_Adik.tar.br :
โฏ strings host-b1c017c9b46813ae.host.faf5bafe4a7818bd-cgu.0.rcgu.o | grep fx_sqlite
.rela.text.roc_fx_sqliteExecute
.gcc_except_table.roc_fx_sqliteExecute
.rela.rodata.roc_fx_sqliteExecute
$ strings host-6d734d3ba16fa1e3.host.6db8a1e53cb1cd2b-cgu.0.rcgu.o | grep fx_sqlite
.rela.text.roc_fx_sqliteReset
.rela.text.roc_fx_sqliteColumns
.gcc_except_table.roc_fx_sqliteColumns
.rela.text.roc_fx_sqliteStep
.rela.text.roc_fx_sqliteColumnValue
.gcc_except_table.roc_fx_sqliteColumnValue
.rela.rodata.roc_fx_sqliteColumnValue
.rela.text.roc_fx_sqlitePrepare
.gcc_except_table.roc_fx_sqlitePrepare
.rela.text.roc_fx_sqliteBind
.gcc_except_table.roc_fx_sqliteBind
.rela.rodata.roc_fx_sqliteBind
Should we have the hashes the same? Or they are local to the build?
I'm not sure about those hashes, but are you also using BgDDIykwcg51W8HA58FE_BjdzgXVk--ucv6pVb_Adik.tar.br ?
That tar.br comes from https://github.com/roc-lang/basic-webserver/releases/tag/0.10.0
nono, I am building the platform locally... that's all because I want the non--release
build of the platform to pinpoint the malloc problem I am triggering from the playground
Can you try setting CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
when you build basic-webserver, that's what I use to build the release
that actually worked :tada:
however the valgrind output is pretty the same :sweat_smile:
==3181233== Memcheck, a memory error detector
==3181233== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==3181233== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==3181233== Command: src/main
==3181233==
==3181233== posix_memalign() invalid size value: 0
==3181233== at 0x484CA38: posix_memalign (vg_replace_malloc.c:2226)
==3181233== by 0x5C0080: aligned_malloc (alloc.rs:102)
==3181233== by 0x5C0080: alloc (alloc.rs:22)
==3181233== by 0x5C0080: __rdl_alloc (alloc.rs:394)
==3181233== by 0x5EAADA: alloc::alloc::alloc (alloc.rs:100)
==3181233== by 0x27069F: roc_host::roc::call_roc_init (roc.rs:1001)
==3181233== by 0x60CF3B: roc_host::http_server::start (http_server.rs:25)
==3181233== by 0x27C615: rust_main (lib.rs:8)
==3181233== by 0x26F996: main (lib.rs:3)
==3181233==
Listening on <http://127.0.0.1:8000>
2024-12-03T15:20:39Z GET /
2024-12-03T15:20:39Z GET /styles.css
2024-12-03T15:20:40Z GET /bootstrap.bundle.min.js
2024-12-03T15:20:40Z GET /bootstrap.min.css
2024-12-03T15:20:40Z GET /htmx.min.js
2024-12-03T15:20:40Z GET /site.js
2024-12-03T15:20:40Z GET /favicon.ico
404 NotFound /favicon.ico
2024-12-03T15:20:41Z GET /bigTask
2024-12-03T15:20:44Z GET /bigTask?page=2&items=25
==3181233== Thread 18 tokio-runtime-w:
==3181233== Invalid read of size 8
==3181233== at 0x265499: decrement_refcounted_ptr_8 (roc_app:0)
==3181233== by 0x26548D: ??? (roc_app:0)
==3181233== by 0x26B11B: ??? (roc_app:0)
==3181233== by 0x1FC1A9: Task_53_b7f067e6f5939fbe06dd68ed4b36fad898cbfd8ef8d993964d5cd10b12ac3ec (roc_app:0)
==3181233== by 0x225CA1: Task_96_38ac12d038fd8df52070eb8edb3aab96b2fa7b50fc7a9367255428634fa0264e (roc_app:0)
==3181233== by 0x25A208: Task_46_5e6d2773e4caec97557de41edef7addcc8c8bc472f779d224a7d61166dbaabe (roc_app:0)
==3181233== by 0x21F082: _158_3fe74881edf546beefa6734056b1899c37505b1c34fcce49bbd7b44b157595 (roc_app:0)
==3181233== by 0x26F94D: roc__forHost_2_caller (in /home/gree/workspace/roc-htmx-playground/src/main)
==3181233== by 0x270F64: roc_host::roc::call_roc_respond (roc.rs:1086)
==3181233== by 0x28AC84: roc_host::http_server::call_roc (http_server.rs:62)
==3181233== by 0x28BB14: roc_host::http_server::handle_req::{{closure}}::{{closure}} (http_server.rs:110)
==3181233== by 0x60DAE4: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll (task.rs:42)
==3181233== Address 0x7549610 is 0 bytes inside a block of size 32 free'd
==3181233== at 0x48478EF: free (vg_replace_malloc.c:989)
==3181233== by 0x26FA02: roc_dealloc (roc.rs:34)
==3181233== by 0x2654DA: decrement_refcounted_ptr_8 (roc_app:0)
==3181233== by 0x26548D: ??? (roc_app:0)
==3181233== by 0x1DFA60: Controllers.BigTask_15_36cf1b423d96d0d1f556ed298e83394497cd597c20b08eba5512c2685cd67751 (in /home/gree/workspace/roc-htmx-playground/src/main)
==3181233== by 0x20012F: Task_46_c436285c5b59d7df49ab96ad8476bdb7c10421fe2225ff48721cb48682ff451 (roc_app:0)
==3181233== by 0x2088CC: Task_46_28ea24f1682fb667c3fb23a9dbc02f29e624f88b5aca38a345144704a3139a (roc_app:0)
==3181233== by 0x23DD1D: Task_46_ee6d8d949dc3617ea48fd44bd0c8f21be51d3676b1b3bdfdfcf8f559e4e0272f (roc_app:0)
==3181233== by 0x2652E6: Task_46_1f3cd98ac177094c9632f9c81aa71556d2feacfd911d3d139427ec94325c8 (roc_app:0)
==3181233== by 0x1FC195: Task_53_b7f067e6f5939fbe06dd68ed4b36fad898cbfd8ef8d993964d5cd10b12ac3ec (roc_app:0)
==3181233== by 0x225CA1: Task_96_38ac12d038fd8df52070eb8edb3aab96b2fa7b50fc7a9367255428634fa0264e (roc_app:0)
==3181233== by 0x25A208: Task_46_5e6d2773e4caec97557de41edef7addcc8c8bc472f779d224a7d61166dbaabe (roc_app:0)
==3181233== Block was alloc'd at
==3181233== at 0x48447A8: malloc (vg_replace_malloc.c:446)
==3181233== by 0x26F9B2: roc_alloc (roc.rs:19)
==3181233== by 0x5A075E: roc_std::roc_list::RocList<T>::elems_with_capacity (roc_list.rs:89)
==3181233== by 0x5A0E7F: roc_std::roc_list::RocList<T>::extend_from_slice (roc_list.rs:371)
==3181233== by 0x5A0BAC: roc_std::roc_list::RocList<T>::from_slice (roc_list.rs:312)
==3181233== by 0x59FE98: roc_std::roc_str::RocStr::from_slice_unchecked (roc_str.rs:76)
==3181233== by 0x5A0074: <roc_std::roc_str::RocStr as core::convert::From<&str>>::from (roc_str.rs:704)
==3181233== by 0x27D23A: <T as core::convert::Into<U>>::into (mod.rs:759)
==3181233== by 0x60C2E6: roc_host::roc_http::RequestToAndFromHost::from_reqwest (roc_http.rs:30)
==3181233== by 0x28AB6C: roc_host::http_server::call_roc (http_server.rs:60)
==3181233== by 0x28BB14: roc_host::http_server::handle_req::{{closure}}::{{closure}} (http_server.rs:110)
==3181233== by 0x60DAE4: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll (task.rs:42)
==3181233==
==3181233== Invalid write of size 8
==3181233== at 0x2654BA: decrement_refcounted_ptr_8 (roc_app:0)
==3181233== by 0x26548D: ??? (roc_app:0)
==3181233== by 0x26B11B: ??? (roc_app:0)
==3181233== by 0x1FC1A9: Task_53_b7f067e6f5939fbe06dd68ed4b36fad898cbfd8ef8d993964d5cd10b12ac3ec (roc_app:0)
==3181233== by 0x225CA1: Task_96_38ac12d038fd8df52070eb8edb3aab96b2fa7b50fc7a9367255428634fa0264e (roc_app:0)
==3181233== by 0x25A208: Task_46_5e6d2773e4caec97557de41edef7addcc8c8bc472f779d224a7d61166dbaabe (roc_app:0)
==3181233== by 0x21F082: _158_3fe74881edf546beefa6734056b1899c37505b1c34fcce49bbd7b44b157595 (roc_app:0)
==3181233== by 0x26F94D: roc__forHost_2_caller (in /home/gree/workspace/roc-htmx-playground/src/main)
==3181233== by 0x270F64: roc_host::roc::call_roc_respond (roc.rs:1086)
==3181233== by 0x28AC84: roc_host::http_server::call_roc (http_server.rs:62)
==3181233== by 0x28BB14: roc_host::http_server::handle_req::{{closure}}::{{closure}} (http_server.rs:110)
==3181233== by 0x60DAE4: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll (task.rs:42)
==3181233== Address 0x7549610 is 0 bytes inside a block of size 32 free'd
==3181233== at 0x48478EF: free (vg_replace_malloc.c:989)
==3181233== by 0x26FA02: roc_dealloc (roc.rs:34)
==3181233== by 0x2654DA: decrement_refcounted_ptr_8 (roc_app:0)
==3181233== by 0x26548D: ??? (roc_app:0)
==3181233== by 0x1DFA60: Controllers.BigTask_15_36cf1b423d96d0d1f556ed298e83394497cd597c20b08eba5512c2685cd67751 (in /home/gree/workspace/roc-htmx-playground/src/main)
==3181233== by 0x20012F: Task_46_c436285c5b59d7df49ab96ad8476bdb7c10421fe2225ff48721cb48682ff451 (roc_app:0)
==3181233== by 0x2088CC: Task_46_28ea24f1682fb667c3fb23a9dbc02f29e624f88b5aca38a345144704a3139a (roc_app:0)
==3181233== by 0x23DD1D: Task_46_ee6d8d949dc3617ea48fd44bd0c8f21be51d3676b1b3bdfdfcf8f559e4e0272f (roc_app:0)
==3181233== by 0x2652E6: Task_46_1f3cd98ac177094c9632f9c81aa71556d2feacfd911d3d139427ec94325c8 (roc_app:0)
==3181233== by 0x1FC195: Task_53_b7f067e6f5939fbe06dd68ed4b36fad898cbfd8ef8d993964d5cd10b12ac3ec (roc_app:0)
==3181233== by 0x225CA1: Task_96_38ac12d038fd8df52070eb8edb3aab96b2fa7b50fc7a9367255428634fa0264e (roc_app:0)
==3181233== by 0x25A208: Task_46_5e6d2773e4caec97557de41edef7addcc8c8bc472f779d224a7d61166dbaabe (roc_app:0)
==3181233== Block was alloc'd at
==3181233== at 0x48447A8: malloc (vg_replace_malloc.c:446)
==3181233== by 0x26F9B2: roc_alloc (roc.rs:19)
==3181233== by 0x5A075E: roc_std::roc_list::RocList<T>::elems_with_capacity (roc_list.rs:89)
==3181233== by 0x5A0E7F: roc_std::roc_list::RocList<T>::extend_from_slice (roc_list.rs:371)
==3181233== by 0x5A0BAC: roc_std::roc_list::RocList<T>::from_slice (roc_list.rs:312)
==3181233== by 0x59FE98: roc_std::roc_str::RocStr::from_slice_unchecked (roc_str.rs:76)
==3181233== by 0x5A0074: <roc_std::roc_str::RocStr as core::convert::From<&str>>::from (roc_str.rs:704)
==3181233== by 0x27D23A: <T as core::convert::Into<U>>::into (mod.rs:759)
==3181233== by 0x60C2E6: roc_host::roc_http::RequestToAndFromHost::from_reqwest (roc_http.rs:30)
==3181233== by 0x28AB6C: roc_host::http_server::call_roc (http_server.rs:60)
==3181233== by 0x28BB14: roc_host::http_server::handle_req::{{closure}}::{{closure}} (http_server.rs:110)
==3181233== by 0x60DAE4: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll (task.rs:42)
==3181233==
I left some more comments on the issue, but we'll have to wait until a specialist can look at it.
I see. Thanks!
Last updated: Jul 06 2025 at 12:14 UTC