-
-
Notifications
You must be signed in to change notification settings - Fork 699
Preliminary shared work #10142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preliminary shared work #10142
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1288,7 +1288,7 @@ private Expression resolvePropertiesX(Scope* sc, Expression e1, Expression e2 = | |
| { | ||
| VarExp ve = cast(VarExp)e1; | ||
| VarDeclaration v = ve.var.isVarDeclaration(); | ||
| if (v && ve.checkPurity(sc, v)) | ||
| if (v && (ve.checkPurity(sc, v) || checkAccessShared(sc, ve.loc, v))) | ||
| return new ErrorExp(); | ||
| } | ||
| if (e2) | ||
|
|
@@ -1605,6 +1605,27 @@ private bool preFunctionParameters(Scope* sc, Expressions* exps) | |
| return err; | ||
| } | ||
|
|
||
| /******************************************** | ||
| * Issue an error if shared state is Accessed. | ||
| * Returns: | ||
| * true an error was issued | ||
| */ | ||
| private bool checkAccessShared(Scope* sc, Loc loc, VarDeclaration vd) | ||
| { | ||
| if (!global.params.restrictiveshared) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (vd.type && vd.type.isShared() && !(sc.flags & SCOPE.allowsharedaccess)) | ||
| { | ||
| loc.error("Invalid access to shared data `%s`", vd.toChars()); | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /******************************************** | ||
| * Issue an error if default construction is disabled for type t. | ||
| * Default construction is required for arrays and 'out' parameters. | ||
|
|
@@ -4011,8 +4032,50 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor | |
| return exp.expressionSemantic(sc); | ||
| } | ||
|
|
||
| void checkAccessSharedCall(CallExp exp) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No description. |
||
| { | ||
| assert (exp.f); | ||
| auto params = exp.f.getParameterList().parameters; | ||
| if (!exp.arguments || !exp.arguments.dim || !params || !params.dim) | ||
| return ; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space |
||
|
|
||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove and unindent the following |
||
| foreach (i, arg;*exp.arguments) | ||
| { | ||
| if (arg.op == TOK.variable) | ||
| { | ||
| auto ve = cast (VarExp) arg; | ||
| auto vd = ve.var.isVarDeclaration(); | ||
| if (vd && | ||
| vd.type && | ||
| vd.type.isShared() && | ||
| i < params.dim && | ||
| !(*params)[i].type.isShared) | ||
| { | ||
| checkAccessShared(sc, arg.loc, vd); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override void visit(CallExp exp) | ||
| { | ||
|
|
||
| // @@@SHARED@@@ | ||
| // overload resolution calls `resolvePropertiesX` which | ||
| // checks for shared access. | ||
| // We need to set allow shared for overload resolution | ||
| sc = sc.startAllowSharedAccess(); | ||
| // after resolution is done | ||
| scope (exit) | ||
UplinkCoder marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| sc = sc.endAllowSharedAccess(); | ||
| if (exp.f && !exp.f.semantic3Errors | ||
| && exp.f.type.isTypeFunction() !is null) | ||
| checkAccessSharedCall(exp); | ||
| } | ||
|
|
||
| static if (LOGSEMANTIC) | ||
| { | ||
| printf("CallExp::semantic() %s\n", exp.toChars()); | ||
|
|
@@ -6798,19 +6861,28 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor | |
| return; | ||
| } | ||
|
|
||
| // for static alias this: https://issues.dlang.org/show_bug.cgi?id=17684 | ||
| if (exp.e1.op == TOK.type) | ||
| exp.e1 = resolveAliasThis(sc, exp.e1); | ||
|
|
||
| auto e1x = resolveProperties(sc, exp.e1); | ||
| if (e1x.op == TOK.error) | ||
| // shared allowed for resolving this | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea what this means. |
||
| // @@@SHARED@@@ | ||
| { | ||
| result = e1x; | ||
| return; | ||
| sc = sc.startAllowSharedAccess(); | ||
|
|
||
| // for static alias this: https://issues.dlang.org/show_bug.cgi?id=17684 | ||
| if (exp.e1.op == TOK.type) | ||
| exp.e1 = resolveAliasThis(sc, exp.e1); | ||
|
|
||
| auto e1x = resolveProperties(sc, exp.e1); | ||
|
|
||
| if (e1x.op == TOK.error) | ||
| { | ||
| result = e1x; | ||
| return; | ||
| } | ||
| if (e1x.checkType()) | ||
| return setError(); | ||
| exp.e1 = e1x; | ||
|
|
||
| sc = sc.endAllowSharedAccess(); | ||
| } | ||
| if (e1x.checkType()) | ||
| return setError(); | ||
| exp.e1 = e1x; | ||
|
|
||
| if (!exp.e1.type) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| REQUIRED_ARGS:-preview=restrictiveshared | ||
| TEST_OUTPUT: | ||
| --- | ||
| --- | ||
| */ | ||
|
|
||
|
|
||
| int f1(shared int x) | ||
| { | ||
| auto r = sync(&x, 22); | ||
| return r; | ||
|
|
||
| } | ||
|
|
||
| int sync(shared int *x, int y) | ||
| { | ||
| auto unshared_x = cast()x; | ||
|
|
||
| return *unshared_x = y; | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| REQUIRED_ARGS:-preview=restrictiveshared | ||
| TEST_OUTPUT: | ||
| --- | ||
| fail_compilation/fail_shared.d(15): Error: Trying to Access shared state `x` | ||
| fail_compilation/fail_shared.d(16): Error: Trying to Access shared state `x` | ||
| fail_compilation/fail_shared.d(17): Error: Trying to Access shared state `x` | ||
| fail_compilation/fail_shared.d(22): Error: Trying to Access shared state `x` | ||
| --- | ||
| */ | ||
|
|
||
|
|
||
| int f1(shared int x) | ||
| { | ||
| x += 7; // Error: Trying to accsess shared state x | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the error should say "Invalid access to shared data x"
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spelling errors |
||
| x = 22; // Error: Trying to accsess shared state x | ||
| return x; // Error: Trying to accsess shared state x | ||
| } | ||
|
|
||
| int sync(shared int *x, int y) | ||
| { | ||
| return x = y; // Error: Trying to accsess shared state x | ||
UplinkCoder marked this conversation as resolved.
Show resolved
Hide resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. integers cannot be assigned to pointers anyway There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. auto-deref. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (e2.type == e1.type.nextof) *e1 = e2
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You said that the other day, but I don't get it... int y = 10;
int* x;
x = y; |
||
| } | ||
|
|
||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 statethen?There was a problem hiding this comment.
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?