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