Skip to content

Conversation

@hhugo
Copy link
Member

@hhugo hhugo commented Apr 26, 2016

  • move closure compilation pass from JavaScript to Intermediate ast
  • Improve tail call optimization pass - do not generate useless closures.
  • Preserve as much as possible the initial OCaml variable names

@hhugo hhugo changed the title Compile closure Preserve as much as possible the initial OCaml variable names Apr 26, 2016
@hhugo
Copy link
Member Author

hhugo commented Apr 27, 2016

@vouillon, this PR does not include the optimization for multiple closure inside a loop [1]. It seems that this optimization is never used when building examples & toplevel. I'm considering not adding the optimization back. What do you think ?

[1] https://github.com/ocsigen/js_of_ocaml/blob/master/compiler/generate.ml#L1243

OCaml code

  let l = ref [] in
  for i = 0 to 2 do
    let rec f1 x = if x = 0 then i else f2 (x -1)
    and f2 x  = if x = 0 then i else f1 (x - 1)
    in l:= f1 :: f2 :: !l
  done;

origin/master

var
       funenv_FX_=
        function(i_FS_)
          {function f1_FV_(x_FT_){return 0===x_FT_?i_FS_:f2_FU_(x_FT_-1|0)}
           function f2_FU_(x_FW_){return 0===x_FW_?i_FS_:f1_FV_(x_FW_-1|0)}
           return [f1_FV_,f2_FU_]}
         (i_FS_),
       f1_FV_=funenv_FX_[0],
       f2_FU_=funenv_FX_[1];

This PR

var
       f1_FV_ =
        function(i_FS_)
          {return function f1_FV_(x_FT_){return 0===x_FT_?i_FS_:f2_FU_(x_FT_-1|0)}}(i_FS_)
      f2_FU_  =
        function(i_FS_)
          {return function f2_FU_(x_FW_){return 0===x_FW_?i_FS_:f1_FV_(x_FW_-1|0)}}(i_FS_)

@vouillon
Copy link
Member

I think it's ok to remove this optimization.

@hhugo hhugo merged commit 30a27f7 into master Apr 27, 2016
@hhugo hhugo deleted the compile_closure branch April 27, 2016 19:59
@hhugo hhugo mentioned this pull request Oct 31, 2016
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