Skip to content

Conversation

hhugo
Copy link
Member

@hhugo hhugo commented May 3, 2020

The PR:

  • updates internalMod to not use the .fun property proxy for functions.
  • adds an optimization to eliminate allocation of dummy function (caml_alloc_dummy_function). The dummy allocation is not necessary in JavaScript due to the weird non-lexical scoping.

Assuming the optimization properly eliminate all occurrences of caml_alloc_dummy_function, we should be able to remove .fun property handling from the runtime.

Note that caml_alloc_dummy_function was introduced in OCaml 4.02.3, we would need to bump the lower bound from 4.02.0 to 4.02.3 which is fine.

@hhugo hhugo requested a review from TyOverby May 3, 2020 17:01
| List _a0 ->
let hsv = fold_int hsv 1 in
let hsv = hsv in hash_fold_list hash_fold_t hsv _a0 : state -> t -> state)
and (hash : t -> hash_value) =
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not seeing this function in the output. Did it get inlined?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a test with functions where none of them get inlined?

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that the inlining was enabled by the last commit. Probably better the review per commits

Copy link
Member Author

Choose a reason for hiding this comment

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

I've tune the test to prevent inlining

@hhugo hhugo added this to the 3.7 milestone May 5, 2020
@hhugo hhugo force-pushed the rec-fun branch 2 times, most recently from 08bf14e to 8c1fc00 Compare May 6, 2020 22:07
@hhugo
Copy link
Member Author

hhugo commented Jul 29, 2020

@xclerc, do you want to take a look at this one ?

@hhugo hhugo requested a review from xclerc July 29, 2020 17:19
@xclerc
Copy link
Collaborator

xclerc commented Jul 30, 2020

Just to be sure I understand the optimization: the idea is that every time we have
both x = caml_alloc_dummy_function(...) and caml_update_dummy(x, y), we
can get rid of both function calls and use y instead of x, right?

It looks like this call to filter is expected to be the identity. My understanding is
that it might be true only given the current state of the code generator of ocamlc
(Bytegen.comp_expr), but then if we want to be independent of the code generator,
wouldn't it be safer to detect e.g. several caml_update_dummy(x, y_i) calls?

@hhugo
Copy link
Member Author

hhugo commented Jul 30, 2020

Just to be sure I understand the optimization: the idea is that every time we have
both x = caml_alloc_dummy_function(...) and caml_update_dummy(x, y), we
can get rid of both function calls and use y instead of x, right?

Correct

It looks like this call to filter is expected to be the identity. My understanding is
that it might be true only given the current state of the code generator of ocamlc
(Bytegen.comp_expr), but then if we want to be independent of the code generator,
wouldn't it be safer to detect e.g. several caml_update_dummy(x, y_i) calls?

That sound correct. We should at least add some assertion.

@hhugo
Copy link
Member Author

hhugo commented Jul 31, 2020

For the record, caml_alloc_dummy_function was introduced in 4.02.3

@hhugo
Copy link
Member Author

hhugo commented Jul 31, 2020

It looks like this call to filter is expected to be the identity.

Looking more closely at the code, it's not the case. [filter] is here to only keep info from [caml_update_dummy] that have a corresponding [caml_alloc_dummy_function]. There are other cases (e.g. let rec l = 0 :: l).

I've updated the code with comments.

@hhugo hhugo merged commit 72768a7 into master Jul 31, 2020
@hhugo hhugo deleted the rec-fun branch July 31, 2020 09:02
kit-ty-kate pushed a commit to ocaml/opam-repository that referenced this pull request Aug 5, 2020
…ml-ppx, js_of_ocaml-lwt, js_of_ocaml-toplevel, js_of_ocaml-tyxml, js_of_ocaml and js_of_ocaml-ppx_deriving_json (3.7.0)

CHANGES:

## Features/Changes
* Runtime: allow one to override xmlHttpRequest.create (ocsigen/js_of_ocaml#1002)
* Runtime: Change the semantic of MlBytes.toString, introduce MlBytes.toUtf16
* Compiler: initial support for OCaml 4.11
* Compiler: initial support for OCaml 4.12
* Compiler: improve the javascript parser by relying on menhir
  incremental api.
* Compiler: Eliminate allocation of dummy function ocsigen/js_of_ocaml#1013

## Bug fixes
* Compiler: fix code generation for recursive function under for-loops (ocsigen/js_of_ocaml#1009)
* Compiler: the jsoo compiler compiled to javascript was not behaving correctly
            when parsing constant in the from the bytecode
* Compiler: make sure inline doesn't loop indefinitly (ocsigen/js_of_ocaml#1043)
* Compiler: fix bug generating invalid javascript for if-then construct (ocsigen/js_of_ocaml#1046)
* Compiler: do not use polymorphic comparison when joining float values (ocsigen/js_of_ocaml#1048)
* Lib: Rename msg to message in Worker (ocsigen/js_of_ocaml#1037)
* Lib: fix graphics_js when build with separate compilation (ocsigen/js_of_ocaml#1029)
hhugo added a commit that referenced this pull request Sep 16, 2020
hhugo added a commit that referenced this pull request Sep 17, 2020
hhugo added a commit to hhugo/opam-repository that referenced this pull request Sep 29, 2020
…ml-ppx, js_of_ocaml-lwt, js_of_ocaml-toplevel, js_of_ocaml-tyxml, js_of_ocaml and js_of_ocaml-ppx_deriving_json (3.7.1)

CHANGES:

## Features/Changes
* lib: Add Navigator.{vendor,maxTouchPoints} (ocsigen/js_of_ocaml#1062)
* lib: adds the intersection observer API (ocsigen/js_of_ocaml#1063)

## Bug fixes
* compiler: revert of "Eliminate allocation of dummy function ocsigen/js_of_ocaml#1013"
* compiler: fix for ocsigen/js_of_ocaml#1051 (ocsigen/js_of_ocaml#1052), Ensure the overflow warning is always displayed
* runtime: add missing primitives for 4.11
* lib: Fix resize-observer (ocsigen/js_of_ocaml#1058)
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.

3 participants