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