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
spec: investigate if we can remove (most or all) needs for the concept of a core type #63940
Comments
cc: @ianlancetaylor |
Also CC @findleyr. |
Thanks for filing this. As a general rule, I think wherever we can avoid referring to core types the spec gets lighter and the generics implementation gets more useful. However, this benefit is not uniformly distributed. For example, while I think it would be very nice to remove restrictions on struct field access, it is less useful to avoid restrictions on e.g. range statements (do we really need to be able to range over So I think it is a good goal to avoid referencing core types. It would be quite an achievement to avoid all references, but that's probably not strictly necessary. (Also, if we can narrow it down to a just handful of references, perhaps we can phrase restrictions without needing to reference a "core type" abstraction). |
@findleyr, I agree that not being able to range over For example, I would expect to be able to range over |
@bcmills I think that's an example of where some restrictions may still be required, but need not be expressed in terms of a "core type" abstraction. For example, we can insist that the key and/or value types be well-defined. |
Does the Go team is waiting to release other Generics features or any Core types refactor that should be part of this investigation at some point? I am trying to understand if there is any current or short-term work that would be preventing this investigation to happen sooner, thanks. |
We are all busy and must prioritize among many different issues. Assigning a release milestone won't affect how quickly we focus on this issue. What would matter instead is reasons in favor of, or against, working on this issue. Thanks. |
The original generics proposal (#43651) and accompanying detailed design doc didn't specify the notion of a core type.
The spec introduced core types to determine whether an operation is permitted on a generic operand (i.e., an operand with a type containing a type parameter). Core types are also used to explain type inference involving constraints. This was mostly to have a somewhat manageable implementation and specification path from the code before generics to the code with generics, while not being too restrictive in practice.
On the other hand, the original proposal essentially just said that an operation is permitted if it is permitted for all types in the type set defined by the constraint. That is a more general approach and it may also be easier to understand (though not easier to implement).
We should investigate if we can avoid the use of core types more widely. We already do avoid them for some operations, such as indexing. If we can avoid them everywhere, we should be able to enable some desired features (such as #48522) w/o extra rules but as a matter of course.
Umbrella issue for changes related to this.
The text was updated successfully, but these errors were encountered: