Permalink
Browse files

Capture intermediate values used in inout arguments

Summary:
for cases like
```
foo(inout $x[f()]);
```
index value returned by `f()` should be the same for both reading (passing the argument into the function)_ and writing (propagating value back). To enforce this intermediate values must be captured in temps so generated code for this case should be
```
...
FPushFuncD 0 "f"
FCall 0
UnboxR
.try_fault F0 {
  SetL _1 # store intermediate value
  BaseL $x Warn
  QueryM 1 InOut EC:0
  FPassC 0 Cell
  FCall 1
  UnboxR
  .try_fault F1 {
    SetL _2
    PopC
    BaseL _2 Warn
    QueryM 0 CGet EI:1
    BaseL $x Define
    SetM 0 EL:_1 # read value using index stored in _1
    PopC
    BaseL _2 Warn
    QueryM 0 CGet EI:0
  }
  UnsetL _2
}
UnsetL _1
...
F1:
UnsetL _2
Unwind
F0:
UnsetL _1
Unwind
```

Reviewed By: oulgen

Differential Revision: D6754554

fbshipit-source-id: f46dc209dcc7c53ad14577e8874fd63e045d0261
  • Loading branch information...
vladima authored and hhvm-bot committed Jan 20, 2018
1 parent 663d08f commit d1a5817a9b6b539ed9d270d484dd519c915003f9

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -375,6 +375,8 @@ type initprop_op =
type instruct_mutator =
| SetL of local_id
(* PopL is put in mutators since it behaves as SetL + PopC *)
| PopL of Local.t
| SetN
| SetG
| SetS of classref_id
@@ -284,6 +284,7 @@ let string_of_initprop_op op =
let string_of_mutator x =
match x with
| SetL id -> sep ["SetL"; string_of_local_id id]
| PopL id -> sep ["PopL"; string_of_local_id id]
| SetN -> "SetN"
| SetG -> "SetG"
| SetS id -> sep ["SetS"; string_of_classref id]
@@ -152,6 +152,7 @@ let instr_popu = instr (IBasic PopU)
let instr_popr = instr (IBasic PopR)
let instr_popc = instr (IBasic PopC)
let instr_popv = instr (IBasic PopV)
let instr_popl l = instr (IMutator (PopL l))
let instr_pop flavor =
match flavor with
| Flavor.Ref -> instr_popv
@@ -794,7 +795,7 @@ let get_input_output_count i =
end
| IMutator i ->
begin match i with
| SetL _ | SetOpL _ | IncDecN _ | IncDecG _ | IncDecS _
| SetL _ | PopL _ | SetOpL _ | IncDecN _ | IncDecG _ | IncDecS _
| BindL _ -> (1, 1)
| SetN | SetG | SetS _ | SetOpN _ | SetOpG _ | SetOpS _ | BindN
| BindG | BindS _ -> (2, 1)
@@ -377,6 +377,7 @@ let readswrites asn l l' =
let check_instruct_mutator asn i i' =
match i, i' with
| SetL l, SetL l'
| PopL l, PopL l'
| BindL l, BindL l'
-> writes asn l l'
| UnsetL l, UnsetL l'
@@ -385,7 +386,8 @@ let check_instruct_mutator asn i i' =
if op=op' then readswrites asn l l' else None
| IncDecL (l,op), IncDecL (l',op') ->
if op=op' then readswrites asn l l' else None
| SetL _, _ | BindL _, _ | UnsetL _, _ | SetOpL _, _ | IncDecL _, _ -> None
| SetL _, _ | PopL _ , _ | BindL _, _ | UnsetL _, _ | SetOpL _, _
| IncDecL _, _ -> None
(* Whitelist the instructions where equality implies equivalence
(e.g. they do not access locals). *)
| SetN, _ | SetG, _ | SetS _, _ | SetOpN _, _ | SetOpG _, _ | SetOpS _, _
@@ -11,8 +11,6 @@ slow/ext_xdebug/xdebug/coverage.php
slow/goto/label_out_finally.php
slow/goto/try_goto_in_finally2.php
slow/goto/try_goto_out_finally.php
slow/inout/bad-call-15.php
slow/inout/side-effects.php
slow/lang/redefine_function.php
slow/parser/afl5934248.php
slow/parser/empty-files/empty-invalid.php
@@ -6,8 +6,6 @@ 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/lang/redefine_function.php
slow/parser/afl5934248.php
slow/parser/empty-files/empty-invalid.php
@@ -22,4 +20,4 @@ slow/traits/require_constraint_basic_error.php
slow/traits/require_constraint_recurse.php
slow/variadic_args/by_reference.php
slow/variadic_args/by_reference_typehints.php
slow/variadic_args/typehints.php
slow/variadic_args/typehints.php
@@ -1,4 +1,2 @@
slow/inout/bad-call-15.php
slow/inout/side-effects.php
slow/parser/hh-namespace-conflict-2.php
slow/parser/hh-namespace-conflict-6.php
slow/parser/hh-namespace-conflict-6.php

0 comments on commit d1a5817

Please sign in to comment.