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

Fix bugzilla issue 24846 - atomicLoad does not work for class arguments with -preview=nosharedaccess #17053

Merged
merged 1 commit into from
Nov 10, 2024

Conversation

rikkimax
Copy link
Contributor

@rikkimax rikkimax commented Nov 7, 2024

No description provided.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @rikkimax! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
24846 normal atomicLoad does not work for class arguments with -preview=nosharedaccess

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 "stable + dmd#17053"

@thewilsonator
Copy link
Contributor

can this not be fixed in druntime?

@rikkimax
Copy link
Contributor Author

rikkimax commented Nov 7, 2024

can this not be fixed in druntime?

I can't see how.

*cast(shared(inout(Foo))*)resultValuePtr

That has to be replaced.

Keep in mind core.internal.atomic is a compiler implementation platform module, its not a regular module.

@thewilsonator
Copy link
Contributor

cast(shared(inout(Foo)))resultValuePtr

IIRC that should then be an unsafe operation, and should therefore be trusted.

@rikkimax
Copy link
Contributor Author

rikkimax commented Nov 7, 2024

cast(shared(inout(Foo)))resultValuePtr

IIRC that should then be an unsafe operation, and should therefore be trusted.

Yes, but I don't see any @safe checks. This is on for all code.

@s-ludwig
Copy link
Member

s-ludwig commented Nov 7, 2024

This was my thought, too, that the whole "nosharedaccess" logic should only be active in @safe code. There are definitely cases where user code would want to circumvent the checks, possibly in an inline assembly block, or by using an ordinary memory access because outer conditions make it safe to do on a particular hardware architecture. There needs to be a way to circumvent the checks.

Now, to be fair, you can already cast away shared, which is naturally @system, and then perform the operation, so we could consider that to be the way of circumventing the checks.

@rikkimax
Copy link
Contributor Author

rikkimax commented Nov 7, 2024

possibly in an inline assembly block

There is no reason to do this.

By not using core.atomic you are bypassing any optimization opportunity that the compiler can offer you. Doing it yourself is both platform specific and compiler IR specific.

@s-ludwig
Copy link
Member

s-ludwig commented Nov 7, 2024

There is no reason to do this.

It depends a lot on the situation, you might be able to use compiler intrinsics, too, but he building blocks in core.atomic can easily be too coarse when doing complex lock-free stuff.

@rikkimax
Copy link
Contributor Author

rikkimax commented Nov 7, 2024

If we want to turn this on only in @safe we're going to need to have a different discussion to decide that. As that is a DIP level change.

Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

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

I don't like this approach, but lets get this fix in

@thewilsonator thewilsonator merged commit a7c85ec into dlang:stable Nov 10, 2024
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants