Skip to content

Commit 6612ebd

Browse files
author
Hongbo Zhang
committed
remove unused primitives
1 parent 6b54402 commit 6612ebd

15 files changed

+147
-197
lines changed

jscomp/lam.ml

Lines changed: 109 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,16 @@ type tag_info = Lambda.tag_info
3333
type mutable_flag = Asttypes.mutable_flag
3434
type field_dbg_info = Lambda.field_dbg_info
3535
type set_field_dbg_info = Lambda.set_field_dbg_info
36-
type raise_kind = Lambda.raise_kind
3736

38-
type primitive (* = Lambda.primitive *) =
37+
38+
type primitive =
3939
| Pbytes_to_string
4040
| Pbytes_of_string
4141
| Pchar_to_int
4242
| Pchar_of_int
43-
| Pmark_ocaml_object
44-
| Pignore
4543
| Prevapply of Location.t
4644
| Pdirapply of Location.t
47-
| Ploc of loc_kind
45+
4846
(* Globals *)
4947
| Pgetglobal of Ident.t
5048
| Psetglobal of Ident.t
@@ -61,7 +59,7 @@ type primitive (* = Lambda.primitive *) =
6159
(* External call *)
6260
| Pccall of Types.type_expr option Primitive.description
6361
(* Exceptions *)
64-
| Praise of raise_kind
62+
| Praise
6563
(* Boolean operations *)
6664
| Psequand | Psequor | Pnot
6765
(* Integer operations *)
@@ -510,122 +508,123 @@ let prim ~primitive:(prim : Prim.t) ~args:(ll : t list) : t =
510508
let not x : t =
511509
prim Pnot [x]
512510

513-
let lam_prim ~primitive:(p : Lambda.primitive) ~args:(ll : t list) : t =
511+
let lam_prim ~primitive:(p : Lambda.primitive) ~args : t =
514512
match p with
515513
| Pidentity ->
516-
begin match ll with [x] -> x | _ -> assert false end
514+
begin match args with [x] -> x | _ -> assert false end
517515
| Pbytes_to_string
518-
-> prim ~primitive:Pbytes_to_string ~args:ll
519-
| Pbytes_of_string -> prim ~primitive:Pbytes_of_string ~args:ll
520-
| Pchar_to_int -> prim ~primitive:Pchar_to_int ~args:ll
521-
| Pchar_of_int -> prim ~primitive:Pchar_of_int ~args:ll
522-
| Pmark_ocaml_object -> prim ~primitive:Pmark_ocaml_object ~args:ll
516+
-> prim ~primitive:Pbytes_to_string ~args
517+
| Pbytes_of_string -> prim ~primitive:Pbytes_of_string ~args
518+
| Pchar_to_int -> prim ~primitive:Pchar_to_int ~args
519+
| Pchar_of_int -> prim ~primitive:Pchar_of_int ~args
520+
| Pmark_ocaml_object ->
521+
begin match args with [l] -> l | _ -> assert false end
523522
| Pignore -> (* Pignore means return unit, it is not an nop *)
524-
prim ~primitive:Pignore ~args:ll
523+
begin match args with [x] -> seq x unit | _ -> assert false end
525524
| Prevapply loc
526-
-> prim ~primitive:(Prevapply loc) ~args:ll
527-
| Pdirapply loc -> prim ~primitive:(Pdirapply loc) ~args:ll
528-
| Ploc loc -> prim ~primitive:(Ploc loc) ~args:ll
529-
| Pgetglobal id -> prim ~primitive:(Pgetglobal id) ~args:ll
530-
| Psetglobal id -> prim ~primitive:(Psetglobal id) ~args:ll
525+
-> prim ~primitive:(Prevapply loc) ~args
526+
| Pdirapply loc -> prim ~primitive:(Pdirapply loc) ~args
527+
| Ploc loc -> assert false (* already compiled away here*)
528+
| Pgetglobal id -> prim ~primitive:(Pgetglobal id) ~args
529+
| Psetglobal id -> prim ~primitive:(Psetglobal id) ~args
531530
| Pmakeblock (tag,info, mutable_flag)
532-
-> prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args:ll
531+
-> prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args
533532
| Pfield (id,info)
534-
-> prim ~primitive:(Pfield (id,info)) ~args:ll
533+
-> prim ~primitive:(Pfield (id,info)) ~args
535534
| Psetfield (id,b,info)
536-
-> prim ~primitive:(Psetfield (id,b,info)) ~args:ll
535+
-> prim ~primitive:(Psetfield (id,b,info)) ~args
537536

