I was playing around with stanc3 and js_of_ocaml (a compiler that compiles arbitrary ocaml code into javascript) and managed to make something that works with nodejs with basically the following commands, once I had nodejs installed and stanc3 was building locally:
opam install js_of_ocaml-compiler
dune build --profile=release src/stanc/stanc.bc.js
Amazingly well integrated with dune! To run it,
hal ~/scm/stanc3 (master) $ time node _build/default/src/stanc/stanc.bc.js test/integration/good/code-gen/mother.stan
Warning: deprecated language construct used in 'test/integration/good/code-gen/mother.stan', line 60, column 21:
-------------------------------------------------
58:
59: void unit_normal_lp(real u) {
60: increment_log_prob(normal_log(u,0,1));
^
61: u ~ uniform(-100,100);
62: }
-------------------------------------------------
increment_log_prob(...); is deprecated and will be removed in the future. Use target += ...; instead.
Warning: deprecated language construct used in 'test/integration/good/code-gen/mother.stan', line 184, column 20:
-------------------------------------------------
182:
183: real foo_lp(real x) {
184: return x + get_lp();
^
185: }
186:
-------------------------------------------------
get_lp() function is deprecated. It will be removed in a future release. Use target() instead.
real 0m1.817s
user 0m2.194s
sys 0m0.066s
Takes about 2s to transpile the (huge, intentionally egregious) mother model to C++ (compared with 0.081s for the native executable). Eight schools takes 0.871s with nodejs.
Given that there is a v8 port for R that runs Javascript, maybe this is a much quicker route to getting something up and running in RStan with stanc3? @bgoodri
Also this would make it easy to run the compiler and any future linters right in someone’s browser without having any server set up, which is kind of neat.