From fffe72d660d3f4ec1c84b945ed8a18dcd0ccb186 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 29 Jun 2017 19:34:13 -0700 Subject: [PATCH] consider only `define(string, ..)` as a form recognized by the emitter Summary: `define` with other shapes of the first argument should be treated as a regular function call Reviewed By: oulgen Differential Revision: D5348286 fbshipit-source-id: 43a57e4fe9e8c09fa52ced9df2afad17dfeaa2ab --- hphp/hack/src/hhbc/emit_expression.ml | 6 +++++- hphp/hack/src/parser/full_fidelity_ast.ml | 8 ++++++-- hphp/test/hhcodegen_failing_tests_slow | 6 ------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/hphp/hack/src/hhbc/emit_expression.ml b/hphp/hack/src/hhbc/emit_expression.ml index 68bbca66940..2579d598d4a 100644 --- a/hphp/hack/src/hhbc/emit_expression.ml +++ b/hphp/hack/src/hhbc/emit_expression.ml @@ -42,7 +42,11 @@ let is_special_function e args = | "isset" -> n > 0 | "empty" -> n = 1 | "tuple" -> true - | "define" -> n = 2 + | "define" -> + begin match args with + | [_, A.String _; _] -> true + | _ -> false + end | "eval" -> n = 1 | "idx" -> n = 2 || n = 3 | "class_alias" -> diff --git a/hphp/hack/src/parser/full_fidelity_ast.ml b/hphp/hack/src/parser/full_fidelity_ast.ml index 0541b778d10..071f44c2172 100644 --- a/hphp/hack/src/parser/full_fidelity_ast.ml +++ b/hphp/hack/src/parser/full_fidelity_ast.ml @@ -1776,7 +1776,9 @@ let pProgram : program parser = fun node env -> *) | { syntax = ExpressionStatement { expression_statement_expression = - { syntax = DefineExpression { define_argument_list = args; _ } ; _ } + { syntax = DefineExpression + { define_keyword; define_argument_list = args; _ } + ; _ } ; _ } ; _ } :: nodel -> ( match List.map ~f:(fun x -> pExpr x env) (as_list args) with @@ -1788,7 +1790,9 @@ let pProgram : program parser = fun node env -> ; cst_value = e ; cst_namespace = Namespace_env.empty !(lowerer_state.popt) } - | _ -> missing_syntax "DefineExpression:inner" args env + | args -> + let name = pos_name define_keyword in + Stmt (Expr (fst name, Call ((fst name, Id name), args, []))) ) :: aux env nodel | node :: nodel -> pDef node env :: aux env nodel in diff --git a/hphp/test/hhcodegen_failing_tests_slow b/hphp/test/hhcodegen_failing_tests_slow index 3e4108c6c69..81bafbaaee0 100644 --- a/hphp/test/hhcodegen_failing_tests_slow +++ b/hphp/test/hhcodegen_failing_tests_slow @@ -111,11 +111,8 @@ slow/concat/1575.php slow/concat/1576.php slow/concat/1577.php slow/concat/1578.php -slow/concat/1581.php slow/concat/1589.php -slow/constant/1594.php slow/constant/1597.php -slow/constant/1600.php slow/constant/alias.php slow/constant/casing.php slow/constant/casing2.php @@ -139,8 +136,6 @@ slow/control-flow/bug-4976291.php slow/copy_prop/1845.php slow/ctor_param_promotion_bad_mod.php slow/debug_backtrace/backtrace_async_generators.php -slow/defined/1627.php -slow/defined/sid.php slow/dict/hh-only1.php slow/dict/hh-only2.php slow/dict/hhbbc-group.php @@ -463,7 +458,6 @@ slow/namespace/alias/alias.php slow/namespace/double_use1.php slow/namespace/double_use2.php slow/namespace/double_use3.php -slow/namespace/dynamic.php slow/namespace/dynamic_extra_slash.php slow/namespace/dynamic_extra_slash_cns.php slow/namespace/dynamic_extra_slash_cns2.php -- 2.11.4.GIT