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

go/types,cmd/compile/internal/types2: APIs for constructing and destructing constraint types #46316

Closed
mdempsky opened this issue May 22, 2021 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mdempsky
Copy link
Member

It seems there are a few methods for querying whether an Interface represents a constraint (e.g., HasTypeList, IsComparable, IsConstraint), but there don't seem to be any APIs currently for users to iterate the type list or to construct the same interface again. This is necessary to support exporting constraints that use type lists.

/cc @griesemer @findleyr @danscales

@mdempsky mdempsky added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 22, 2021
@mdempsky mdempsky added this to the Go1.18 milestone May 22, 2021
@griesemer
Copy link
Contributor

griesemer commented May 22, 2021

With the pending CL 321689, interfaces that contain constraints are not different anymore from interfaces that have embedded types. There's one new type(set), called a Union. I believe we simply need to export the explicitly declared methods and embedded elements, some of which may be unions. A union in turn is simply a list of types, together with a bit for each type indicating whether it's a "~" or not. Upon import, we should construct the internal representation lazily.

@mdempsky
Copy link
Member Author

Thanks, that sounds good to me.

NewUnion looks good for importers. I think Union will need term/tilde accessors for exporters though; I don't see any at https://go-review.googlesource.com/c/go/+/321689/8/src/cmd/compile/internal/types2/union.go.

@mdempsky
Copy link
Member Author

mdempsky commented Jun 8, 2021

I'm going to close this issue. We have the APIs needed in types2 on the dev.typeparams, and I expect the corresponding go/types APIs will be included as part of @findleyr 's go/types API extensions proposals.

@mdempsky mdempsky closed this as completed Jun 8, 2021
@golang golang locked and limited conversation to collaborators Jun 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants