Replacing `$members` generation with reflection/cache
commit218df0291bb4d023ec4127b7be46c8ece5169c71
authorVincent Siles <vsiles@fb.com>
Fri, 17 Apr 2020 13:03:17 +0000 (17 06:03 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Fri, 17 Apr 2020 13:06:44 +0000 (17 06:06 -0700)
tree4f5771e71cbcd4775bc5fd3a4bc502ffcd4f220b
parentdc670e520b58a1687f5acfae00c9a7242c75c0c1
Replacing `$members` generation with reflection/cache

Summary:
The current generation of the `Members()` method for PU (which outputs the list of all PU instances in a PU) is currently not recursively looking into parent classes, where it should. In the following, I don't mention mangling to make things more clear:

If the class is not extending any other, `Members` just return a keyset with all the local information available. We use memoization here.

```
  class C  {
  ...

  <<__Memoize>>
  public static function Members() : keyset<string> {
    return keyset[ .. strings based on local PU instances ...];
  }
}
```

If the class is extending another one, we look up the hierarchy, which be costly, so here, we also use memoization. The code looks like:

```
  class C extends D {
  ...

  <<__Override, __Memoize>>
  public static function Members() : keyset<string> {
    $result = keyset[ .. strings based on local PU instances ...];
    $class = new ReflectionClass(parent::class);
    try {
      // might throw if the method is not in the parent class
      $method = $class->getMethod('Members');
      // method is here, call it
      $parent_members = $method->invoke(null);
      foreach ($parent_members as $p) {
        $result[] = $p;
      }
    } catch (ReflectionException $_) {
      // nothing in the parent, only use local info
    }
    return $result;
  }
}
```

This diff also update the name mangling (because it didn't work with properties). Now
```
class C {
   enum E {
     :Foo (...);
  }
}
```
will lead to a property `C::pu$E$Members`.

Reviewed By: francesco-zappa-nardelli

Differential Revision: D20920121

fbshipit-source-id: ec9e957521b283553e74d8cdb7d175390cbf6134
hphp/hack/src/oxidized/gen/tast.rs
hphp/hack/src/pocket_universes/pocket_universes.ml
hphp/hack/src/typing/tast.ml
hphp/hack/test/pocket_universes/compile/closure.good.php.exp
hphp/hack/test/pocket_universes/compile/members.good.php.exp
hphp/hack/test/pocket_universes/compile/members2.good.php [new file with mode: 0644]
hphp/hack/test/pocket_universes/compile/members2.good.php.exp [new file with mode: 0644]
hphp/hack/test/pocket_universes/compile/members3.good.php [new file with mode: 0644]
hphp/hack/test/pocket_universes/compile/members3.good.php.exp [new file with mode: 0644]
hphp/hack/test/pocket_universes/compile/translate.good.php.exp