[nem-en] On unreachable code inside macro generated code
Alexey Borzenkov
snaury at gmail.com
Wed Aug 30 19:03:07 CEST 2006
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?
More information about the devel-en
mailing list