-
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
spec: review/clarify uses of "slice of bytes" #23814
Comments
I just ran into this issue. I think it's valuable to at least come to a shared agreement on what we think the right behavior is, so we can start aligning the implementations. I think the spec cases relevant here are:
My 2c is that the spec should allow this compilation unit:
That is, I think we should liberally interpret "slice of bytes" and "slice of runes" to mean "slice type with element type of underlying type byte/rune". I.e., defined slice types and (user-)defined element type should be allowed. gccgo accepts this. cmd/compile and go/types currently reject the go/types currently additionally rejects the (Also notably, cmd/compile's typechecker allows |
@rsc, @ianlancetaylor, @robpike Do you have any opinions here? We're inconsistent at the moment and different implementations (cmd/compile, gccgo, go/types) differ for operations where this matters. |
Personally, if there's any ambiguity that needs to be specified, I'd prefer to be a permissive as possible, letting copies/appends/conversions work as expected if the underlying representation is the same. |
I'm inclined to agree with @mdempsky 's comment #23814 (comment) . I don't see any particular reason to restrict operations on a "slice of bytes" to only the type |
I just rediscovered this in #36965. Is there sufficient consensus here that I can fix cmd/compile’s implementation to use a maximally liberal interpretation of “byte slices? Other things to check on once the desired direction is clear: is the spec clear enough? Do go/types, package reflect, cmd/compile, and gccgo agree? |
(The reason I’d like to fix cmd/compile now/soon is that I’m touching this code anyway for #36890.) |
@josharian The reason for this issue is that not all implementations agree. @mdempsky 's comment explains how they disagree. I think we should first get the spec to be crystal clear before making changes. It sounds like we're leaning towards making the interpretation more liberal, so this should not break future code, but enable more. This is not urgent, either. |
Marking for Go 1.15. |
It looks like the consensus here is that "slice of bytes" should be maximally liberal, which would mean any slice of elements whose underlying type is bytes. |
@griesemer This issue has milestone 1.18; shall we move to 1.19 or backlog? |
This is documentation that we might be able to address. Prefer to leaving open for now. |
Moving to 1.19. See also: test cases. |
Change https://go.dev/cl/412094 mentions this issue: |
The above CL adjusts the spec to interpret slice of bytes/runes in the most liberal way (underlying type of the slices' element types must be The behavior for Since this issue is about "slice of bytes/runes", terminology that is only used in the Conversions section of the spec, the CL addresses only that aspect. If we want to change the behavior for append/copy, we probably need to file a mini-proposal. |
Change https://go.dev/cl/412095 mentions this issue: |
Matches examples in spec section on string conversions. For #23814. Change-Id: I08099c27bfdb98735868266f5a42901321b97b56 Reviewed-on: https://go-review.googlesource.com/c/go/+/412095 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Robert Griesemer <gri@google.com>
Maybe, the reflect implementation should also be made consistent with this change: #23536 (comment) |
This is a follow-up issue for #23536: Comb through documentation (spec, builtins) to verify the use of the term "slice of bytes". The spec appears to mean by this any type whose underlying type is
[]byte
. But not all implementations agree.The text was updated successfully, but these errors were encountered: