caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: rich@annexia.org
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] How to compile different implementations of the same lib
Date: Fri, 02 Dec 2005 12:29:14 +0900 (JST)	[thread overview]
Message-ID: <20051202.122914.122623939.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <20051201200944.GA30251@furbychan.cocan.org>

From: Richard Jones <rich@annexia.org>

> I don't quite understand this.  I get that if the .cmx isn't
> available, then one obviously cannot inline the code.  But why is it
> that you cannot use a simple call instruction even if the .cmx isn't
> available?

There are many causes:
The first one is that functions in ocaml are represented as closures,
which are data generated at runtime, including a code pointer.
When you access a function without the .cmx, you're just extracting
data at a certain offset from an array representing the module the
function belongs to. The name of the code pointer, on which C linking
is usually based, doesn't appear in this scheme: everything is extracted
from a single data pointer to the module.

If you want to call functions directly, you would first have to reveal
the names of their code pointers, which is currently generated in a code
dependent way, and stored in the cmx. The generation could be made
uniform for exported functions (not as easy as it seems), but this
would still be the easy part.

The hard part is that you also need to know which representation the
optimized version of the function is using.

Has it a closure? For many functions, you need to pass them some
environment data as an extra parameter. However not all functions need
this extra parameter (some functions don't access any external data),
and in that case there optimized form doesn't expect such an extra
parameter. If you don't know that, you can only call the non-optimized
form, looking up the data, which happens to be empty.

What is its arity? Because of currying, the arity of the type of a
function is not necessarily equal to the arity of its
implementation. That is, some partial applications might actually
produce side-effects. The optimized version of the function is based
on the actual arity, not that of the type. So you cannot call it
wihout knowing this arity.

All this might be solved in one way or another, but the solution would
be sub-optimal, and would not allow for the inlining one would expect
for native code.

Jacques Garrigue


  parent reply	other threads:[~2005-12-02  3:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-30  9:05 Best way to choose an implementation of a lib ? Christophe Raffalli
2005-11-30 12:19 ` [Caml-list] " Jacques Garrigue
2005-11-30 14:38   ` How to compile different implementations of the same lib Daniel Bünzli
2005-11-30 16:09     ` [Caml-list] " Daniel Bünzli
2005-12-01  1:07       ` Jacques Garrigue
2005-12-01  1:53         ` malc
2005-12-01 17:03         ` Christophe Raffalli
2005-12-01 17:54           ` skaller
2005-12-01 20:09             ` Richard Jones
2005-12-01 23:47               ` skaller
2005-12-02  3:29               ` Jacques Garrigue [this message]
2005-12-01 21:33             ` Christophe Raffalli
2005-12-02  3:06               ` Jacques Garrigue
2005-11-30 16:24   ` how to detect .cmx incompatibility Stefano Zacchiroli
2005-11-30 19:48   ` [Caml-list] Best way to choose an implementation of a lib ? Eric Cooper
2005-12-01 17:05     ` Christophe Raffalli
2005-12-01 17:31       ` Eric Cooper

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=20051202.122914.122623939.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=rich@annexia.org \
    /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).