Add type parameters to linearization
commit4cc49ef8fd0c928633ee8f84e2fbff1565ba8d52
authorJames Wu <jjwu@fb.com>
Wed, 26 Sep 2018 16:20:38 +0000 (26 09:20 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Wed, 26 Sep 2018 16:27:24 +0000 (26 09:27 -0700)
tree1548a6647d8d949cfe439727f59c0eb216c38ac1
parent29898e39bfbac0fdca65a9878d4a837a39751780
Add type parameters to linearization

Summary:
This diff adds type parameters to the list of things linearization stores. Each type parameterization of a class is a separate class when it comes to linearization. Consider the example test:

```
<?hh

interface Ico<+T> {}

interface I2 extends Ico<mixed> {}

interface I3 extends I2, Ico<num> {}

interface I4 extends I3, Ico<int> {}
```

this becomes:

```
L(I4) = I4 + L(I3) + L(Ico<int>)
        = I4 + [I3 + L(I2) + L(Ico<num>)] + Ico<int>
        = I4 + I3 + [I2 + L(Ico<mixed>)] + Ico<num> + Ico<int>
        = I4 + I3 + I2 + Ico<mixed> + Ico<num> + Ico<int>
        = [I4, I3, I2, Ico<mixed>, Ico<num>, Ico<int>]
```

which is correct according to our current behavior.

If you instead switch Ico<int> and I3, you get a completely different linearization.

Reviewed By: vassilmladenov

Differential Revision: D9757934

fbshipit-source-id: bad330eecd4117e459f28ddb57f01edf45453a2c
hphp/hack/src/decl/decl_defs.ml
hphp/hack/src/decl/decl_linearize.ml
hphp/hack/src/hh_single_type_check.ml
hphp/hack/test/mro/type_params.php [new file with mode: 0644]
hphp/hack/test/mro/type_params.php.exp [new file with mode: 0644]
hphp/hack/test/mro/type_params2.php [new file with mode: 0644]
hphp/hack/test/mro/type_params2.php.exp [new file with mode: 0644]
hphp/hack/test/mro/type_params3.php [new file with mode: 0644]
hphp/hack/test/mro/type_params3.php.exp [new file with mode: 0644]