Skip to content

Commit

Permalink
remove [@mel.invoke] in favor of [@mel.this] on the core_type arg
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Jan 18, 2025
1 parent 685b90a commit eec2436
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 159 deletions.
2 changes: 1 addition & 1 deletion jscomp/common/external_ffi_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type arg_type = External_arg_spec.attr
hand *)

type arg_label = External_arg_spec.Obj_label.t
type js_send_kind = Send | Invoke | Pipe
type js_send_kind = Pipe | Send of int

type external_spec =
| Js_var of {
Expand Down
2 changes: 1 addition & 1 deletion jscomp/common/external_ffi_types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type external_module_name = {

type arg_type = External_arg_spec.attr
type arg_label = External_arg_spec.Obj_label.t
type js_send_kind = Send | Invoke | Pipe
type js_send_kind = Pipe | Send of int

type external_spec =
| Js_var of {
Expand Down
55 changes: 14 additions & 41 deletions jscomp/core/lam_compile_external_call.ml
Original file line number Diff line number Diff line change
Expand Up @@ -266,44 +266,17 @@ let translate_scoped_module_val
let start = E.js_global x in
List.fold_left ~f:E.dot ~init:start (rest @ [ fn ]))

let js_send_self_and_args =
let rec inner args arg_types (acc_args, acc_arg_types) =
match (args, arg_types) with
| [], [] -> assert false
| ( self :: args,
{
(* The "self" arg in `[@mel.send]` is the first non-labelled argument
that we find, e.g. `t` in `external foo: ?a:int -> t -> unit`.
This allows to write expressive bindings to JS that are applied
via dot-notation and still model the "self" arg after those in OCaml
such that those labels can be applied optionally. *)
External_arg_spec.arg_label = External_arg_spec.Arg_label.Arg_empty;
_;
}
:: arg_types ) ->
( self,
List.rev_append acc_args args,
List.rev_append acc_arg_types arg_types )
| ( arg :: rest,
({ arg_label = Arg_label | Arg_optional; _ } as arg_type) :: types_rest
) ->
inner rest types_rest (arg :: acc_args, arg_type :: acc_arg_types)
| [], _ :: _ | _ :: _, [] -> assert false
in
fun args arg_types ~kind ->
match kind with
| External_ffi_types.Pipe -> assert false
| Send -> (
match args with
| self :: args ->
(* PR2162 [self_type] more checks in syntax:
let js_send_self_and_args args arg_types ~self_idx =
(* PR2162 [self_type] more checks in syntax:
- should not be [@as] *)
let[@ocaml.warning "-partial-match"] (_self_type :: arg_types) =
arg_types
in
(self, args, arg_types)
| _ -> assert false)
| Invoke -> inner args arg_types ([], [])
let[@ocaml.warning "-partial-match"] args_pre, self :: args_post =
List.split_at args self_idx
in
let[@ocaml.warning "-partial-match"] ( arg_types_pre,
_self_types :: arg_types_post ) =
List.split_at arg_types self_idx
in
(self, args_pre @ args_post, arg_types_pre @ arg_types_post)

let translate_ffi =
let translate_scoped_access scopes obj =
Expand Down Expand Up @@ -412,9 +385,9 @@ let translate_ffi =
add_eff eff
(let self = translate_scoped_access scopes self in
process_send ~new_ self name args)
| (Send | Invoke), true ->
| Send self_idx, true ->
let self, args, arg_types =
js_send_self_and_args args arg_types ~kind
js_send_self_and_args args arg_types ~self_idx
in
let args, eff, dynamic = assemble_args_has_splice arg_types args in
add_eff eff
Expand All @@ -424,9 +397,9 @@ let translate_ffi =
| true -> splice_fn_new_apply (E.dot self name) args
| false -> splice_obj_fn_apply self name args
else process_send ~new_ self name args)
| (Send | Invoke), false ->
| Send self_idx, false ->
let self, args, arg_types =
js_send_self_and_args args arg_types ~kind
js_send_self_and_args args arg_types ~self_idx
in
(* PR2162 [self_type] more checks in syntax:
- should not be [@mel.as] *)
Expand Down
Loading

0 comments on commit eec2436

Please sign in to comment.