Transformation for parameter dependent contexts
commitb9cfc1b6c0ab44720a146eb862bbef9720ae8c92
authorVassil Mladenov <vmladenov@fb.com>
Mon, 21 Dec 2020 08:10:46 +0000 (21 00:10 -0800)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Mon, 21 Dec 2020 08:12:48 +0000 (21 00:12 -0800)
treed1cc17270d743b6d1fed2a5ddfce5ef36c7542c3
parent51d3c7ca374379c695915bb231f4e3b1cd57304d
Transformation for parameter dependent contexts

Summary:
This diff adds rewriting for $x::C contexts.

```
function f(A $x)[$x::Co]: void {}

==>

function f<
  T$x as A,
  T$x@Co,
>(
  T$x $x
)[$x::Co]: void where
  T$x@Co = T$x::Co
{}
```

The transformation also handles the case of ?A, and when $x's type is already a type parameter. The latter is useful because the runtime will enforce $x as an A (upper bound enforcement) in this function

```
function f<T as A>(T $x): void {}
```

but it will not do so in the following case

```
function f<T as A, T$x as T>(T$x $x): void {}
```

The use of Rust here is a tradeoff. Pattern matching is very poor which makes this less readable than if the rewrite happened in Naming, but mutating the data structures in place as opposed to rebuilding them in a functional world ends up being less cumbersome overall.

Reviewed By: losvald

Differential Revision: D25608862

fbshipit-source-id: 3e14bf3825f8a1cd6f83d0511b7f641c0de89eb9
19 files changed:
hphp/hack/Cargo.lock
hphp/hack/src/annotated_ast/aast_defs.ml
hphp/hack/src/decl/decl_hint.ml
hphp/hack/src/hhbc/reified_generics_helpers.rs
hphp/hack/src/naming/naming.ml
hphp/hack/src/oxidized/aast_visitor/node_impl_gen.rs
hphp/hack/src/oxidized/aast_visitor/node_mut_impl_gen.rs
hphp/hack/src/oxidized/gen/aast_defs.rs
hphp/hack/src/oxidized/impl_gen/aast_defs_impl_gen.rs
hphp/hack/src/oxidized_by_ref/gen/aast_defs.rs
hphp/hack/src/parser/lowerer/Cargo.toml
hphp/hack/src/parser/lowerer/lowerer.rs
hphp/hack/src/parser/syntax_error.rs
hphp/hack/src/server/serverExtractStandalone.ml
hphp/hack/src/typing/tast_check/instantiability_check.ml
hphp/hack/src/typing/typing_check_decls.ml
hphp/hack/test/nast/coeffects/poly_var.php.exp
hphp/hack/test/nast/coeffects_poly_var.php [new file with mode: 0644]
hphp/hack/test/nast/coeffects_poly_var.php.exp [new file with mode: 0644]