Thicket thicket
cambridge
REPOS 4

Projects covers Forester, Merry, xdge and ocaml-crockford.

W36.2026 · 31 Aug – 6 Sep / Issue

forester hangs on some forests

tangled · jonmsterling.com/ocaml-forester · did:plc:jjiv56ot7d6sgethto3jr3r5

Previously this ticket referred to --emit-legacy-xml, but in fact Forester (both LSP and build) hangs on my laptop with my forest.

Comments

did:plc:jjiv56ot7d6sgethto3jr3r5

Running in verbose mode, the last thing that it appears to do is plant all the articles. This has the feeling of a deadlock in the renderer.


did:plc:jjiv56ot7d6sgethto3jr3r5

This doesn't seem to have been introduced recently; it happens only on my laptop (Apple M2 processor), and not (that I've seen so far) on my desktop (Apple M4).


did:plc:jjiv56ot7d6sgethto3jr3r5

I have bisected the issue and the first bad commit is dda8f14eb661d5bdbe385abbc37394ed76f04b67.


did:plc:jjiv56ot7d6sgethto3jr3r5

It appears that if I remove the State.submit around Asset_router.install in the evaluator, this solves this particular deadlock:

diff --git a/lib/compiler/Eval.ml b/lib/compiler/Eval.ml
index 32b9255..946bc28 100644
--- a/lib/compiler/Eval.ml
+++ b/lib/compiler/Eval.ml
@@ -492,9 +492,9 @@ and eval_node ~env ({value; range} as node) : (Value.t, Eval_error.t) result =
       pop_text_arg_loc ~env ~range
     in
     begin match
-      State.submit ~forest:env.forest (fun () ->
+      (* State.submit ~forest:env.forest (fun () -> *)
           Asset_router.install ~env:env.forest.env ~config:env.forest.config
-            ~range:path_range ~source_path ())
+            ~range:path_range ~source_path ()
     with
     | Ok (uri, Some content) ->
       begin

(This was suggested by ChatGPT, and I tried it out.) But I am a little worried in general and would like to better understand why this was submitted to the executor pool.


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

This is because asset hashing is among the most expensive things that forester does. I don't get why this would fix a deadlock though. I have encountered similar issues in the past, but the fixes involved some mutex that was locking access to a domain-unsafe data structure.


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

Hm, I suppose there is actually no reason to submit to the executor pool here, since we need to await the hash result to proceed anyway. BTW, hashing is now done in the eval routine so we can avoid unnecessarily hashing assets that are never referred to.

I'll remove this call to State.submit


did:plc:jjiv56ot7d6sgethto3jr3r5

I think the call may be concerning if it causes re-entrancy... The evaluator might be called from inside a locked routine, and if this thing has to acquire the lock... But I don't understand the code very well so it is hard for me to say.


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

I meant to paste the commit that removed this unnecessary call: https://tangled.org/jonmsterling.com/ocaml-forester/commit/82edd45f00f88533012a03a980e6482adbbcccfe