Pessimize get and set on object and class properties
commit11bb0c2e7f8b5569ed489d240b0f9b51e33f01be
authorVassil Mladenov <vmladenov@fb.com>
Tue, 20 Aug 2019 18:54:49 +0000 (20 11:54 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Tue, 20 Aug 2019 18:56:45 +0000 (20 11:56 -0700)
tree3a19d3a18dd350722eab1e64376ec78fa3b10644
parent3809f39b82d04f32237e0e9cf157b9059bdec72e
Pessimize get and set on object and class properties

Summary:
The easiest way to explain this diff is by example. We consider property access and assignment on unenforceable types to be operating on like types. So:
```
class C {
  public shape('a' => int) $mem = shape('a' => 4);
  public static shape('a' => int) $stat_mem = shape('a' => 4);
}
```
is treated implicitly as
```
class C {
  private shape('a' => int) $mem = shape('a' => 4);
  private static shape('a' => int) $stat_mem = shape('a' => 4);

  public function get_mem(): shape('a' => int) { return $this->mem; }
  public function set_mem(shape('a' => int) $s):  { $this->mem = $s; }

  public static function get_static_mem(): shape('a' => int) { return self::$static_mem; }
  public static function set_static_mem(shape('a' => int) $s):  { self::$static_mem = $s; }
}
```
and then the get/set methods are pessimized to
```
class C {
  ...

  public function get_mem(): ~shape('a' => int) { ... }
  public function set_mem(~shape('a' => int) $s):  { ... }

  public static function get_static_mem(): ~shape('a' => int) { ... }
  public static function set_static_mem(~shape('a' => int) $s):  { ... }
}
```

The end result is that unenforced properties are retrieved as like types, and it is now possible to write `dynamic` into unenforced properties.

Reviewed By: Matt-Schellhas

Differential Revision: D16906171

fbshipit-source-id: 901d102dd3aa2f4bd29ae0f65f10eb8f0ccb1b99
hphp/hack/src/typing/typing.ml
hphp/hack/src/typing/typing_enforceability.ml
hphp/hack/test/typecheck/like_types/simple_pessimization/class_get_set.php [new file with mode: 0644]
hphp/hack/test/typecheck/like_types/simple_pessimization/class_get_set.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/like_types/simple_pessimization/obj_get_set.php [new file with mode: 0644]
hphp/hack/test/typecheck/like_types/simple_pessimization/obj_get_set.php.exp [new file with mode: 0644]