From 89a07e8e0bc30b2fdd823c6d684436461158342c Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Mon, 1 Oct 2018 11:16:20 +0800 Subject: [PATCH 1/2] Allow implicit conversion to shared. so that methods that are shared can be called using unshared objects. This is fine because any extra synchronisation done as a result of being shared will not cause race conditions, see https://forum.dlang.org/thread/mailman.4068.1538360998.29801.digitalmars-d@puremagic.com --- src/dmd/mtype.d | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dmd/mtype.d b/src/dmd/mtype.d index a589aa421b43..1d28eb7a7b4e 100644 --- a/src/dmd/mtype.d +++ b/src/dmd/mtype.d @@ -79,7 +79,9 @@ bool MODimplicitConv(MOD modfrom, MOD modto) pure nothrow @nogc @safe case X(MODFlags.wild, MODFlags.const_): case X(MODFlags.wild, MODFlags.wildconst): case X(MODFlags.wildconst, MODFlags.const_): - return (modfrom & MODFlags.shared_) == (modto & MODFlags.shared_); + case X(0, 0): + // Casting to shared is fine, but otherwise casting from shared is not. + return (modto & MODFlags.shared_) || !(modfrom & MODFlags.shared_); case X(MODFlags.immutable_, MODFlags.const_): case X(MODFlags.immutable_, MODFlags.wildconst): From c5fa5f587de9c1ee3020613418b52eb7c17af06e Mon Sep 17 00:00:00 2001 From: Nicholas Lindsay Wilson Date: Mon, 1 Oct 2018 12:46:28 +0800 Subject: [PATCH 2/2] Use MATCH.shared_ --- src/dmd/globals.d | 1 + src/dmd/mtype.d | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dmd/globals.d b/src/dmd/globals.d index 2149b98b0fcc..3b5f15e37da6 100644 --- a/src/dmd/globals.d +++ b/src/dmd/globals.d @@ -504,6 +504,7 @@ enum MATCH : int { nomatch, // no match convert, // match with conversions + shared_, // match with conversion to shared constant, // match with conversion to const exact, // exact match } diff --git a/src/dmd/mtype.d b/src/dmd/mtype.d index 1d28eb7a7b4e..04f1e0ea7d26 100644 --- a/src/dmd/mtype.d +++ b/src/dmd/mtype.d @@ -79,7 +79,6 @@ bool MODimplicitConv(MOD modfrom, MOD modto) pure nothrow @nogc @safe case X(MODFlags.wild, MODFlags.const_): case X(MODFlags.wild, MODFlags.wildconst): case X(MODFlags.wildconst, MODFlags.const_): - case X(0, 0): // Casting to shared is fine, but otherwise casting from shared is not. return (modto & MODFlags.shared_) || !(modfrom & MODFlags.shared_); @@ -118,6 +117,9 @@ MATCH MODmethodConv(MOD modfrom, MOD modto) pure nothrow @nogc @safe case X(MODFlags.shared_ | MODFlags.wildconst, MODFlags.shared_ | MODFlags.wild): return MATCH.constant; + case X(0,MODFlags.shared_): + return MATCH.shared_; + default: return MATCH.nomatch; }