Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(152)

Issue 5372095: code review 5372095: allow copy of struct containing unexported fields (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 10 months ago by rsc
Modified:
13 years, 10 months ago
Reviewers:
CC:
golang-dev, adg, dvyukov, r, bradfitz, jnml, gri
Visibility:
Public.

Description

allow copy of struct containing unexported fields An experiment: allow structs to be copied even if they contain unexported fields. This gives packages the ability to return opaque values in their APIs, like reflect does for reflect.Value but without the kludgy hacks reflect resorts to. In general, we trust programmers not to do silly things like *x = *y on a package's struct pointers, just as we trust programmers not to do unicode.Letter = unicode.Digit, but packages that want a harder guarantee can introduce an extra level of indirection, like in the changes to os.File in this CL or by using an interface type. All in one CL so that it can be rolled back more easily if we decide this is a bad idea. Originally discussed in March 2011. https://groups.google.com/group/golang-dev/t/3f5d30938c7c45ef

Patch Set 1 #

Patch Set 2 : diff -r c987cc71cf15 https://go.googlecode.com/hg #

Patch Set 3 : diff -r 507c01c355a1 https://go.googlecode.com/hg #

Patch Set 4 : diff -r 507c01c355a1 https://go.googlecode.com/hg #

Total comments: 1

Patch Set 5 : diff -r 507c01c355a1 https://go.googlecode.com/hg #

Patch Set 6 : diff -r 4b5c859153bb https://go.googlecode.com/hg #

Total comments: 1

Patch Set 7 : diff -r d29fa3306eaf https://go.googlecode.com/hg #

Unified diffs Side-by-side diffs Delta from patch set Stats (+56 lines, -221 lines) Patch
M doc/go_spec.html View 1 2 3 2 chunks +1 line, -10 lines 0 comments Download
M src/cmd/gc/go.h View 1 1 chunk +0 lines, -1 line 0 comments Download
M src/cmd/gc/subr.c View 1 2 chunks +0 lines, -4 lines 0 comments Download
M src/cmd/gc/typecheck.c View 1 7 chunks +0 lines, -69 lines 0 comments Download
M src/pkg/os/file_plan9.go View 1 2 3 4 3 chunks +14 lines, -2 lines 0 comments Download
M src/pkg/os/file_unix.go View 1 2 3 chunks +14 lines, -2 lines 0 comments Download
M src/pkg/os/file_windows.go View 1 2 3 chunks +14 lines, -2 lines 0 comments Download
M src/pkg/sync/mutex.go View 1 2 3 4 5 1 chunk +2 lines, -0 lines 0 comments Download
M test/assign.go View 1 2 3 4 1 chunk +11 lines, -11 lines 0 comments Download
R test/fixedbugs/bug226.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
R test/fixedbugs/bug226.dir/x.go View 1 1 chunk +0 lines, -9 lines 0 comments Download
R test/fixedbugs/bug226.dir/y.go View 1 1 chunk +0 lines, -31 lines 0 comments Download
R test/fixedbugs/bug310.go View 1 1 chunk +0 lines, -20 lines 0 comments Download
R test/fixedbugs/bug359.go View 1 1 chunk +0 lines, -26 lines 0 comments Download
R test/fixedbugs/bug378.go View 1 1 chunk +0 lines, -27 lines 0 comments Download

Messages

Total messages: 12
rsc
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://go.googlecode.com/hg
13 years, 10 months ago (2011-11-14 06:11:45 UTC) #1
adg
LGTM I'm pretty happy with how much this removes from the spec, compiler, and tests. ...
13 years, 10 months ago (2011-11-14 06:22:14 UTC) #2
dvyukov
Additional level of indirection enforces sharing rather than prevents copying. I am worry about structs ...
13 years, 10 months ago (2011-11-14 06:26:15 UTC) #3
rsc
On Mon, Nov 14, 2011 at 01:26, <dvyukov@google.com> wrote: > Additional level of indirection enforces ...
13 years, 10 months ago (2011-11-14 06:33:52 UTC) #4
dvyukov
On 2011/11/14 06:33:52, rsc wrote: > On Mon, Nov 14, 2011 at 01:26, <mailto:dvyukov@google.com> wrote: ...
13 years, 10 months ago (2011-11-14 06:39:04 UTC) #5
r
LGTM i think http://codereview.appspot.com/5372095/diff/2018/doc/go_spec.html File doc/go_spec.html (left): http://codereview.appspot.com/5372095/diff/2018/doc/go_spec.html#oldcode1377 doc/go_spec.html:1377: </p> this is good, but is ...
13 years, 10 months ago (2011-11-14 16:20:09 UTC) #6
rsc
On Mon, Nov 14, 2011 at 11:20, <r@golang.org> wrote: > this is good, but is ...
13 years, 10 months ago (2011-11-14 16:23:17 UTC) #7
bradfitz
On Sun, Nov 13, 2011 at 10:33 PM, Russ Cox <rsc@golang.org> wrote: > On Mon, ...
13 years, 10 months ago (2011-11-14 16:30:18 UTC) #8
jnml
On Monday, November 14, 2011 7:11:45 AM UTC+1, rsc wrote: > > In general, we ...
13 years, 10 months ago (2011-11-14 17:35:07 UTC) #9
rsc
On Mon, Nov 14, 2011 at 12:33, Jan Mercl <jan.mercl@nic.cz> wrote: > Considering how many ...
13 years, 10 months ago (2011-11-14 17:45:26 UTC) #10
gri
LGTM
13 years, 10 months ago (2011-11-14 17:53:46 UTC) #11
rsc
13 years, 10 months ago (2011-11-15 17:21:03 UTC) #12
*** Submitted as http://code.google.com/p/go/source/detail?r=6f8b9654e929 ***

allow copy of struct containing unexported fields

An experiment: allow structs to be copied even if they
contain unexported fields.  This gives packages the
ability to return opaque values in their APIs, like reflect
does for reflect.Value but without the kludgy hacks reflect
resorts to.

In general, we trust programmers not to do silly things
like *x = *y on a package's struct pointers, just as we trust
programmers not to do unicode.Letter = unicode.Digit,
but packages that want a harder guarantee can introduce
an extra level of indirection, like in the changes to os.File
in this CL or by using an interface type.

All in one CL so that it can be rolled back more easily if
we decide this is a bad idea.

Originally discussed in March 2011.
https://groups.google.com/group/golang-dev/t/3f5d30938c7c45ef

R=golang-dev, adg, dvyukov, r, bradfitz, jan.mercl, gri
CC=golang-dev
http://codereview.appspot.com/5372095
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b