www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why no mutable shared from uniqueness?

reply Quirin Schroll <qs.il.paperinik gmail.com> writes:
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.
Feb 11
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
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`.
Feb 15
parent Quirin Schroll <qs.il.paperinik gmail.com> writes:
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.
Feb 17