Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Julien Moutinho <julien.moutinho@gmail.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] weird behavior with built-in ignore function (a bug?)
Date: Sun, 25 Nov 2007 07:05:49 +0100	[thread overview]
Message-ID: <20071125060549.GA6395@localhost> (raw)
In-Reply-To: <200711241348.22594.peng.zang@gmail.com>

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 = <fun>
# f ();;
Stack overflow during evaluation (looping recursion?).

# let rec f () = f ();;
val f : unit -> 'a = <fun>
# f ();;
Interrupted.

# let rec f () = let _ = f () in ();;
val f : unit -> unit = <fun>
# f ();;
Stack overflow during evaluation (looping recursion?).

# let rec f () : unit = Obj.magic (f ());;
val f : unit -> unit = <fun>
# f ();;
Interrupted.

Regards,
  Julien.


  reply	other threads:[~2007-11-25  6:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-23 16:09 Peng Zang
2007-11-23 16:19 ` [Caml-list] " Vincent Aravantinos
2007-11-24  0:31 ` Julien Moutinho
2007-11-24 18:48   ` Peng Zang
2007-11-25  6:05     ` Julien Moutinho [this message]
2007-11-25 14:21       ` Peng Zang

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=20071125060549.GA6395@localhost \
    --to=julien.moutinho@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /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