Purity, @safety, etc., in generic code

Jonathan M Davis jmdavisProg at gmx.com
Sun Feb 17 22:31:48 PST 2013


On Sunday, February 17, 2013 22:19:19 H. S. Teoh wrote:
> On Sun, Feb 17, 2013 at 10:08:13PM -0800, Walter Bright wrote:
> > On 2/17/2013 9:23 PM, Jonathan M Davis wrote:
> > >So, I think that the problem is essentially solved for @safe, pure,
> > >and nothrow as long as the implementation issues get solved.
> > 
> > Yup, I believe that for templates using inference is the way to go.
> > Currently, dmd does a rudimentary job of it, much improvement is
> > possible.
> 
> That's good to know.
> 
> It would be very cool if things like std.conv.to and std.format can be
> inferred pure/const/nothrow/@safe if the particular set of parameters
> with which they are instantiated permits it. There are many places in my
> code where I'd love to be able to use std.format, but can't because it
> would break pure/@safe/nothrow.

They're supposed to be, but the inferrence isn't advanced as it needs to be, 
and key stuff (like Appender) still can't be pure last time I checked. Similar 
issues exist with nothrow (and probably @safe), including issues in druntime 
(like with dup not being nothrow).

Also, David Nadlinger's suggestions on making @trusted applicable to 
statements or blocks of code rather than just whole functions would help a lot 
with dealing with @safe stuff, but that probably needs a DIP to sort it out 
before anyone can look at implementing changes like that.

- Jonathan M Davis


More information about the Digitalmars-d mailing list