Skip to content

Commit

Permalink
Bug fixes in dynamic array generation and silent null coalesce
Browse files Browse the repository at this point in the history
Summary: Bug fixes in dynamic array generation and silent null coalesce

Reviewed By: vladima

Differential Revision: D5214762

fbshipit-source-id: 5b250a3f97889a0f4eb6c87100f8c232e9a2ca4d
  • Loading branch information
oulgen authored and hhvm-bot committed Jun 9, 2017
1 parent 97e9402 commit 3abc1bc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
27 changes: 24 additions & 3 deletions hphp/hack/src/hhbc/emit_expression.ml
Expand Up @@ -908,7 +908,17 @@ and emit_dynamic_collection ~transform_to_collection env expr es =
in
let is_array = match snd expr with A.Array _ -> true | _ -> false in
let count = List.length es in
if is_only_values && transform_to_collection = None && not has_references
let stack_limit =
Hhbc_options.max_array_elem_size_on_the_stack !Hhbc_options.compiler_options
in
let is_php_array =
transform_to_collection = None
&& match snd expr with | A.Array _ -> true | _ -> false
in
if is_only_values
&& transform_to_collection = None
&& not has_references
&& (not is_php_array || count <= stack_limit)
then begin
let lit_constructor = match snd expr with
| A.Array _ -> NewPackedArray count
Expand All @@ -925,7 +935,10 @@ and emit_dynamic_collection ~transform_to_collection env expr es =
| _ -> failwith "impossible");
instr @@ ILitConst lit_constructor;
]
end else if are_all_keys_strings && is_array && not has_references then begin
end else if are_all_keys_strings
&& is_array
&& not has_references
then begin
let es =
List.map es
~f:(function
Expand All @@ -939,8 +952,10 @@ and emit_dynamic_collection ~transform_to_collection env expr es =
]
end else begin
let lit_constructor = match snd expr with
| A.Array _ when is_only_values && count > stack_limit -> NewArray count
| A.Array _ -> NewMixedArray count
| A.Collection ((_, ("dict" | "Set" | "ImmSet" | "Map" | "ImmMap")), _) ->
| A.Collection ((_, ("dict" | "Set" | "ImmSet" | "Map" | "ImmMap"
| "HH\\Set" | "HH\\ImmSet" | "HH\\Map" | "HH\\Immmap")), _) ->
NewDictArray count
| _ -> failwith "emit_dynamic_collection: unexpected expression"
in
Expand All @@ -962,6 +977,7 @@ and emit_dynamic_collection ~transform_to_collection env expr es =
end

