digitalmars.D.learn - union mutability
- Jack Applegame (19/19) Aug 25 2016 Code:
- Jonathan M Davis via Digitalmars-d-learn (14/32) Aug 25 2016 Well, Rebindable depends on it (though Rebindable is in a legal grey are...
- Meta (3/23) Aug 25 2016 This should be fixed pretty soon:
- Jack Applegame (2/4) Aug 25 2016 Bye-bye immutable classes. :'(
- Jonathan M Davis via Digitalmars-d-learn (9/13) Aug 25 2016 Why? I don't know exactly what that PR is supposed to do, but std.dateti...
- Jack Applegame (5/13) Aug 25 2016 Because lack of mutable references to immutable classes in @safe
- Jack Applegame (1/1) Aug 25 2016 Also I hate Rebindable.
- Jonathan M Davis via Digitalmars-d-learn (7/8) Aug 25 2016 Yeah, well, without a language change, it's the best that we have for
Code: union A { immutable int f; } union B { immutable int f; int e; } void main() { A a = A(1); //a = A(2); // a.f is immutable, fails to compile as expected B b = B(1); b = B(2); // compiles!!! } It turns out that if the union contains at least one mutable member, then the entire union is considered to be mutable. It's logical, but does it meet the specs? I couldn't find description of this behavior.
Aug 25 2016
On Thursday, August 25, 2016 15:22:23 Jack Applegame via Digitalmars-d-learn wrote:Code: union A { immutable int f; } union B { immutable int f; int e; } void main() { A a = A(1); //a = A(2); // a.f is immutable, fails to compile as expected B b = B(1); b = B(2); // compiles!!! } It turns out that if the union contains at least one mutable member, then the entire union is considered to be mutable. It's logical, but does it meet the specs? I couldn't find description of this behavior.Well, Rebindable depends on it (though Rebindable is in a legal grey area at best and technically in violation of the rules at worst). It's basically the same as when you cast away const or immutable - it's fine as long as you don't mutate the variable and thus break the guarantees that compiler has for const or immutable objects. But I don't know how you can really do anything with it without violating immutable. Certainly, in any case other than what Rebindable is up to, I wouldn't do it, and even then, I suspect that Rebindable is in a situation where it's technically violating the compiler's guarantees but does so in a way that will never actually result in problems in practice. But yes, this behavior is known, albeit questionable. - Jonathan M Davis
Aug 25 2016
On Thursday, 25 August 2016 at 15:22:23 UTC, Jack Applegame wrote:Code: union A { immutable int f; } union B { immutable int f; int e; } void main() { A a = A(1); //a = A(2); // a.f is immutable, fails to compile as expected B b = B(1); b = B(2); // compiles!!! } It turns out that if the union contains at least one mutable member, then the entire union is considered to be mutable. It's logical, but does it meet the specs? I couldn't find description of this behavior.This should be fixed pretty soon: https://github.com/dlang/dmd/pull/5940
Aug 25 2016
On Thursday, 25 August 2016 at 17:01:40 UTC, Meta wrote:This should be fixed pretty soon: https://github.com/dlang/dmd/pull/5940Bye-bye immutable classes. :'(
Aug 25 2016
On Thursday, August 25, 2016 18:27:25 Jack Applegame via Digitalmars-d-learn wrote:On Thursday, 25 August 2016 at 17:01:40 UTC, Meta wrote:Why? I don't know exactly what that PR is supposed to do, but std.datetime uses immutable time zone objects, and if that PR made it so that you couldn't have an immutable instance of a class, then it would have failed the auto-tester. And it clearly doesn't stop having unions with immutable members, or it would have failed to compile because of Rebindable (though it may be that Rebindable can no longer be used in safe code). - Jonathan M DavisThis should be fixed pretty soon: https://github.com/dlang/dmd/pull/5940Bye-bye immutable classes. :'(
Aug 25 2016
On Thursday, 25 August 2016 at 19:19:49 UTC, Jonathan M Davis wrote:Why? I don't know exactly what that PR is supposed to do, but std.datetime uses immutable time zone objects, and if that PR made it so that you couldn't have an immutable instance of a class, then it would have failed the auto-tester. And it clearly doesn't stop having unions with immutable members, or it would have failed to compile because of Rebindable (though it may be that Rebindable can no longer be used in safe code). - Jonathan M DavisBecause lack of mutable references to immutable classes in safe code is big PITA for me. It is easier to not use immutable classes at all.
Aug 25 2016
On Thursday, August 25, 2016 19:43:49 Jack Applegame via Digitalmars-d-learn wrote:Also I hate Rebindable.Yeah, well, without a language change, it's the best that we have for dealing with the problem that it's designed to solve. D just isn't designed with the idea that there's any distinction between the type of a class reference and the type of the class it refers to. - Jonathan M Davis
Aug 25 2016