DIP69 - Implement scope for escape proof references

Tobias Pankrath via Digitalmars-d digitalmars-d at puremagic.com
Fri Dec 5 06:14:10 PST 2014


On Friday, 5 December 2014 at 02:38:48 UTC, Daniel Murphy wrote:
> "H. S. Teoh via Digitalmars-d"  wrote in message 
> news:mailman.2709.1417745546.9932.digitalmars-d at puremagic.com...
>
>> I've often pondered about the possibility of a language where 
>> the
>> compiler will analyze each module and infer any number of 
>> attributes and
>> optimization opportunities for each symbol exported by that 
>> module, and
>> this information will be saved in the object file (or some 
>> other kind of
>> interfacing file). This includes any half-compiled template 
>> bodies and
>> whatever else that can't be fully codegen'd until actual use.  
>> The
>> attributes will include all sorts of stuff that programmers 
>> normally
>> wouldn't want to deal with -- there could be 10+ or 50+ 
>> attributes
>> representing various optimization / static checking 
>> opportunities.  Then
>> every time a module is imported by another module, the 
>> compiler never
>> goes to the source code of the imported module anymore, but it 
>> will read
>> the object (interface) file, which is fully attributed, and 
>> the saved
>> attributes will be used internally for static checking, 
>> optimization,
>> and inferring attributes for the current module.
>
> This can't be used to infer attributes that can produce errors 
> - those attributes have to be user-visible or the errors don't 
> make any sense.  If it's purely for optimization, then that's 
> basically what LTO does.

We could inter attributes if not specified instead of assuming a
default, for example @nogc and a possible @gc.

---

int[] foo1(int[] bar) @nogc // function is @nogc, error if gc is
used
int[] foo2(int[] bar) @gc // function is @gc, functions that call
foo2 cannot be @nogc
int[] foo3(int[] bar) // neither @nogc nor @gc, compiler infers
attribute
---


More information about the Digitalmars-d mailing list