caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alain Frisch <alain.frisch@lexifi.com>
To: Nicolas Ojeda Bar <nojb@math.harvard.edu>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] reference cells
Date: Mon, 31 Jan 2011 19:12:46 +0100	[thread overview]
Message-ID: <4D46FB9E.5040805@lexifi.com> (raw)
In-Reply-To: <476C4EB3-59D2-4756-927C-C1697E7AE4D8@math.harvard.edu>

On 01/31/2011 05:29 PM, Nicolas Ojeda Bar wrote:
> I am translating an imperative language into Ocaml. Right now I am
> translating mutable variables into ref cells. Will they be optimized
> when I compile the corresponding Ocaml program? Or will they be heap
> allocated? If this is the case, I will have to translate my language
> into some sort of SSA form before, and I would like to avoid that.

Mutable variables which are used only internally in a function's body
are not heap allocated.

If you write:

    let r = ref e0 in e1

and r only appears in e1 under the form:

     r := ...
     !r

and not under a local abstraction, then the reference is kept in a local 
variable.

You can use the -dlambda switch to the compilers and toplevel to see that.


-- Alain

  parent reply	other threads:[~2011-01-31 18:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-31 16:29 Nicolas Ojeda Bar
2011-01-31 16:36 ` Michael Ekstrand
2011-01-31 16:46 ` Guillaume Yziquel
2011-02-04 11:49   ` David Baelde
2011-02-04 12:30     ` Guillaume Yziquel
2011-01-31 18:12 ` Alain Frisch [this message]
2011-02-02 19:38   ` Jon Harrop

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=4D46FB9E.5040805@lexifi.com \
    --to=alain.frisch@lexifi.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=nojb@math.harvard.edu \
    /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).