-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
reflect: deprecate SliceHeader and StringHeader #56906
Comments
Change https://go.dev/cl/452762 mentions this issue: |
Change https://go.dev/cl/452761 mentions this issue: |
There has been no proposal discussion about adding these notices. Also, even if we did decide to add them, then since their replacements are only appearing in Go 1.20, go.dev/wiki/Deprecation says that we should wait until Go 1.22 to add the deprecation notice. Filed #56906 for the proposal discussion. Fixes #56905. Change-Id: If86cce65aa00b4b62b2b18e82503431dcbdbcfed Reviewed-on: https://go-review.googlesource.com/c/go/+/452761 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This proposal has been added to the active column of the proposals project |
It would be very helpful to know how much code this will affect. Despite the dire warnings in the commentary right now, there are compiler special cases (which we can't remove) that make the code correct today. If there is a lot of code like this, flagging it with a deprecation warning is a lot of churn. |
Per https://github.com/golang/go/wiki/Deprecated we cannot add deprecated notices until Go 1.22. I'd still like to know more about how much code this will flag. |
I downloaded the latest release and prerelease version of each module known to proxy.golang.org (using index.golang.org's list) as of a few weeks ago. Grepping for StringHeader or SliceHeader in that code turns up many many many matches (attached). Since the vast majority of existing uses are correct, I am not sure that it makes sense to mark these types deprecated and trigger warnings in all this code. If we ever decide to change the representation of strings or slices, then it might make sense to go through that pain. Today I am not sure it does. |
It still seems like we don't know the full impact, but we do know that much code using these is incorrect, and there are much better alternatives now, so marking them deprecated seems at least worth trying. Have all concerns about this proposal been addressed? |
Based on the discussion above, this proposal seems like a likely accept. |
According to https://github.com/golang/go/wiki/Deprecated, "An API feature should only be marked deprecated if its use is problematic in some way, not simply because something newer exists." I agree that reflect.{String,Slice}Header are problematic in the sense that they're much easier to misuse than the newer unsafe.{String,Slice}{,Data} APIs, and that misuse can lead to very subtle memory corruption. But I also believe the cmd/vet checks added for #40701 are reasonably precise at catching all misuse patterns that appear in practice. So arguably users that pay attention to warnings should already have correct code bases, and the deprecation warning would serve just as noise/churn for them. So as much as I dislike the reflect header types, it's not obvious to me that formally marking them deprecated is actually a net-win for end users. Though I'm not against it either. |
@bcmills No, it looks like it's not included in go/src/cmd/go/internal/test/test.go Line 655 in 88a36c9
|
I think the question is whether whatever tool surfaces warnings about using deprecated API (staticcheck?) would also run the vet check. |
Re #56906 (comment), you're right that we don't know the impact. I addressed that in #56906 (comment):
We can roll this back if we need to. |
No change in consensus, so accepted. 🎉 |
It might be because I didn't follow the unsafe.{String,Slice}{,Data} proposals closely enough, but I feel like there's hidden context in the decision process here that would be worth linking to or spelling out. #56906 (comment) says
and the next comment #56906 (comment) says
Those two can just both be true at the same time, but maybe there was a discussion in between? Also, are we officially amending the https://go.dev/wiki/Deprecated rule
to "Go 1.N+1", since we didn't find a better explanation than an off-by-one error for Go 1.N+2? |
I changed https://go.dev/wiki/Deprecated. I don't think there was any big discussion in between, I think it's more what you say: it does seem that most current uses are correct, but there are also many (but a minority) of incorrect uses. |
Change https://go.dev/cl/498757 mentions this issue: |
Added Value.Clear, deprecated SliceHeader and StringHeader. For #55002 For #56906 Change-Id: Ib7497aff830d56fad90c31ec28596e71a448e9ce Reviewed-on: https://go-review.googlesource.com/c/go/+/498757 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Eli Bendersky <eliben@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
reflect.SliceHeader and reflect.StringHeader were marked deprecated in the Go 1.19 cycle and in the Go 1.20 cycle, both times without a proposal discussion. Filing this issue for the proposal discussion.
The text was updated successfully, but these errors were encountered: