Add lifetimes to DeclProvider trait to nest DeclProviders
commitefe31b4231b3988d3d8df6baa2bf5d241af86b3b
authorThomas Jiang <thomasjiang@fb.com>
Wed, 28 Sep 2022 01:38:12 +0000 (27 18:38 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 28 Sep 2022 01:38:12 +0000 (27 18:38 -0700)
tree8a8ee60a9e7d4c6956a00be6a40c5b3731ae91b1
parent4e0c9e1edb6a30004b72b8837b0aa5728dd2440a
Add lifetimes to DeclProvider trait to nest DeclProviders

Summary:
In this stack, I want to allow HackC to populate itself with decls from the file that it is currently compiling - the intention is for this behavior to be the default when decls in comp are turned on everywhere.

I want to do this by creating a new DeclProvider that falls back to decls in the current file in case the "default" DeclProvider could not find the decl.

Currently, we have a Memoized Provider that wraps the "default" DeclProvider so that it can cache the results from the default DeclProvider. I want it to wrap my new DeclProvider. When setting it up this way, I ran into some lifetime/borrow checker errors. The errors that I ran into can sort of be condensed into this example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=bc63e6ce8b831647417674930d026c8f

The problem seems to be that the reference is inferred to be the lifetime of the trait/struct. The solution seems to be to introduce a separate lifetime: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=099f533072907b196e5ef922e844ae59 so that the returned reference can outlive the self reference.

In this diff, I just implement this lifetime change to the DeclProvider trait. The remainder of the stack implements the rest of the change. It might be good to review the whole stack before accepting this change in case there's a better way to set up the providers, especially where I nest them here: D39331187

Reviewed By: edwinsmith

Differential Revision: D39323438

fbshipit-source-id: fb03be363792f292dbd53c5821e65cad7befef94
hphp/hack/src/hackc/compile/compile.rs
hphp/hack/src/hackc/decl_provider/decl_provider.rs
hphp/hack/src/hackc/decl_provider/memo_provider.rs
hphp/hack/src/hackc/emitter/emitter.rs
hphp/hack/src/hackc/ffi_bridge/compiler_ffi.rs
hphp/hack/src/hackc/ffi_bridge/external_decl_provider.rs
hphp/hack/src/hackc/hackc/compile.rs