Support PHP-decl mode
commit771e8af71200cd763dcbcf4dbc01205944669977
authorJosh Watzman <jwatzman@fb.com>
Thu, 10 Apr 2014 03:06:29 +0000 (9 20:06 -0700)
committerSara Golemon <sgolemon@fb.com>
Fri, 11 Apr 2014 04:44:52 +0000 (10 21:44 -0700)
treee6a84e729ee14f43f6a679b590ea8d222e7bcdd3
parenta8307c505c57cce8ef73565ba24217484f8d6089
Support PHP-decl mode

Support reading a `<?php` file as decl mode. This might seem
weird, but hear me out.

We need a good story around how 3rd party libraries, who may love Hack
and want to be maximally Hack compatible, can still remain compatible
with upstream PHP-5. The best we have right now is hhi, but those can
easily get out of sync with reality. We might also be able to build a
Hack => PHP type erasure tool, but then we create a new subset of the
language -- whatever PHP-5 supports, minus types. (Unless we built a
much more complicated tool that dealt with collections, short lambdas,
etc, which is a can of worms I really don't want to open.)

This solves the compatibility problem. If your code is largely
Hack-clean, you can at least let the typechecker suck in your class and
function definitions for any users of your library. But we do this
without creating a new subset of Hack or even really without defining a
new Hack mode -- this is just standard `decl` mode, but it happens to be
in a PHP file. We can even suck in PHP-5-compatible type information, if
you have any. (Creating a new subset of the language is an argument
against `<?php // partial`, which is technically easy to implement but
probably not directionally where we want to take the language.)

Basically, this means we can morally pull an HHI-like interface directly
out of your PHP source, if you are Hack-aware and add the annotation for
us.

Massive props to GitHub users pvh and naderman for coming up with this
idea during Hack dev day.

Reviewed By: @gabelevi

Differential Revision: D1268908
hphp/hack/src/parsing/lexer_hack.mll
hphp/hack/src/parsing/parser_hack.ml
hphp/hack/test/more_tests/decl_php.php [new file with mode: 0644]
hphp/hack/test/more_tests/decl_php.php.exp [new file with mode: 0644]