-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
go/types, types2: fix SizesFor("gc", ...) to match actual gc behavior #61035
Comments
Change https://go.dev/cl/506715 mentions this issue: |
Change https://go.dev/cl/506716 mentions this issue: |
Change https://go.dev/cl/506856 mentions this issue: |
For future reference: The typechecker's StdSizes documentation explains how sizes are computed. If we want to use it for gc sizes, we need to either update the documentation for array and struct sizes, or add a flag to StdSizes that allows clients to choose the new behavior. https://go.dev/cl/506856 already has an implementation that uses an internal (const) flag to select the appropriate sizes computation. We could simply move this flag into the StdSizes struct and expose it as a field. This way we don't change the existing behavior for backward-compatibility and also can enable the new behavior as needed. |
Kicking over to proposal process for minor API change (even if the only change is in doc comments). |
Worth noting that we cannot return a different type from SizesFor, because x/tools/go/package assumes StdSizes:
|
Yeah, I realized this when doing https://go-review.googlesource.com/c/go/+/506856. |
The two choices here are:
It would be highly preferable to do (1), assuming gc and gccgo do agree and go/types is the current outlier. @ianlancetaylor do you know whether gc and gccgo disagree about any specific type size calculations? |
This proposal has been added to the active column of the proposals project |
The gofrontend code used by gccgo and GoLLVM lets the backend determine the sizes of all types. The effect is that gccgo and GoLLVM use the C ABI on all platforms. This does indeed mean different type characteristics in some cases, though they are mostly the same. For example for package main
import (
"fmt"
"unsafe"
)
func main() {
fmt.Println(unsafe.Alignof(float64(0)))
} |
@ianlancetaylor It seems to me that the only difference between
So probably we could just go for (1) in @rsc 's comment. cc @griesemer |
It sounds like we cannot make StdSizes return numbers matching gc and gccgo because the two don't match. The constraints are that types.SizesFor returns a *StdSizes, and so it needs to return the StdSizes filled out differently for SizesFor("gc", "386") and SizesFor("gccgo", "386"), but we need to know what extra information to add to StdSizes. (We'd rather not have 'Compiler string' in StdSizes. It seems better to have the specific details from the algorithm, and let the compiler name be "compiled away" by SizesFor.) |
I don't see why this means SizesFor cannot return a different type. SizesFor was never documented to always return a *StdSizes. I would call this x/tools/go/package depending on an implementation detail. Is it really easier to change the definition of StdSizes for everyone than to fix the assumption in x/tools? |
Nothing ever promised SizesFor would return a *StdSizes. Updates golang/go#61035 Change-Id: Ib54a7c9d4898cd435e87aea32067a9cfa6975367 Reviewed-on: https://go-review.googlesource.com/c/tools/+/516917 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Michael Matloob <matloob@golang.org>
Change https://go.dev/cl/519295 mentions this issue: |
Same as CL 516917, but for gopls. Updates golang/go#61035 Change-Id: Id6cc1d84f7cac06e95a1fb151a7c3f9a8ef25302 Reviewed-on: https://go-review.googlesource.com/c/tools/+/519295 gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
With #61035 fixed, types2.Sizes matches the compiler behavior, so use its Sizes implementation instead of rolling our own copy. Updates #61035 Change-Id: I7b9efd27a01f729a04c79cd6b4ee5f417fe6e664 Reviewed-on: https://go-review.googlesource.com/c/go/+/506716 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
Change https://go.dev/cl/520435 mentions this issue: |
go get golang.org/x/tools@74c255b # CL 519295 go mod tidy go mod vendor Pulling in the fix for unnecessary dependency on *types.StdSizes, which is non guaranteed behavior. Updates #61035 Change-Id: Ifb04bab060343b6a849980db6bb65da9889b4665 Reviewed-on: https://go-review.googlesource.com/c/go/+/520435 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Change https://go.dev/cl/520835 mentions this issue: |
Change https://go.dev/cl/520855 mentions this issue: |
This picks up CL 516917 to fix test failures in internal/worker. For golang/go#61035. Change-Id: I1d7162f2775548423647f7b00ccdc8d860afdc97 Reviewed-on: https://go-review.googlesource.com/c/pkgsite-metrics/+/520855 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This picks up CL 516917 to fix test failures in cmd/gobind. For golang/go#61035. Change-Id: Ibecb7ace6ce9133a25559191ee6075bbb714a7d7 Reviewed-on: https://go-review.googlesource.com/c/mobile/+/520835 Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com>
We've seen quite a few tests fail in Go subrepos and in Google-internal testing from this. Is it feasible to add a |
I'm not sure it's worth, given Russ's comment here: #61035 (comment) I think most of the test failed because it's buggy code which is relying on SizesFor always returns StdSizes, we should rather fix them then leaving them continue with buggy behavior. |
Change https://go.dev/cl/546837 mentions this issue: |
For #61035. Change-Id: I27e2c44f9275b508d9dccc50da80896384a4c8fc Reviewed-on: https://go-review.googlesource.com/c/go/+/546837 TryBot-Bypass: Robert Griesemer <gri@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com>
For golang#61035. Change-Id: I27e2c44f9275b508d9dccc50da80896384a4c8fc Reviewed-on: https://go-review.googlesource.com/c/go/+/546837 TryBot-Bypass: Robert Griesemer <gri@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com>
Replace https://go.dev/cl/501495 with proper fix in go/types.
The text was updated successfully, but these errors were encountered: