On Wednesday, 2 November 2016 at 05:00:23 UTC, Andrei Alexandrescu wrote:
In order to make opAssign safe, a language change will be necessary.

Technically, it should be possible with runtime checks:

https://forum.dlang.org/post/aeeffshzkfjbrejzt...@forum.dlang.org

The checking overheads disappear when -noboundschecks is passed. The user has to manually copy the RCSlice when necessary for correct code.

The RCSlice in the link is just a basic proof of concept, using RCRef for temporary references. It doesn't handle reallocations - I think to have early diagnostics of potential errors it would need to have a separate RCRef reference count from the main count. That would be used to check there are no RCRef references alive when the main count is one and a reallocation could potentially occur - e.g. when appending. I think with this (hypothetical) RCSlice it's bug-prone to allow the user *not* to make a temporary copy of the RCSlice in this scenario because errors could depend on unknown runtime behaviour, not showing up in testing.

I mention this partly because I think this scenario has an impact on the design of a DIP to address when to automatically add reference counting bumps - perhaps a @rcbump attribute is necessary. Otherwise the compiler can't know if an external function taking an RCString performs an append or not.

Reply via email to