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

Paul Backus snarwin at gmail.com
Tue Nov 9 17:04:29 UTC 2021


On Tuesday, 9 November 2021 at 06:32:40 UTC, tsbockman wrote:
> 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.

Here's a basic sketch of the scheme I had in mind: 
https://gist.github.com/run-dlang/d1982a29423b2cb545bc9fa452d94c5e

It's entirely possible I've overlooked something and this is 
actually unsound. As Andrei says: "destroy!"


More information about the Digitalmars-d mailing list