Enforce output & access to static properties via coeffects
commit79b39791d64eab338557394f02649a1ecac64225
authorLeo Osvald <leoo@fb.com>
Sat, 21 Nov 2020 02:29:19 +0000 (20 18:29 -0800)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Sat, 21 Nov 2020 02:31:31 +0000 (20 18:31 -0800)
tree43520f1d3d082fc753c1ad1274b143e4cfb038b5
parent3fdd317e4d403e8576d1ef5e4f00934443f20345
Enforce output & access to static properties via coeffects

Summary:
Write logic for conveniently enforcing an operation based on the
*local* capability if coeffects are enabled in the typechecker (noop, otherwise).
This is *always* sound; unsafe capabilities are only used for enforcing calls
to other user-space functions.

Enforcing an operation requires 2 lines of code, e.g.:

```
let enforce_static_property_access =
  enforce_local_capability Capabilities.(mk globals) "Static property access"
```

and insert a single line during typing at the appropriate place:

  Typing_local_ops.enforce_static_property_access pos env;

and **coeffect tracking does all the magic**!

Reviewed By: vassilmladenov

Differential Revision: D24969913

fbshipit-source-id: 30ec8ebaf7cc27161af4eb6439224d4f1a67cef7
13 files changed:
hphp/hack/src/errors/error_codes.ml
hphp/hack/src/errors/errors.ml
hphp/hack/src/errors/errors.mli
hphp/hack/src/naming/naming_special_names.ml
hphp/hack/src/oxidized/gen/error_codes.rs
hphp/hack/src/typing/dune
hphp/hack/src/typing/tast_check/basic_reactivity_check.ml
hphp/hack/src/typing/typing.ml
hphp/hack/src/typing/typing_local_ops.ml [new file with mode: 0644]
hphp/hack/test/typecheck/coeffects/local/globals_static_property.php [new file with mode: 0644]
hphp/hack/test/typecheck/coeffects/local/globals_static_property.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/coeffects/local/output.php [new file with mode: 0644]
hphp/hack/test/typecheck/coeffects/local/output.php.exp [new file with mode: 0644]