538537
| Pfloatfield (id,info)
539-
-> prim ~primitive:(Pfloatfield (id,info)) ~args:ll
538+
-> prim ~primitive:(Pfloatfield (id,info)) ~args
540539
| Psetfloatfield (id,info)
541-
-> prim ~primitive:(Psetfloatfield (id,info)) ~args:ll
540+
-> prim ~primitive:(Psetfloatfield (id,info)) ~args
542541
| Pduprecord (repr,i)
543-
-> prim ~primitive:(Pduprecord(repr,i)) ~args:ll
544-
| Plazyforce -> prim ~primitive:Plazyforce ~args:ll
545-
546-
| Pccall a -> prim ~primitive:(Pccall a) ~args:ll
547-
| Praise kind -> prim ~primitive:(Praise kind) ~args:ll
548-
| Psequand -> prim ~primitive:Psequand ~args:ll
549-
| Psequor -> prim ~primitive:Psequor ~args:ll
550-
| Pnot -> prim ~primitive:Pnot ~args:ll
551-
| Pnegint -> prim ~primitive:Pnegint ~args:ll
552-
| Paddint -> prim ~primitive:Paddint ~args:ll
553-
| Psubint -> prim ~primitive:Psubint ~args:ll
554-
| Pmulint -> prim ~primitive:Pmulint ~args:ll
555-
| Pdivint -> prim ~primitive:Pdivint ~args:ll
556-
| Pmodint -> prim ~primitive:Pmodint ~args:ll
557-
| Pandint -> prim ~primitive:Pandint ~args:ll
558-
| Porint -> prim ~primitive:Porint ~args:ll
559-
| Pxorint -> prim ~primitive:Pxorint ~args:ll
560-
| Plslint -> prim ~primitive:Plslint ~args:ll
561-
| Plsrint -> prim ~primitive:Plsrint ~args:ll
562-
| Pasrint -> prim ~primitive:Pasrint ~args:ll
563-
| Pstringlength -> prim ~primitive:Pstringlength ~args:ll
564-
| Pstringrefu -> prim ~primitive:Pstringrefu ~args:ll
565-
| Pstringsetu -> prim ~primitive:Pstringsetu ~args:ll
566-
| Pstringrefs -> prim ~primitive:Pstringrefs ~args:ll
567-
| Pstringsets -> prim ~primitive:Pstringsets ~args:ll
568-
| Pbyteslength -> prim ~primitive:Pbyteslength ~args:ll
569-
| Pbytesrefu -> prim ~primitive:Pbytesrefu ~args:ll
570-
| Pbytessetu -> prim ~primitive:Pbytessetu ~args:ll
571-
| Pbytesrefs -> prim ~primitive:Pbytesrefs ~args:ll
572-
| Pbytessets -> prim ~primitive:Pbytessets ~args:ll
573-
| Pisint -> prim ~primitive:Pisint ~args:ll
574-
| Pisout -> prim ~primitive:Pisout ~args:ll
575-
| Pbittest -> prim ~primitive:Pbittest ~args:ll
576-
| Pintoffloat -> prim ~primitive:Pintoffloat ~args:ll
577-
| Pfloatofint -> prim ~primitive:Pfloatofint ~args:ll
578-
| Pnegfloat -> prim ~primitive:Pnegfloat ~args:ll
579-
| Pabsfloat -> prim ~primitive:Pabsfloat ~args:ll
580-
| Paddfloat -> prim ~primitive:Paddfloat ~args:ll
581-
| Psubfloat -> prim ~primitive:Psubfloat ~args:ll
582-
| Pmulfloat -> prim ~primitive:Pmulfloat ~args:ll
583-
| Pdivfloat -> prim ~primitive:Pdivfloat ~args:ll
584-
| Pint_as_pointer -> prim ~primitive:Pint_as_pointer ~args:ll
585-
| Pbswap16 -> prim ~primitive:Pbswap16 ~args:ll
586-
| Pintcomp x -> prim ~primitive:(Pintcomp x) ~args:ll
587-
| Poffsetint x -> prim ~primitive:(Poffsetint x) ~args:ll
588-
| Poffsetref x -> prim ~primitive:(Poffsetref x) ~args:ll
589-
| Pfloatcomp x -> prim ~primitive:(Pfloatcomp x) ~args:ll
590-
| Pmakearray x -> prim ~primitive:(Pmakearray x) ~args:ll
591-
| Parraylength x -> prim ~primitive:(Parraylength x) ~args:ll
592-
| Parrayrefu x -> prim ~primitive:(Parrayrefu x) ~args:ll
593-
| Parraysetu x -> prim ~primitive:(Parraysetu x) ~args:ll
594-
| Parrayrefs x -> prim ~primitive:(Parrayrefs x) ~args:ll
595-
| Parraysets x -> prim ~primitive:(Parraysets x) ~args:ll
596-
| Pbintofint x -> prim ~primitive:(Pbintofint x) ~args:ll
597-
| Pintofbint x -> prim ~primitive:(Pintofbint x) ~args:ll
598-
| Pnegbint x -> prim ~primitive:(Pnegbint x) ~args:ll
599-
| Paddbint x -> prim ~primitive:(Paddbint x) ~args:ll
600-
| Psubbint x -> prim ~primitive:(Psubbint x) ~args:ll
601-
| Pmulbint x -> prim ~primitive:(Pmulbint x) ~args:ll
602-
| Pdivbint x -> prim ~primitive:(Pdivbint x) ~args:ll
603-
| Pmodbint x -> prim ~primitive:(Pmodbint x) ~args:ll
604-
| Pandbint x -> prim ~primitive:(Pandbint x) ~args:ll
605-
| Porbint x -> prim ~primitive:(Porbint x) ~args:ll
606-
| Pxorbint x -> prim ~primitive:(Pxorbint x) ~args:ll
607-
| Plslbint x -> prim ~primitive:(Plslbint x) ~args:ll
608-
| Plsrbint x -> prim ~primitive:(Plsrbint x) ~args:ll
609-
| Pasrbint x -> prim ~primitive:(Pasrbint x) ~args:ll
610-
| Pbigarraydim x -> prim ~primitive:(Pbigarraydim x) ~args:ll
611-
| Pstring_load_16 x -> prim ~primitive:(Pstring_load_16 x) ~args:ll
612-
| Pstring_load_32 x -> prim ~primitive:(Pstring_load_32 x) ~args:ll
613-
| Pstring_load_64 x -> prim ~primitive:(Pstring_load_64 x) ~args:ll
614-
| Pstring_set_16 x -> prim ~primitive:(Pstring_set_16 x) ~args:ll
615-
| Pstring_set_32 x -> prim ~primitive:(Pstring_set_32 x) ~args:ll
616-
| Pstring_set_64 x -> prim ~primitive:(Pstring_set_64 x) ~args:ll
617-
| Pbigstring_load_16 x -> prim ~primitive:(Pbigstring_load_16 x) ~args:ll
618-
| Pbigstring_load_32 x -> prim ~primitive:(Pbigstring_load_32 x) ~args:ll
619-
| Pbigstring_load_64 x -> prim ~primitive:(Pbigstring_load_64 x) ~args:ll
620-
| Pbigstring_set_16 x -> prim ~primitive:(Pbigstring_set_16 x) ~args:ll
621-
| Pbigstring_set_32 x -> prim ~primitive:(Pbigstring_set_32 x) ~args:ll
622-
| Pbigstring_set_64 x -> prim ~primitive:(Pbigstring_set_64 x) ~args:ll
623-
| Pctconst x -> prim ~primitive:(Pctconst x) ~args:ll
624-
| Pbbswap x -> prim ~primitive:(Pbbswap x) ~args:ll
625-
| Pcvtbint (a,b) -> prim ~primitive:(Pcvtbint (a,b)) ~args:ll
626-
| Pbintcomp (a,b) -> prim ~primitive:(Pbintcomp (a,b)) ~args:ll
627-
| Pbigarrayref (a,b,c,d) -> prim ~primitive:(Pbigarrayref (a,b,c,d)) ~args:ll
628-
| Pbigarrayset (a,b,c,d) -> prim ~primitive:(Pbigarrayset (a,b,c,d)) ~args:ll
542+
-> prim ~primitive:(Pduprecord(repr,i)) ~args
543+
| Plazyforce -> prim ~primitive:Plazyforce ~args
544+
545+
| Pccall a -> prim ~primitive:(Pccall a) ~args
546+
| Praise _ -> prim ~primitive:Praise ~args
547+
| Psequand -> prim ~primitive:Psequand ~args
548+
| Psequor -> prim ~primitive:Psequor ~args
549+
| Pnot -> prim ~primitive:Pnot ~args
550+
| Pnegint -> prim ~primitive:Pnegint ~args
551+
| Paddint -> prim ~primitive:Paddint ~args
552+
| Psubint -> prim ~primitive:Psubint ~args
553+
| Pmulint -> prim ~primitive:Pmulint ~args
554+
| Pdivint -> prim ~primitive:Pdivint ~args
555+
| Pmodint -> prim ~primitive:Pmodint ~args
556+
| Pandint -> prim ~primitive:Pandint ~args
557+
| Porint -> prim ~primitive:Porint ~args
558+
| Pxorint -> prim ~primitive:Pxorint ~args
559+
| Plslint -> prim ~primitive:Plslint ~args
560+
| Plsrint -> prim ~primitive:Plsrint ~args
561+
| Pasrint -> prim ~primitive:Pasrint ~args
562+
| Pstringlength -> prim ~primitive:Pstringlength ~args
563+
| Pstringrefu -> prim ~primitive:Pstringrefu ~args
564+
| Pstringsetu -> prim ~primitive:Pstringsetu ~args
565+
| Pstringrefs -> prim ~primitive:Pstringrefs ~args
566+
| Pstringsets -> prim ~primitive:Pstringsets ~args
567+
| Pbyteslength -> prim ~primitive:Pbyteslength ~args
568+
| Pbytesrefu -> prim ~primitive:Pbytesrefu ~args
569+
| Pbytessetu -> prim ~primitive:Pbytessetu ~args
570+
| Pbytesrefs -> prim ~primitive:Pbytesrefs ~args
571+
| Pbytessets -> prim ~primitive:Pbytessets ~args
572+
| Pisint -> prim ~primitive:Pisint ~args
573+
| Pisout -> prim ~primitive:Pisout ~args
574+
| Pbittest -> prim ~primitive:Pbittest ~args
575+
| Pintoffloat -> prim ~primitive:Pintoffloat ~args
576+
| Pfloatofint -> prim ~primitive:Pfloatofint ~args
577+
| Pnegfloat -> prim ~primitive:Pnegfloat ~args
578+
| Pabsfloat -> prim ~primitive:Pabsfloat ~args
579+
| Paddfloat -> prim ~primitive:Paddfloat ~args
580+
| Psubfloat -> prim ~primitive:Psubfloat ~args
581+
| Pmulfloat -> prim ~primitive:Pmulfloat ~args
582+
| Pdivfloat -> prim ~primitive:Pdivfloat ~args
583+
| Pint_as_pointer -> prim ~primitive:Pint_as_pointer ~args
584+
| Pbswap16 -> prim ~primitive:Pbswap16 ~args
585+
| Pintcomp x -> prim ~primitive:(Pintcomp x) ~args
586+
| Poffsetint x -> prim ~primitive:(Poffsetint x) ~args
587+
| Poffsetref x -> prim ~primitive:(Poffsetref x) ~args
588+
| Pfloatcomp x -> prim ~primitive:(Pfloatcomp x) ~args
589+
| Pmakearray x -> prim ~primitive:(Pmakearray x) ~args
590+
| Parraylength x -> prim ~primitive:(Parraylength x) ~args
591+
| Parrayrefu x -> prim ~primitive:(Parrayrefu x) ~args
592+
| Parraysetu x -> prim ~primitive:(Parraysetu x) ~args
593+
| Parrayrefs x -> prim ~primitive:(Parrayrefs x) ~args
594+
| Parraysets x -> prim ~primitive:(Parraysets x) ~args
595+
| Pbintofint x -> prim ~primitive:(Pbintofint x) ~args
596+
| Pintofbint x -> prim ~primitive:(Pintofbint x) ~args
597+
| Pnegbint x -> prim ~primitive:(Pnegbint x) ~args
598+
| Paddbint x -> prim ~primitive:(Paddbint x) ~args
599+
| Psubbint x -> prim ~primitive:(Psubbint x) ~args
600+
| Pmulbint x -> prim ~primitive:(Pmulbint x) ~args
601+
| Pdivbint x -> prim ~primitive:(Pdivbint x) ~args
602+
| Pmodbint x -> prim ~primitive:(Pmodbint x) ~args
603+
| Pandbint x -> prim ~primitive:(Pandbint x) ~args
604+
| Porbint x -> prim ~primitive:(Porbint x) ~args
605+
| Pxorbint x -> prim ~primitive:(Pxorbint x) ~args
606+
| Plslbint x -> prim ~primitive:(Plslbint x) ~args
607+
| Plsrbint x -> prim ~primitive:(Plsrbint x) ~args
608+
| Pasrbint x -> prim ~primitive:(Pasrbint x) ~args
609+
| Pbigarraydim x -> prim ~primitive:(Pbigarraydim x) ~args
610+
| Pstring_load_16 x -> prim ~primitive:(Pstring_load_16 x) ~args
611+
| Pstring_load_32 x -> prim ~primitive:(Pstring_load_32 x) ~args
612+
| Pstring_load_64 x -> prim ~primitive:(Pstring_load_64 x) ~args
613+
| Pstring_set_16 x -> prim ~primitive:(Pstring_set_16 x) ~args
614+
| Pstring_set_32 x -> prim ~primitive:(Pstring_set_32 x) ~args
615+
| Pstring_set_64 x -> prim ~primitive:(Pstring_set_64 x) ~args
616+
| Pbigstring_load_16 x -> prim ~primitive:(Pbigstring_load_16 x) ~args
617+
| Pbigstring_load_32 x -> prim ~primitive:(Pbigstring_load_32 x) ~args
618+
| Pbigstring_load_64 x -> prim ~primitive:(Pbigstring_load_64 x) ~args
619+
| Pbigstring_set_16 x -> prim ~primitive:(Pbigstring_set_16 x) ~args
620+
| Pbigstring_set_32 x -> prim ~primitive:(Pbigstring_set_32 x) ~args
621+
| Pbigstring_set_64 x -> prim ~primitive:(Pbigstring_set_64 x) ~args
622+
| Pctconst x -> prim ~primitive:(Pctconst x) ~args
623+
| Pbbswap x -> prim ~primitive:(Pbbswap x) ~args
624+
| Pcvtbint (a,b) -> prim ~primitive:(Pcvtbint (a,b)) ~args
625+
| Pbintcomp (a,b) -> prim ~primitive:(Pbintcomp (a,b)) ~args
626+
| Pbigarrayref (a,b,c,d) -> prim ~primitive:(Pbigarrayref (a,b,c,d)) ~args
627+
| Pbigarrayset (a,b,c,d) -> prim ~primitive:(Pbigarrayset (a,b,c,d)) ~args
629628

