Fix calculation of direct required ancestors
Summary:
The heap API for fetching class decls offers functions for fetching the set of *all* ancestors and the set of *all* required ancestored (acquired through `require extends` and `require implements`). Given these, we calculate the set of *direct* ancestors (to be put into `extends` and `implements` clauses) and the set of *direct* required ancestors (to be added by placing suitable `require extends` / `require implements` in the body of a trait or interface). We calculate these sets by subtracting from the set of all ancestors the set of all ancestors' ancestors. Except that for required ancestors we calculate the ancestors' ancestors by taking the union of all required ancestors of the required ancestors of a given trait or interface, which is not correct. Consider this example (added as a new test case below):
```
abstract class B {
public function f(): void {}
}
interface I {
require extends B;
}
interface J extends I {}
function with_indirect_require_extends(J $x): void {
$x->f();
}
```
The set of required ancestors of `J` is `{B}` and `B` doesn't have require ancestors, so we end up with `{B}` as the set of direct required ancestors of `J`, and similarly for `I`, so that the extracted code looks like
```
interface I {
require extends B;
}
interface J extends I {
require extends B;
}
```
Instead, we should take the union of all required ancestors over all ancestors and required ancestors.
Reviewed By: Wilfred
Differential Revision:
D18764680
fbshipit-source-id:
fff08335e23fd990d767470e3acd04ee0423782a