Permalink
Browse files

Do not eagerly release goto state ids for HHVM compatibility

Summary: HackC currently tries to avoid allocation of state ids for named labels if target label and source goto are not separated by finally - suppress this behavior to make generated code closer to HHVM (also HHVM does not seem to release state ids)

Reviewed By: andrewjkennedy

Differential Revision: D6738811

fbshipit-source-id: 185374ccb0cbe924e1d2a1c8c818fd18a31c017c
  • Loading branch information...
vladima authored and hhvm-bot committed Jan 17, 2018
1 parent 9c5e6aa commit dbfc160afd617e52a6a5ff4663940c2f2ba82740
@@ -204,7 +204,7 @@ let release_id l =
(* runs a given function and then released label ids that were possibly assigned
to labels at the head of the list *)
let run_and_release_ids labels f s t =
let run_and_release_ids _labels f s t =
let r = f t s in
begin match t with
| Loop ({ label_break; label_continue; _ }, _) ::_ ->
@@ -215,7 +215,10 @@ let run_and_release_ids labels f s t =
| (Function _ | Finally _) :: _ -> ()
| [] -> failwith "impossible"
end;
SSet.iter (fun l -> release_id (Label.Named l)) labels;
(* CONSIDER: now HHVM does not release state ids for named labels
even after leaving the scope where labels are accessible
Do the same for now for compatibility reasons *)
(* SSet.iter (fun l -> release_id (Label.Named l)) labels; *)
r
let with_loop is_hh_file label_break label_continue iterator t s f =
@@ -92,6 +92,10 @@ let emit_goto ~in_finally_epilogue env label =
err_pos @@ "'goto' to undefined label '" ^ label ^ "'"
| Some in_using ->
let named_label = Label.named label in
(* CONSIDER: we don't need to assign state id for label
for cases when it is not necessary, i.e. when jump target is in the same
scope. HHVM does not do this today, do the same for compatibility reasons *)
let label_id = JT.get_id_for_label named_label in
let jump_targets = Emit_env.get_jump_targets env in
begin match JT.find_goto_target jump_targets label with
| JT.ResolvedGoto_label iters ->
@@ -108,7 +112,7 @@ let emit_goto ~in_finally_epilogue env label =
} ->
let preamble =
if in_finally_epilogue then empty
else emit_save_label_id (JT.get_id_for_label named_label) in
else emit_save_label_id label_id in
gather [
preamble;
emit_jump_to_label rgf_finally_start_label rgf_iterators_to_release;
@@ -2,5 +2,4 @@ slow/class_type_constant/type_constant.php
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/using/goto.php
slow/parser/hh-namespace-conflict-6.php

0 comments on commit dbfc160

Please sign in to comment.