Add module declaration type checking
commit25c3e71624fb5c0be78899a52580d33b5424a8c8
authorHunter Goldstein <hgoldstein@fb.com>
Thu, 17 Mar 2022 18:17:03 +0000 (17 11:17 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 17 Mar 2022 18:17:03 +0000 (17 11:17 -0700)
tree5db5a1f74b87db12da7129265ee0e30b0434c1d7
parent85b55e9c85c84c6cfb7c3937668912ce7197cd1e
Add module declaration type checking

Summary:
# High Level
This threads module declarations through `hh_server` such that they are now understood and are accessible across files. The main effect is that declaring a file to be a part of a module requires that said module has an existing declaration in the current codebase. For example:
```
//// a-decl.php
<?hh
<<file:__EnableUnstableFeatures('modules')>
module A {}

//// a.php
<?hh

// Unbound name error w/o `a-decl.php`
<<file:__EnableUnstableFeatures('modules'), __Module('A')>>
```
# This Diff

## Naming

It's now an unbound name error to reference being a part of a module w/o a corresponding module declaration, as per the high level context.

## Tests

This is where most of the tests are added / modified, including but not limited to:
* Adding module declarations to existing tests so that we aren't flooded w/ naming errors. This is generally in a separate file, but there's no set rule about where to put module decls.
* Added a test to ensure that modules are included in the naming table
* Added fanout tests covering:
  * Adding a reference to a nonexistent module, then adding the module decl
  * Making a file part of a module and making a class internal
  * Changing the membership for a module in a class
  * Making a function internal
  * Making a typedef internal
  * Removing a module decl
* Added *some* more typechecking tests, such as an edge case around ordering between top level decls and file attributes. Notably, the `hphp/hack/test/typecheck/modules/file_attribute_order.php` file has a difference here.

Differential Revision: D34481127

fbshipit-source-id: c47dd9eaf15fb7eb1164a3e503a536f649299987
118 files changed:
hphp/hack/src/decl/direct_decl_smart_constructors.rs
hphp/hack/src/errors/name_context.ml
hphp/hack/src/errors/naming_error.ml
hphp/hack/src/hh_single_decl.ml
hphp/hack/src/naming/naming_table.ml
hphp/hack/src/oxidized/gen/tast.rs
hphp/hack/src/oxidized_by_ref/gen/tast.rs
hphp/hack/src/typing/nast_check/unbound_name_check.ml
hphp/hack/src/typing/tast.ml
hphp/hack/src/typing/typing_check_job.ml
hphp/hack/src/typing/typing_check_job.mli
hphp/hack/src/typing/typing_check_service.ml
hphp/hack/src/typing/typing_env.ml
hphp/hack/src/typing/typing_env.mli
hphp/hack/src/typing/typing_env_from_def.ml
hphp/hack/src/typing/typing_env_from_def.mli
hphp/hack/src/typing/typing_toplevel.ml
hphp/hack/src/typing/typing_toplevel.mli
hphp/hack/src/typing/typing_typedef.ml
hphp/hack/test/decl/module_attr.php
hphp/hack/test/decl/module_attr.php.exp
hphp/hack/test/decl/module_attr.php.rupro_folded_decl.exp
hphp/hack/test/decl/module_enums.php
hphp/hack/test/decl/module_enums.php.exp
hphp/hack/test/decl/module_enums.php.rupro_folded_decl.exp
hphp/hack/test/decl/module_hint.php
hphp/hack/test/decl/module_hint.php.exp
hphp/hack/test/decl/module_hint.php.rupro_folded_decl.exp
hphp/hack/test/decl/module_methods.php
hphp/hack/test/decl/module_methods.php.exp
hphp/hack/test/decl/module_methods.php.rupro_folded_decl.exp
hphp/hack/test/decl/module_properties.php
hphp/hack/test/decl/module_properties.php.exp
hphp/hack/test/decl/module_properties.php.rupro_folded_decl.exp
hphp/hack/test/decl/module_static_prop.php
hphp/hack/test/decl/module_static_prop.php.exp
hphp/hack/test/decl/module_static_prop.php.rupro_folded_decl.exp
hphp/hack/test/fanout/modules/module-add-ref-to-nonexist.php [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-add-ref-to-nonexist.php.incr_no_old_decls.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-add-ref-to-nonexist.php.incr_old_decl.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-add-ref-to-nonexist.php.saved_state.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-add-reference.php [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-add-reference.php.incr_no_old_decls.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-add-reference.php.incr_old_decl.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-add-reference.php.saved_state.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-change-class-membership.php [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-change-class-membership.php.incr_no_old_decls.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-change-class-membership.php.incr_old_decl.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-change-class-membership.php.saved_state.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-change-membership.php [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-change-membership.php.incr_no_old_decls.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-change-membership.php.incr_old_decl.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-change-membership.php.saved_state.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-make-internal-func.php [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-make-internal-func.php.incr_no_old_decls.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-make-internal-func.php.incr_old_decl.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-make-internal-func.php.saved_state.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-make-internal-typedef.php [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-make-internal-typedef.php.incr_no_old_decls.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-make-internal-typedef.php.incr_old_decl.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-make-internal-typedef.php.saved_state.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-make-internal.php [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-make-internal.php.incr_no_old_decls.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-make-internal.php.incr_old_decl.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-make-internal.php.saved_state.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-remove-decl-by-comment.php [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-remove-decl-by-comment.php.incr_no_old_decls.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-remove-decl-by-comment.php.incr_no_old_decls.out [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-remove-decl-by-comment.php.incr_old_decl.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-remove-decl-by-comment.php.incr_old_decls.out [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-remove-decl-by-comment.php.saved_state.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-remove-decl-by-comment.php.saved_state.out [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-remove-decl.php [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-remove-decl.php.incr_no_old_decls.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-remove-decl.php.incr_old_decl.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-remove-decl.php.saved_state.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-simple.php [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-simple.php.incr_no_old_decls.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-simple.php.incr_old_decl.exp [new file with mode: 0644]
hphp/hack/test/fanout/modules/module-simple.php.saved_state.exp [new file with mode: 0644]
hphp/hack/test/typecheck/modules/basic_fun_call.php
hphp/hack/test/typecheck/modules/case_insensitive.php [new file with mode: 0644]
hphp/hack/test/typecheck/modules/case_insensitive.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/modules/file_attribute_order.php [new file with mode: 0644]
hphp/hack/test/typecheck/modules/file_attribute_order.php.direct_decl_exp [new file with mode: 0644]
hphp/hack/test/typecheck/modules/file_attribute_order.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/modules/fun_pointer.php
hphp/hack/test/typecheck/modules/module_attr.php
hphp/hack/test/typecheck/modules/module_attr.php.direct_decl_exp
hphp/hack/test/typecheck/modules/module_attr_bad.php
hphp/hack/test/typecheck/modules/module_attr_bad.php.exp
hphp/hack/test/typecheck/modules/module_bad_arity.php
hphp/hack/test/typecheck/modules/module_bad_override.php
hphp/hack/test/typecheck/modules/module_bad_visibility.php
hphp/hack/test/typecheck/modules/module_bad_visibility.php.exp
hphp/hack/test/typecheck/modules/module_class_expr.php
hphp/hack/test/typecheck/modules/module_constructor.php
hphp/hack/test/typecheck/modules/module_decl_and_use.php [new file with mode: 0644]
hphp/hack/test/typecheck/modules/module_decl_and_use.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/modules/module_enums.php
hphp/hack/test/typecheck/modules/module_file_attr.php
hphp/hack/test/typecheck/modules/module_hint.php
hphp/hack/test/typecheck/modules/module_inheritance.php
hphp/hack/test/typecheck/modules/module_interfaces.php
hphp/hack/test/typecheck/modules/module_internal_class.php
hphp/hack/test/typecheck/modules/module_methods_basic.php
hphp/hack/test/typecheck/modules/module_properties.php
hphp/hack/test/typecheck/modules/module_static_method.php
hphp/hack/test/typecheck/modules/module_static_prop.php
hphp/hack/test/typecheck/modules/module_traits.php
hphp/hack/test/typecheck/modules/module_typedef.php
hphp/hack/test/typecheck/modules/module_typedef.php.exp
hphp/hack/test/typecheck/modules/module_weird_type_locations.php
hphp/hack/test/typecheck/modules/multiple_module_decls.php [new file with mode: 0644]
hphp/hack/test/typecheck/modules/multiple_module_decls.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/modules/multiple_module_use_decls.php [new file with mode: 0644]
hphp/hack/test/typecheck/modules/multiple_module_use_decls.php.exp [new file with mode: 0644]
hphp/hack/test/unit/naming/naming_table_tests.ml