caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Frederic van der Plancke <fvdp@decis.be>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Why doesn't ocamlopt detect a missing ; afterfailwith  statement?
Date: Mon, 29 Nov 2004 11:07:55 +0000	[thread overview]
Message-ID: <41AB030B.EA2E9530@decis.be> (raw)
In-Reply-To: <20041129.094035.02308731.garrigue@math.nagoya-u.ac.jp>



Jacques Garrigue wrote:
> 
> From: Damien Doligez <damien.doligez@inria.fr>
> > > I believe the problem with failwith is solvable, albeit rather
> > > complicated. The idea is that you want to be warned when you apply a
> > > function of type (\forall 'a. 'a) to something, because no such
> > > function may exist, so that this application will never actually take
> > > place.
> >
> > More generally, you want to output a warning whenever the computation
> > of such a value is not immediately followed by a join in the control
> > flow graph, because at that point you know you're compiling dead code.
> >
> > Then you would also get a warning for things like this:
> >
> >    failwith "foo";
> >    print_string "hello world"
> >
> > or
> >
> >    f (a, b, failwith "foo", c, d)
> >
> > etc.
> >
> > Don't ask me to implement it, though.
> 
> This is not specially hard to implement case by case.
> The problem is rather that the technique I use, based on type
> inference, is not foolproof (you can avoid the warning with a type
> annotation for instance) and is wrong in presence of Obj.magic.
> So the question is in which cases having a warning is worth the
> inconvenience and the extra code in the compiler.

Why not create a special type "noreturn" or "empty" with special typing properties ? in most respect it would act like 'a; but the compiler would know the difference.
* raise : exn -> noreturn   (and hence: failwith : string -> noreturn)
  (similarly: [assert false : noreturn])
  but Obj.magic keeps its type : 'a -> 'b
* noreturn can be unified to any type t (including 'a), this yields type t
   (so [function [] -> assert false | x::_ -> x] has type ['a list -> 'a])
* a warning would be issued
   - for an "apply" node when any input term has type noreturn
   - for a ";" node when the first term has type noreturn
   - etc
* problem: one could write [Obj.magic 123 : noreturn]
  (or similarly in other cases like marshalling where a lone 'a *can*
   correspond to a value) and defeat the system.
  possible solution: forbid or restrict explicit casts (er, type annotations,
  sorry ;-) to noreturn. (i.e. since 'a annotates "a value of any type" and
  noreturn annotates "no value", there's no reason to allow "casting" 'a as
  noreturn.)

Frédéric vdP


  reply	other threads:[~2004-11-29 11:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-25 20:46 Why doesn't ocamlopt detect a missing ; after failwith statement? Richard Jones
2004-11-25 21:14 ` [Caml-list] " Nicolas Cannasse
2004-11-26  0:11   ` skaller
2004-11-26  0:44     ` Jacques Garrigue
2004-11-26  3:08       ` skaller
2004-11-26  5:25         ` Jacques Garrigue
2004-11-26  7:08           ` Nicolas Cannasse
2004-11-26 14:42             ` Jacques Garrigue
2004-11-26 17:01               ` Alain Frisch
2004-11-26 19:36             ` Michal Moskal
2004-11-26 17:01           ` Damien Doligez
2004-11-29  0:40             ` Jacques Garrigue
2004-11-29 11:07               ` Frederic van der Plancke [this message]
2004-11-29 11:43                 ` [Caml-list] Why doesn't ocamlopt detect a missing ; afterfailwith statement? Jacques Garrigue
2004-11-29 11:27               ` Frederic van der Plancke
2004-11-26 22:24           ` [Caml-list] Why doesn't ocamlopt detect a missing ; after failwith statement? Hendrik Tews
2004-11-27  3:47             ` skaller
2004-11-29  0:01             ` Jacques Garrigue
2004-11-29  7:52               ` Marcin 'Qrczak' Kowalczyk
2004-11-26  3:58       ` skaller
2004-11-26 19:16     ` Brian Hurt
2004-11-26  9:01   ` Richard Jones
2004-11-26  9:56     ` skaller
2004-11-26 13:32     ` Ville-Pertti Keinonen

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=41AB030B.EA2E9530@decis.be \
    --to=fvdp@decis.be \
    --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;
as well as URLs for NNTP newsgroup(s).