and emit_named_collection env expr pos name fields =
let name = SU.strip_ns name in
match name with
| "dict" | "vec" | "keyset" -> emit_collection env expr fields
| "Vector" | "ImmVector" ->
Expand Down Expand Up @@ -1121,6 +1137,11 @@ and emit_quiet_expr env (_, expr_ as expr) =
match expr_ with
| A.Lvar (_, x) when not (is_local_this env x) ->
instr_cgetquietl (get_local env x)
| A.Lvarvar (n, id) ->
gather [
emit_lvarvar ~need_ref:false (n-1) id;
instr_cgetquietn;
]
| A.Array_get((_, A.Lvar (_, x)), Some e) when x = SN.Superglobals.globals ->
gather [
emit_expr ~need_ref:false env e;
Expand Down
4 changes: 4 additions & 0 deletions hphp/hack/src/hhbc/hhbc_options.ml
Expand Up @@ -17,6 +17,7 @@ type t = {
option_constant_folding : bool;
option_optimize_null_check : bool;
option_optimize_cuf : bool;
option_max_array_elem_size_on_the_stack : int;
}

(* Default, as with HHVM, is for Eval.EnableHipHopSyntax=0 *)
Expand All @@ -26,12 +27,15 @@ let default = {
option_constant_folding = true;
option_optimize_null_check = true;
option_optimize_cuf = true;
option_max_array_elem_size_on_the_stack = 12;
}

let enable_hiphop_syntax options = options.option_enable_hiphop_syntax
let constant_folding options = options.option_constant_folding
let optimize_null_check options = options.option_optimize_null_check
let optimize_cuf options = options.option_optimize_cuf
let max_array_elem_size_on_the_stack options =
options.option_max_array_elem_size_on_the_stack

(* The Hack.Lang.IntsOverflowToInts setting overrides the
* Eval.EnableHipHopSyntax setting *)
Expand Down
1 change: 1 addition & 0 deletions hphp/hack/src/hhbc/instruction_sequence.ml
Expand Up @@ -103,6 +103,7 @@ let instr_vgetl local = instr (IGet (VGetL local))
let instr_vgetn = instr (IGet VGetN)
let instr_cgetl2 local = instr (IGet (CGetL2 local))
let instr_cgetquietl local = instr (IGet (CGetQuietL local))
let instr_cgetquietn = instr (IGet CGetQuietN)
let instr_cgetn_seq n = gather @@ List.replicate ~num:n instr_cgetn
let instr_bindn = instr (IMutator BindN)
let instr_bindl local = instr (IMutator (BindL local))
Expand Down
2 changes: 0 additions & 2 deletions hphp/test/hhcodegen_failing_tests_quick
Expand Up @@ -8,7 +8,6 @@ quick/Xhp.php
quick/__isset.php
quick/abs_codegen.php
quick/all_type_comparison_test.php
quick/array_packed.php
quick/arrayidx.php
quick/backtick.php
quick/builtin_extension_DateTime.php
Expand Down Expand Up @@ -187,7 +186,6 @@ quick/static_prop_eval_order.php
quick/static_vars.php
quick/strict_hashbang_start.php
quick/string-cse.php
quick/switch_special_cases.php
quick/syntax-error.php
quick/trailing_comma_bad1.php
quick/trailing_comma_bad2.php
Expand Down
13 changes: 0 additions & 13 deletions hphp/test/hhcodegen_failing_tests_slow
Expand Up @@ -2,7 +2,6 @@ slow/anon_class/anon_1.php
slow/anon_class/extend_local.php
slow/arithmetic/addo-member-key.php
slow/arithmetic/edge_cases.php
slow/arithmetic/power-grid.php
slow/array/empty.php
slow/array_access/436.php
slow/array_cse/543.php
Expand Down Expand Up @@ -51,8 +50,6 @@ slow/break_statement/badexp.php
slow/break_statement/zero.php
slow/bug-5127251.php
slow/call_static/maybe_has_this.php
slow/cget_quiet.php
slow/chr-invalid-type.php
slow/class_constant/1608.php
slow/class_constant/1618.php
slow/class_constant/1619.php
Expand Down Expand Up @@ -106,8 +103,6 @@ slow/collection_classes/invalid-initializers.php
slow/collection_classes/iterator-clone-bug.php
slow/collection_classes/map-buffer-sharing.php
slow/collection_classes/migration/unserialize-map.php
slow/collection_classes/preg-replace.php
slow/collection_classes/set-addall-bug.php
slow/compilation/1237.php
slow/compilation/1238.php
slow/compilation/1247.php
Expand Down Expand Up @@ -225,7 +220,6 @@ slow/ext_apc_iterator/iterator_003.php
slow/ext_apc_iterator/iterator_004.php
slow/ext_apc_iterator/iterator_005.php
slow/ext_array/array_rand.php
slow/ext_array/count-opts.php
slow/ext_asio/backtrace.php
slow/ext_bzip2/wrapper.php
slow/ext_class/is-subclass-of-opt.php
Expand All @@ -248,7 +242,6 @@ slow/ext_function/register_shutdown_function-simple.php
slow/ext_imagick/draw_vector_graphics.php
slow/ext_imagick/iterator_exception.php
slow/ext_imagick/iterator_test.php
slow/ext_imagick/php_imagick_tests/024_ispixelsimilar.php
slow/ext_imagick/pixel_color.php
slow/ext_imagick/pixel_exception.php
slow/ext_imagick/pixel_issimilar.php
Expand Down Expand Up @@ -408,19 +401,16 @@ slow/hh_namespace_migration/hh_frozenset4.php
slow/hh_namespace_migration/hh_frozenset6.php
slow/hh_namespace_migration/hh_frozenset7.php
slow/hh_namespace_migration/hh_frozenvector4.php
slow/hh_namespace_migration/hh_frozenvector6.php
slow/hh_namespace_migration/hh_frozenvector7.php
slow/hh_namespace_migration/hh_map4.php
slow/hh_namespace_migration/hh_map6.php
slow/hh_namespace_migration/hh_map7.php
slow/hh_namespace_migration/hh_pair4.php
slow/hh_namespace_migration/hh_pair6.php
slow/hh_namespace_migration/hh_pair7.php
slow/hh_namespace_migration/hh_set4.php
slow/hh_namespace_migration/hh_set6.php
slow/hh_namespace_migration/hh_set7.php
slow/hh_namespace_migration/hh_vector3.php
slow/hh_namespace_migration/hh_vector4.php
slow/hh_namespace_migration/hh_vector5.php
slow/hhbbc/array_011.php
slow/hhbbc/array_access_004.php
Expand Down Expand Up @@ -756,7 +746,6 @@ slow/php7_backported/scalar-types/scalar_strict_declaration_placement_003.php
slow/php7_backported/scalar-types/scalar_strict_declaration_placement_004.php
slow/php7_backported/scalar-types/scalar_weak_reference.php
slow/php7_backported/scalar-types/self_on_closure_in_method.php
slow/php7_backported/spaceship.php
slow/php7_backported/varSyntax/indirect-fcall.php
slow/php7_backported/varSyntax/issetOnTemp.php
slow/php7_backported/varSyntax/staticMember.php
Expand Down Expand Up @@ -844,7 +833,6 @@ slow/sanity/2.php
slow/sanity/3.php
slow/sanity/4.php
slow/sanity/5.php
slow/scalar_array/545.php
slow/scalar_array/546.php
slow/serialization/repo_types_002.php
slow/session/session_start_undefined_scheme.php
Expand Down Expand Up @@ -874,7 +862,6 @@ slow/streams/user_filter_autoload.php
slow/string/164.php
slow/string/heredoc_end_after_variable.php
slow/string/issue_3160.php
slow/string/str_offset_isset_empty.php
slow/stringish.php
slow/super_globals/1387.php
slow/switch_statement/1754.php
Expand Down

0 comments on commit 3abc1bc

Please sign in to comment.