[Issue 8121] "scope ref" is perfectly OK

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Oct 13 21:13:16 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=8121

--- Comment #8 from Jonathan M Davis <jmdavisProg at gmx.com> ---
There has been quite a bit of debate about what it means for a reference to
something to escape a function - e.g whether returning something as scope makes
sense and counts as not escaping, because the caller can then see that what's
being returned was what was being passed in or whether that counts as escaping
and should be disallowed. _All_ that the spec says on the matter is

"references in the parameter cannot be escaped (e.g. assigned to a global
variable)"

http://dlang.org/function.html

And while you may think that it's clear exactly what that should mean, that
doesn't mean that it's actually completely clear and generally accepted as
having a particular set of semantics by the community at large or by compiler
devs. All we have is the basic idea of what it's supposed to do, and then
everyone has their own ideas as to what exactly means, many of which are likely
close, but we need to know what the exact semantics are going to be in order to
say what does and doesn't make sense, and since it does _nothing_ right now
(save for delegates), using scope at all (aside from delegates) is arguably a
bad idea. Obviously, you can do whatever you want in your own code, but until
scope is properly and fully defined, don't expect things like scope ref to
start working if they don't work now.

I fully expect that scope is going to get fully hashed out sometime in the near
future, because it has the potential of having definite benefits for stuff like
reference counting, and that's a priority for Andrei right now, but for now, it
wouldn't make any sense to do anything with scope ref. If anything, I'd argue
that scope should be an error in all cases except for delegates, because it
does _nothing_ for them right now and just risks breaking code once it does.

--


More information about the Digitalmars-d-bugs mailing list