D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19279 - mutable does not promote to shared
Summary: mutable does not promote to shared
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-01 04:13 UTC by Manu
Modified: 2024-12-13 19:00 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Manu 2018-10-01 04:13:20 UTC
struct Bob
{
  void setThing() shared;
}

As I understand, `shared` attribution intends to guarantee that I dun
synchronisation internally.
This method is declared shared, so if I have shared instances, I can
call it... because it must handle thread-safety internally.

void f(ref shared Bob a, ref Bob b)
{
  a.setThing(); // I have a shared object, can call shared method

  b.setThing(); // ERROR
}

The method is shared, which suggests that it must handle thread-safety. My instance `b` is NOT shared, that is, it is thread-local.
A method that handles thread-safety doesn't not work when it's only accessed from a single thread.

mutable -> shared should work the same as mutable -> const... because surely that's safe?
Comment 1 Manu 2018-10-01 05:32:29 UTC
Conversation: https://github.com/dlang/dmd/pull/8782

Reveals that `scope` is also necessary to guarantee that the promoted reference does not escape.
Promotion is safe so long as no promoted-reference outlives the call where the instance was promoted.

struct Bob
{
  void setThing() shared scope;
}

void f(ref shared Bob a, ref Bob b)
{
  a.setThing(); // I have a shared object, can call shared method

  b.setThing(); // this should work with `scope`
}
Comment 2 dlangBugzillaToGithub 2024-12-13 19:00:46 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17880

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB