-
Notifications
You must be signed in to change notification settings - Fork 18k
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
x/sys/unix: consolidate duplicate information #33059
Comments
This sounds like a very good idea to me! While adding this post-processing step using |
Hello, I am having a "go" at this, since I have been using the go/ast recently and would like to finally contribute to the project. I have a few questions as I have started looking into this.
Thanks. |
We should only be looking at merging information in the generated files, whose names all start with 'z'. The merged file names should also start with 'z'. We currently have 13 files zerrors_linux_GOARCH.go. I'm suggesting that the common aspects be merged into zerrors_linux.go. We shouldn't touch the non-generated files, at least not with an automated process. In the generated files it is not important to preserve blocks of constants. |
Change https://golang.org/cl/221317 mentions this issue: |
Change https://golang.org/cl/221318 mentions this issue: |
I just sent CL 221318 which merges duplicate code for linux files. To make validation easier, please see https://gist.github.com/jupj/639b5cda305d251161fec2304c27c9b9 for a script, and my results, for comparing the changes in the generated files with the merged files. |
Change https://golang.org/cl/221320 mentions this issue: |
Change https://golang.org/cl/221319 mentions this issue: |
mkmerge.go parses generated code (z*_GOOS_GOARCH.go) and merges duplicate consts, funcs, and types, into one file per GOOS (z*_GOOS.go). Updates golang/go#33059 Change-Id: I1439f260dc8c09e887e5917a3101c39b080f2882 Reviewed-on: https://go-review.googlesource.com/c/sys/+/221317 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run mkmerge.go on zerrors_linux_*.go to merge duplicate consts, funcs, and types into zerrors_linux.go Please see https://gist.github.com/jupj/639b5cda305d251161fec2304c27c9b9 for a script to validate these changes. Updates golang/go#33059 Change-Id: I168b5efc7fd6d2fcf7fc8dfe1ef5eea07f07f9c2 Reviewed-on: https://go-review.googlesource.com/c/sys/+/221318 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run mkmerge.go on zsyscall_linux_*.go to merge duplicate consts, funcs, and types into zsyscall_linux.go Also, run mkmerge.go on zsysnum_linux_*.go; currently there is nothing to merge. Please see https://gist.github.com/jupj/639b5cda305d251161fec2304c27c9b9 for a script to validate these changes. Updates golang/go#33059 Change-Id: I715ada044ee957475669d94b16de059ebb9162d1 Reviewed-on: https://go-review.googlesource.com/c/sys/+/221319 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
In the current golang.org/x/sys/unix package, there is a lot of duplication, especially in the GNU/Linux files. We currently support 13 different
GOARCH
values, and more are possible. If I diff, say,zerrors_linux_amd64.go
andzerrors_linux_mips
.go, I see that a bit more than 500 lines are different, but the files are just over 3000 lines long. That suggests that we are repeating 2500 lines of information 13 times.This doesn't really matter all that much, but it does make the package somewhat larger than necessary and makes it slightly harder to review CLs. Since we generate the information automatically anyhow, I propose that we add another step: run a merge step on all the files for a given
GOOS
. For all constants, types, and functions that are defined precisely identically for eachGOARCH
, move them into a single unified file named simplyzerrors_linux.go
. Similarly for zsyscall, zsysnum, and ztypes, of course. It should be straightforward to write the merge program based using go/ast. It doesn't have to be smart: just merge definitions that are exactly identical. If in the future the values are different on some specificGOARCH
, the automatic generation should automatically leave the definitions back in theGOARCH
-specific files.CC @tklauser @paulzhol @mdlayher @josephlr
The text was updated successfully, but these errors were encountered: