Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
November 30, 2017 Inference of Scoped Destruction | ||||
---|---|---|---|---|
| ||||
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`? |
November 30, 2017 Re: Inference of Scoped Destruction | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Thursday, 30 November 2017 at 16:31:25 UTC, Nordlöw wrote:
> 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`?
The problem with this; as with most types of inference is the time it can take.
And the number of false negatives.
|
November 30, 2017 Re: Inference of Scoped Destruction | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On Thursday, 30 November 2017 at 16:50:02 UTC, Stefan Koch wrote:
> On Thursday, 30 November 2017 at 16:31:25 UTC, Nordlöw wrote:
>> 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`?
>
> The problem with this; as with most types of inference is the time it can take.
> And the number of false negatives.
Is there a formal definition of the complexity of such an inference?
|
December 04, 2017 Re: Inference of Scoped Destruction | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Thursday, 30 November 2017 at 16:31:25 UTC, Nordlöw wrote: > How would this interact with explicit scope-qualification of `x`? That would allow the compiler to avoid GC allocation for x. It seems essentially the same case as Walter describes here: http://forum.dlang.org/post/ofo9f5$2bt7$1@digitalmars.com |
December 04, 2017 Re: Inference of Scoped Destruction | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Treleaven | On Monday, 4 December 2017 at 16:03:50 UTC, Nick Treleaven wrote:
> On Thursday, 30 November 2017 at 16:31:25 UTC, Nordlöw wrote:
>> How would this interact with explicit scope-qualification of `x`?
>
> That would allow the compiler to avoid GC allocation for x. It seems essentially the same case as Walter describes here:
> http://forum.dlang.org/post/ofo9f5$2bt7$1@digitalmars.com
Nice. Thanks.
|
Copyright © 1999-2021 by the D Language Foundation