News for hackers. Stuff that matters.
Re:Jane Street Tech Blog – Oxidizing OCaml: Locality by evmar on Saturday May 27, 2023 @06:08PM (#36098859)
My understanding is that Go does a similar kind of optimization (where locals that don't escape don't go on the heap) but it does it automatically. This has the positive that you don't need annotations but the negative that you can assume some code is benefitting from the optimization when it isn't and there's no warning about it.

I'm curious whether the authors here considered this. I didn't see any discussion of related work in the post.

Re:Jane Street Tech Blog – Oxidizing OCaml: Locality by georgyo on Saturday May 27, 2023 @06:50PM (#36099194)
My reading seems to be that the compiler can and will do it automatically.

The annotations make enforcement. It's easy to make the compiler put something on the heap by accident.

Re:Jane Street Tech Blog – Oxidizing OCaml: Locality by ianthehenry on Saturday May 27, 2023 @06:57PM (#36099245)
From the post:

> Even without explicit mode annotations, the compiler can statically determine which variables may escape their enclosing region. Such variables are assigned the global mode; all others are automatically inferred to be local.

There's a little more info about mode inference in the proposal:

https://github.com/ocaml-flambda/ocaml-jst/blob/main/jane/do...

So arguments to "public functions" do require explicit annotations in order to be local, but otherwise the compiler is able to infer locality and this acts as a transparent optimization.