Inference of Scoped Destruction

Nordlöw per.nordlow at gmail.com
Thu Nov 30 16:31:25 UTC 2017


Are there any plans to D compilers to use recent DIP-1000 to 
infer scoped destruction of GC-allocated data such as in the 
following case:

T sum(T)(in T[] x) // x cannot escape scope of `sum`
{
     /// calculate and return sum of `x` ...
}

double f(size_t n)
{
     auto x = new int[n]; // scoped (deallocation) should be 
inferred
     auto y = sum(x); // cannot alias `x`
     return y;
}

I believe this would make D more competitive against Rust's and 
C++'s (more) deterministic RAII memory management.

How would this interact with explicit scope-qualification of `x`?


More information about the Digitalmars-d mailing list