Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive

[core.atomic] atomicStore for alias this#3052

Closed
thewilsonator wants to merge 4 commits intodlang:masterfrom
thewilsonator:atomic-implicit-conv
Closed

[core.atomic] atomicStore for alias this#3052
thewilsonator wants to merge 4 commits intodlang:masterfrom
thewilsonator:atomic-implicit-conv

Conversation

@thewilsonator
Copy link
Contributor

@kinke the corresponding LDC commit mentions some unit tests, but I presume that they are in the main LDC repo, but I can't fin the correspond PR/commit. Do you know where they are and should they be moved to druntime?

@dlang-bot
Copy link
Contributor

dlang-bot commented Apr 21, 2020

Thanks for your pull request and interest in making D better, @thewilsonator! 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

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

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 + druntime#3052"

@kinke
Copy link
Contributor

kinke commented Apr 21, 2020

I couldn't find the unittest after a quick search either, maybe it has been removed in the meantime. Anyway, a simple test that works for LDC but not DMD due to this would be:

unittest
{
    static struct S
    {
        int a;
        alias a this;
    }

    import core.atomic;
    S s;
    atomicStore(s, 123);
}

@thewilsonator
Copy link
Contributor Author

Awesome. Thanks!

@thewilsonator
Copy link
Contributor Author

Tests added.

@Geod24
Copy link
Member

Geod24 commented Apr 21, 2020

Do we really need this implicit conversion magic though ? The argument is passed by ref, implicit conversions are not expected. I'd argue that anyone that wants to do this should specify T explicitly on the caller side.
If you really want implicit conversions, the signature should reflect it, e.g. T should be deduced to be the common acceptable type.

@thewilsonator
Copy link
Contributor Author

Git blames #2745 for the comment // resolve implicit conversions
cc'ing @TurkeyMan

@TurkeyMan
Copy link
Contributor

TurkeyMan commented Apr 22, 2020

My refactor to simplify and untangle the implementation expects that all weird type wrangling is in the front-end wrappers. The internal functions deal only with one type, and should be the only functions required for the implementations to fork.

"Implicit conversion" is for cases like T == int and V == short. Or T == Base* and V == Derived*.

The case in question with alias this feels weird to me. I'm not sure I call that an 'implicit conversion'... that's something else, and I don't know how deep that rabbit hole goes.
I think I'd rather make a patch to exclude this case (leading to compile error) rather than trying to handle it like this.

Should we add the constraint is(V : T) to the function?

@RazvanN7
Copy link
Contributor

@Geod24 Since alias this is a language feature I don't see why we should not support it in this case. I wouldn't call it implicit conversion since the user explicitly defined the alias this.

I agree that a better solution would be to stress out the condition in the template constraint so that in case of screw ups the compiler doesn't point to the innards of atomicStore.

@thewilsonator Please update the function signature so that we can get this in.

@thewilsonator
Copy link
Contributor Author

Please update the function signature so that we can get this in.

To what? && is(V : T)?

@RazvanN7
Copy link
Contributor

To what? && is(V : T)?

Yes.

@thewilsonator
Copy link
Contributor Author

Done..

@RazvanN7 RazvanN7 added the 72h no objection -> merge The PR will be merged if there are no objections raised. label Aug 31, 2021
@RazvanN7
Copy link
Contributor

Thanks!

@thewilsonator
Copy link
Contributor Author

Hmm, this probably needs a rebase

@RazvanN7
Copy link
Contributor

RazvanN7 commented Aug 31, 2021

Nope, the error is legit. You probably need to switch the types of the is expression: is(T : V)

@thewilsonator
Copy link
Contributor Author

Sorry, seems I missed this. Suggestion applied. Lets see if this works.

@RazvanN7
Copy link
Contributor

This doesn't seem to be going anywhere. Also, pondering upon it, I agree with @Geod24 : "Do we really need this implicit conversion magic though ? The argument is passed by ref, implicit conversions are not expected.". Feel free to reopen if you still want to pursue this.

@RazvanN7 RazvanN7 closed this Nov 25, 2021
@RazvanN7 RazvanN7 removed the 72h no objection -> merge The PR will be merged if there are no objections raised. label Nov 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants