spec: Conversions_from_slice_to_array_pointer: clarify behavior for subslices #47599
Labels
Documentation
Issues describing a change to documentation.
FrozenDueToAge
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
Currently the spec says the following:
go/doc/go_spec.html
Lines 4324 to 4326 in 72ab3ff
However, it is not clear what "underlying array" should mean for a slice created as a subslice of another array. Consider the following code:
Several interpretations are possible:
&v0[0] == &v[2]
.v[2:4]
doesn't point at the beginning of the v's underlying array.&v0[0] == &v[0]
, since the "underlying array" is interpreted as the block of memory that was originally allocated forv
. This is perhaps counter-intuitive, but not prohibited by the spec.In my experimentation #1 is the actual behavior, and it makes sense, since in a general case the user has no way of knowing whether a slice is sharing its underlying array with any other slice and how they may be overlapping. Formalizing it in the spec would be useful to ensure third-party Go implementations behave similarly.
CC @flimzy since it's relevant to gopherjs/gopherjs#1043.
The text was updated successfully, but these errors were encountered: