Avoid redundant calls to subtype_method
commit6d2ff47c4ced0718dc08fcb9497ed8eff34fa35d
authorAndrew Kennedy <akenn@fb.com>
Wed, 5 Aug 2020 06:40:20 +0000 (4 23:40 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 5 Aug 2020 06:55:37 +0000 (4 23:55 -0700)
treef3d37d2be98d764f0c2c5423b81e94cc8e262326
parentdb86c4f64599c187064a25bde7c988f12a298bcb
Avoid redundant calls to subtype_method

Summary:
The `Typing_subtype_method.subtype_method` function checks that an "overriding" method signature is compatible with the "overridden" method signature. But we call it redundantly, e.g. in the following

```
class C {
  public function foo():mixed { ... }
}
class D extends C {
  public function foo():string { ... }
}
class E extends D {
}
```
we check not only that the signature of `D::foo` is compatible with `C::foo`, but also that `E::foo` is compatible with `D::foo`. But as the signature of `E::foo` is just copied down from `D::foo`, this is just an identity check, and so completely redundant.

There is an easy way to avoid the redundant checks: just look at the `ce_origin` field in the class element. When these are the same in parent and child, then any override checks are redundant.

The override checks (which are dominated by subtyping, but include various other tests) are expensive: on large codebases the overall saving in total type check time is over 15%.

Reviewed By: vsiles

Differential Revision: D22358580

fbshipit-source-id: 5ce78f528de3fd481d34736df3823e5f9873e2bd
hphp/hack/src/typing/typing_extends.ml
hphp/hack/test/typecheck/iface_require_incompat4.php
hphp/hack/test/typecheck/iface_require_incompat4.php.exp
hphp/hack/test/typecheck/iface_require_incompat4.php.legacy_decl.exp
hphp/hack/test/typecheck/iface_require_incompat4.php.like_types.exp