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

Add CompareAndSwap and Swap for String and Error. Deperecate CAS to reflect stdlib Value. #108

Closed
wants to merge 4 commits into from

Conversation

eNV25
Copy link
Contributor

@eNV25 eNV25 commented Jul 12, 2022

Before opening your pull request, please make sure that you've:

  • updated the changelog if the change is user-facing;
  • added tests to cover your changes;
  • run the test suite locally (make test); and finally,
  • run the linters locally (make lint).

Thanks for your contribution!

Add CompareAndSwap and Swap for String and Error. Deperecate CAS to reflect stdlib Value.

This is not done for Time since it is not meant to be compared.

@CLAassistant
Copy link

CLAassistant commented Jul 12, 2022

CLA assistant check
All committers have signed the CLA.

@eNV25 eNV25 marked this pull request as ready for review July 12, 2022 10:12
@eNV25 eNV25 changed the title My Add type for func(), Backport atomic.Value, Use CompareAndSwap not CAS Jul 12, 2022
@eNV25 eNV25 marked this pull request as draft July 30, 2022 06:05
@eNV25 eNV25 changed the title Add type for func(), Backport atomic.Value, Use CompareAndSwap not CAS Backport atomic.Value from go1.17 to previous versions Jul 30, 2022
@eNV25 eNV25 marked this pull request as ready for review July 30, 2022 06:36
@eNV25
Copy link
Contributor Author

eNV25 commented Jul 30, 2022

I updated the PR. I removed the atomic type for func() here, since that was not the main point of the PR.

@rabbbit
Copy link

rabbbit commented Jul 31, 2022

Thank you for the contribution, but could you explain why you're doing this? What is the ultimate goal?

Go <1.17 is EOL, so it doesn't seem very useful to support that. It looks like Go 1.19 will bring it's own changes to the atomic as well.

@eNV25
Copy link
Contributor Author

eNV25 commented Jul 31, 2022

I was looking for the CompareAndSwap and Swap methods for atomic.String (and atomic.Error) and I couldn't find them. I thought it must have been since atomic.Value didn't support them before go1.17, but now it just looks like nobody bothered to update them.

I will change the PR to remove the backport, since you are fine with old versions being unsupported, but I will keep the rest of the changes that add CompareAndSwap and Swap, and deprecate CAS.

@eNV25 eNV25 changed the title Backport atomic.Value from go1.17 to previous versions Add CompareAndSwap and Swap for String and Error. Deperecate CAS to reflect stdlib Value. Jul 31, 2022
@rabbbit
Copy link

rabbbit commented Aug 3, 2022

Hey,

Generally, since the PR title is now "do X and do Y", and X is independent from Y, I would keep them as separate PRs.

Regarding the change itself:

  • I'm not sure whether we want to deprecate the naming. Doesn't seem worth it, unless you convince other maintainers.
  • I don't have much context on string.Swap, but it seems to seem reasonable.

@eNV25
Copy link
Contributor Author

eNV25 commented Aug 4, 2022

I'm not sure whether we want to deprecate the naming. Doesn't seem worth it, unless you convince other maintainers.

This is to align with stdlib sync/atomic. From go1.19 it has types much like this package, (e.g. sync/atomic.Bool.CompareAndSwap).

https://pkg.go.dev/sync/atomic

I don't have much context on string.Swap, but it seems to seem reasonable.

There was the following comment in the source code:

// Note: No Swap as String wraps Value, which wraps the stdlib sync/atomic.Value which
// only supports Swap as of go1.17: golang/go#39351

Now the situation is different. go1.17 added Value.CompareAndSwap and Value.Swap, and go1.19 added T.CompareAndSwap, T.Swap.

Go <1.17 is EOL, so it doesn't seem very useful to support that. It looks like Go 1.19 will bring it's own changes to the atomic as well.

@rabbbit
Copy link

rabbbit commented Aug 5, 2022

Could you put up all the 3 changes (names, swap, formatting) in separate PRs, please?

We can discuss merits of each of them individually.

@eNV25
Copy link
Contributor Author

eNV25 commented Aug 5, 2022

Could you put up all the 3 changes (names, swap, formatting) in separate PRs, please?

You want like this?

  • all: go fmt ./... go1.19
  • Add CAS, Swap for String, Error
  • Deprecate CAS, Add CompareAndSwap

@eNV25 eNV25 closed this Aug 5, 2022
@eNV25
Copy link
Contributor Author

eNV25 commented Aug 5, 2022

Now I have 4 commits in this branch.

The deprecation change depends on the previous one, and so can't submit simultaneous PRs without the history looking weird. I will have to keeps those together.

I will submit the other commits as separate PRs.

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.

3 participants