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

all: use github.com/deckarep/golang-set/v2 (generic set) #26159

Merged
merged 2 commits into from
Nov 14, 2022
Merged

all: use github.com/deckarep/golang-set/v2 (generic set) #26159

merged 2 commits into from
Nov 14, 2022

Conversation

Jolly23
Copy link
Contributor

@Jolly23 Jolly23 commented Nov 11, 2022

NEW Generics based implementation (requires Go 1.18 or higher) of mapset

@fjl
Copy link
Contributor

fjl commented Nov 11, 2022

This change is good, and we can apply it, but I want to do the upgrade to minimum Go version 1.18 as a separate step.

@fjl
Copy link
Contributor

fjl commented Nov 11, 2022

go.mod Go requirement bump has been submitted in this PR: #26160

@Jolly23
Copy link
Contributor Author

Jolly23 commented Nov 11, 2022

Good to know!

@Jolly23
Copy link
Contributor Author

Jolly23 commented Nov 11, 2022

This change is good, and we can apply it, but I want to do the upgrade to minimum Go version 1.18 as a separate step.

Should I rewrite the fix this PR or you will handle the conflicts?

@fjl
Copy link
Contributor

fjl commented Nov 11, 2022

Looks like the PR is still mergeable even though I updated the go line in master branch.

@fjl fjl changed the title go: update to 1.18 to implement mapset with generics all: use github.com/deckarep/golang-set/v2 (generic set) Nov 11, 2022
@@ -81,8 +81,8 @@ func (s *Server) ServeCodec(codec ServerCodec, options CodecOption) {
}

// Add the codec to the set so it can be closed by Stop.
s.codecs.Add(codec)
defer s.codecs.Remove(codec)
s.codecs.Add(&codec)
Copy link
Contributor

Choose a reason for hiding this comment

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

This change looks like it changes the semantics, since it now adds the pointer to a codec instead of the codec struct. @fjl PTAL to double-check if this is ok

Copy link
Contributor

Choose a reason for hiding this comment

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

I will fix this in a follow-up PR. Using a set here is weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the generic mapset requests a comparable data type. The interface ServerCodec doesn't implement it. So I changed it to a pointer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. This is one the cases where Go generics codifies something that couldn't be expressed in types before. Go allows interface values to be used as map keys, but will panic at runtime if the value contained in the interface is not comparable. With the generic set, this is not possible anymore. There is also no easy way to turn ServerCodec into something 'comparable'.

Have submitted #26180 to remove the pointer.

@fjl fjl merged commit f58ebd9 into ethereum:master Nov 14, 2022
@fjl fjl added this to the 1.11.0 milestone Nov 14, 2022
shekhirin pushed a commit to shekhirin/go-ethereum that referenced this pull request Jun 6, 2023
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