630629

631630
let rec convert (lam : Lambda.lambda) : t =

jscomp/lam.mli

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,50 +33,39 @@ type tag_info = Lambda.tag_info
3333
type mutable_flag = Asttypes.mutable_flag
3434
type field_dbg_info = Lambda.field_dbg_info
3535
type set_field_dbg_info = Lambda.set_field_dbg_info
36-
type raise_kind = Lambda.raise_kind
36+
3737

3838
type primitive (* = Lambda.primitive *) =
3939
| Pbytes_to_string
4040
| Pbytes_of_string
4141
| Pchar_to_int
4242
| Pchar_of_int
43-
| Pmark_ocaml_object
44-
| Pignore
4543
| Prevapply of Location.t
4644
| Pdirapply of Location.t
47-
| Ploc of Lambda.loc_kind
48-
(* Globals *)
4945
| Pgetglobal of Ident.t
5046
| Psetglobal of Ident.t
51-
(* Operations on heap blocks *)
5247
| Pmakeblock of int * Lambda.tag_info * Asttypes.mutable_flag
5348
| Pfield of int * Lambda.field_dbg_info
5449
| Psetfield of int * bool * Lambda.set_field_dbg_info
55-
(* could have field info at least for record *)
5650
| Pfloatfield of int * Lambda.field_dbg_info
5751
| Psetfloatfield of int * Lambda.set_field_dbg_info
5852
| Pduprecord of Types.record_representation * int
59-
(* Force lazy values *)
6053
| Plazyforce
61-
(* External call *)
6254
| Pccall of Types.type_expr option Primitive.description
63-
(* Exceptions *)
64-
| Praise of Lambda.raise_kind
65-
(* Boolean operations *)
55+
| Praise
6656
| Psequand | Psequor | Pnot
67-
(* Integer operations *)
6857
| Pnegint | Paddint | Psubint | Pmulint | Pdivint | Pmodint
6958
| Pandint | Porint | Pxorint
7059
| Plslint | Plsrint | Pasrint
7160
| Pintcomp of Lambda.comparison
7261
| Poffsetint of int
7362
| Poffsetref of int
74-
(* Float operations *)
63+
7564
| Pintoffloat | Pfloatofint
7665
| Pnegfloat | Pabsfloat
7766
| Paddfloat | Psubfloat | Pmulfloat | Pdivfloat
7867
| Pfloatcomp of Lambda.comparison
79-
(* String operations *)
68+
8069
| Pstringlength
8170
| Pstringrefu
8271
| Pstringsetu

