From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p0VICxXJ025148 for ; Mon, 31 Jan 2011 19:12:59 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al0BAAOKRk3B/BfVkWdsb2JhbAClDQEBAQEJCwoHEQMhvWeFTgSMIYNFiEw X-IronPort-AV: E=Sophos;i="4.60,405,1291590000"; d="scan'208";a="98949889" Received: from msa04.smtpout.orange.fr (HELO msa.smtpout.orange.fr) ([193.252.23.213]) by mail1-smtp-roc.national.inria.fr with ESMTP; 31 Jan 2011 19:12:54 +0100 Received: from [192.168.1.63] ([83.199.112.88]) by mwinf5d33 with ME id 2JCs1g00U1uVNnn03JCtNf; Mon, 31 Jan 2011 19:12:53 +0100 Message-ID: <4D46FB9E.5040805@lexifi.com> Date: Mon, 31 Jan 2011 19:12:46 +0100 From: Alain Frisch Organization: LexiFi User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 To: Nicolas Ojeda Bar CC: caml-list@yquem.inria.fr References: <476C4EB3-59D2-4756-927C-C1697E7AE4D8@math.harvard.edu> In-Reply-To: <476C4EB3-59D2-4756-927C-C1697E7AE4D8@math.harvard.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] reference cells 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