Basic flow analysis on if statements
commit82894dbd8dff78a1f4b55b94c2a7e8dcbcd15f21
authorJames Wu <jjwu@fb.com>
Wed, 25 Aug 2021 18:52:42 +0000 (25 11:52 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 25 Aug 2021 18:54:02 +0000 (25 11:54 -0700)
tree7a07756a247707156d69570a1a1a1d9f892bc2c9
parent1a781f62d056f67ca3b0e0ad14d495363a2bc866
Basic flow analysis on if statements

Summary:
This will be the first in a bunch of diffs to support flow analysis for readonly. Here we remove the old behavior of erroring upon changing mutability of readonlyness, and instead use flow analysis to correctly deduce the most conservative type for a given variable in the local environment.

Note: this will be kinda slow in the beginning because we are copying so many environments around. I'll work on optimizing it once I can get the correctness there.

FWIW, the analysis will technically not be sound right now because we haven't implemented flow analysis on all the other control flow structures(switch, loops, etc), but by the end of the diff stack this should all be safe.

Reviewed By: oulgen

Differential Revision: D30205978

fbshipit-source-id: 4b15189a821773519eba412410c8c5c1e990fa91
hphp/hack/src/parser/readonly_check.rs
hphp/hack/src/parser/syntax_error.rs
hphp/test/slow/readonly/attempted_redefines_mutable.php.expectf
hphp/test/slow/readonly/attempted_redefines_readonly.php.expectf
hphp/test/slow/readonly/shape.php
hphp/test/slow/readonly/shape.php.expectf