jscomp/lam_analysis.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
7171
| Pbytes_of_string
7272
| Pchar_to_int (* might throw .. *)
7373
| Pchar_of_int
74-
| Ploc _
74+
7575

7676
| Pgetglobal _
7777
| Pmakeblock _ (* whether it's mutable or not *)
@@ -128,7 +128,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
128128
(* Integer to external pointer *)
129129
| Pint_as_pointer
130130
| Poffsetint _
131-
| Pignore
131+
132132
-> true
133133

134134

@@ -166,9 +166,8 @@ let rec no_side_effects (lam : Lam.t) : bool =
166166
| Pbbswap _
167167
| Parraysetu _
168168
| Poffsetref _
169-
| Praise _
169+
| Praise
170170
| Plazyforce
171-
| Pmark_ocaml_object (* TODO*)
172171
| Psetfield _
173172
| Psetfloatfield _
174173
| Psetglobal _ -> false
@@ -239,7 +238,7 @@ let rec size (lam : Lam.t) =
239238
args = [Lprim { primitive = Pgetglobal _; args = [ ]; _}]
240239
; _}
241240
-> 1
242-
| Lprim {primitive = Praise _; args = [l ]; _}
241+
| Lprim {primitive = Praise ; args = [l ]; _}
243242
-> size l
244243
| Lprim {args = ll; _} -> size_lams 1 ll
245244

jscomp/lam_compile.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ and
666666
-> (* should be before Pgetglobal *)
667667
get_exp_with_index cxt lam (id,n, env)
668668

669-
| Lprim {primitive = Praise _raise_kind; args = [ e ]; _} ->
669+
| Lprim {primitive = Praise ; args = [ e ]; _} ->
670670
begin
671671
match compile_lambda {
672672
cxt with should_return = False; st = NeedValue} e with

0 commit comments

Comments
 (0)