Skip to content

Replace ocaml style oo with js style #4967

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

Merged
merged 12 commits into from
Feb 24, 2021
Merged
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
16 changes: 1 addition & 15 deletions jscomp/core/js_exp_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -883,21 +883,7 @@ let tag ?comment e : t =
(* according to the compiler, [Btype.hash_variant],
it's reduced to 31 bits for hash
*)
(* FIXME: unused meth_name *)
let public_method_call _meth_name obj label cache args =
let len = List.length args in
(* econd (int_equal (tag obj ) obj_int_tag_literal) *)
if len <= 7 then
runtime_call Js_runtime_modules.caml_oo_curry
("js" ^ string_of_int (len + 1) )
(label:: ( int cache) :: obj::args)
else
runtime_call Js_runtime_modules.caml_oo_curry "js"
[label;
int cache;
obj ;
array NA (obj::args)
]


(* TODO: handle arbitrary length of args ..
we can reduce part of the overhead by using
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_exp_make.mli
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ val runtime_ref :
string ->
t

val public_method_call : string -> t -> t -> Int32.t -> t list -> t



val str :
Expand Down
11 changes: 4 additions & 7 deletions jscomp/core/lam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ module Types = struct
| Lwhile of t * t
| Lfor of ident * t * t * Asttypes.direction_flag * t
| Lassign of ident * t
| Lsend of Lam_compat.meth_kind * t * t * t list * Location.t
(* | Lsend of Lam_compat.meth_kind * t * t * t list * Location.t *)
end

module X = struct
Expand Down Expand Up @@ -187,7 +187,7 @@ module X = struct
| Lwhile of t * t
| Lfor of ident * t * t * Asttypes.direction_flag * t
| Lassign of ident * t
| Lsend of Lam_compat.meth_kind * t * t * t list * Location.t
(* | Lsend of Lam_compat.meth_kind * t * t * t list * Location.t *)
end
include Types

Expand Down Expand Up @@ -258,11 +258,11 @@ let inner_map
| Lassign(id, e) ->
let e = f e in
Lassign(id,e)
| Lsend (k, met, obj, args, loc) ->
(* | Lsend (k, met, obj, args, loc) ->
let met = f met in
let obj = f obj in
let args = Ext_list.map args f in
Lsend(k,met,obj,args,loc)
Lsend(k,met,obj,args,loc) *)



Expand Down Expand Up @@ -415,7 +415,6 @@ let rec
| Lstaticcatch _
| Ltrywith _
| Lfor (_,_,_,_,_)
| Lsend _
-> false
and eq_option l1 l2 =
match l1 with
Expand Down Expand Up @@ -487,8 +486,6 @@ let for_ v e1 e2 dir e3 : t =
Lfor(v,e1,e2,dir,e3)

let assign v l : t = Lassign(v,l)
let send u m o ll v : t =
Lsend(u, m, o, ll, v)
let staticcatch a b c : t = Lstaticcatch(a,b,c)
let staticraise a b : t = Lstaticraise(a,b)

Expand Down
6 changes: 1 addition & 5 deletions jscomp/core/lam.mli
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ and t = private
| Lwhile of t * t
| Lfor of ident * t * t * Asttypes.direction_flag * t
| Lassign of ident * t
| Lsend of Lambda.meth_kind * t * t * t list * Location.t
(* | Lsend of Lambda.meth_kind * t * t * t list * Location.t *)
(* | Levent of t * Lambda.lambda_event
[Levent] in the branch hurt pattern match,
we should use record for trivial debugger info
Expand Down Expand Up @@ -165,10 +165,6 @@ val while_ : t -> t -> t
val try_ : t -> ident -> t -> t
val assign : ident -> t -> t

val send :
Lambda.meth_kind ->
t -> t -> t list ->
Location.t -> t

(** constant folding *)
val prim : primitive:Lam_primitive.t -> args:t list -> Location.t -> t
Expand Down
4 changes: 2 additions & 2 deletions jscomp/core/lam_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
| Lwhile _ -> false (* conservative here, non-terminating loop does have side effect *)
| Lfor _ -> false
| Lassign _ -> false (* actually it depends ... *)
| Lsend _ -> false
(* | Lsend _ -> false *)
| Lapply {
ap_func = Lprim {primitive = Pfield (_, Fld_module {name = "from_fun"})};
ap_args = [arg]}
Expand Down Expand Up @@ -272,7 +272,7 @@ let rec size (lam : Lam.t) =
| Lwhile _ -> really_big ()
| Lfor _ -> really_big ()
| Lassign (_,v) -> 1 + size v (* This is side effectful, be careful *)
| Lsend _ -> really_big ()
(* | Lsend _ -> really_big () *)

with Too_big_to_inline -> 1000
and size_constant x =
Expand Down
1 change: 0 additions & 1 deletion jscomp/core/lam_arity_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ let rec get_arity (meta : Lam_stats.t) (lam : Lam.t) : Lam_arity.t =
all_lambdas meta [l2;l3]
| Lsequence(_, l2) -> get_arity meta l2
| Lstaticraise _ (* since it will not be in tail position *)
| Lsend _
-> Lam_arity.na
| Lwhile _
| Lfor _
Expand Down
5 changes: 0 additions & 5 deletions jscomp/core/lam_bounded_vars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ let rewrite (map : _ Hash_ident.t)
Lam.while_ l1 l2
| Lassign(v, l)
-> Lam.assign v (aux l)
| Lsend(u, m, o, ll, v) ->
let m = aux m in
let o = aux o in
let ll = Ext_list.map ll aux in
Lam.send u m o ll v
in
aux lam

Expand Down
6 changes: 0 additions & 6 deletions jscomp/core/lam_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ let check file lam =

| Lassign(_id, e) ->
check_staticfails e cxt
| Lsend (_k, met, obj, args, _) ->
check_list (met::obj::args) cxt
in
let rec
iter_list xs = Ext_list.iter xs iter
Expand Down Expand Up @@ -160,10 +158,6 @@ let check file lam =
| Lassign(id, e) ->
use id ;
iter e
| Lsend (_k, met, obj, args, _) ->
iter met; iter obj;
iter_list args

in
begin
check_staticfails lam Set_int.empty;
Expand Down
5 changes: 1 addition & 4 deletions jscomp/core/lam_closure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ let free_variables
| Lassign(id, e) ->
used top id ;
iter top e
| Lsend (_k, met, obj, args, _) ->
iter sink_pos met ;
iter sink_pos obj;
List.iter (iter sink_pos) args in
in
iter Lam_var_stats.fresh_env lam ;
!fv

Expand Down
69 changes: 1 addition & 68 deletions jscomp/core/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let rec apply_with_arity_aux (fn : J.expression)
let apply_with_arity ~arity fn args =
apply_with_arity_aux fn arity args (List.length args)

let method_cache_id = ref 1 (*TODO: move to js runtime for re-entrant *)


let change_tail_type_in_try
(x : Lam_compile_context.tail_type)
Expand Down Expand Up @@ -1145,71 +1145,6 @@ and compile_trywith lam id catch (lambda_cxt : Lam_compile_context.t) =
mutable initializers: (obj -> unit) list }
]}
*)
and compile_send (meth_kind : Lam_compat.meth_kind)
(met : Lam.t)
(obj : Lam.t) (args : Lam.t list)
(lambda_cxt : Lam_compile_context.t) =
let new_cxt = {lambda_cxt with continuation = NeedValue Not_tail} in
match Ext_list.split_map (met :: obj :: args) (fun x ->
match x with
| Lprim {primitive = Pccall {prim_name ; _}; args = []}
(* nullary external call*)
->
[], E.var (Ext_ident.create_js prim_name)
| _ ->
match compile_lambda new_cxt x with
| {value = None} -> assert false
| {block; value = Some b} -> block, b
) with
| _, ([] | [_]) -> assert false
| (args_code, label::nobj::args)
->
let cont3 nobj k =
match Js_ast_util.named_expression nobj with
| None ->
let cont =
Js_output.output_of_block_and_expression
lambda_cxt.continuation (List.concat args_code)
in
cont (k nobj)
| Some (obj_code, v) ->
let cont2 obj_code v =
Js_output.output_of_block_and_expression
lambda_cxt.continuation
( Ext_list.concat_append args_code [obj_code]) v in
let cobj = E.var v in
cont2 obj_code (k cobj) in
match meth_kind with
| Self ->
(* TODO: horrible hack -- fixed later -- CHECK*)
cont3 nobj (fun aobj -> E.call ~info:Js_call_info.dummy
(Js_of_lam_array.ref_array
(E.array_index_by_int aobj 0l) label )
(aobj :: args))
(* [E.small_int 1] is because we use array,
when we change the runtime represenation, it needs to be adapted
*)

| Cached | Public None
(* TODO: check -- 1. js object propagate 2. js object create *)
->
let get = E.runtime_ref Js_runtime_modules.oo "caml_get_public_method" in
let cache = !method_cache_id in
let () = incr method_cache_id in
cont3 nobj (fun obj' ->
E.call ~info:Js_call_info.dummy
(E.call ~info:Js_call_info.dummy get
[obj'; label; E.small_int cache]) (obj'::args)
) (* avoid duplicated compuattion *)


| Public (Some name) ->
let cache = !method_cache_id in
incr method_cache_id ;
cont3 nobj
(fun aobj -> E.public_method_call name aobj label
(Int32.of_int cache) args )


and compile_ifthenelse
(predicate : Lam.t)
Expand Down Expand Up @@ -1661,5 +1596,3 @@ and compile_lambda
compile_assign id lambda lambda_cxt
| Ltrywith(lam,id, catch) -> (* generate documentation *)
compile_trywith lam id catch lambda_cxt
| Lsend(meth_kind,met, obj, args,_loc) ->
compile_send meth_kind met obj args lambda_cxt
10 changes: 4 additions & 6 deletions jscomp/core/lam_convert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ let exception_id_destructed (l : Lam.t) (fv : Ident.t): bool =
hit e1 || hit e2
| Lwhile(e1, e2) ->
hit e1 || hit e2
| Lsend (_k, met, obj, args, _) ->
hit met || hit obj || hit_list args
in hit l


Expand Down Expand Up @@ -818,7 +816,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
Lam.for_ id (convert_aux from_) (convert_aux to_) dir (convert_aux loop)
| Lassign (id, body) ->
Lam.assign id (convert_aux body)
| Lsend (kind, a,b,ls, loc) ->
| Lsend (kind, _,b,ls, _loc) ->
(* Format.fprintf Format.err_formatter "%a@." Printlambda.lambda b ; *)
(match convert_aux b with
| Lprim {primitive = Pjs_unsafe_downgrade {loc}; args}
Expand All @@ -836,13 +834,13 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
~args loc
| _ -> assert false
end
| b ->
Lam.send kind (convert_aux a) b (Ext_list.map ls convert_aux) loc)
| _ ->
assert false)

