Permalink
Browse files

Consolidate checks if ref wrappers should be emitted

Summary: as in title - this covers a few places where HipHopSyntaxEnabled=1 check was missed

Reviewed By: andrewjkennedy

Differential Revision: D6719139

fbshipit-source-id: 6099d6ab888c6f27e97b1d0b0be83b1f16fd9ddb
  • Loading branch information...
vladima authored and hhvm-bot committed Jan 17, 2018
1 parent 74acc62 commit c635aa5276c8637a6e4f4e100d970a26f5875c32
@@ -19,9 +19,6 @@ module SU = Hhbc_string_utils
let constant_folding () =
Hhbc_options.constant_folding !Hhbc_options.compiler_options
let create_inout_wrapper_functions () =
Hhbc_options.create_inout_wrapper_functions !Hhbc_options.compiler_options
type variables = {
(* all variables declared/used in the scope*)
all_vars: SSet.t;
@@ -803,9 +800,10 @@ and convert_stmt env st (p, stmt_ as stmt) : _ * stmt =
| Fun fd :: _defs ->
let st, fd = convert_fun env st fd in
let has_inout_params =
List.exists fd.Ast.f_params
~f:(fun p -> p.Ast.param_callconv = Some Ast.Pinout
|| (create_inout_wrapper_functions () && p.Ast.param_is_reference)) in
let wrapper, _ = Emit_inout_helpers.extract_inout_or_ref_param_locations
~is_closure_or_func:true
fd.Ast.f_params in
Option.is_some wrapper in
let st, stub_fd =
add_function ~has_inout_params:has_inout_params env st fd in
st, (p, Def_inline (Fun stub_fd))
@@ -13,20 +13,8 @@ module A = Ast
open Hh_core
let extract_inout_or_ref_param_locations params =
let inout_param_locations = List.filter_mapi params
~f:(fun i p -> if p.Ast.param_callconv <> Some Ast.Pinout
then None else Some i) in
let ref_param_locations = List.filter_mapi params
~f:(fun i p -> if not p.Ast.param_is_reference
then None else Some i) in
if List.length inout_param_locations <> 0 then
Some (Emit_inout_helpers.InoutWrapper), inout_param_locations
else if List.length ref_param_locations <> 0 &&
Hhbc_options.create_inout_wrapper_functions !Hhbc_options.compiler_options
then
Some (Emit_inout_helpers.RefWrapper), ref_param_locations
else
None, []
let module EIOH = Emit_inout_helpers in
EIOH.extract_inout_or_ref_param_locations ~is_closure_or_func:true params
(* Given a function definition, emit code, and in the case of <<__Memoize>>,
* a wrapper function
@@ -14,6 +14,25 @@ module H = Hhbc_ast
type wrapper_type = InoutWrapper | RefWrapper
let extract_inout_or_ref_param_locations ~is_closure_or_func params =
let inout_param_locations = List.filter_mapi params
~f:(fun i p -> if p.Ast.param_callconv <> Some Ast.Pinout
then None else Some i) in
if List.length inout_param_locations <> 0 then
Some InoutWrapper, inout_param_locations
else
let module O = Hhbc_options in
let need_wrapper =
O.create_inout_wrapper_functions !O.compiler_options
&& (Emit_env.is_hh_syntax_enabled ())
&& (O.reffiness_invariance !O.compiler_options || is_closure_or_func) in
let l =
if need_wrapper
then List.filter_mapi params ~f:(fun i p -> Option.some_if p.Ast.param_is_reference i)
else [] in
if List.is_empty l then None, []
else Some RefWrapper, l
let inout_suffix param_location =
let param_location = List.map ~f:string_of_int param_location in
"$"
@@ -50,20 +50,10 @@ let rec hint_uses_tparams tparam_names (_, hint) =
* Or ref params only if the function is a closure
*)
let extract_inout_or_ref_param_locations is_closure params =
let inout_param_locations = List.filter_mapi params
~f:(fun i p -> if p.Ast.param_callconv <> Some Ast.Pinout
then None else Some i) in
if List.length inout_param_locations <> 0 then
inout_param_locations
else
let module O = Hhbc_options in
let need_wrapper =
O.create_inout_wrapper_functions !O.compiler_options
&& (Emit_env.is_hh_syntax_enabled ())
&& (O.reffiness_invariance !O.compiler_options || is_closure) in
if need_wrapper
then List.filter_mapi params ~f:(fun i p -> Option.some_if p.Ast.param_is_reference i)
else []
let module EIOH = Emit_inout_helpers in
let _, l =
EIOH.extract_inout_or_ref_param_locations ~is_closure_or_func:is_closure params in
l
let has_kind m k = List.mem m.Ast.m_kind k
@@ -49,9 +49,11 @@ let emit_return ~need_ref env =
let emit_def_inline = function
| A.Fun fd ->
let has_inout_params =
List.exists fd.Ast.f_params
~f:(fun p -> p.Ast.param_callconv = Some Ast.Pinout
|| (create_inout_wrapper_functions () && p.Ast.param_is_reference)) in
let r, _ =
Emit_inout_helpers.extract_inout_or_ref_param_locations
~is_closure_or_func:true
fd.Ast.f_params in
Option.is_some r in
Emit_pos.emit_pos_then (fst fd.Ast.f_name) @@
let n = int_of_string (snd fd.Ast.f_name) in
gather [
@@ -19,7 +19,6 @@ slow/function_no_param_modifier.php
slow/goto/label_out_finally.php
slow/goto/try_goto_in_finally2.php
slow/goto/try_goto_out_finally.php
slow/hack_arr_compat/variadic-by-ref.php
slow/inout/bad-call-15.php
slow/inout/side-effects.php
slow/keyset/hh-only1.php
@@ -65,7 +64,6 @@ slow/typecheck/type_coersion_7strict.php
slow/typecheck/type_coersion_7strict_include.php
slow/unpack_args/unpack_call_error.php
slow/unpack_args/unpack_call_multi.php
slow/variadic_args/by_reference.php
slow/variadic_args/by_reference_typehints.php
slow/variadic_args/typehints.php
slow/vec/hh-only1.php

0 comments on commit c635aa5

Please sign in to comment.