<div dir="ltr">On 13 May 2013 13:46, Walter Bright <span dir="ltr"><<a href="mailto:newshound2@digitalmars.com" target="_blank">newshound2@digitalmars.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 5/12/2013 6:23 PM, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It is done by the optimiser, but I'm suggesting that it doesn't only have value<br>
in terms of optimisation. It could improve language usability if performed in<br>
the front end.<br>
</blockquote>
<br></div>
I understand.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
In that context, unless the analysis is very powerful(/mature) and can<br>
statically determine 'expr', then x would need to be relaxed to unlimited at<br>
that point, since it obviously can't know the limits within (or after) that loop.<br>
In this case, the compiler would complain that it can't determine x and you<br>
would need an explicit cast as usual.<br>
<br>
I can see the effective forward reference issue here, which could be addressed<br>
in time, but even just reasonably simple limits tracking (ie, within sequential<br>
code) would make a massive difference. I think programmers would intuitively<br>
understand this situation and wouldn't expect magic from the compiler.<br>
The places where it matters the most are places where it's dead obvious what the<br>
numeric limits are, and it should be equally obvious to the compiler.<br>
<br>
It's the sort of thing that could be improved with time, but even a very simple<br>
start would be a big help in many cases.<br>
</blockquote>
<br></div>
It's true you could do a sequential only, very conservative form of data flow analysis.<br>
<br>
But be aware there are other problems, such as:<br>
<br>
  int *p = ...;<br>
  ...<br>
  x &= 0xFFFF;<br>
  ++(*p);      // hmm, is x affected?<br>
  short s = x;<br></blockquote><div><br></div><div style>Yes indeed, there are certainly many ways to interfere with it, but I certainly hope that most lines of code you deal with on a daily basis aren't like this ;)</div>
<div style>Obviously it would grow in maturity over time. In that example, just revert to unlimited assumptions when it encounters the pointer operation. Limits may then be refined again in following code.</div><div style>
I can imagine things like proper escaping analysis as planned could eventually help in cases like this.</div><div style><br></div><div style>Anyway, it's just something to think about. I think it would offer additional safety/correctness to the language; anywhere you type a blind cast, you are potentially hiding a future bug. I'd rather never cast when I don't absolutely need/intend to.</div>
</div></div></div>