-preview=in might break code

Max Haughton maxhaton at gmail.com
Fri Oct 2 19:49:32 UTC 2020


On Friday, 2 October 2020 at 18:31:20 UTC, Per Nordlöw wrote:
> On Friday, 2 October 2020 at 17:16:46 UTC, Max Haughton wrote:
>> Could we be ambitious and aim to have ownership taken to the 
>> max and catch this statically? This particular case is 
>> relatively low hanging fruit but having the in parameter work 
>> this way would be nice if it was safe.
>
> For which parameter types should such ownership checking be 
> performed?
>
> All kinds of references types including ref params, classes and 
> pointers or a subset of them?

I think for any scheme to be successful it would have to (within 
@safe code) have to cover pretty much everything, from the 
parameter all the way up to the allocation (be that a class, 
pointer to struct etc.). A more limited ownership system could 
still be very useful (what exists now is getting there) but to 
*guarantee* safety it must go further.

Obviously this would be a huge task - not impossible (we have 
some very clever people) but big - but if it happens at some 
point it would need to be very thoroughly planned i.e. from the 
"basics" like how to handle malloc and free (or your allocator of 
choice) to the more subtle issues like where to make the surgical 
cuts to the languages design - D only sort of has move semantics 
at the moment, which (recall that assignment in rust is move by 
default) at a glance make a provably safe system more difficult 
(especially wrt types that own pointers I think).

On a more meta level I think dmd needs to be carefully structured 
to separate the AST from the analysis. I'm aware that talk is 
cheap, but it could get very ugly if done wrong .






More information about the Digitalmars-d mailing list