-
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: reference-like properties of channels, slices, and maps not well specified #5083
Comments
Owner changed to @griesemer. |
Issue #6529 has been merged into this issue. |
Someone once explained them to me as types containing _unexported pointers_. That seems to align with the sliceHeader example in http://blog.golang.org/slices. |
Concluding a recent thread https://groups.google.com/d/topic/golang-nuts/86N_xtgcZqo/discussion, I think the the burden is on the spec to make clear
and on the memory model to state
|
I remain unconvinced that we should enforce in the language spec that a map value may be represented by an unsafe.Pointer. We don't specify the internal format of slices or interface values or channels, and I don't think we should specify maps. |
I understand your concern. The (reflect.Value).Pointer method seems to suggest that a map value is just a pointer, but it's not clear what it actually commits us to. It would be nice if the language provided a reliable and portable way for programs to detect cycles in arbitrary object graphs. This requires a robust notion of identity for maps, channels, functions, and slices. (reflect.Value).Pointer + unsafe.Pointer is sufficient for the first three; slices require runtime.SliceHeader + unsafePointer, which is not portable. |
After running into this one again myself, here's a thought. I think the issue is actually most significant for maps and channels, because they refer to programmer-invisible common state. While slices and pointers refer to common state as well, this state is much more explicitly exposed to the programmer for these types, while map and channel state is completely opaque. Functions are in practice similar as well, but because there are no modifying operations on functions, this is irrelevant (an implementation which actually passed around executable code would perhaps have authors in need of a stern talking to, but would not otherwise be an issue). So I think this could be resolved by:
Thoughts? |
@alercah Thanks for your suggestions! I can't respond in a meaningful way at the moment as this is a non-urgent issue and I haven't spent any time thinking about it more seriously. Just wanted to acknowledge that your feedback is appreciated. |
For sure! Some follow-up clarifications:
|
Sorry for bringing this up 5 years later, but are there any updates or plans regarding this? I think this has become even more relevant now that Effective Go is officially frozen and the specification is (at least, in my humble opinion) expected to describe the behavior that might come as a surprise. |
Marking for 1.18 since we're still working on completing the spec for generics. If not 1.18, then 1.19. |
We won't get to this for 1.18. Moving to 1.19 so it stays on the radar. |
Change https://go.dev/cl/391634 mentions this issue: |
Change https://go.dev/cl/391634 mentions this issue: |
Change https://go.dev/cl/391635 mentions this issue: |
Change https://go.dev/cl/413615 mentions this issue: |
Change https://go.dev/cl/413714 mentions this issue: |
This permits a clear distinction between an individual assignment and an assignment statement which may assign more than one value. It also makes this section title consistent with all other section titles about statements. Adjust internal links and prose where appropriate. (Note that the spec already referred to assignment statements in a couple of places, even before this change.) Add an introductory paragraph to the section on assignment statements. Preparation for adding a section on value vs reference types (issue #5083). Change-Id: Ie140ac296e653c67da2a5a203b63352b3dc4f9f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/413615 Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
CL in progress. Not urgent. Moving to 1.20. |
This permits a clear distinction between an individual assignment and an assignment statement which may assign more than one value. It also makes this section title consistent with all other section titles about statements. Adjust internal links and prose where appropriate. (Note that the spec already referred to assignment statements in a couple of places, even before this change.) Add an introductory paragraph to the section on assignment statements. Preparation for adding a section on value vs reference types (issue golang#5083). Change-Id: Ie140ac296e653c67da2a5a203b63352b3dc4f9f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/413615 Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
The text was updated successfully, but these errors were encountered: