| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
November 03, 2011 Re: checkedTo | ||||
|---|---|---|---|---|
| ||||
I think this could be integrated into "to" template without need for
extra symbols.
There are tons of optimization opportunities like this, that are
currently not being utilized.
If the result won't change, then the release version should drop safety checks.
... IMO ...
On Thu, Nov 3, 2011 at 1:40 AM, Martin Nowak <dawg@dawgfoto.de> wrote:
> I often write snippets like this for narrowing numerical conversions.
>
> debug
> return to!T(exp);
> else
> return cast(T)exp;
>
> How about adding a construct for this to std.conv?
> Could be checkedTo!T(val).
>
> martin
>
| ||||
November 03, 2011 Re: checkedTo | ||||
|---|---|---|---|---|
| ||||
On Thursday, November 03, 2011 13:38:44 Gor Gyolchanyan wrote:
> I think this could be integrated into "to" template without need for
> extra symbols.
> There are tons of optimization opportunities like this, that are
> currently not being utilized.
> If the result won't change, then the release version should drop safety
> checks.
And how would std.conv.to know that the result won't change? It k
nows nothing about the variable it's being passed, and that variable could
depend on user input or what's in a file or some other value which is runtime-
dependent.
I don't believe that anything in Phobos changes behavior based on -debug (there are a few places where -debug=something results in a module printing extra stuff for unittests - e.g. -debug=string for std.string - but not for - debug), and -debug is really meant for debugging purposes, not for enabling or disabling checks. That's for -release, which, for better or worse, you can't actually check for in code. So, really, there is no way to have -release affect any code in Phobos beyond what it does to the language in general (remove assertions and remove array bounds checking in @system code), even if we wanted it to, which is debatable.
- Jonathan M Davis
| ||||
November 03, 2011 Re: checkedTo | ||||
|---|---|---|---|---|
| ||||
On Thu, 03 Nov 2011 16:54:14 +0100, Jonathan M Davis <jmdavisProg@gmx.com> wrote: > On Thursday, November 03, 2011 13:38:44 Gor Gyolchanyan wrote: >> I think this could be integrated into "to" template without need for >> extra symbols. >> There are tons of optimization opportunities like this, that are >> currently not being utilized. >> If the result won't change, then the release version should drop safety >> checks. > No way, it does unsafe conversions to safe quite some cycles. You have no way of guaranteeing correct output for to! without doing the check. > And how would std.conv.to know that the result won't change? It k > nows nothing about the variable it's being passed, and that variable could > depend on user input or what's in a file or some other value which is runtime- > dependent. > > I don't believe that anything in Phobos changes behavior based on -debug > (there are a few places where -debug=something results in a module printing > extra stuff for unittests - e.g. -debug=string for std.string - but not for - > debug), and -debug is really meant for debugging purposes, not for enabling or > disabling checks. That's for -release, which, for better or worse, you can't > actually check for in code. So, really, there is no way to have -release affect I guess one would make it an assertion in phobos code. > any code in Phobos beyond what it does to the language in general (remove > assertions and remove array bounds checking in @system code), even if we > wanted it to, which is debatable. > > - Jonathan M Davis | ||||
November 03, 2011 Re: checkedTo | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | Am 03.11.2011, 16:54 Uhr, schrieb Jonathan M Davis <jmdavisProg@gmx.com>:
> [...] So, really, there is no way to have -release affect
> any code in Phobos beyond what it does to the language in general (remove
> assertions and remove array bounds checking in @system code), even if we
> wanted it to, which is debatable.
>
> - Jonathan M Davis
So the current situation for D2 is that in -release mode only code explicitly annotated @safe/@trusted will do boundary checking, while it is still removed from all 'normal' functions?
| |||
November 03, 2011 Re: checkedTo | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Marco Leise | On Thursday, November 03, 2011 20:36:03 Marco Leise wrote:
> Am 03.11.2011, 16:54 Uhr, schrieb Jonathan M Davis <jmdavisProg@gmx.com>:
> > [...] So, really, there is no way to have -release affect
> > any code in Phobos beyond what it does to the language in general
> > (remove
> > assertions and remove array bounds checking in @system code), even if we
> > wanted it to, which is debatable.
> >
> > - Jonathan M Davis
>
> So the current situation for D2 is that in -release mode only code explicitly annotated @safe/@trusted will do boundary checking, while it is still removed from all 'normal' functions?
Well, templated functions could be inferred as @safe and would then presumably be treated the same, but yes, from what I understand, -release removes bounds checking on arrays (and AAs) in @system code but not @safe or @trusted code. Compiling with -noboundscheck will turn off bounds checking completely.
- Jonathan M Davis
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply