Type-check context constants [2/?]: access
commita69f1f5d45932a76de54b022f72bca835ce02dd5
authorLeo Osvald <leoo@fb.com>
Wed, 7 Apr 2021 20:41:11 +0000 (7 13:41 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 7 Apr 2021 20:42:56 +0000 (7 13:42 -0700)
tree65f92711a1b4f83f3d39ed7bea4df0716c0c50a5
parent46993ace53a318e289a67889cf323b564f13dcda
Type-check context constants [2/?]: access

Summary:
When type-checking a type constant desugared from a
context constant, read its lower bounds in addition to its upper bound.
(The subtyping logic (constraint-based solver) already works with both bounds.)
The extra expressive power is best demonstrated with a brief example:

```
interface I {
  const ctx C super [write_props];
  function m()[this::C]: void;
}

function good_caller(I $i)[write_props]: void { $i->m(); }
function bad_caller(I $i)[]: void {} // ERROR: write_props is missing
```

Without the lower (`super`) bounds, this `good_caller` would _not_ type-check,
since the implicit lower bound on dependent type `this::C` is `nothing`;
only a caller with `nothing` (infinite set of capabilities) was previously
allowed to call a context-dependent function such as `I::m`
That _major_ limitation has greatly limited the use of (co)effect polymorphism so far.

Coming up: unban the typechecker-only (not HHVM) parser error that prohibits
any bounds on context constants.

Reviewed By: vsiles

Differential Revision: D27369568

fbshipit-source-id: bc0242b33274b12d2a6516ce28493b4394b7dad2
hphp/hack/src/typing/typing_env.ml
hphp/hack/src/typing/typing_env.mli
hphp/hack/src/typing/typing_taccess.ml
hphp/hack/test/typecheck/coeffects/ctx-const-bounds_call-from-less-pure.php [new file with mode: 0644]
hphp/hack/test/typecheck/coeffects/ctx-const-bounds_call-from-less-pure.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/coeffects/ctx-const-bounds_call-from-policied-of.php [new file with mode: 0644]
hphp/hack/test/typecheck/coeffects/ctx-const-bounds_call-from-policied-of.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/coeffects/ctx_const_constraints.php.direct_decl_exp [new file with mode: 0644]