Add declarations for internal keyword in direct decl and legacy parsers
commit940324f02d1cbb7f8c8cdfd439427ebcee4c3ff7
authorJames Wu <jjwu@fb.com>
Mon, 11 Apr 2022 19:55:27 +0000 (11 12:55 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Mon, 11 Apr 2022 19:55:27 +0000 (11 12:55 -0700)
treea45fcc7a2514a7328c1177b204762d4d909c07c0
parentfbb8a38fc7df7bdd318f5ae6848d603bccfc05e0
Add declarations for internal keyword in direct decl and legacy parsers

Summary:
This diff adds declarations for the internal keyword on toplevel entities in the direct decl and legacy parsers.

For classes, we add a field sc_internal to shallow_class. sc_internal is true when the class is preceded by the internal keyword. (This is true for classes, interfaces, traits, enum classes etc). Note that the typechecker does not consume this new field in this diff; it looks at sc_user_attributes instead for the <<__Internal>> attribute.

In decl_provider.Class, we consume sc_user_attributes to check if a class is internal. I change it to consume both the attribute and sc_internal above.

For functions, it was a bit trickier. Functions are represented in decl by a function element type defined in typing_defs here: https://fburl.com/code/gdxzcgbk
Since it already has an internal field, toplevel functions have the field `fe_internal` populated by the `<<__Internal>>` attribute. To keep backward compatibility before we port the typechecker to no longer use attributes, I make fe_internal true when *either* `<<__Internal>>` is set on the function or the internal keyword is present as a modifier.

In the next diff, Melanie can then remove the ability to use the internal attribute altogether, and consume sc_internal in the typechecker instead.

Reviewed By: chenmela

Differential Revision: D35478638

fbshipit-source-id: bd3f5136ae038adc9a1af17bd8d350d85af91807
122 files changed:
hphp/hack/src/decl/decl_folded_class.ml
hphp/hack/src/decl/decl_nast.ml
hphp/hack/src/decl/decl_pos_utils.ml
hphp/hack/src/decl/direct_decl_smart_constructors.rs
hphp/hack/src/decl/shallow_decl.ml
hphp/hack/src/decl/shallow_decl_defs.ml
hphp/hack/src/decl/shallow_decl_defs.mli
hphp/hack/src/oxidized_by_ref/decl_visitor/node_impl_gen.rs
hphp/hack/src/oxidized_by_ref/gen/shallow_decl_defs.rs
hphp/hack/src/parser/lowerer/lowerer.rs
hphp/hack/src/parser/lowerer/modifier.rs
hphp/hack/src/typing/typing_classes_heap.ml
hphp/hack/test/decl/abstract_method.php.exp
hphp/hack/test/decl/accept_disposable.php.exp
hphp/hack/test/decl/class_const_declarator_list.php.exp
hphp/hack/test/decl/class_const_int_literals.php.exp
hphp/hack/test/decl/class_const_referencing_enum.php.exp
hphp/hack/test/decl/class_const_referencing_global_const.php.exp
hphp/hack/test/decl/class_const_with_parens.php.exp
hphp/hack/test/decl/class_in_namespace.php.exp
hphp/hack/test/decl/class_level_where.php.exp
hphp/hack/test/decl/classes.php.exp
hphp/hack/test/decl/classes_consistent_construct.php.exp
hphp/hack/test/decl/classes_const_attribute.php.exp
hphp/hack/test/decl/classes_const_keyword.php.exp
hphp/hack/test/decl/classes_inferred_constant_types.php.exp
hphp/hack/test/decl/classes_inheritance.php.exp
hphp/hack/test/decl/classes_reified_generics.php.exp
hphp/hack/test/decl/classes_require.php.exp
hphp/hack/test/decl/classes_typeconst.php.exp
hphp/hack/test/decl/classname.php.exp
hphp/hack/test/decl/coeffect_contexts.php.exp
hphp/hack/test/decl/coeffect_parameter_dependent.php.exp
hphp/hack/test/decl/const_attribute.php.exp
hphp/hack/test/decl/const_misc1.php.exp
hphp/hack/test/decl/const_missing_hint.php.exp
hphp/hack/test/decl/const_string_escaping.php.exp
hphp/hack/test/decl/constraints_mentioning_tparams_in_same_list.php.exp
hphp/hack/test/decl/constraints_with_fully_qualified_name.php.exp
hphp/hack/test/decl/constraints_with_fully_qualified_name_in_namespace.php.exp
hphp/hack/test/decl/consts_misc2.php.exp
hphp/hack/test/decl/ctx_const_both_bounds.php.exp
hphp/hack/test/decl/ctx_const_lower_bound.php.exp
hphp/hack/test/decl/ctx_const_no_bounds.php.exp
hphp/hack/test/decl/ctx_const_upper_bound.php.exp
hphp/hack/test/decl/cyclic.php.exp
hphp/hack/test/decl/denotable_unions.php.exp
hphp/hack/test/decl/deprecated.php.exp
hphp/hack/test/decl/dynamically_callable.php.exp
hphp/hack/test/decl/empty_method_name.php.exp
hphp/hack/test/decl/enforceable_type_const.php.exp
hphp/hack/test/decl/enum_class.php.exp
hphp/hack/test/decl/enum_constraint.php.exp
hphp/hack/test/decl/enum_user_attributes.php.exp
hphp/hack/test/decl/enums.php.exp
hphp/hack/test/decl/explicit_type_collection.php.exp
hphp/hack/test/decl/file_mode.php.exp
hphp/hack/test/decl/final_method.php.exp
hphp/hack/test/decl/function_where_constraints.php.exp
hphp/hack/test/decl/functions.php.exp
hphp/hack/test/decl/generic_classes.php.exp
hphp/hack/test/decl/generic_method_tparam_scope.php.exp
hphp/hack/test/decl/hhi.hhi.exp
hphp/hack/test/decl/ifc_policied.php.exp
hphp/hack/test/decl/interface.php.exp [copied from hphp/hack/test/decl/abstract_method.php.exp with 77% similarity]
hphp/hack/test/decl/interfaces.php.exp
hphp/hack/test/decl/like_types.php.exp
hphp/hack/test/decl/memoize_lsb.php.exp
hphp/hack/test/decl/module_attr.php.exp
hphp/hack/test/decl/module_enums.php.exp
hphp/hack/test/decl/module_hint.php.exp
hphp/hack/test/decl/module_methods.php.exp
hphp/hack/test/decl/module_properties.php.exp
hphp/hack/test/decl/module_static_prop.php.exp
hphp/hack/test/decl/multifile.php.exp
hphp/hack/test/decl/multiple_user_attributes_on_class.php.exp
hphp/hack/test/decl/namespace_import.php.exp
hphp/hack/test/decl/namespace_keyword.hhi.exp
hphp/hack/test/decl/namespace_self.php.exp
hphp/hack/test/decl/namespace_use.php.exp
hphp/hack/test/decl/namespaces1.php.exp
hphp/hack/test/decl/namespaces2.php.exp
hphp/hack/test/decl/nested_namespaces.php.exp
hphp/hack/test/decl/override_attribute.php.exp
hphp/hack/test/decl/php_std_lib.hhi.exp
hphp/hack/test/decl/private_method.php.exp
hphp/hack/test/decl/prop_without_visibility_modifier.php.exp
hphp/hack/test/decl/property_declarations.php.exp
hphp/hack/test/decl/property_needs_init.hhi.exp
hphp/hack/test/decl/readonly.php.exp
hphp/hack/test/decl/return_disposable.php.exp
hphp/hack/test/decl/return_pos.php.exp
hphp/hack/test/decl/rewritten_tparams.php.exp
hphp/hack/test/decl/self_in_type_constant.php.exp
hphp/hack/test/decl/shape_expression_key_types.php.exp
hphp/hack/test/decl/shape_self.php.exp
hphp/hack/test/decl/sound_dynamic_call_meth_1.bad.php.exp
hphp/hack/test/decl/static_method_call_with_explicit_targ.php.exp
hphp/hack/test/decl/tparams_on_class_and_method.php.exp
hphp/hack/test/decl/trait_require_class.php.exp
hphp/hack/test/decl/trait_use_conflict_resolution.php.exp
hphp/hack/test/decl/traits.php.exp
hphp/hack/test/decl/type_param_attrs.php.exp
hphp/hack/test/decl/typeconst_property_promotion.php.exp
hphp/hack/test/decl/unnamed_variadic_method_parameter.php.exp
hphp/hack/test/decl/untyped_prop.php.exp
hphp/hack/test/decl/use_type.php.exp
hphp/hack/test/decl/user_attributes_in_namespaces.php.exp
hphp/hack/test/decl/wildcard_invalid.php.exp
hphp/hack/test/decl/wildcard_invalid_targ.php.exp
hphp/hack/test/decl/xhp.php.exp
hphp/hack/test/decl/xhp_attr.php.exp
hphp/hack/test/decl/xhp_class_const.php.exp
hphp/hack/test/decl/xhp_modifier.php.exp
hphp/hack/test/decl/xhp_self.php.exp
hphp/hack/test/typecheck/attributes/create_attributes.php.direct_decl_exp
hphp/hack/test/typecheck/func_ptr_in_constants/allowed_func_ptr_builtins.php.direct_decl_exp
hphp/hack/test/typecheck/modules/internal_keyword.php
hphp/hack/test/typecheck/modules/internal_keyword.php.exp
hphp/hack/test/typecheck/modules/internal_keyword.php.rupro_folded_decl.exp [new file with mode: 0644]
hphp/hack/test/typecheck/modules/module_attr.php.direct_decl_exp
hphp/hack/test/typecheck/user_attributes_typedef.php.direct_decl_exp