DIP 1021--Argument Ownership and Function Calls--Formal Assessment

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Tue Nov 5 15:36:54 UTC 2019


On Monday, 28 October 2019 at 19:23:30 UTC, jmh530 wrote:
> they are all const. That there is only one mutable way to 
> access data sounds like restrict to me.

Well, if you add the constraint that there also is no const way 
to access the data.

But unique ownership is stricter than «restrict», which only 
guarantees that there is no aliasing (overlapping) between the 
pointed-too-memory. No guarantees for there not being other 
pointers to the same memory.

It is basically only significant when accessing arrays, like when 
you are calling a function with two windows onto the same array. 
Proving that the two windows don't overlap is not always possible 
without a performance loss.

Being able to tell the compiler that there is no overlap makes 
sense when doing inline updates in an array, so that the compiler 
can restructure instructions and use SIMD.  Without restrict you 
would often have to write the single array element before reading 
another (as they could point to the same memory location).

BUT «restrict» is very crude. It would probably be better to 
provide more narrow guarantees (e.g. «the offset between the two 
pointers is at least 16 bytes»).


More information about the Digitalmars-d-announce mailing list