On Monday, 4 November 2013 at 09:34:52 UTC, Simen Kjærås wrote:
On 04.11.2013 09:46, deadalnix wrote:
You are trying to solve a non problem here. s is not shared in
the first
place, so you can start by fixing it here.
Now, if S has some indirection, then it make sense to mark it
as shared,
but then the trick you propose won't work.
I believe we're talking past each other here. Perhaps a better
example:
module foo;
struct S {
immutable(int)[] arr;
void fuzz() const pure {
}
}
void bar(S s) {
s.fuzz();
}
void main() {
shared S* s = new shared S;
bar(*s); // a
s.fuzz(); // b
}
This example demonstrates the exact same behavior as before,
and again I'm not doing a lot of anything special to get line a
to compile.
Now, I'm still of the opinion that the 'trick' I propose works
- making a copy of s is cheap (as that's what the spec says
about copying structs), s is implicitly castable to immutable,
and the function to be called is guaranteed not to change s in
any way. From all that, it seems safe to call fuzz on a shared
S.
Any read of arr in fuzz won't be sequentially consistent, so it
would be incorrect to let you call fuzz on a shared object.