Skip to content
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

Merged
merged 1 commit into from
Jul 3, 2020

Conversation

UplinkCoder
Copy link
Member

This is okay because we are passing a pointer and not the acutal value.

@dlang-bot
Copy link
Contributor

dlang-bot commented Sep 16, 2019

Thanks for your pull request, @UplinkCoder!

Bugzilla references

Auto-close Bugzilla Severity Description
20195 normal -preview=nosharedaccess has some access problems

Testing this PR locally

If 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)
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Contributor

@MoonlightSentinel MoonlightSentinel Jun 6, 2020

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) { .... }

Copy link
Contributor

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.

Copy link
Contributor

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.

@12345swordy
Copy link
Contributor

Does this require a spec change?
cc @thewilsonator

@TurkeyMan
Copy link
Contributor

-preview=restrictiveshared is not spec-ed, it's experimental.

@thewilsonator
Copy link
Contributor

Does this require a spec change?

No, it requires a test though.

@TurkeyMan
Copy link
Contributor

No, it requires a test though.

Definitely.

@thewilsonator
Copy link
Contributor

@UplinkCoder ping

@thewilsonator
Copy link
Contributor

@UplinkCoder ping

@UplinkCoder
Copy link
Member Author

@thewilsonator Ah yeah sorry.
Will add tests.

@UplinkCoder
Copy link
Member Author

UplinkCoder commented Jun 6, 2020 via email

@UplinkCoder
Copy link
Member Author

UplinkCoder commented Jun 6, 2020 via email

@UplinkCoder
Copy link
Member Author

@thewilsonator Done.

@thewilsonator
Copy link
Contributor

@UplinkCoder I'll leave you to readd auto-merge if you need to force push more.

@UplinkCoder
Copy link
Member Author

@thewilsonator can't do.
I am not a member of the dmd group

@WalterBright
Copy link
Member

This looks like https://issues.dlang.org/show_bug.cgi?id=20195

If it is, please adjust the title and commit message accordingly.

Copy link
Member

@WalterBright WalterBright left a 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`.
@MoonlightSentinel
Copy link
Contributor

Updated commit title to include the bug reference and the commit message to state the current limitation regarding auto ref.

@Geod24
Copy link
Member

Geod24 commented Jul 2, 2020

Auto-ref hasn't been addressed tho

@thewilsonator thewilsonator merged commit 0b7a0d4 into dlang:master Jul 3, 2020
@Geod24
Copy link
Member

Geod24 commented Sep 10, 2020

Did this fix the issue ? Because it's still open.

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