Add support for XHP namespaces (#8645)
commit26cfb0cac7f6bf04a5f2e1268320b28b5a5df0f1
authorJohan Oskarsson <johan@slack-corp.com>
Thu, 13 Feb 2020 22:48:50 +0000 (13 14:48 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 13 Feb 2020 22:50:51 +0000 (13 14:50 -0800)
treefb84582e762d2b458399e5bb912b10f7a54cbf54
parent408faaa46b4e423e5fb36133fcd09ff4efcfae36
Add support for XHP namespaces (#8645)

Summary:
This contains the second half of the split https://github.com/facebook/hhvm/issues/8595 PR. It adds namespace support for XHP. Note that this is only supported if the xhp class has been defined using the xhp modifier style. For example `xhp class name {}`.

Examples of supported syntax:
<:foo:bar> finds the xhp class \foo\bar
Use namespace
Use namespace as
Use type
Use type group

Currently not supported in this PR:
Declaring a class inside of a namespace using the xhp syntax. For example: `xhp class foo:bar {}`
I've struggled to get this to work. Will try again in a follow up PR when there are fewer moving parts to take care of. I think that's free standing enough that it's not a requirement to for this PR (that is already getting quite big).

See a more detailed list of syntax here: https://gist.github.com/fredemmott/de7eeb91765b0c98fafac9c591263aca

The meat of this PR is in `namespaces.ml` where we change an incoming :foo:bar into \foo\bar to match regular namespaces. `parser_trait.rs` contains the other big chunk where we change xhp elements to allow a colon prefix. This is to allow `<:foo:bar>` to be looked up as `\foo\bar` (as opposed to `<foo:bar>` that will look in `currentnamespace\foo\bar`.

Most of this functionality is hidden behind the flag `disable_xhp_element_mangling`. Perhaps that should be called enable_xhp_namespaces instead since it's not truly just about mangling anymore.

This also contains the following bug fix PR but that one should probably go in sooner rather than later:
https://github.com/facebook/hhvm/issues/8644
Pull Request resolved: https://github.com/facebook/hhvm/pull/8645

Reviewed By: Wilfred

Differential Revision: D19501207

fbshipit-source-id: 35e1112233fc29f07903260b5a6ea2c5b9761b42
171 files changed:
hphp/hack/src/annotated_ast/namespace_env.ml
hphp/hack/src/annotated_ast/namespace_env.mli
hphp/hack/src/hh_compile.rs
hphp/hack/src/hh_parse.ml
hphp/hack/src/hh_single_type_check.ml
hphp/hack/src/hhbc/closure_convert.rs
hphp/hack/src/hhbc/closure_convert_ffi.rs
hphp/hack/src/hhbc/compile.ml
hphp/hack/src/hhbc/emit_memoize_method.rs
hphp/hack/src/hhbc/hhbc_options.ml
hphp/hack/src/hhbc/hhbc_string_utils.ml
hphp/hack/src/naming/naming_elaborate_namespaces_endo.ml
hphp/hack/src/options/globalOptions.ml
hphp/hack/src/options/globalOptions.mli
hphp/hack/src/options/parserOptions.ml
hphp/hack/src/oxidized/gen/global_options.rs
hphp/hack/src/oxidized/gen/namespace_env.rs
hphp/hack/src/oxidized/gen/parser_options.rs
hphp/hack/src/oxidized/manual/global_options_impl.rs
hphp/hack/src/oxidized/manual/namespace_env_impl.rs
hphp/hack/src/parser/core/declaration_parser.rs
hphp/hack/src/parser/core/lexer.rs
hphp/hack/src/parser/core/parser_trait.rs
hphp/hack/src/parser/lowerer.rs
hphp/hack/src/parser/namespaces.ml
hphp/hack/src/parser/rust_parser_errors_ffi.rs
hphp/hack/src/server/serverConfig.ml
hphp/hack/test/nast/class_level_where_clauses/test_class_level_where_clauses.php.exp
hphp/hack/test/nast/file_attributes_from_multiple_namespaces.php.exp
hphp/hack/test/nast/file_attributes_in_namespaces.php.exp
hphp/hack/test/nast/file_attributes_in_namespaces_with_namespaced_values.php.exp
hphp/hack/test/nast/fun_decl.php.exp
hphp/hack/test/nast/fun_empty.php.exp
hphp/hack/test/nast/function_pointers/class_meth.php.exp
hphp/hack/test/nast/function_pointers/function_pointer.php.exp
hphp/hack/test/nast/function_pointers/inst_meth.php.exp
hphp/hack/test/nast/top_level.php.exp
hphp/hack/test/tast/add_vector.php.exp
hphp/hack/test/tast/arith_plus.php.exp
hphp/hack/test/tast/array_filter.php.exp
hphp/hack/test/tast/array_map.php.exp
hphp/hack/test/tast/array_order.php.exp
hphp/hack/test/tast/assert.php.exp
hphp/hack/test/tast/async_lambda.php.exp
hphp/hack/test/tast/awaitall.php.exp
hphp/hack/test/tast/call_args.php.exp
hphp/hack/test/tast/class_const.php.exp
hphp/hack/test/tast/class_get.php.exp
hphp/hack/test/tast/class_level_where_clauses/test_class_level_where_clauses.php.exp
hphp/hack/test/tast/concurrent_error.php.exp
hphp/hack/test/tast/construct_unknown_class.php.exp
hphp/hack/test/tast/contravariant_solve.php.exp
hphp/hack/test/tast/control_flow/do.php.exp
hphp/hack/test/tast/control_flow/do_throw_while.php.exp
hphp/hack/test/tast/control_flow/dos.php.exp
hphp/hack/test/tast/control_flow/loop_cond.php.exp
hphp/hack/test/tast/control_flow/while.php.exp
hphp/hack/test/tast/control_flow/while_throw.php.exp
hphp/hack/test/tast/dict_attribute.php.exp
hphp/hack/test/tast/dynamic_member_access.php.exp
hphp/hack/test/tast/eq_op.php.exp
hphp/hack/test/tast/fake_member.php.exp
hphp/hack/test/tast/file_attributes_from_multiple_namespaces.php.exp
hphp/hack/test/tast/file_attributes_in_namespaces.php.exp
hphp/hack/test/tast/file_attributes_in_namespaces_with_namespaced_values.php.exp
hphp/hack/test/tast/finally.php.exp
hphp/hack/test/tast/fun_meth_variadic.php.exp
hphp/hack/test/tast/global_inference/call_chain.php.exp
hphp/hack/test/tast/global_inference/call_chain_evil.php.exp
hphp/hack/test/tast/global_inference/call_chain_evil2.php.exp
hphp/hack/test/tast/global_inference/call_chain_evil_evil.php.exp
hphp/hack/test/tast/global_inference/call_chain_evil_evil1.php.exp
hphp/hack/test/tast/global_inference/call_chain_evil_evil1_static.php.exp
hphp/hack/test/tast/global_inference/fun_composed.php.exp
hphp/hack/test/tast/global_inference/id_composed.php.exp
hphp/hack/test/tast/global_inference/one_two_three.php.exp
hphp/hack/test/tast/global_inference/params/type_hint_inferred_parameters.php.exp
hphp/hack/test/tast/global_inference/params/type_hint_inferred_parameters_constructor.php.exp
hphp/hack/test/tast/global_inference/params/type_hint_parameter_call.php.exp
hphp/hack/test/tast/global_inference/params/type_hint_parameter_call_method.php.exp
hphp/hack/test/tast/global_inference/params/type_hint_parameter_indirect.php.exp
hphp/hack/test/tast/global_inference/params/type_hint_parameter_method.php.exp
hphp/hack/test/tast/global_inference/params/type_hint_parameter_survive_assignment.php.exp
hphp/hack/test/tast/global_inference/properties/inherit.php.exp
hphp/hack/test/tast/global_inference/properties/type_hint_inferred_property_assignment.php.exp
hphp/hack/test/tast/global_inference/properties/type_hint_inferred_property_constructor.php.exp
hphp/hack/test/tast/global_inference/properties/type_hint_inferred_property_getter.php.exp
hphp/hack/test/tast/global_inference/properties/type_hint_inferred_property_initializer.php.exp
hphp/hack/test/tast/global_inference/properties/type_hint_inferred_property_setter.php.exp
hphp/hack/test/tast/global_inference/return/type_hint_inferred_awaitable.php.exp
hphp/hack/test/tast/global_inference/return/type_hint_inferred_function.php.exp
hphp/hack/test/tast/global_inference/return/type_hint_inferred_method.php.exp
hphp/hack/test/tast/global_inference/type_hint_inferred_anon_function.php.exp
hphp/hack/test/tast/global_inference/typeparams/type_hint_typeparameter_custom.php.exp
hphp/hack/test/tast/global_inference/typeparams/type_hint_typeparameter_method.php.exp
hphp/hack/test/tast/global_inference/typeparams/type_hint_typeparameter_subtyping.php.exp
hphp/hack/test/tast/global_inference/typeparams/type_hint_typeparameter_variance.php.exp
hphp/hack/test/tast/initializer.php.exp
hphp/hack/test/tast/invalid_fun_pointer.php.exp
hphp/hack/test/tast/lambda1.php.exp
hphp/hack/test/tast/lambda_contextual.php.exp
hphp/hack/test/tast/lambda_efun.php.exp
hphp/hack/test/tast/mixed_mixed.php.exp
hphp/hack/test/tast/multiple_type.php.exp
hphp/hack/test/tast/null_check.php.exp
hphp/hack/test/tast/null_coalesce.php.exp
hphp/hack/test/tast/null_coalesce_assignment.php.exp
hphp/hack/test/tast/parent_construct.php.exp
hphp/hack/test/tast/parent_method.php.exp
hphp/hack/test/tast/pseudofunctions.php.exp
hphp/hack/test/tast/re_prefixed_string/re_prefixed_string.php.exp
hphp/hack/test/tast/reactive.php.exp
hphp/hack/test/tast/reified_generic_attributes.php.exp
hphp/hack/test/tast/reified_generic_shadowing.php.exp
hphp/hack/test/tast/reified_generic_shadowing2.php.exp
hphp/hack/test/tast/reified_generic_shadowing3.php.exp
hphp/hack/test/tast/reify_mix_with_erased.php.exp
hphp/hack/test/tast/shapes_special_functions.php.exp
hphp/hack/test/tast/singleton_unresolved_function_call.php.exp
hphp/hack/test/tast/switch_fallthrough.php.exp
hphp/hack/test/tast/try_catch.php.exp
hphp/hack/test/tast/typeconsts.php.exp
hphp/hack/test/tast/typedef.php.exp
hphp/hack/test/tast/unbound_func.php.exp
hphp/hack/test/tast/unbound_global.php.exp
hphp/hack/test/tast/unbound_name_partial.php.exp
hphp/hack/test/tast/unresolved_grown_after_lambda.php.exp
hphp/hack/test/tast/using.php.exp
hphp/hack/test/tast/wildcard_generic_depth.php.exp
hphp/hack/test/tast/xhp.php.exp
hphp/hack/test/tast/xhp_modifier/xhp.php.exp
hphp/hack/test/typecheck/xhp_modifier/HH_FLAGS
hphp/hack/test/typecheck/xhp_modifier/xhp_abstract.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_abstract.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_modifier_extend_colon_syntax.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_modifier_extend_colon_syntax.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_classname1.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_classname1.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_classname2.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_classname2.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_explicit_usage.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_explicit_usage.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_full.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_full.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_in_same_namespace.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_in_same_namespace.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_namespace.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_namespace.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_namespace_alias.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_namespace_alias.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_outside_namespace_1.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_outside_namespace_1.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_outside_namespace_2.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_outside_namespace_2.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_outside_namespace_3.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_outside_namespace_3.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_outside_namespace_4.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_outside_namespace_4.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_type.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_type.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_type_alias.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_type_alias.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_type_group.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhp_namespace_use_type_group.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhpchild.php [new file with mode: 0644]
hphp/hack/test/typecheck/xhp_modifier/xhpchild.php.exp [new file with mode: 0644]
hphp/runtime/base/runtime-option.h
hphp/test/quick/xhp_modifier/config.ini [new file with mode: 0644]
hphp/test/quick/xhp_modifier/hphp_config.ini [new file with mode: 0644]
hphp/test/quick/xhp_modifier/xhp_modifier.php [new file with mode: 0644]
hphp/test/quick/xhp_modifier/xhp_modifier.php.expect [new file with mode: 0644]