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

Comments

@mdempsky
Copy link
Member

@mdempsky mdempsky commented May 22, 2021

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 this to the Go1.18 milestone May 22, 2021
@griesemer
Copy link
Contributor

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

Loading

@mdempsky
Copy link
Member Author

@mdempsky mdempsky commented May 22, 2021

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.

Loading

@mdempsky
Copy link
Member Author

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

Loading

@mdempsky mdempsky closed this Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants