caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pierre Chambart <pierre.chambart@ocamlpro.com>
To: Alexey Egorov <electreg@list.ru>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] <DKIM> flambda for bytecode backend
Date: Sun, 14 Jan 2018 19:29:26 +0100	[thread overview]
Message-ID: <937c674a-bf63-b2be-44eb-9ad331aa622f@ocamlpro.com> (raw)
In-Reply-To: <1515782196.604079108@f381.i.mail.ru>

On 12/01/2018 19:36, Alexey Egorov wrote:
> Hello,
>
> I'm curious why flambda doesn't supported in bytecode compiler? It
> seems that js_of_ocaml can greatly benefit from such possibility.
>
It has been considered, and in fact Grégoire Henry did a version of the
bytecode compiler after flambda. But it was discarded as it was not very
useful. It couldn't work with js_of_ocaml, and there was no obvious way
how to do it properly.

The reason being that flambda takes place after closure conversion.
Hence after flambda, functions takes an explicit environment value. But
on the other hand, js_of_ocaml represents OCaml functions directly as
javascript function since the closures are working correctly.

The best we could do (without doing some magic) would look like:

let f x =
  let y = x + 1 in
  let g z = z + y in
  g

compiled to:

function f_code(x, env) {
  let y = x + 1;
  function g_code(y, env) {
    return(z + env.y);
  }
  let g = { code : g_code, env : { y: y };
  return(g);
}

let f = { code : f_code, env : { } }

This would probably be far slower than what js_of_ocaml currently does.
-- 
Pierre



  reply	other threads:[~2018-01-14 18:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-12 18:36 [Caml-list] " Alexey Egorov
2018-01-14 18:29 ` Pierre Chambart [this message]
2018-01-15 10:34   ` [Caml-list] <DKIM> " Leo White
2018-01-15 10:51     ` Leandro Ostera
2018-01-29 16:26     ` [Caml-list] OCaml <-> Computer Algebra Nicolas Ratier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=937c674a-bf63-b2be-44eb-9ad331aa622f@ocamlpro.com \
    --to=pierre.chambart@ocamlpro.com \
    --cc=caml-list@inria.fr \
    --cc=electreg@list.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).