Handle builtin default argument values which are constants
commit4c3be15fa06f7cc7acd3f2b2210de51e7b6995a4
authorRick Lavoie <rlavoie@fb.com>
Fri, 2 Dec 2016 03:27:00 +0000 (1 19:27 -0800)
committerHhvm Bot <hhvm-bot-bot@fb.com>
Fri, 2 Dec 2016 03:46:56 +0000 (1 19:46 -0800)
treedfc344aab06b0563b9e7e933122f840648e81734
parent498f20b44377155cfca8813c287e86cf1c3a2b01
Handle builtin default argument values which are constants

Summary:
If a call to a builtin meets certain requirements, we can emit a more
optimized call sequence to invoke it using the FCallBuiltin opcode. Furthermore,
we can specially optimize FCallBuiltin for certain builtins. One of the
requirements is that any non-supplied parameter have a default value which is a
scalar. This is so that we can easily supply the default arguments at the
call-site. However, some builtins specify their default argument values with
constants, which are non-scalars. This prevents us from optimizing them to
FCallBuiltins. A prime example is count().

Add the ability to pre-optimize ConstantExpressions in the parser, which will
replace references to constants with their equivalent scalar values. Since some
constants may be defined in native extensions, also use
Unit::lookupPersistentCns to attempt to find the constant's value.

Since this will replace references to constants with their scalar values in the
AST, it can break reflection functionality with wants to see the constant
name. So, have ParameterExpression (which is where this matters) store the
textual representation of the default value and use that for reflection data.

While we're at it, treat sizeof() as a synonym for count() in HHBC and IR-gen.

Reviewed By: markw65

Differential Revision: D4174970

fbshipit-source-id: cb499ede13846e8a55dbbccc90a0a78c1a391e5c
hphp/compiler/analysis/emitter.cpp
hphp/compiler/analysis/file_scope.cpp
hphp/compiler/expression/constant_expression.cpp
hphp/test/quick/reflection_default_param.php.expect-repo [new file with mode: 0644]