Safe mode in D?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Oct 18 10:30:14 PDT 2013


On Fri, Oct 18, 2013 at 07:19:16PM +0200, Adam D. Ruppe wrote:
> On Friday, 18 October 2013 at 17:06:57 UTC, H. S. Teoh wrote:
> >But if we're gonna do it, I say we should go all the way:
> 
> And make scope the default parameter thingy, and implement it.
> 
> God I want some kind of escaping check thing so badly, it is
> supposed to work already!

+1. I'm waiting for scope to be implemented too.

@Walter: Just out of curiosity, what exactly is holding up the
implementation of scope? AFAICT, a relatively simple one-pass flow
analysis would do the job; am I missing something obvious?


> http://dlang.org/function.html
> scope: references in the parameter cannot be escaped (e.g. assigned to
> a global variable)
> 
> 
> But what's interesting here is that references to immutable are
> virtually value types; string, or immutable(int)[] *can* be escaped
> safely, whereas const(int)[] or int[] might not, they can be
> overwritten elsewhere (the case now) and can also be freed elsewhere
> (if you don't use the gc on them). An immutable reference would
> necessarily use the gc, since otherwise it isn't really immutable.
> 
> So you can store immutable stuff in a global or anything and that's
> perfectly ok, so scope immutable == immutable. scope const is
> different though.

Interesting.

Though I'm still unclear about the meaning of a scope delegate (its
*intended* meaning, that is, not necessarily its current
implementation).


> >I'm not as sure about making nothrow default.
> 
> i think throwing is really the default anyway just writing normal D.
> If we sampled 100 random D functions, I think we'd find most of them
> are @safe in practice, even if not marked, and probably throw too.
> So that'd be the sane default.

True, most "normal" D code would allow throwing exceptions, since that's
a core language feature, so nothrow shouldn't be default. But pure and
@safe *should* be default IMO.


T

-- 
English is useful because it is a mess. Since English is a mess, it maps
well onto the problem space, which is also a mess, which we call
reality. Similarly, Perl was designed to be a mess, though in the
nicests of all possible ways. -- Larry Wall


More information about the Digitalmars-d mailing list