| Levent _ ->
(* disabled by upstream*)
assert false
| Lifused (_, e) -> convert_aux e (* TODO: remove it ASAP *)
| Lifused (_, _) -> assert false

and convert_let (kind : Lam_compat.let_kind) id (e : Lambda.lambda) body : Lam.t =
match kind, e with
Expand Down
7 changes: 1 addition & 6 deletions jscomp/core/lam_dispatch_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,6 @@ let translate loc (prim_name : string)
call Js_runtime_modules.exceptions
| "caml_as_js_exn" ->
call Js_runtime_modules.caml_js_exceptions
| "caml_set_oo_id" (* needed in {!camlinternalOO.set_id} *)
->
call Js_runtime_modules.oo

| "caml_sys_get_argv"
(** TODO: refine
Expand Down Expand Up @@ -543,9 +540,7 @@ let translate loc (prim_name : string)
begin match args with
| [e] -> E.tag e
| _ -> assert false end
| "caml_get_public_method"
->
call Js_runtime_modules.oo

(** TODO: Primitives not implemented yet ...*)
| "caml_install_signal_handler"
->
Expand Down
1 change: 0 additions & 1 deletion jscomp/core/lam_exit_count.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ let count_helper (lam : Lam.t) : collection =
| Lwhile(l1, l2) -> count l1; count l2
| Lfor(_, l1, l2, _dir, l3) -> count l1; count l2; count l3
| Lassign(_, l) -> count l
| Lsend(_, m, o, ll, _) -> count m; count o; List.iter count ll
and count_default sw =
match sw.sw_failaction with
| None -> ()
Expand Down
2 changes: 0 additions & 2 deletions jscomp/core/lam_free_variables.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@
free e1; free e2
| Lwhile(e1, e2) ->
free e1; free e2
| Lsend (_k, met, obj, args, _) ->
free met; free obj; free_list args
in free l;
!fv

Expand Down
4 changes: 0 additions & 4 deletions jscomp/core/lam_hit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ let hit_variables (fv : Set_ident.t) (l : t) : bool =
hit e1 || hit e2
| Lwhile(e1, e2) ->
hit e1 || hit e2
| Lsend (_k, met, obj, args, _) ->
hit met || hit obj || hit_list args
end
in hit l

Expand Down Expand Up @@ -137,7 +135,5 @@ let hit_variable (fv : Ident.t) (l : t) : bool =
hit e1 || hit e2
| Lwhile(e1, e2) ->
hit e1 || hit e2
| Lsend (_k, met, obj, args, _) ->
hit met || hit obj || hit_list args
end
in hit l
4 changes: 0 additions & 4 deletions jscomp/core/lam_iter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ let inner_iter (l : t) (f : t -> unit ) : unit =
f e1 ; f e2; f e3
| Lassign(_id, e) ->
f e
| Lsend (_k, met, obj, args, _loc) ->
f met; f obj; List.iter f args


let inner_exists (l : t) (f : t -> bool) : bool =
Expand Down Expand Up @@ -124,5 +122,3 @@ let inner_exists (l : t) (f : t -> bool) : bool =
f e1 || f e2 || f e3
| Lassign(_id, e) ->
f e
| Lsend (_k, met, obj, args, _loc) ->
f met || f obj || Ext_list.exists args f
3 changes: 0 additions & 3 deletions jscomp/core/lam_pass_alpha_conversion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ let alpha_conversion (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
(* Lalias-bound variables are never assigned, so don't increase
v's refsimpl *)
Lam.assign v (simpl l)
| Lsend (u, m, o, ll, v) ->
Lam.send u (simpl m) (simpl o) (Ext_list.map ll simpl) v

in

simpl lam
1 change: 0 additions & 1 deletion jscomp/core/lam_pass_collect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ let collect_info (meta : Lam_stats.t) (lam : Lam.t) =
(* Lalias-bound variables are never assigned, so don't increase
v's refcollect *)
collect l
| Lsend(_, m, o, ll, _) -> collect m ; collect o; List.iter collect ll
in collect lam


Expand Down
4 changes: 0 additions & 4 deletions jscomp/core/lam_pass_count.ml
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ let collect_occurs lam : occ_tbl =
| Ltrywith(l1, _v, l2) -> count bv l1; count bv l2
| Lifthenelse(l1, l2, l3) -> count bv l1; count bv l2; count bv l3
| Lsequence(l1, l2) -> count bv l1; count bv l2
| Lsend(_, m, o, ll, _) ->
count bv m ;
count bv o;
List.iter (count bv) ll
and count_default bv sw =
match sw.sw_failaction with
| None -> ()
Expand Down
2 changes: 0 additions & 2 deletions jscomp/core/lam_pass_deep_flatten.ml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,4 @@ let deep_flatten
(* Lalias-bound variables are never assigned, so don't increase
v's refaux *)
Lam.assign v (aux l)
| Lsend(u, m, o, ll, v) ->
Lam.send u (aux m) (aux o) (Ext_list.map ll aux) v
in aux lam
Loading