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

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Nov 9 01:56:53 UTC 2021


On Tue, Nov 09, 2021 at 02:22:26PM +1300, rikki cattermole via Digitalmars-d wrote:
> 
> On 09/11/2021 2:14 PM, tsbockman wrote:
> > What you seem to be asking for instead is a way to trick the type
> > system into agreeing that mutating a reference count doesn't
> > actually mutate anything, which is nonsense. If that's really
> > necessary for some reason, it needs to be special cased into the
> > language spec, like how `pure` explicitly permits memory allocation.
> 
> Imagine saying to someone:
> 
> Yes you have made this struct immutable.
> 
> Yes you have set this bit of memory containing that immutable struct
> to read only.
> 
> Yes you ended up with a crashed program because that immutable struct
> went ahead and tried to write to that read only memory.
> 
> And yes, I understand that you couldn't have known that a field that
> you didn't write the implementation of used an escape hatch to write
> to const data.
> 
> It doesn't make sense.

Yes, subverting the type system with __mutable doesn't make sense. It
just adds all kinds of loopholes and other unwanted interactions to the
language.  A better approach is to have a nice way of converting
const(Wrapper!T) -> Wrapper!(const T), so that we can implement a
refcount in Wrapper without violating the type system.


T

-- 
Freedom of speech: the whole world has no right *not* to hear my spouting off!


More information about the Digitalmars-d mailing list