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

constraints: move to x/exp for Go 1.18 #50792

Closed
rsc opened this issue Jan 25, 2022 · 8 comments
Closed

constraints: move to x/exp for Go 1.18 #50792

rsc opened this issue Jan 25, 2022 · 8 comments

Comments

@rsc
Copy link
Contributor

@rsc rsc commented Jan 25, 2022

There are still questions about the the constraints package. To start with, although many people are happy with the name, many are not. On top of that, it is unclear exactly which interfaces are important and should be present and which should be not. More generally, all the considerations that led us to move slices and maps to x/exp apply to constraints as well.

We left constraints behind in the standard library because we believed it was fundamental to using generics, but in practice that hasn't proven to be the case. In particular, most code uses any or comparable. If those are the only common constraints, maybe we don't need the package. Or if constraints.Ordered is the only other commonly used constraint, maybe that should be a predeclared identifier next to any and comparable. The ability to abbreviate simple constraints let us remove constraints.Chan, constraints.Map, and constraints.Slice, which probably would have been commonly used, but they're gone.

Unlike other interfaces like, say, context.Context, there is no compatibility issue with having a constraint interface defined in multiple packages. The problems that happen with duplicate interfaces involve other types built using that type, such as func(context.Context) vs func(othercontext.Context). But that cannot happen with constraints, because they can only appear as type parameters, and they are irrelevant to type equality for a particular substitution. So having x/exp/constraints and later having constraints does not cause any kind of migration problem at all, unlike what happened with context.

For all these reasons, it probably makes sense to move constraints to x/exp along with slices and maps for Go 1.18 and then revisit it in the Go 1.19 or maybe Go 1.20 cycle. (Realistically, we may not know much more for Go 1.19 than we do now.)

Discussed with @robpike, @griesemer, and @ianlancetaylor, who all agree.

@rsc rsc added the Proposal label Jan 25, 2022
@gopherbot gopherbot added this to the Proposal milestone Jan 25, 2022
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals Jan 25, 2022
@rsc rsc moved this from Incoming to Active in Proposals Jan 26, 2022
@rsc
Copy link
Contributor Author

@rsc rsc commented Jan 27, 2022

Based on the discussion above, this proposal seems like a likely accept.
— rsc for the proposal review group

@rsc rsc moved this from Active to Likely Accept in Proposals Jan 27, 2022
@rsc rsc moved this from Likely Accept to Accepted in Proposals Feb 2, 2022
@rsc
Copy link
Contributor Author

@rsc rsc commented Feb 2, 2022

No change in consensus, so accepted. 🎉
This issue now tracks the work of implementing the proposal.
— rsc for the proposal review group

@rsc rsc changed the title proposal: constraints: move to x/exp for Go 1.18 constraints: move to x/exp for Go 1.18 Feb 2, 2022
@rsc rsc removed this from the Proposal milestone Feb 2, 2022
@rsc rsc added this to the Backlog milestone Feb 2, 2022
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 2, 2022

Change https://golang.org/cl/382535 mentions this issue: constraints: new package

gopherbot pushed a commit to golang/exp that referenced this issue Feb 2, 2022
Move to exp from the pre-1.18 standard library.

For golang/go#45458
For golang/go#50792

Change-Id: I70f054c9d68c20e98e750f6501f3eabd04a70f17
Reviewed-on: https://go-review.googlesource.com/c/exp/+/382535
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 2, 2022

Change https://golang.org/cl/382460 mentions this issue: constraints: remove package

@bcmills
Copy link
Member

@bcmills bcmills commented Feb 3, 2022

The tests for x/exp/constraints had apparently imported the wrong package, and were broken by this removal.
I'll send a CL to update them. (Reopening until the test cleanup is complete.)

@bcmills bcmills reopened this Feb 3, 2022
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 3, 2022

Change https://golang.org/cl/382834 mentions this issue: constraints: test against the constraints package from x/exp instead of std

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 4, 2022

Change https://golang.org/cl/383254 mentions this issue: _content: change generic min example to index

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 7, 2022

Change https://golang.org/cl/383694 mentions this issue: _content/doc: Update generics tutorial to not mention constraints package

gopherbot pushed a commit to golang/website that referenced this issue Feb 8, 2022
…kage

Following decision in golang/go#50792

Change-Id: I71d74b4b386aacef5319663c397479cac6feb32f
Reviewed-on: https://go-review.googlesource.com/c/website/+/383694
Reviewed-by: DO NOT USE <iant@google.com>
Reviewed-by: Eli Bendersky <eliben@google.com>
gopherbot pushed a commit to golang/website that referenced this issue Feb 8, 2022
This avoids importing the constraints package, which is no longer in
the standard library.

For golang/go#50792

Change-Id: I0e0f48d414e87418a1fe95e500bb7629127007cc
Reviewed-on: https://go-review.googlesource.com/c/website/+/383254
Reviewed-by: Eli Bendersky‎ <eliben@golang.org>
Reviewed-by: Eli Bendersky <eliben@google.com>
Trust: DO NOT USE <iant@google.com>
Run-TryBot: DO NOT USE <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
barweiss pushed a commit to barweiss/go-tuple that referenced this issue Mar 16, 2022
The constraints builtin has been removed as per
[this issue](golang/go#50792).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Proposals
Accepted
Development

No branches or pull requests

3 participants