-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: doc: clarify that Named types are canonical only within one Importer #66690
Comments
CC @griesemer, @findleyr. |
This is expected behavior. Two (non-generic) Named types are only identical if they were produced during the same type-checking pass. See #57497 for a proposal to change this behavior, which is similar to what you request. It would be a very large change, but is perhaps doable and would be useful in a number of scenarios. CC @adonovan |
I was going to close this as "working as intended", but perhaps there's a doc change that could highlight the risk. I've retitled the issue. Although it says go/types, corresponding changes may be wanted in packages.Load and ssautil.BuildPackages. |
Change https://go.dev/cl/577015 mentions this issue: |
Change https://go.dev/cl/577256 mentions this issue: |
Updates golang/go#66690 Change-Id: I26199c39434ab83c1a25756bd5f135a0ea785fad Reviewed-on: https://go-review.googlesource.com/c/tools/+/577256 Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Fixes golang/go#66690 Updates golang/go#57497 Change-Id: I3d8f48d6b9baae8d5518eefeff59c83b12728cf5 Reviewed-on: https://go-review.googlesource.com/c/go/+/577015 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
Go version
go version go1.21.3 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
I used SSA to load the packages and tried to compare the types using
types.Identical
, but if the packages are loaded separately, thetypes.Identical
won't return the correct result.I have written my use cases here: https://github.com/xieyuschen/verify-identical/blob/master/main_test.go.
Its pipeline shows the result: https://github.com/xieyuschen/verify-identical/actions/runs/8564767599/job/23471810349
What did you see happen?
Unexpected Cases
sync
package and get theMutex
type twice, and then check whether they are identical. The result is they're not identical.sync
package and another package which has a variable with typesync.Mutex
, and then check whether they are identical. The result is they're not identical.Successful Case
If I load the package only once, and then get the variable with
sync.Mutex
type from the user-package and the Mutex type from sync package, their types are identical.What did you expect to see?
I want to see that no matter how the packages are loaded and types are retrieved, as long as they're identical(for example, they comes from the same revision of the same code, the
types.Identical
should returntrue
. Sorry for the possible un-precise description of theidentical
due to my limited knowledge about type system. The possible of this idea is that what if users change their dependencies on the fly as the SSA will help you to resolve the dependencies.The current implementation compares the
pointer
directly in the identicalOrigin, which will of course fail the cases I mentioned because loading multiple times produce different pointers. It hits the concern left by @griesemer .I tried a simple change in the
identicalOrigin
in my fork: xieyuschen@78b6c82, but it's not really helpful because even theobj
fields contain different values. I believe this is caused by the pointers hold inside theobj
structure.Due to this, I stoped my investigation as I feel like it's very likely something that closely embedded inside the compiler and a great of complexities are hidden. I am not sure:
go/types
packageIf it's worthy fixing, i would like to spend more time about the details. If not, i'd like to add a comment for both types and SSA to state more details about this.
The text was updated successfully, but these errors were encountered: