Challenge: write a reference counted slice that works as much as possible like a built-in slice

tsbockman thomas.bockman at gmail.com
Tue Nov 9 06:32:40 UTC 2021


On Tuesday, 9 November 2021 at 03:43:01 UTC, Paul Backus wrote:
> On Tuesday, 9 November 2021 at 01:14:24 UTC, tsbockman wrote:
>> With current language semantics, the destructor (and any other 
>> similar operations, such as reassignment) of the reference 
>> type must be `@system` to prevent misuse of the destructor in 
>> `@safe` code.
>>     https://issues.dlang.org/show_bug.cgi?id=21981
>>
>> The solution to this problem is to introduce some way of 
>> telling the compiler, "this destructor is `@safe` to call 
>> automatically at the end of the object's scope, but `@system` 
>> to call early or manually."
>
> I believe it is also possible to make this `@safe` by doing 
> borrow checking at runtime, although it would introduce some 
> overhead, and make the API less ergonomic.

How? All of the runtime borrow checking schemes that I have 
considered turn out to have the same fundamental problems as 
reference counting, when examined closely.


More information about the Digitalmars-d mailing list