Use ocamlrep in editable_positioned_syntax
commita20925908327efa5c755a4be1b02f39478a5cca3
authorJake Bailey (Hacklang) <jakebailey@fb.com>
Sun, 27 Oct 2019 00:20:58 +0000 (26 17:20 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sun, 27 Oct 2019 00:23:08 +0000 (26 17:23 -0700)
tree1860c56de71a7a8000604d63eeddf86c82212daa
parentc5717fd286a527e5d13dd78b8453f6a8996d7200
Use ocamlrep in editable_positioned_syntax

Summary:
We currently have four methods of converting between Rust and OCaml values (that I know of):

- the `ocaml` crate, which provides a few limited wrappers around OCaml runtime allocation functions. Since it calls into the OCaml runtime, the garbage collector may run, and we must be careful to keep values rooted while using it.
- `ToOcaml`, which was implemented for passing the CST from the Rust parser to OCaml. It passes around a SerializationContext containing a pointer to the OCaml source text, since we chose not to write those pointers into positioned tokens and trivia on the Rust side, but those fields still exist on the OCaml side. It is backed by `ocamlpool`, a library which allows us to allocate values on the OCaml heap without running the garbage collector (so that we need not root our values).
- `OcamlRep`, which was originally conceived as a means of allocating OCaml values into Rust-managed memory (coupled with generation of implementations using a procedural macro). It is now (after {D17864960}) a generic interface for allocating OCaml values and deserializing OCaml values into Rust values.
- `Ocamlvalue`, which used a similar approach to OcamlRep (i.e., a trait and a procedural macro) to allocate values using `ocamlpool`.

Now that `ocamlrep` can allocate values using `ocamlpool` (after {D17864957}), I think it would be nice to bring this number from four down to three. Replacing the Ocamlvalue trait with OcamlRep will also allow us to use types which implement OcamlRep in Rust binaries. This was difficult before because implementations of Ocamlvalue linked against the OCaml runtime (via `ocamlpool`).

This diff replaces Ocamlvalue with OcamlRep in EditablePositionedSyntax.

Reviewed By: shiqicao

Differential Revision: D18076615

fbshipit-source-id: fb9457ed44d8f89b03df8981ecb159da590550f9
hphp/hack/src/parser/editable_positioned_syntax_to_ocaml.rs