-
-
Notifications
You must be signed in to change notification settings - Fork 610
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 Issue 23639 - Casting to shared not allowed with -preview=nosharedaccess #14836
Conversation
|
Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
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
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#14836" |
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.
Given it's still in preview, and in the absence of anything better, I think this is okay.
However, I think this will permit this:
shared string s;
string s2 = cast(shared) s;
So it might need more thought long term.
|
No it doesn't. If you run that code it gives: "direct access to shared |
|
Oh, that's good |
|
Isn't this a special case patching over an issue with the nosharedaccess check? IIRC this same issue also breaks nosharedaccess atomics with ldc because the cast is badly analyzed and/or then "optimized" to strip out the shared (this is actually tested with a static assert somewhere in the test suite) |
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.
Couple of thing I'd like clarified before this is merged.
| if (e.type.isShared()) | ||
| // https://issues.dlang.org/show_bug.cgi?id=23639 | ||
| // Should be able to cast(shared) | ||
| if (!e.isCastExp() && e.type.isShared()) |
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.
what does this do to const shared?
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.
If you cast to const shared it just performs the cast.
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.
please augment the test case then.
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? Before this patch the cast would not have been allowed, but now it is allowed. Note that the code would fail because you cannot convert a const(shared) to a shared.
| { | ||
| void *p; | ||
| // assume p is allocated here | ||
| return cast(shared(T))p; |
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.
what is the @safety of this operation?
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.
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.
and if typeof(p) == T?
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.
The modified code has nothing to do with the safety checks. Casts to differently qualified types remain unsafe, that part is not modified.
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.
-preview=nosharedaccess is all about safety. even if the end result is that the code must be system. Perhaps I was thinking things wrong, but it seems to me that the only reason why you would want to do this with -preview=nosharedaccess is because you have a unique reference to an object you then want to share. Its fine if that needs to be trusted, then please disregard this request for changes, but please do document this discussion in the test case.
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.
Yes, a prime example of this is memory allocation. You allocate heap memory which is naturally shared among threads and you want to express that. What other way of casting the mallocd memory to shared is there?
Well, You call this patch special casing. Fine, but I have no idea what is the general problem other than "casting to shared is not allowed".
Without a test case, I have no idea what you are referring to. |
|
@thewilsonator I have added a fail_compilation test. @maxhaton Ping. This is blocking progress on templating druntime hooks. |
Casting to shared should be allowed even if the result is returned, read or written because the variable has just been "promoted" to shared so it's not being actually shared with anyone. This is currently blocking the templatization of the __d_new_class runtime hook (cc @teodutu ).