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

nested mel uncurry experiment #952

Closed
wants to merge 1 commit into from
Closed

Conversation

anmonteiro
Copy link
Member

putting this up to show how it can't really work at the melange level because nested mel.uncurry callbacks aren't arguments that we pass, but rather passed from the JS side.

@@ -106,8 +106,8 @@ let ocaml_to_js_eff ~(arg_label : Melange_ffi.External_arg_spec.label_noname)
in
match arg_type with
Copy link
Member Author

@anmonteiro anmonteiro Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function shows why we can't optimize nested [@mel.uncurry] implicitly. Here's the explanation:

  • whenever we apply arguments to an external function, we walk both the external argument list (as declared by the user), and the params passed to the function
  • nested [@mel.uncurry] are, however, and by definition, not parameters that we pass, but rather, arguments to some callback. Take the simplest example:
external foo : (((unit -> unit)[@mel.uncurry]) -> unit) -> unit = "foo"

let () = foo (fun f -> f ())

You can see how, in the function application, f is passed to us by the callback (the one we actually pass as a parameter). We don't have that information later on to apply f in the uncurried way.

Take, for example, a pathological case that could happen:

external foo : (((unit -> unit)[@mel.uncurry]) -> unit) -> unit = "foo"

let () = 
  let the_function = ref (fun () -> ()) in
  foo (fun f -> the_function := f);
  !the_function ()

@anmonteiro
Copy link
Member Author

we merged #875 which links here to the explanation. Closing this.

@anmonteiro anmonteiro closed this Dec 5, 2023
@anmonteiro anmonteiro deleted the anmonteiro/nested-uncurry branch December 5, 2023 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant