DIP 1021--Argument Ownership and Function Calls--Community Review Round 1
Mike Franklin
slavo5150 at yahoo.com
Fri Jul 19 08:32:13 UTC 2019
Consider this contrived example:
someLibrary.d
-------------
module someLibrary;
import core.stdc.stdlib;
int a;
int b;
ref int foo() @safe
{
if ((rand() % 2) == 0)
return a;
else
return b;
}
ref int bar() @safe
{
if ((rand() % 4) == 0)
return a;
else
return b;
}
main.d
------
import someLibrary;
void doSomething(scope ref int a, scope ref int b) @safe
{
// whatever...
}
void main() @safe
{
doSomething(foo(), bar());
}
How can the compiler statically determine whether `foo` and `bar`
will return a reference to the same data?
It seems the language or type system must provide this guarantee,
which would require a full-fledged ownership/borrowing system to
accurately enforce what this DIP is proposing.
More information about the Digitalmars-d
mailing list