Why no mutable shared from uniqueness?
Quirin Schroll
qs.il.paperinik at gmail.com
Tue Feb 17 18:22:00 UTC 2026
On Sunday, 15 February 2026 at 21:20:12 UTC, Timon Gehr wrote:
> On 2/11/26 13:26, Quirin Schroll wrote:
>> If a pure factory function returns an non-`shared`-type
>> object, that type should be convertible to `shared` or am I
>> mistaken?
>> Essentially, this should compile:
>> ```d
>> int[] make() pure @safe;
>>
>> void main() @safe
>> {
>> shared xs = make();
>> }
>> ```
>> Currently, only the conversion to `const shared` is enabled by
>> uniqueness. I don’t understand that limitation, but I’m not
>> sure I understand `shared` very well.
>
> `const shared` works because it is a supertype of `immutable`
> and `immutable` works. Even that existing rule is perhaps
> unsound (depending on what you consider to be the intended
> semantics of `shared`):
>
> https://forum.dlang.org/post/jfqsgpkcduptjyryebrq@forum.dlang.org
>
> Basically the issue is that you will have unsynchronized memory
> writes to some locations that later get transitively typed as
> `shared`.
That thread is very interesting. Thanks.
More information about the Digitalmars-d-learn
mailing list