-
Notifications
You must be signed in to change notification settings - Fork 23
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
Generate code using Go generics #20
Conversation
Pull Request Test Coverage Report for Build 2819578613Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Makefile
Outdated
generics: codegen-generics | ||
# generics -> T, except in tests | ||
( cd generics_tree && $(SED) -i -E -e 's/\bgenerics\b/string/g' *_test.go) | ||
( cd generics_tree && $(SED) -i -E -e 's/\bgenerics\b/T/g' *.go) | ||
# Each defined type should be parametrized with T | ||
( cd generics_tree && $(SED) -nE 's/^type (\w+).*/\1/p' *.go \ | ||
| while read T; do \ | ||
$(SED) -i -E -e 's/\b'$$T'\b/\0[T]/g' *.go ; \ | ||
$(SED) -i -E -e 's/\b('$$T')\[T\]/\1[string]/g' *_test.go ; \ | ||
done ) | ||
# Fix type definition | ||
( cd generics_tree && $(SED) -i -E -e 's/^(type \w+)\[T\]/\1[T any]/' *.go) | ||
# NewTreeVX function should be parametrized | ||
( cd generics_tree && $(SED) -i -E -e 's/^(func NewTreeV.)/\1[T any]/' *.go) | ||
( cd generics_tree && $(SED) -i -E -e 's/(NewTreeV.)\(/\1[string](/g' *_test.go) | ||
# No need to cast interfaces | ||
( cd generics_tree && $(SED) -i -E -e 's/\.\(string\)//g' *_test.go) |
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.
@vincentbernat Whats that part of makefile responsible for?
You have used is as part of generating generics_tree
and it still can be used somehow?
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 am unsure to understand your question. For generics_tree
, the codegen-%
rule is used as a first step, but further adaptations are needed. This code does that. The comments should show the different steps, specific to generics.
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.
Ok.. now I understood.. thanks..
@vincentbernat Thanks for contribution. Please give us some time to dig thru generics code and do internal testing. |
I have pushed another commit to update the linter action to support Go 1.18. I think that's why it is failing. Also, before merging this PR, I suppose the README would need to be updated as well. Also, I wonder if there is any difference between code using generics and the specialized code. If not, an option would be to simply wait for Go 1.19 to be released, then Go 1.17 will be out of support and the code using generics could become the main one, without needing to generate stuff. Or it could be done in a v2 branch. |
85df33d
to
0e85eea
Compare
The code mutation is a bit less pretty but it still works well. Tests are kept in this case as they are easy to mutate to check that everything is working. However, this requires bumping the minimal Go version to 1.18. For clarity, generated code will be in a separate commit.
0e85eea
to
51cd9a7
Compare
I have updated the PR to make it work with PR #22. |
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 think this looks good to me. At least it will not break anything.
Note that it will prevent people using older versions of Go, even when they don't use generics. |
I just released |
Pull Request Test Coverage Report for Build 2765547490Details
💛 - Coveralls |
The code mutation is a bit less pretty but it still works well. Tests
are kept in this case as they are easy to mutate to check that
everything is working.
However, this requires bumping the minimal Go version to 1.18.