[nem-en] On unreachable code inside macro generated code

Kamil Skalski kamil.skalski at gmail.com
Wed Aug 30 22:38:54 CEST 2006


Just like before, I would rather try to fix the reason of these
warnings instead of disabling the (usually valid and!) warning.
Most probably what we observe here is a bug in implementation of
foreach (in context of jumps) or something, which compiler does not
correctly recognize as unreachable code. Compiling with -dt switch
gives:

  def found = block (found) :     block (_N_break) :       def
[]foreach_loop (_N_u1203 : list[bool]) : void {
        match (_N_u1203) {
          | Nemerle.Core.list {hd = (_) as x; tl = (_) as xs} =>
            block (_N_continue) :               when (x) {
                found (true);
                ()
              };
            foreach_loop (xs)
          | _ =>
            ()
        }
      }
      foreach_loop (l);
    false;

My guess is that compiler warns that  ()  expression is unreachable,
which should be somehow prevented, since () is an empty expression
(though it might load null on the stack if some conversions are
happening).

Some places of compiler has got similar hacks that you propose (for
example disabling the unused pattern warning in foreach macro), but we
should search for some better solutions.

On 8/30/06, Alexey Borzenkov <snaury at gmail.com> wrote:
> Hi all,
>
> It was in one of conversations with Kamil a long time ago, however now
> I think I want to return to it again. There are some standard macros
> in Nemerle (foreach, do { ... } while, I don't know, maybe more) that
> under some uses produce unreachable code warnings. This is very
> confusing especially in foreach, consider this:
>
>   def l = [false, false, false, true, false];
>   def found = found: {
>     foreach(true in l)
>       found(true);
>     false
>   }
>
> This code just looks if there's any true in a given list. Now, when I
> first used such construct and it gave me warning I thought that it's
> `found(true)' code that is unreachable, and thus I thought that it
> won't work and I quickly changed it into:
>
>   foreach(b in l) when(b)
>     found(true);
>
> This spotted giving me warnings. Only later I finally understood that
> it is actually incrementing code inside of foreach generated code that
> becomes unreachable: the code that is supposed to execute after doing
> `found(true)', which will of course never happen. There are also some
> other situations where I wanted to use `code only for first element'
> with foreach, for example:
>
>   foreach(elem is XmlElement
>               when elem.Name == "something"
>               in doc.DocumentElement) {
>     // we only process the very first element here and don't need anything else
>     Nemerle.Imperative.Break();
>   }
>
> What I'd want is that such code shouldn't give any warnings. This
> might be accomplished by making some special macro, like
> _N_ignore_unreachable, which then maybe gets transformed into
> TExpr.IgnoreUnreachable wrapper around real code and which then gets
> ignored by ILEmitter.skipped, thus eliminating unwanted unreachable
> code warnings.
>
> What do you all think about it?
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>


-- 
Kamil Skalski
http://nazgul.omega.pl



More information about the devel-en mailing list