Why no mutable shared from uniqueness?
Timon Gehr
timon.gehr at gmx.ch
Sun Feb 15 21:20:12 UTC 2026
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`.
More information about the Digitalmars-d-learn
mailing list