Skip to content
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

Open
griesemer opened this issue Nov 3, 2023 · 7 comments
Assignees
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. umbrella
Milestone

Comments

@griesemer
Copy link
Contributor

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.

@griesemer griesemer added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. umbrella labels Nov 3, 2023
@griesemer griesemer added this to the gopls/unplanned milestone Nov 3, 2023
@griesemer griesemer self-assigned this Nov 3, 2023
@griesemer
Copy link
Contributor Author

cc: @ianlancetaylor

@dmitshur
Copy link
Contributor

dmitshur commented Nov 3, 2023

Also CC @findleyr.

@findleyr findleyr modified the milestones: gopls/unplanned, Unplanned Nov 3, 2023
@findleyr
Copy link
Contributor

findleyr commented Nov 3, 2023

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 []int|map[string]bool?).

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).

@bcmills
Copy link
Contributor

bcmills commented Nov 6, 2023

@findleyr, I agree that not being able to range over []int|map[string]bool is not a big deal, but I think core types are problematic even for range statements.

For example, I would expect to be able to range over map[string]bool | map[string]struct{}, even though IIUC such a constraint does not have a core type today.

@findleyr
Copy link
Contributor

findleyr commented Nov 6, 2023

@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.

@piroux
Copy link

piroux commented Apr 12, 2024

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?
If not, could we add this investigation to a release milestone?

I am trying to understand if there is any current or short-term work that would be preventing this investigation to happen sooner, thanks.

@ianlancetaylor
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. umbrella
Projects
None yet
Development

No branches or pull requests

6 participants