Function scope arguments

Artur Skawina art.08.09 at gmail.com
Tue Jan 15 02:58:02 PST 2013


On 01/15/13 00:07, Timon Gehr wrote:
> 'scope' is supposed to restrict escaping references, but it is not entirely clear what that means, and how to make it powerful enough. Eg. what if part of a structure can be freely escaped, such as the contents of an array of Objects, but not the array itself? I'd argue that indirections in parameters should not be covered by 'scope', because it is not something that is transitive. (the opposite would be)

A non-transitive scope would not be very useful. Eg. a 'scope' arg could
never refer to a stack object - which is the main advantage of having 'scope'.
Introducing a second kind of top-level-scope would probably complicate the
language too much.

> Furthermore, there is the issue of how to treat 'ref' parameters.

Different problem - lifetime. One approach would be to disallow escaping
them (which in this case includes returning them) unless the compiler is
able to do the right - ie the body of the function is available. Somewhat
unorthodox, but could work. (The problem are not the trivial cases; it's the
ones where the compiler has no idea which ref is escaped/returned at runtime)

artur


More information about the Digitalmars-d mailing list