From: Peng Zang <peng.zang@gmail.com>
To: caml-list@yquem.inria.fr
Cc: Julien Moutinho <julien.moutinho@gmail.com>
Subject: Re: [Caml-list] weird behavior with built-in ignore function (a bug?)
Date: Sun, 25 Nov 2007 09:21:40 -0500 [thread overview]
Message-ID: <200711250921.46365.peng.zang@gmail.com> (raw)
In-Reply-To: <20071125060549.GA6395@localhost>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Thanks for the link to that thread and the examples, it was very helpful.
Peng
On Sunday 25 November 2007 01:05:49 am Julien Moutinho wrote:
> 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/838a1399a42491c4db9a
>eaa684458a6b.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.
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)
iD8DBQFHSYT6fIRcEFL/JewRAj6eAJ49xNEBIF37V/rC56wlJmApUPkmMwCgo3K4
/8yXSailKazYrspH57e29u8=
=rGYM
-----END PGP SIGNATURE-----
prev parent reply other threads:[~2007-11-25 14:21 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
2007-11-25 14:21 ` Peng Zang [this message]
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=200711250921.46365.peng.zang@gmail.com \
--to=peng.zang@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=julien.moutinho@gmail.com \
/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