Skip to content

Comments

Preliminary shared work#10142

Closed
UplinkCoder wants to merge 3 commits intodlang:masterfrom
UplinkCoder:shared_
Closed

Preliminary shared work#10142
UplinkCoder wants to merge 3 commits intodlang:masterfrom
UplinkCoder:shared_

Conversation

@UplinkCoder
Copy link
Member

@UplinkCoder UplinkCoder commented Jul 6, 2019

This will block read/write access to shared variables
execpt for the casting shared away operation, and when passing a shared argument to a shared parameter.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @UplinkCoder!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#10142"

@UplinkCoder UplinkCoder force-pushed the shared_ branch 2 times, most recently from e4b602d to 8f85d33 Compare July 6, 2019 09:34
@thewilsonator thewilsonator changed the title Prelimianry shared work Preliminary shared work Jul 6, 2019
@TurkeyMan
Copy link
Contributor

You should rebase this on nicks -preview PR, since that wasn't merged because there was no code that made use of it, and this needs that flag.

@UplinkCoder UplinkCoder force-pushed the shared_ branch 8 times, most recently from b96ebf8 to 3851551 Compare July 12, 2019 15:05

int f1(shared int x)
{
x += 7; // Error: Trying to accsess shared state x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the error should say "Invalid access to shared data x"
'Trying' feels like an intent rather than an error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling errors

return exp.expressionSemantic(sc);
}

void checkAccessSharedCall(CallExp exp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No description.

override void visit(CallExp exp)
{
// @@@SHARED@@@
// we need to set allow shared for overload resolution
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why should this affect overload resolution?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why indeed :)
because for some reason overload-resolution needs to resolve properties.


auto e1x = resolveProperties(sc, exp.e1);
if (e1x.op == TOK.error)
// shared allowed for resolving this
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what this means.

src/dmd/dscope.d Outdated
}


extern (C++) Scope* startRelaxShared()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. No description
  2. I have no idea what "relaxed shared" means


int sync(shared int *x, int y)
{
return x = y; // Error: Trying to accsess shared state x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

integers cannot be assigned to pointers anyway

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto-deref.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (e2.type == e1.type.nextof) *e1 = e2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto-deref.

You said that the other day, but I don't get it...

    int y = 10;
    int* x;
    x = y;
error : cannot implicitly convert expression `y` of type `int` to `int*`

Feature("rvaluerefparam", "rvalueRefParam",
"enable rvalue arguments to ref parameters"),
Feature("restrictiveshared", "restrictiveshared",
"implement a more restrictive shared", false),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"more restrictive shared" has no particular meaning

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disallow reading and writing shared state then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'd go with 'data' or 'values', in my melon 'state' means something a little more specific; it evokes emotions of state machines or perhaps the 'state' of whether something is shared or not, like "reading or writing the shared-ness of the thing"... I mean, it's obvious that's not what this error means, it's just that I would lean away from using the word 'state' for those reasons. Is there precedent elsewhere?

{
assert (exp.f);
auto params = exp.f.getParameterList().parameters;
if (exp.arguments && exp.arguments.dim && params && params.dim)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write this function as

if (!(exp.arguments && exp.arguments.dim && params && params.dim)
    return;
foreach (i, arg;*exp.arguments)
{
    if (arg.op != TOK.variable)
        continue;
    ...
}

@thewilsonator
Copy link
Contributor

@UplinkCoder please take a look at dlang/druntime#2679 (comment)

assert (exp.f);
auto params = exp.f.getParameterList().parameters;
if (!exp.arguments || !exp.arguments.dim || !params || !params.dim)
return ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space

if (!exp.arguments || !exp.arguments.dim || !params || !params.dim)
return ;

{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove and unindent the following

@RazvanN7
Copy link
Contributor

@UplinkCoder It seems like Walter has taken the matter into his hands [1]. Maybe you can take a look at his implementation and see which one is better.

[1] #10209

@UplinkCoder UplinkCoder closed this Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants