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
Issue 22300 - Allow shared <-> unshared reinterpreting casts during CTFE #13203
Issue 22300 - Allow shared <-> unshared reinterpreting casts during CTFE #13203
Conversation
CTFE evaluation is single threaded only, hence it's safe to discard the `shared` qualifier in a reinterpreting cast. This change allows `-checkaction=context` to use a reinterpreting cast for compile and runtime - which removes the problematic workaround that caused the regression.
Thanks for your pull request and interest in making D better, @MoonlightSentinel! 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 "stable + dmd#13203" |
cc @UplinkCoder |
@MoonlightSentinel CTFE must not expose the undefined behavior. |
@MoonlightSentinel I'd like to see the usecase first before coming to a decision is this is okay to do. |
There's no undefined behavior involved. Casting away |
It's intended as a fallback for code that would normally use |
@MoonlightSentinel If you intended to have |
That doesn't work for types not supported by |
I dislike the idea of allowing shared to be cast away at CTFE without having had time to think about it properly. |
Certain constructs not working in CTFE is good if the results are not portable (rely on UB as you mentioned before). But removing Note that this PR retains the restriction for |
@MoonlightSentinel I'll merge it if it's behind a preview. |
(Also note that this is already supported for basic integral types) |
That's a concerning. |
I don't think this is a problem. CTFE variables are evaluated in a single-threaded environment. Also, I think resolving this and other reinterpret cast issues are a good way forward to make CTFE less restrictive. |
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 hate special cases, but it does have proven utility and no foreseeable downside.
Oh, I just realized why you CCed me. Forgot about that issue. And yeah, we disabled |
Using the same method for compile- and runtime was enabled by dlang/dmd#13203. Using a reinterpreting cast avoids any potentially calling into user-defined `opCast` methods which might reject the cast.
Me neither. CTFE could even safely support mutable <-> immutable because it keeps track whether the referenced value is actually mutable and hence rejects invalid modifications. But that's out of scope for this PR. |
Using the same method for compile- and runtime was enabled by dlang/dmd#13203. Using a reinterpreting cast avoids any potentially calling into user-defined `opCast` methods which might reject the cast.
Using the same method for compile- and runtime was enabled by dlang/dmd#13203. Using a reinterpreting cast avoids any potentially calling into user-defined `opCast` methods which might reject the cast.
CTFE evaluation is single threaded only, hence it's safe to discard the
shared
qualifier in a reinterpreting cast.This change allows
-checkaction=context
to use a reinterpreting castfor compile and runtime - which removes the problematic workaround
that caused the regression.
CC @Geod24