-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: go/types: Create a public CoreType() function #60994
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
Comments
cc @findleyr |
Thanks. IIRC the only reason we didn't expose this function originally is that we weren't quite sure what the API should be (and there was a lot of new API in 1.18). The x/exp/typeparams.NormalTerms API was meant as a placeholder, but we never proposed an API for go/types. Thanks for prodding us in the right direction. We definitely should have an API for the this operation of reducing type sets, because otherwise libraries like Therefore, +1 to this proposal, but I think we should bundle it with an additional API that exposes the normalized representation of the type set. |
@findleyr thanks for the response. I am currently implementing generics support in gopherjs and |
@nevkontakte for something like a compiler I think For analyses (e.g. the printf analyzer), we need to be able to ask questions like "is this true for all/any types in the type set". We should expose APIs that can answer these questions. But there is no question in my mind that we should have a |
I opened #61013 to track an API for interface terms. I don't want that to distract from this proposal, which can be decided independently. |
I agree that we should export CoreType. But unlike Underlying it may return nil, which is quite a subtlety that needs to be at least documented clearly. Does it warrant a (Type, bool) result to force callers to consider this case? I tend to think not. |
|
If we export CoreType(), we probably need to decide on a representation for bytestring which is both a core type and has a type set size of 2 (https://go.dev/ref/spec#Core_types). |
Putting this on hold until we have decided #70128, which may make this redundant. |
Closing as obsolete. |
Core types is a first-class concept in the Go Spec, which was introduced with type parameter support. go/types is the official package for tooling developers to interact with type information for Go programs, but it doesn't offer a public API to determine a core type. As a result, this logic has been reimplemented multiple times by independent parties [1, 2, 3], which isn't ideal for obvious maintenance reasons.
Proposal: Make the currently unexported
coreType()
implementation ingo/types
exported for everyone to use.The text was updated successfully, but these errors were encountered: