From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id F0149BC6B for ; Sun, 25 Nov 2007 07:04:42 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAANKfSEdA6ba/mGdsb2JhbACPPgEBAQEHBAQr X-IronPort-AV: E=Sophos;i="4.21,462,1188770400"; d="scan'208";a="19644866" Received: from nf-out-0910.google.com ([64.233.182.191]) by mail4-smtp-sop.national.inria.fr with ESMTP; 25 Nov 2007 07:04:33 +0100 Received: by nf-out-0910.google.com with SMTP id e27so260878nfd for ; Sat, 24 Nov 2007 22:04:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:date:to:subject:message-id:mail-followup-to:references:mime-version:content-type:content-disposition:in-reply-to:user-agent:from; bh=iuci5m/jj1lBml1nymVlGov2REjUh52Y2y/Q3/Oh5Jk=; b=YhOwQNWYc3ZhkjZSBEnud+m4d9/5Lx504VyKApYGAMFOiOoS+TIGohmnvRsOj3x3iWNYQisw5hxYRbYQ8VQYdkHJ9L7Y8wDKjMFY0Xa5bwjQPVsISr714txLfUT1SyRBv9IjkIWjUrubKhl6Py23p2bKA9g6WmSwtt1O89ImLOk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=received:date:to:subject:message-id:mail-followup-to:references:mime-version:content-type:content-disposition:in-reply-to:user-agent:from; b=oL5uju0cQ68oQGcRds2y6Syov+qF7QrnCZOQ5pIV4E+NT/RNPqvI9EF9MgbSvDWYMakfh9/OCRIwoYFWAIef0sNCXf95gOOFHAwF1odNjmC8zaDI6K0kP/kBggwGV5JaKsZ0tNalkGkMceMIx1yMq7eqzhlQG2tR1scgbzMO+ts= Received: by 10.86.4.2 with SMTP id 2mr1274850fgd.1195970672378; Sat, 24 Nov 2007 22:04:32 -0800 (PST) Received: from localhost ( [82.122.248.16]) by mx.google.com with ESMTPS id d4sm143259fga.2007.11.24.22.04.28 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 24 Nov 2007 22:04:30 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Sun, 25 Nov 2007 07:05:49 +0100 Date: Sun, 25 Nov 2007 07:05:49 +0100 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] weird behavior with built-in ignore function (a bug?) Message-ID: <20071125060549.GA6395@localhost> Mail-Followup-To: Julien Moutinho , caml-list@yquem.inria.fr References: <200711231109.47460.peng.zang@gmail.com> <20071124003110.GA32596@localhost> <200711241348.22594.peng.zang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <200711241348.22594.peng.zang@gmail.com> User-Agent: Mutt/1.5.17 (2007-11-01) From: Julien Moutinho X-Spam: no; 0.00; bug:01 bug:01 externally:01 compiler:01 bytecomp:01 translcore:01 asmcomp:01 cmmgen:01 transl:01 pervasives:01 ocamlopt:01 ocamlopt:01 ocaml:01 val:01 recursion:01 On Sat, Nov 24, 2007 at 01:48:18PM -0500, Peng Zang wrote: > Ahhh... it's good to know this is a bug and that it has been fixed. I think > for the interim I will simply define my own ignore function. It also bothers > me that even in the fixed version ignore does not equal itself. Have a glance at this little thread: http://caml.inria.fr/pub/ml-archives/caml-list/2005/04/838a1399a42491c4db9aeaa684458a6b.en.html > I also don't see why ignore is even defined externally. > Doesn't the compiler optimize ignore calls away? Well, in bytecomp/translcore.ml in the primitives_table "%ignore" is associated with Pignore and in asmcomp/cmmgen.ml: | Pignore -> return_unit(remove_unit (transl arg)) So I guess Pervasives.ignore is defined like that to be able to segregate it at compile time to avoid a function call. % cat t.ml ignore (Random.bits ()) % ocamlopt -dcmm t.ml [...] (function camlT__entry () (app{random.ml:157,14-32} "camlRandom__bits_89" (load (+a "camlRandom" 52)) unit) 1a) [...] % cat tt.ml let ignore _ = () in ignore (Random.bits ()) % ocamlopt -dcmm tt.ml [...] (data int 2295 "camlTt__1": addr "camlTt__ignore_58" int 3) (function camlTt__ignore_58 (x/59: addr) 1a) (function camlTt__entry () (let ignore/58 "camlTt__1" (app{random.ml:157,14-32} "camlRandom__bits_89" (load (+a "camlRandom" 52)) unit)) 1a) [...] BTW that's the use of return_unit which disables tail-rec optimization: % ocaml Objective Caml version 3.10.1+dev2 (2007-11-20) # let rec f () = ignore (f ());; val f : unit -> unit = # f ();; Stack overflow during evaluation (looping recursion?). # let rec f () = f ();; val f : unit -> 'a = # f ();; Interrupted. # let rec f () = let _ = f () in ();; val f : unit -> unit = # f ();; Stack overflow during evaluation (looping recursion?). # let rec f () : unit = Obj.magic (f ());; val f : unit -> unit = # f ();; Interrupted. Regards, Julien.