Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove TFor #11891

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1227,11 +1227,6 @@ class hxb_reader
let e1 = loop () in
let e2 = loop () in
TWhile(e1,e2,DoWhile),(Some api#basic_types.tvoid)
| 86 ->
let v = declare_local () in
let e1 = loop () in
let e2 = loop () in
TFor(v,e1,e2),(Some api#basic_types.tvoid)

(* control flow 90-99 *)
| 90 ->
Expand Down
6 changes: 0 additions & 6 deletions src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1499,12 +1499,6 @@ module HxbWriter = struct
loop e1;
loop e2;
false;
| TFor(v,e1,e2) ->
Chunk.write_u8 writer.chunk 86;
declare_var v;
loop e1;
loop e2;
false;
(* control flow 90-99 *)
| TReturn None ->
Chunk.write_u8 writer.chunk 90;
Expand Down
2 changes: 1 addition & 1 deletion src/context/display/diagnostics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ let check_other_things com e =
| TCall({eexpr = TField(e1,fa)},el) when not in_value && PurityState.is_pure_field_access fa -> compound "call" el e.epos
| TNew _ | TCall _ | TBinop ((Ast.OpAssignOp _ | Ast.OpAssign),_,_) | TUnop ((Ast.Increment | Ast.Decrement),_,_)
| TReturn _ | TBreak | TContinue | TThrow _ | TCast (_,Some _)
| TIf _ | TTry _ | TSwitch _ | TWhile _ | TFor _ ->
| TIf _ | TTry _ | TSwitch _ | TWhile _ ->
had_effect := true;
Type.iter (loop true) e
| TParenthesis e1 | TMeta(_,e1) ->
Expand Down
4 changes: 0 additions & 4 deletions src/context/display/statistics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ let collect_statistics ctx pos_filters with_expressions =
| TVar(v,eo) ->
Option.may loop eo;
var_decl v;
| TFor(v,e1,e2) ->
var_decl v;
loop e1;
loop e2;
| TFunction tf ->
List.iter (fun (v,_) -> var_decl v) tf.tf_args;
loop tf.tf_expr;
Expand Down
6 changes: 0 additions & 6 deletions src/core/json/genjson.ml
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,6 @@ and generate_texpr ctx e =
| TBlock el ->
let el = List.map (generate_texpr ctx) el in
"TBlock",Some (jarray el)
| TFor(v,e1,e2) ->
"TFor",Some (jobject [
"v",generate_tvar ctx v;
"expr1",generate_texpr ctx e1;
"expr2",generate_texpr ctx e2;
]);
| TIf(e1,e2,eo) ->
"TIf",Some (jobject [
"eif",generate_texpr ctx e1;
Expand Down
3 changes: 0 additions & 3 deletions src/core/tOther.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ module TExprToExpr = struct
and eo = eopt eo in
EVars ([mk_evar ~final ?t ?eo ~meta:v.v_meta (v.v_name,v.v_pos)])
| TBlock el -> EBlock (List.map convert_expr el)
| TFor (v,it,e) ->
let ein = (EBinop (OpIn,(EConst (Ident v.v_name),it.epos),convert_expr it),it.epos) in
EFor (ein,convert_expr e)
| TIf (e,e1,e2) -> EIf (convert_expr e,convert_expr e1,eopt e2)
| TWhile (e1,e2,flag) -> EWhile (convert_expr e1, convert_expr e2, flag)
| TSwitch {switch_subject = e;switch_cases = cases;switch_default = def} ->
Expand Down
4 changes: 0 additions & 4 deletions src/core/tPrinting.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ let s_expr_kind e =
| TFunction _ -> "Function"
| TVar _ -> "Vars"
| TBlock _ -> "Block"
| TFor (_,_,_) -> "For"
| TIf (_,_,_) -> "If"
| TWhile (_,_,_) -> "While"
| TSwitch _ -> "Switch"
Expand Down Expand Up @@ -249,8 +248,6 @@ let rec s_expr_pretty print_var_ids tabs top_level s_type e =
(match el with
| [] -> "{}"
| _ -> s ^ tabs ^ "}")
| TFor (v,econd,e) ->
sprintf "for (%s in %s) %s" (local v) (loop econd) (loop e)
| TIf (e,e1,e2) ->
sprintf "if (%s) %s%s" (loop e) (loop e1) (match e2 with None -> "" | Some e -> " else " ^ loop e)
| TWhile (econd,e,flag) ->
Expand Down Expand Up @@ -359,7 +356,6 @@ let rec s_expr_ast print_var_ids tabs s_type e =
| TReturn (Some e1) -> tag "Return" [loop e1]
| TWhile (e1,e2,NormalWhile) -> tag "While" [loop e1; loop e2]
| TWhile (e1,e2,DoWhile) -> tag "Do" [loop e1; loop e2]
| TFor (v,e1,e2) -> tag "For" [local v None; loop e1; loop e2]
| TTry (e1,catches) ->
let sl = List.map (fun (v,e) ->
sprintf "Catch %s%s" (local v None) (tag_args (tabs ^ "\t") [loop ~extra_tabs:"\t" e]);
Expand Down
1 change: 0 additions & 1 deletion src/core/tType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ and texpr_expr =
| TFunction of tfunc
| TVar of tvar * texpr option
| TBlock of texpr list
| TFor of tvar * texpr * texpr
| TIf of texpr * texpr * texpr option
| TWhile of texpr * texpr * Ast.while_flag
| TSwitch of tswitch
Expand Down
30 changes: 2 additions & 28 deletions src/core/texpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ let iter f e =
()
| TArray (e1,e2)
| TBinop (_,e1,e2)
| TFor (_,e1,e2)
| TWhile (e1,e2,_) ->
f e1;
f e2;
Expand Down Expand Up @@ -66,7 +65,7 @@ let check_expr predicate e =
match e.eexpr with
| TConst _ | TLocal _ | TBreak | TContinue | TTypeExpr _ | TIdent _ ->
false
| TArray (e1,e2) | TBinop (_,e1,e2) | TFor (_,e1,e2) | TWhile (e1,e2,_) ->
| TArray (e1,e2) | TBinop (_,e1,e2) | TWhile (e1,e2,_) ->
predicate e1 || predicate e2;
| TThrow e | TField (e,_) | TEnumParameter (e,_,_) | TEnumIndex e | TParenthesis e
| TCast (e,_) | TUnop (_,_,e) | TMeta(_,e) ->
Expand Down Expand Up @@ -105,9 +104,6 @@ let map_expr f e =
| TBinop (op,e1,e2) ->
let e1 = f e1 in
{ e with eexpr = TBinop (op,e1,f e2) }
| TFor (v,e1,e2) ->
let e1 = f e1 in
{ e with eexpr = TFor (v,e1,f e2) }
| TWhile (e1,e2,flag) ->
let e1 = f e1 in
{ e with eexpr = TWhile (e1,f e2,flag) }
Expand Down Expand Up @@ -176,10 +172,6 @@ let map_expr_type f ft fv e =
| TBinop (op,e1,e2) ->
let e1 = f e1 in
{ e with eexpr = TBinop (op,e1,f e2); etype = ft e.etype }
| TFor (v,e1,e2) ->
let v = fv v in
let e1 = f e1 in
{ e with eexpr = TFor (v,e1,f e2); etype = ft e.etype }
| TWhile (e1,e2,flag) ->
let e1 = f e1 in
{ e with eexpr = TWhile (e1,f e2,flag); etype = ft e.etype }
Expand Down Expand Up @@ -301,7 +293,6 @@ let rec equal e1 e2 = match e1.eexpr,e2.eexpr with
| TFunction tf1,TFunction tf2 -> tf1 == tf2
| TVar(v1,None),TVar(v2,None) -> v1 == v2
| TVar(v1,Some e1),TVar(v2,Some e2) -> v1 == v2 && equal e1 e2
| TFor(v1,ec1,eb1),TFor(v2,ec2,eb2) -> v1 == v2 && equal ec1 ec2 && equal eb1 eb2
| TIf(e1,ethen1,None),TIf(e2,ethen2,None) -> equal e1 e2 && equal ethen1 ethen2
| TIf(e1,ethen1,Some eelse1),TIf(e2,ethen2,Some eelse2) -> equal e1 e2 && equal ethen1 ethen2 && equal eelse1 eelse2
| TWhile(e1,eb1,flag1),TWhile(e2,eb2,flag2) -> equal e1 e2 && equal eb2 eb2 && flag1 = flag2
Expand Down Expand Up @@ -337,9 +328,6 @@ let duplicate_tvars f_this e =
| TVar (v,eo) ->
let v2 = copy_var v in
{e with eexpr = TVar(v2, Option.map build_expr eo)}
| TFor (v,e1,e2) ->
let v2 = copy_var v in
{e with eexpr = TFor(v2, build_expr e1, build_expr e2)}
| TTry (e1,cl) ->
let cl = List.map (fun (v,e) ->
let v2 = copy_var v in
Expand Down Expand Up @@ -407,10 +395,6 @@ let foldmap f acc e =
let acc,e1 = f acc e1 in
let acc,e2 = f acc e2 in
acc,{ e with eexpr = TBinop (op,e1,e2) }
| TFor (v,e1,e2) ->
let acc,e1 = f acc e1 in
let acc,e2 = f acc e2 in
acc,{ e with eexpr = TFor (v,e1,e2) }
| TWhile (e1,e2,flag) ->
let acc,e1 = f acc e1 in
let acc,e2 = f acc e2 in
Expand Down Expand Up @@ -594,7 +578,7 @@ let rec constructor_side_effects e =
true
| TField (_,FEnum _) ->
false
| TUnop _ | TArray _ | TField _ | TEnumParameter _ | TEnumIndex _ | TCall _ | TNew _ | TFor _ | TWhile _ | TSwitch _ | TReturn _ | TThrow _ ->
| TUnop _ | TArray _ | TField _ | TEnumParameter _ | TEnumIndex _ | TCall _ | TNew _ | TWhile _ | TSwitch _ | TReturn _ | TThrow _ ->
true
| TBinop _ | TTry _ | TIf _ | TBlock _ | TVar _
| TFunction _ | TArrayDecl _ | TObjectDecl _
Expand Down Expand Up @@ -760,10 +744,6 @@ let dump_with_pos tabs e =
| TBlock el ->
add "TBlock";
List.iter loop el
| TFor(v,e1,e2) ->
add ("TFor " ^ v.v_name);
loop e1;
loop e2;
| TIf(e1,e2,eo) ->
add "TIf";
loop e1;
Expand Down Expand Up @@ -821,10 +801,6 @@ let collect_captured_vars e =
| TVar(v,eo) ->
Option.may loop eo;
declare v
| TFor(v,e1,e2) ->
declare v;
loop e1;
loop e2;
| TFunction tf ->
List.iter (fun (v,_) -> declare v) tf.tf_args;
loop tf.tf_expr
Expand Down Expand Up @@ -942,8 +918,6 @@ module DeadEnd = struct
Option.map_default (loop ) true switch.switch_default (* true because we know it's exhaustive *)
in
loop switch.switch_subject || check_exhaustive ()
| TFor(_, e1, _) ->
loop e1
| TBinop(OpBoolAnd, e1, e2) ->
loop e1 || is_true_expr e1 && loop e2
| TBinop(OpBoolOr, e1, e2) ->
Expand Down
7 changes: 1 addition & 6 deletions src/filters/capturedVars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ let captured_vars com e =
{ e with eexpr = TVar (v,ve) }
| TLocal v when PMap.mem v.v_id used ->
impl#mk_ref_access e v
| TFor (v,it,expr) when PMap.mem v.v_id used ->
let vtmp = mk_var v used in
let it = wrap used it in
let expr = wrap used expr in
mk (TFor (vtmp,it,Type.concat (impl#mk_init v vtmp e.epos) expr)) e.etype e.epos
| TTry (expr,catchs) ->
let catchs = List.map (fun (v,e) ->
let e = wrap used e in
Expand Down Expand Up @@ -194,7 +189,7 @@ let captured_vars com e =

and out_loop e =
match e.eexpr with
| TFor _ | TWhile _ ->
| TWhile _ ->
(*
collect variables that are declared in loop but used in subfunctions
*)
Expand Down
23 changes: 1 addition & 22 deletions src/filters/filters.ml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ let mark_switch_break_loops e =
let ret = Type.map_expr run e in
num := old_num;
ret
| TWhile _ | TFor _ ->
| TWhile _ ->
let last_switch = !in_switch in
let last_found = !did_found in
let last_num = !cur_num in
Expand Down Expand Up @@ -437,26 +437,6 @@ let iter_expressions fl mt =
| _ ->
()

module ForRemap = struct
let apply ctx e =
let rec loop e = match e.eexpr with
| TFor(v,e1,e2) ->
let e1 = loop e1 in
let e2 = loop e2 in
let iterator = ForLoop.IterationKind.of_texpr ctx e1 (ForLoop.get_unroll_params_t ctx e2) e.epos in
let restore = save_locals ctx in
let e = ForLoop.IterationKind.to_texpr ctx v iterator e2 e.epos in
restore();
begin match e.eexpr with
| TFor _ -> for_remap ctx.com.basic v e1 e2 e.epos
| _ -> e
end
| _ ->
Type.map_expr loop e
in
loop e
end

open FilterContext

let destruction tctx ectx detail_times main locals =
Expand Down Expand Up @@ -707,7 +687,6 @@ let run tctx ectx main before_destruction =
NullSafety.run com new_types;
(* PASS 1: general expression filters *)
let filters = [
"ForRemap",ForRemap.apply;
"handle_abstract_casts",AbstractCast.handle_abstract_casts;
] in
List.iter (run_expression_filters tctx detail_times filters) new_types;
Expand Down
6 changes: 0 additions & 6 deletions src/filters/localUsage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ let rec local_usage f e =
f (Function cc)
| TBlock l ->
f (Block (fun f -> List.iter (local_usage f) l))
| TFor (v,it,e) ->
local_usage f it;
f (Loop (fun f ->
f (Declare v);
local_usage f e;
))
| TWhile _ ->
f (Loop (fun f ->
iter (local_usage f) e
Expand Down
13 changes: 0 additions & 13 deletions src/filters/renameVars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,6 @@ let rec collect_vars ?(in_block=false) rc scope e =
if flag = DoWhile then
collect_vars scope condition;
)
(*
This only happens for `cross` target, because for real targets all loops are converted to `while` at this point
Idk if this works correctly.
*)
| TFor (v, iterator, body) ->
collect_loop scope (fun() ->
if rc.rc_hoisting then
declare_var rc scope v;
collect_vars scope iterator;
if not rc.rc_hoisting then
declare_var rc scope v;
collect_vars scope body
)
| _ ->
iter (collect_vars scope) e

Expand Down
4 changes: 2 additions & 2 deletions src/filters/tre.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ let rec transform_function ctx is_recursive_call fn =
let rec transform_expr cancel_tre function_end e =
match e.eexpr with
(* cancel tre inside of loops bodies *)
| TWhile _ | TFor _ ->
| TWhile _ ->
map_expr (transform_expr true false) e
(* cancel tre inside of try blocks *)
| TTry (e_try, catches) ->
Expand Down Expand Up @@ -167,7 +167,7 @@ let rec transform_function ctx is_recursive_call fn =
let rec has_tail_recursion is_recursive_call cancel_tre function_end e =
match e.eexpr with
(* cancel tre inside of loops bodies *)
| TFor _ | TWhile _ ->
| TWhile _ ->
check_expr (has_tail_recursion is_recursive_call true false) e
(* cancel tre inside of try blocks *)
| TTry (e, catches) ->
Expand Down
7 changes: 0 additions & 7 deletions src/generators/cpp/cppRetyper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1081,13 +1081,6 @@ let expression ctx request_type function_args function_type expression_tree forI
| Spread -> die ~p:expr.epos "Unexpected spread operator" __LOC__
in
(reference, cpp_type_of expr.etype)
| TFor (v, init, block) ->
let old_declarations = Hashtbl.copy !declarations in
Hashtbl.add !declarations v.v_name ();
let init = retype (cpp_type_of v.v_type) init in
let block = retype TCppVoid (mk_block block) in
declarations := old_declarations;
(CppFor (v, init, block), TCppVoid)
| TWhile (e1, e2, flag) ->
let condition = retype (TCppScalar "bool") e1 in
let close = begin_loop () in
Expand Down
6 changes: 0 additions & 6 deletions src/generators/cpp/gen/cppCppia.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1230,12 +1230,6 @@ class script_writer ctx filename asciiOut =
(this#op IaWhile ^ (if flag = NormalWhile then "1" else "0") ^ "\n");
this#gen_expression e1;
this#gen_expression e2
| TFor (tvar, init, loop) ->
this#writeOp IaFor;
this#writeVar tvar;
this#write "\n";
this#gen_expression init;
this#gen_expression loop
| TEnumParameter (expr, ef, i) ->
let enum =
match follow ef.ef_type with
Expand Down
2 changes: 0 additions & 2 deletions src/generators/genhl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2868,8 +2868,6 @@ and eval_expr ctx e =
die "" __LOC__)
| TMeta (_,e) ->
eval_expr ctx e
| TFor (v,it,loop) ->
eval_expr ctx (Texpr.for_remap ctx.com.basic v it loop e.epos)
| TSwitch {switch_subject = en;switch_cases = cases;switch_default = def} ->
let rt = to_type ctx e.etype in
let r = alloc_tmp ctx rt in
Expand Down
Loading
Loading