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

reflect: deprecate SliceHeader and StringHeader #56906

Closed
rsc opened this issue Nov 22, 2022 · 18 comments
Closed

reflect: deprecate SliceHeader and StringHeader #56906

rsc opened this issue Nov 22, 2022 · 18 comments
Assignees
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Nov 22, 2022

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.

@rsc rsc added the Proposal label Nov 22, 2022
@rsc rsc added this to the Proposal milestone Nov 22, 2022
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/452762 mentions this issue: reflect: deprecate SliceHeader and StringHeader

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/452761 mentions this issue: reflect: remove deprecation notices from SliceHeader, StringHeader

gopherbot pushed a commit that referenced this issue Nov 23, 2022
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>
@rsc
Copy link
Contributor Author

rsc commented Nov 30, 2022

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

@rsc
Copy link
Contributor Author

rsc commented Dec 7, 2022

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.

@rsc
Copy link
Contributor Author

rsc commented Dec 14, 2022

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.

@rsc
Copy link
Contributor Author

rsc commented Jan 5, 2023

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.

headers.txt.gz

@rsc
Copy link
Contributor Author

rsc commented Jan 25, 2023

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?

@rsc
Copy link
Contributor Author

rsc commented Feb 1, 2023

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

@mdempsky
Copy link
Contributor

mdempsky commented Feb 2, 2023

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
Copy link
Contributor

bcmills commented Feb 2, 2023

@mdempsky, are the cmd/vet checks from #40701 included in the subset run automatically by go test?

If not, perhaps including them would be a good starting point, and we could reassess whether to fully deprecate them after we give that a release or two to soak.

@mdempsky
Copy link
Contributor

mdempsky commented Feb 2, 2023

@bcmills No, it looks like it's not included in go test by default:

// "-unsafeptr",

@randall77
Copy link
Contributor

I think the question is whether whatever tool surfaces warnings about using deprecated API (staticcheck?) would also run the vet check.

@bcmills
Copy link
Contributor

bcmills commented Feb 3, 2023

@mdempsky, #41205 suggests that the cmd/vet check might not be precise enough.
(That, or we may have some existing violations to clean up ourselves. 😅)

@rsc
Copy link
Contributor Author

rsc commented Feb 8, 2023

Re #56906 (comment), you're right that we don't know the impact. I addressed that in #56906 (comment):

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.

We can roll this back if we need to.

@rsc
Copy link
Contributor Author

rsc commented Feb 9, 2023

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: reflect: deprecate SliceHeader and StringHeader reflect: deprecate SliceHeader and StringHeader Feb 9, 2023
@rsc rsc modified the milestones: Proposal, Backlog Feb 9, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 9, 2023
@FiloSottile
Copy link
Contributor

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

Since the vast majority of existing uses are correct, [...]

and the next comment #56906 (comment) says

we do know that much code using these is incorrect

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

If function F1 is being replaced by function F2 and the first release in which F2 is available is Go 1.N, then an official deprecation notice for F1 should not be added until Go 1.N+2.

to "Go 1.N+1", since we didn't find a better explanation than an off-by-one error for Go 1.N+2?

@ianlancetaylor
Copy link
Contributor

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.

@mknyszek mknyszek modified the milestones: Backlog, Go1.21 Feb 22, 2023
@rsc rsc self-assigned this Mar 31, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/498757 mentions this issue: doc/go1.21: mention changes to the reflect package

gopherbot pushed a commit that referenced this issue May 26, 2023
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>
@golang golang locked and limited conversation to collaborators May 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants