Skip to content

Commit edcd921

Browse files
committed
dce lambda
1 parent 23cbd99 commit edcd921

18 files changed

+22
-192
lines changed

compiler/core/js_of_lam_block.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let make_block mutable_flag (tag_info : Lam_tag_info.t) tag args =
3333

3434
let field (field_info : Lam_compat.field_dbg_info) e (i : int32) =
3535
match field_info with
36-
| Fld_tuple | Fld_array ->
36+
| Fld_tuple ->
3737
E.array_index_by_int ?comment:(Lam_compat.str_of_field_info field_info) e i
3838
| Fld_poly_var_content -> E.poly_var_value_access e
3939
| Fld_poly_var_tag -> E.poly_var_tag_access e

compiler/core/lam_analysis.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
9797
(* TODO *)
9898
| Praw_js_code _
9999
(* byte swap *)
100-
| Parraysets | Parraysetu | Poffsetref _ | Praise | Plazyforce | Psetfield _
101-
->
100+
| Parraysets | Parraysetu | Poffsetref _ | Praise | Psetfield _ ->
102101
false)
103102
| Llet (_, _, arg, body) -> no_side_effects arg && no_side_effects body
104103
| Lswitch (_, _) -> false

compiler/core/lam_compat.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ type field_dbg_info = Lambda.field_dbg_info =
7373
| Fld_extension
7474
| Fld_variant
7575
| Fld_cons
76-
| Fld_array
7776

7877
let str_of_field_info (x : field_dbg_info) : string option =
7978
match x with
80-
| Fld_array | Fld_extension | Fld_variant | Fld_cons | Fld_poly_var_tag
79+
| Fld_extension | Fld_variant | Fld_cons | Fld_poly_var_tag
8180
| Fld_poly_var_content | Fld_tuple ->
8281
None
8382
| Fld_record {name; _}

compiler/core/lam_compat.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ type field_dbg_info = Lambda.field_dbg_info =
3737
| Fld_extension
3838
| Fld_variant
3939
| Fld_cons
40-
| Fld_array
4140

4241
val str_of_field_info : field_dbg_info -> string option
4342

compiler/core/lam_compile_primitive.ml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -605,13 +605,3 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
605605
match args with
606606
| [e1] -> E.runtime_call Primitive_modules.hash "hash_final_mix" args
607607
| _ -> assert false)
608-
| Plazyforce
609-
(* FIXME: we don't inline lazy force or at least
610-
let buckle handle it
611-
*)
612-
(* let parm = Ident.create "prim" in
613-
Lfunction(Curried, [parm],
614-
Matching.inline_lazy_force (Lvar parm) Location.none)
615-
It is inlined, this should not appear here *)
616-
->
617-
assert false

compiler/core/lam_constant_convert.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ let rec convert_constant (const : Lambda.structured_constant) : Lam_constant.t =
6363
if Ext_string.is_valid_hash_number name then
6464
Const_int {i = Ext_string.hash_number_as_i32_exn name; comment = None}
6565
else Const_pointer name)
66-
| Const_float_array s -> assert false
6766
| Const_immstring s -> Const_string {s; unicode = false}
6867
| Const_block (t, xs) -> (
6968
let tag = Lambda.tag_of_tag_info t in

compiler/core/lam_convert.ml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
229229
| Pfield (id, info) -> prim ~primitive:(Pfield (id, info)) ~args loc
230230
| Psetfield (id, info) -> prim ~primitive:(Psetfield (id, info)) ~args loc
231231
| Pduprecord -> prim ~primitive:Pduprecord ~args loc
232-
| Plazyforce -> prim ~primitive:Plazyforce ~args loc
233232
| Praise _ -> prim ~primitive:Praise ~args loc
234233
| Pobjcomp x -> prim ~primitive:(Pobjcomp x) ~args loc
235234
| Pobjorder -> prim ~primitive:Pobjorder ~args loc
@@ -248,8 +247,8 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
248247
| Paddint -> prim ~primitive:Paddint ~args loc
249248
| Psubint -> prim ~primitive:Psubint ~args loc
250249
| Pmulint -> prim ~primitive:Pmulint ~args loc
251-
| Pdivint _is_safe (*FIXME*) -> prim ~primitive:Pdivint ~args loc
252-
| Pmodint _is_safe (*FIXME*) -> prim ~primitive:Pmodint ~args loc
250+
| Pdivint -> prim ~primitive:Pdivint ~args loc
251+
| Pmodint -> prim ~primitive:Pmodint ~args loc
253252
| Pandint -> prim ~primitive:Pandint ~args loc
254253
| Porint -> prim ~primitive:Porint ~args loc
255254
| Pxorint -> prim ~primitive:Pxorint ~args loc
@@ -334,11 +333,6 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
334333
| Pjs_fn_make arity -> prim ~primitive:(Pjs_fn_make arity) ~args loc
335334
| Pjs_fn_make_unit -> prim ~primitive:Pjs_fn_make_unit ~args loc
336335
| Pjs_fn_method -> prim ~primitive:Pjs_fn_method ~args loc
337-
| Pjs_unsafe_downgrade ->
338-
let primitive : Lam_primitive.t =
339-
Pjs_unsafe_downgrade {name = Ext_string.empty; setter = false}
340-
in
341-
prim ~primitive ~args loc
342336

343337
(* Does not exist since we compile array in js backend unlike native backend *)
344338

compiler/core/lam_primitive.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ type t =
4040
| Psetfield of int * Lam_compat.set_field_dbg_info
4141
(* could have field info at least for record *)
4242
| Pduprecord
43-
(* Force lazy values *)
44-
| Plazyforce
4543
(* External call *)
4644
| Pjs_call of {
4745
prim_name: string;
@@ -222,10 +220,10 @@ let eq_primitive_approx (lhs : t) (rhs : t) =
222220
| Pjs_apply | Pjs_runtime_apply | Pval_from_option | Pval_from_option_not_nest
223221
| Pundefined_to_opt | Pnull_to_opt | Pnull_undefined_to_opt | Pis_null
224222
| Pis_not_none | Psome | Psome_not_nest | Pis_undefined | Pis_null_undefined
225-
| Pimport | Ptypeof | Pfn_arity | Plazyforce | Pis_poly_var_block | Pdebugger
226-
| Pinit_mod | Pupdate_mod | Pduprecord | Pmakearray | Parraylength
227-
| Parrayrefu | Parraysetu | Parrayrefs | Parraysets | Pjs_fn_make_unit
228-
| Pjs_fn_method | Phash | Phash_mixstring | Phash_mixint | Phash_finalmix ->
223+
| Pimport | Ptypeof | Pfn_arity | Pis_poly_var_block | Pdebugger | Pinit_mod
224+
| Pupdate_mod | Pduprecord | Pmakearray | Parraylength | Parrayrefu
225+
| Parraysetu | Parrayrefs | Parraysets | Pjs_fn_make_unit | Pjs_fn_method
226+
| Phash | Phash_mixstring | Phash_mixint | Phash_finalmix ->
229227
rhs = lhs
230228
| Pcreate_extension a -> (
231229
match rhs with

compiler/core/lam_primitive.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ type t =
3636
| Pfield of int * Lambda.field_dbg_info
3737
| Psetfield of int * Lambda.set_field_dbg_info
3838
| Pduprecord
39-
| Plazyforce
4039
| Pjs_call of {
4140
(* Location.t * [loc] is passed down *)
4241
prim_name: string;

compiler/core/lam_print.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ let primitive ppf (prim : Lam_primitive.t) =
8282
let instr = "setfield " in
8383
fprintf ppf "%s%i" instr n
8484
| Pduprecord -> fprintf ppf "duprecord"
85-
| Plazyforce -> fprintf ppf "force"
8685
| Pjs_call {prim_name} -> fprintf ppf "%s[js]" prim_name
8786
| Pjs_object_create _ -> fprintf ppf "[js.obj]"
8887
| Praise -> fprintf ppf "raise"

compiler/ml/env.ml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ let prefixed_sg = Hashtbl.create 113
5757
type error =
5858
| Illegal_renaming of string * string * string
5959
| Inconsistent_import of string * string * string
60-
| Need_recursive_types of string * string
6160
| Missing_module of Location.t * Path.t * Path.t
6261
| Illegal_value_name of Location.t * string
6362

@@ -147,8 +146,6 @@ type summary =
147146
| Env_extension of summary * Ident.t * extension_constructor
148147
| Env_module of summary * Ident.t * module_declaration
149148
| Env_modtype of summary * Ident.t * modtype_declaration
150-
| Env_class of unit
151-
| Env_cltype of unit
152149
| Env_open of summary * Path.t
153150
| Env_functor_arg of summary * Ident.t
154151
| Env_constraints of summary * type_declaration PathMap.t
@@ -732,8 +729,6 @@ let check_pers_struct name =
732729
" %a@ contains the compiled interface for @ %s when %s was expected"
733730
Location.print_filename filename ps_name name
734731
| Inconsistent_import _ -> assert false
735-
| Need_recursive_types (name, _) ->
736-
Format.sprintf "%s uses recursive types" name
737732
| Missing_module _ -> assert false
738733
| Illegal_value_name _ -> assert false
739734
in
@@ -2129,10 +2124,6 @@ let report_error ppf = function
21292124
"@[<hov>The files %a@ and %a@ make inconsistent assumptions@ over \
21302125
interface %s@]"
21312126
Location.print_filename source1 Location.print_filename source2 name
2132-
| Need_recursive_types (import, export) ->
2133-
fprintf ppf
2134-
"@[<hov>Unit %s imports from %s, which uses recursive types.@ %s@]" export
2135-
import "The compilation flag -rectypes is required"
21362127
| Missing_module (_, path1, path2) ->
21372128
fprintf ppf "@[@[<hov>";
21382129
if Path.same path1 path2 then

compiler/ml/env.mli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ type summary =
2727
| Env_extension of summary * Ident.t * extension_constructor
2828
| Env_module of summary * Ident.t * module_declaration
2929
| Env_modtype of summary * Ident.t * modtype_declaration
30-
| Env_class of unit
31-
| Env_cltype of unit
3230
| Env_open of summary * Path.t
3331
| Env_functor_arg of summary * Ident.t
3432
| Env_constraints of summary * type_declaration PathMap.t
@@ -239,7 +237,6 @@ val env_of_only_summary : (summary -> Subst.t -> t) -> t -> t
239237
type error =
240238
| Illegal_renaming of string * string * string
241239
| Inconsistent_import of string * string * string
242-
| Need_recursive_types of string * string
243240
| Missing_module of Location.t * Path.t * Path.t
244241
| Illegal_value_name of Location.t * string
245242

compiler/ml/error_message_utils.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ type type_clash_statement = FunctionCall
55
type type_clash_context =
66
| SetRecordField
77
| ArrayValue
8-
| FunctionReturn
98
| MaybeUnwrapOption
109
| IfCondition
1110
| IfReturn
@@ -53,8 +52,6 @@ let error_expected_type_text ppf type_clash_context =
5352
fprintf ppf
5453
"But it's being used with the @{<info>%s@} operator, which works on:"
5554
operator
56-
| Some FunctionReturn ->
57-
fprintf ppf "But this function is expecting you to return:"
5855
| Some StringConcat -> fprintf ppf "But string concatenation is expecting:"
5956
| _ -> fprintf ppf "But it's expected to have type:"
6057

compiler/ml/lambda.ml

Lines changed: 3 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ type field_dbg_info =
125125
| Fld_extension
126126
| Fld_variant
127127
| Fld_cons
128-
| Fld_array
129128

130129
let fld_record (lbl : label) =
131130
Fld_record
@@ -164,8 +163,6 @@ let fld_record_extension_set (lbl : label) =
164163

165164
type immediate_or_pointer = Immediate | Pointer
166165

167-
type is_safe = Safe | Unsafe
168-
169166
type primitive =
170167
| Pidentity
171168
| Pignore
@@ -183,8 +180,6 @@ type primitive =
183180
| Pfield of int * field_dbg_info
184181
| Psetfield of int * set_field_dbg_info
185182
| Pduprecord
186-
(* Force lazy values *)
187-
| Plazyforce
188183
(* External call *)
189184
| Pccall of Primitive.description
190185
(* Exceptions *)
@@ -209,8 +204,8 @@ type primitive =
209204
| Paddint
210205
| Psubint
211206
| Pmulint
212-
| Pdivint of is_safe
213-
| Pmodint of is_safe
207+
| Pdivint
208+
| Pmodint
214209
| Pandint
215210
| Porint
216211
| Pxorint
@@ -310,13 +305,12 @@ type primitive =
310305
| Pjs_fn_make of int
311306
| Pjs_fn_make_unit
312307
| Pjs_fn_method
313-
| Pjs_unsafe_downgrade
314308

315309
and comparison = Ceq | Cneq | Clt | Cgt | Cle | Cge
316310

317311
and value_kind = Pgenval
318312

319-
and raise_kind = Raise_regular | Raise_reraise | Raise_notrace
313+
and raise_kind = Raise_regular | Raise_reraise
320314

321315
type pointer_info =
322316
| Pt_constructor of {
@@ -334,7 +328,6 @@ type structured_constant =
334328
| Const_base of Asttypes.constant
335329
| Const_pointer of int * pointer_info
336330
| Const_block of tag_info * structured_constant list
337-
| Const_float_array of string list
338331
| Const_immstring of string
339332
| Const_false
340333
| Const_true
@@ -507,16 +500,6 @@ let name_lambda strict arg fn =
507500
let id = Ident.create "let" in
508501
Llet (strict, Pgenval, id, arg, fn id)
509502

510-
let name_lambda_list args fn =
511-
let rec name_list names = function
512-
| [] -> fn (List.rev names)
513-
| (Lvar _ as arg) :: rem -> name_list (arg :: names) rem
514-
| arg :: rem ->
515-
let id = Ident.create "let" in
516-
Llet (Strict, Pgenval, id, arg, name_list (Lvar id :: names) rem)
517-
in
518-
name_list [] args
519-
520503
let iter_opt f = function
521504
| None -> ()
522505
| Some e -> f e
@@ -650,16 +633,6 @@ let transl_value_path ?(loc = Location.none) env path =
650633

651634
let transl_extension_path = transl_value_path
652635

653-
(* compatibility alias, deprecated in the .mli *)
654-
(* Compile a sequence of expressions *)
655-
656-
let rec make_sequence fn = function
657-
| [] -> lambda_unit
658-
| [x] -> fn x
659-
| x :: rem ->
660-
let lam = fn x in
661-
Lsequence (lam, make_sequence fn rem)
662-
663636
(* Apply a substitution to a lambda-term.
664637
Assumes that the bound variables of the lambda-term do not
665638
belong to the domain of the substitution.
@@ -713,83 +686,16 @@ let subst_lambda s lam =
713686
in
714687
subst lam
715688

716-
let rec map f lam =
717-
let lam =
718-
match lam with
719-
| Lvar _ -> lam
720-
| Lconst _ -> lam
721-
| Lapply {ap_func; ap_args; ap_loc; ap_inlined} ->
722-
Lapply
723-
{
724-
ap_func = map f ap_func;
725-
ap_args = List.map (map f) ap_args;
726-
ap_loc;
727-
ap_inlined;
728-
}
729-
| Lfunction {params; body; attr; loc} ->
730-
Lfunction {params; body = map f body; attr; loc}
731-
| Llet (str, k, v, e1, e2) -> Llet (str, k, v, map f e1, map f e2)
732-
| Lletrec (idel, e2) ->
733-
Lletrec (List.map (fun (v, e) -> (v, map f e)) idel, map f e2)
734-
| Lprim (p, el, loc) -> Lprim (p, List.map (map f) el, loc)
735-
| Lswitch (e, sw, loc) ->
736-
Lswitch
737-
( map f e,
738-
{
739-
sw_numconsts = sw.sw_numconsts;
740-
sw_consts = List.map (fun (n, e) -> (n, map f e)) sw.sw_consts;
741-
sw_numblocks = sw.sw_numblocks;
742-
sw_blocks = List.map (fun (n, e) -> (n, map f e)) sw.sw_blocks;
743-
sw_failaction = Misc.may_map (map f) sw.sw_failaction;
744-
sw_names = sw.sw_names;
745-
},
746-
loc )
747-
| Lstringswitch (e, sw, default, loc) ->
748-
Lstringswitch
749-
( map f e,
750-
List.map (fun (s, e) -> (s, map f e)) sw,
751-
Misc.may_map (map f) default,
752-
loc )
753-
| Lstaticraise (i, args) -> Lstaticraise (i, List.map (map f) args)
754-
| Lstaticcatch (body, id, handler) ->
755-
Lstaticcatch (map f body, id, map f handler)
756-
| Ltrywith (e1, v, e2) -> Ltrywith (map f e1, v, map f e2)
757-
| Lifthenelse (e1, e2, e3) -> Lifthenelse (map f e1, map f e2, map f e3)
758-
| Lsequence (e1, e2) -> Lsequence (map f e1, map f e2)
759-
| Lwhile (e1, e2) -> Lwhile (map f e1, map f e2)
760-
| Lfor (v, e1, e2, dir, e3) -> Lfor (v, map f e1, map f e2, dir, map f e3)
761-
| Lassign (v, e) -> Lassign (v, map f e)
762-
| Lsend (k, o, loc) -> Lsend (k, map f o, loc)
763-
in
764-
f lam
765-
766689
(* To let-bind expressions to variables *)
767690

768691
let bind str var exp body =
769692
match exp with
770693
| Lvar var' when Ident.same var var' -> body
771694
| _ -> Llet (str, Pgenval, var, exp, body)
772695

773-
and commute_comparison = function
774-
| Ceq -> Ceq
775-
| Cneq -> Cneq
776-
| Clt -> Cgt
777-
| Cle -> Cge
778-
| Cgt -> Clt
779-
| Cge -> Cle
780-
781-
and negate_comparison = function
782-
| Ceq -> Cneq
783-
| Cneq -> Ceq
784-
| Clt -> Cge
785-
| Cle -> Cgt
786-
| Cgt -> Cle
787-
| Cge -> Clt
788-
789696
let raise_kind = function
790697
| Raise_regular -> "raise"
791698
| Raise_reraise -> "reraise"
792-
| Raise_notrace -> "raise_notrace"
793699

794700
let lam_of_loc kind loc =
795701
let loc_start = loc.Location.loc_start in
@@ -821,5 +727,3 @@ let lam_of_loc kind loc =
821727
in
822728
Lconst (Const_immstring loc)
823729
| Loc_LINE -> Lconst (Const_base (Const_int lnum))
824-
825-
let reset () = raise_count := 0

0 commit comments

Comments
 (0)