keep info about what variables are assigned in unsafe blocks
commitd3f7d20d241ae256aac892f5ab49db8be278cc91
authorCatherine Gasnier <catg@fb.com>
Sun, 14 Oct 2018 17:37:52 +0000 (14 10:37 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Sun, 14 Oct 2018 17:40:05 +0000 (14 10:40 -0700)
tree9237994e44da61f27beac2623678008753efcb1d
parent5cbd44099b4be4dc1ec301e63ce0749fe7f98433
keep info about what variables are assigned in unsafe blocks

Summary:
In order to be able to properly report undefined variables in Typing, we need to traverse unsafe blocks in search of variables being defined, just like Naming currently does. This diff is a prerequisite to D7763002 "Fix control flow in naming".

We traverse the unsafe block Nast using a visitor and gather defined variables. We deal with control flow using continuations, in a similar way as the `hack/doc/type_system/flowtypes.ml` toy.

That's a lot of lines just for unsafe blocks, but `// UNSAFE` is sometimes used for performance reasons, so we cannot run the inference algorithm on it even if we replace all types with Tany.
Besides, if we did that, the unification of type variables sometimes "leak" types out of the unsafe block, so test unsafe_block_lambda.php would fail.

Reviewed By: Wilfred

Differential Revision: D9766253

fbshipit-source-id: fe2cd1ddf783fd29de7885bcfff5f308634ac312
hphp/hack/src/typing/typing.ml
hphp/hack/src/typing/typing_gather_defined.ml [new file with mode: 0644]
hphp/hack/src/typing/typing_lenv.mli
hphp/hack/test/typecheck/control_flow/block.php [new file with mode: 0644]
hphp/hack/test/typecheck/control_flow/block.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/defined/unsafe_block.php [new file with mode: 0644]
hphp/hack/test/typecheck/defined/unsafe_block.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/defined/unsafe_block_control_flow.php [new file with mode: 0644]
hphp/hack/test/typecheck/defined/unsafe_block_control_flow.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/defined/unsafe_block_lambda.php [new file with mode: 0644]
hphp/hack/test/typecheck/defined/unsafe_block_lambda.php.exp [new file with mode: 0644]