[Issue 22221] [dip1000] pure function can escape parameters through Exception

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Mar 7 18:05:32 UTC 2022


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

--- Comment #5 from Atila Neves <atila.neves at gmail.com> ---
> I'm not sure, what's left blocking the fix PR is 1 function in excel-D (shouldEqual) and some Phobos unittests. It's unknown how much breakage results from your proposal.

Are you sure about that? I checked out your branch some weeks ago and started
adding scope to a *lot* of Phobos functions before I gave up.

I think the real issue is illustrated by the fact that this correctly doesn't
compile:

-----
void f_throw(scope /*explicit scope here*/ string x) @safe pure
{
    throw new Exception(x);
}
-----

In the original example, the compiler is looking at the signature of the
function and the fact that it's strongly pure and adding scope to the parameter
when it's being called from `escape_throw_20150`, but not when compiling the
function itself! I don't think we can consider it to be scope in one context
but not in the other.

My proposal is that we decide to implicitly add scope to the parameters of
strongly pure functions. The escape hatch would be to add a dummy parameter
with mutable indirection to make it weakly pure.

This is ugly but it's for a niche use-case and other than introducing a keyword
or some way to mark the function as "pure but don't scope my params" I'm not
sure what to do.

--


More information about the Digitalmars-d-bugs mailing list