convert ffi pointer as ref
commit7b23c5cf22f98b1399beedf39150e76f70f4d6ee
authorSteve Cao <shiqicao@fb.com>
Tue, 1 Oct 2019 19:51:56 +0000 (1 12:51 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 1 Oct 2019 19:53:59 +0000 (1 12:53 -0700)
tree4903dfb180caa6ebdae47408f7f4e626a44347f7
parent7401fe8a68b6ae09132c038ad165445541899248
convert ffi pointer as ref

Summary:
In `lowerer_ffi`, Ocaml passes a `SyntaxTree` pointer to lowerer, the invariant is "Rust borrows a ref from Ocaml", so , `lowerer_ffi` wraps it with `Box` and leak it at the end, however, if lowerer panics `Box::Leak` won't get invoked, then boxed syntax tree will be dropped, this breaks the invariant and Ocaml caller actually will try to drop the tree again.

One solution is to avoid boxing if Rust borrows from Ocaml.

Reviewed By: dabek

Differential Revision: D17671228

fbshipit-source-id: 7236db4f2c73314e2d63a41dc826d56a01320bed
hphp/hack/src/parser/lowerer_ffi.rs
hphp/hack/src/parser/rust_parser_errors_ffi.rs
hphp/hack/src/parser/syntax_tree.rs