-
-
Notifications
You must be signed in to change notification settings - Fork 609
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
Allow ref-returns of shared Variables #10412
Conversation
|
Thanks for your pull request, @UplinkCoder! Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#10412" |
| @@ -3161,7 +3161,10 @@ else | |||
| rs.exp = inferType(rs.exp, fld.treq.nextOf().nextOf()); | |||
|
|
|||
| rs.exp = rs.exp.expressionSemantic(sc); | |||
| rs.exp.checkSharedAccess(sc); | |||
| if(inferRef || !tf.isref) | |||
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.
Why if inferRef? What case does that represent?
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.
inferRef means auto ref.
In which case we don't want to allow unsolicited shared access.
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.
Why should auto ref not infer ref?
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.
Because then code you have no control over affects the behavior of shared
How so, it should just do the appropriate shared checks after inferring ref/value. Why should there any differences between foo and bar?
void main()
{
shared bool b;
foo(b);
bar(b);
}
void foo(ref shared bool b) { ... }
void bar()(auto ref shared bool b) { .... }
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.
Because the ref was explicitly written and will always be ref.
That will be the case for bar as well because reading actual shared data would't compile at alll.
shared is all about making you AWARE of problem with sharing data
When using auto ref you already have to make the defensive assumption that it infers ref, not the other way round. Raising awareness is certainly a good intention but it doesn't justify odd special cases IMHO.
Anyway, this can also be deferred into another PR as the current change provides a net benefit already.
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.
I agree that the exception is weird. If auto ref infers ref, then the call should work normally.
76ae99e to
ba4c25b
Compare
|
Does this require a spec change? |
|
|
No, it requires a test though. |
Definitely. |
|
@UplinkCoder ping |
|
@UplinkCoder ping |
|
@thewilsonator Ah yeah sorry. |
|
Because then code you have no control over affects the behavior of shared
…On Sat, Jun 6, 2020, 12:50 PM Florian ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/dmd/statementsem.d
<#10412 (comment)>:
> @@ -3161,7 +3161,10 @@ else
rs.exp = inferType(rs.exp, fld.treq.nextOf().nextOf());
rs.exp = rs.exp.expressionSemantic(sc);
- rs.exp.checkSharedAccess(sc);
+ if(inferRef || !tf.isref)
Why should auto ref not infer ref?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10412 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVWSCEY4VXTGQLSX6AMJ4DRVINPJANCNFSM4IXFZ7XA>
.
|
|
Because the ref was explicitly written and will always be ref.
shared is all about making you AWARE of problem with sharing data.
Am Sa., 6. Juni 2020 um 13:56 Uhr schrieb Florian <notifications@github.com
…:
***@***.**** commented on this pull request.
------------------------------
In src/dmd/statementsem.d
<#10412 (comment)>:
> @@ -3161,7 +3161,10 @@ else
rs.exp = inferType(rs.exp, fld.treq.nextOf().nextOf());
rs.exp = rs.exp.expressionSemantic(sc);
- rs.exp.checkSharedAccess(sc);
+ if(inferRef || !tf.isref)
Because then code you have no control over affects the behavior of shared
How so, it should just do the appropriate shared checks after inferring
ref/value. Why should there any differences between foo and bar?
void main()
{
shared bool b = void;
foo(b);
bar(b);
}
void foo(ref shared bool b) { atomicStore(b, false); }
void bar()(auto ref shared bool b) { atomicStore(b, false); }
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10412 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVWSCEU4LHCKUJBSXULPVLRVIVHJANCNFSM4IXFZ7XA>
.
|
|
@thewilsonator Done. |
|
@UplinkCoder I'll leave you to readd auto-merge if you need to force push more. |
|
@thewilsonator can't do. |
|
This looks like https://issues.dlang.org/show_bug.cgi?id=20195 If it is, please adjust the title and commit message accordingly. |
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.
This looks like https://issues.dlang.org/show_bug.cgi?id=20195
If it is, please adjust the title and commit message accordingly.
… fix) This is okay because we are passing a pointer and not the actual value. Currently excludes `ref` inferred from `auto ref`.
59a1aa0 to
02fd0cd
Compare
|
Updated commit title to include the bug reference and the commit message to state the current limitation regarding |
|
Auto-ref hasn't been addressed tho |
|
Did this fix the issue ? Because it's still open. |
This is okay because we are passing a pointer and not the acutal value.