The next iteration of scope

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 1 13:26:51 PDT 2015


On 4/1/2015 10:00 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm at gmx.net>" wrote:
> On Tuesday, 31 March 2015 at 20:07:19 UTC, Walter Bright wrote:
>> Consider the code:
>>
>>   struct Foo { C obj; }
>>   @safe void bar(C c, Foo* f) { f.obj = c; }
>>
>> Under the proposal, for @safe code, this would have to be written as:
>>
>>   @safe void bar(static C c, Foo* f) ...
>>
>
> Either that, or:
>
>      @safe void bar(C c return!f, Foo* f) ...
>
> or:
>
>      @safe void bar()(C c, Foo* f) ...
>
>> I'm concerned this may break an astonishing amount of code.
>
> We could go a step further and infer scope for all @safe functions, except those
> with at least one explicit annotation. This would be almost backward compatible,
> except for the fact that some arguments then suddenly become scope and therefore
> the mangling changes.

The problem with inferring attributes on non-template functions is the source 
must be available to the compiler. That's obviously true for templates, but not 
so true for non-templates, where only the signature is available.

I'm thinking of a modest step which would be a subset of your proposal:

1. implement 'scope' and 'return' for arrays, classes, and pointers
2. implement inference for templates and lambdas
3. enable it with the -dip25 switch

and see how far that takes us.


More information about the Digitalmars-d mailing list