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

Issue 66730052: go.tools/go/types: Enable enumeration of the fields of a type.

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 2 months ago by gmk
Modified:
9 years, 9 months ago
Reviewers:
gri, adonovan
CC:
golang-codereviews
Visibility:
Public.

Description

go.tools/go/types: Enable enumeration of the fields of a type - its field set, analogous to method set. SelectionSet replaces MethodSet and is used for both field sets and method sets. The field set and method set for a type are tightly bound -- computing one necessarily involves computing the other. MethodSetCache therefore becomes SelectionSetCache and stores both field and method sets. These changes were tested by plugging NewMethodSet and NewFieldSet into MissingMethod and LookupFieldOrMethod, but I don't submit those changes because they slowed things down; but that shouldn't be a problem once caching is figured out. All affected clients in go.tools are updated.

Patch Set 1 #

Patch Set 2 : diff -r 08c7e94f38c8 https://code.google.com/p/go.tools #

Total comments: 1

Patch Set 3 : diff -r c7ed95187f53 https://code.google.com/p/go.tools #

Patch Set 4 : diff -r c7ed95187f53 https://code.google.com/p/go.tools #

Patch Set 5 : diff -r c7ed95187f53 https://code.google.com/p/go.tools #

Total comments: 21

Patch Set 6 : diff -r c7ed95187f53 https://code.google.com/p/go.tools #

Patch Set 7 : diff -r c7ed95187f53 https://code.google.com/p/go.tools #

Patch Set 8 : diff -r c7ed95187f53 https://code.google.com/p/go.tools #

Patch Set 9 : diff -r c7ed95187f53 https://code.google.com/p/go.tools #

Total comments: 14

Patch Set 10 : diff -r c7ed95187f53 https://code.google.com/p/go.tools #

Patch Set 11 : diff -r c7ed95187f53 https://code.google.com/p/go.tools #

Unified diffs Side-by-side diffs Delta from patch set Stats (+227 lines, -185 lines) Patch
M cmd/godex/print.go View 1 2 3 4 5 6 7 8 9 1 chunk +3 lines, -3 lines 0 comments Download
M cmd/vet/copylock.go View 1 2 3 4 5 6 7 8 9 1 chunk +2 lines, -2 lines 0 comments Download
M go/gcimporter/gcimporter_test.go View 1 2 3 4 5 6 7 8 9 1 chunk +1 line, -1 line 0 comments Download
M go/pointer/gen.go View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M go/pointer/reflect.go View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M go/ssa/builder.go View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M go/ssa/builder_test.go View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M go/ssa/interp/reflect.go View 1 2 3 2 chunks +2 lines, -2 lines 0 comments Download
M go/ssa/print.go View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M go/ssa/promote.go View 1 2 3 2 chunks +2 lines, -2 lines 0 comments Download
M go/ssa/source.go View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M go/ssa/ssa.go View 1 2 3 2 chunks +6 lines, -6 lines 0 comments Download
M go/ssa/ssautil/visit.go View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M go/types/call.go View 1 2 3 4 5 6 7 8 9 2 chunks +5 lines, -5 lines 0 comments Download
M go/types/lookup.go View 1 2 1 chunk +1 line, -1 line 0 comments Download
M go/types/selectionset.go View 1 2 3 4 5 6 7 8 9 10 8 chunks +130 lines, -99 lines 0 comments Download
M go/types/selectionsetcache.go View 1 2 3 4 5 6 7 8 9 10 2 chunks +38 lines, -24 lines 0 comments Download
M go/types/typeutil/ui.go View 1 2 3 1 chunk +7 lines, -8 lines 0 comments Download
M godoc/analysis/analysis.go View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M godoc/analysis/implements.go View 1 2 3 2 chunks +4 lines, -4 lines 0 comments Download
M godoc/analysis/typeinfo.go View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M oracle/describe.go View 1 2 1 chunk +1 line, -1 line 0 comments Download
M oracle/implements.go View 1 2 5 chunks +16 lines, -18 lines 0 comments Download

Messages

Total messages: 20
gmk
10 years, 2 months ago (2014-02-23 21:30:05 UTC) #1
gri
Thanks. This will need to wait for a bit since we are about to freeze ...
10 years, 2 months ago (2014-02-24 18:12:19 UTC) #2
gmk
Ping. On Mon, Feb 24, 2014 at 7:12 PM, Robert Griesemer <gri@golang.org> wrote: > Thanks. ...
9 years, 10 months ago (2014-06-12 07:03:13 UTC) #3
gri
Apologies for the delay. I'd be more open to this if it would simplify the ...
9 years, 9 months ago (2014-07-10 18:07:12 UTC) #4
gmk
On 2014/07/10 18:07:12, gri wrote: > Apologies for the delay. No problem. > I'd be ...
9 years, 9 months ago (2014-07-11 07:04:54 UTC) #5
gmk
I expanded MethodSet into SelectionSet, and updated the affected clients in go.tools. Upon reflection, I ...
9 years, 9 months ago (2014-07-12 18:04:27 UTC) #6
gmk
I went the route of caching field and method sets together in an unexported type ...
9 years, 9 months ago (2014-07-12 20:25:12 UTC) #7
gmk
On 2014/07/12 20:25:12, gmk wrote: > I went the route of caching field and method ...
9 years, 9 months ago (2014-07-13 12:58:33 UTC) #8
gri
This looks pretty good to me so far. Handing over to adonovan for some more ...
9 years, 9 months ago (2014-07-14 18:40:10 UTC) #9
gmk
Thanks for the feedback. https://codereview.appspot.com/66730052/diff/100001/go/ssa/ssa.go File go/ssa/ssa.go (right): https://codereview.appspot.com/66730052/diff/100001/go/ssa/ssa.go#newcode29 go/ssa/ssa.go:29: Cache types.SelectionSetCache // cache of ...
9 years, 9 months ago (2014-07-14 20:38:36 UTC) #10
gri
leaving for adonovan https://codereview.appspot.com/66730052/diff/100001/go/types/selectionset.go File go/types/selectionset.go (right): https://codereview.appspot.com/66730052/diff/100001/go/types/selectionset.go#newcode79 go/types/selectionset.go:79: type selectionSets struct { On 2014/07/14 ...
9 years, 9 months ago (2014-07-14 20:56:43 UTC) #11
gmk
https://codereview.appspot.com/66730052/diff/100001/go/types/selectionset.go File go/types/selectionset.go (right): https://codereview.appspot.com/66730052/diff/100001/go/types/selectionset.go#newcode79 go/types/selectionset.go:79: type selectionSets struct { On 2014/07/14 20:56:43, gri wrote: ...
9 years, 9 months ago (2014-07-15 07:23:38 UTC) #12
adonovan
LGTM https://codereview.appspot.com/66730052/diff/180001/go/types/call.go File go/types/call.go (right): https://codereview.appspot.com/66730052/diff/180001/go/types/call.go#newcode395 go/types/call.go:395: // lookup. // ... (requires locking). https://codereview.appspot.com/66730052/diff/180001/go/types/selectionset.go File ...
9 years, 9 months ago (2014-07-15 10:00:17 UTC) #13
gri
https://codereview.appspot.com/66730052/diff/180001/go/types/selectionset.go File go/types/selectionset.go (right): https://codereview.appspot.com/66730052/diff/180001/go/types/selectionset.go#newcode63 go/types/selectionset.go:63: // It always returns a (possibly empty) non-nil set. ...
9 years, 9 months ago (2014-07-15 16:47:58 UTC) #14
gri
https://codereview.appspot.com/66730052/diff/100001/go/types/selectionset.go File go/types/selectionset.go (right): https://codereview.appspot.com/66730052/diff/100001/go/types/selectionset.go#newcode84 go/types/selectionset.go:84: var emptySelectionSet = &selectionSets{&SelectionSet{}, &SelectionSet{}} On 2014/07/15 07:23:37, gmk ...
9 years, 9 months ago (2014-07-15 16:50:18 UTC) #15
gmk
https://codereview.appspot.com/66730052/diff/180001/go/types/call.go File go/types/call.go (right): https://codereview.appspot.com/66730052/diff/180001/go/types/call.go#newcode395 go/types/call.go:395: // lookup. On 2014/07/15 10:00:17, adonovan wrote: > // ...
9 years, 9 months ago (2014-07-15 21:01:04 UTC) #16
adonovan
On 15 July 2014 22:01, <gordon.klaus@gmail.com> wrote: > Now that you mention it, I like ...
9 years, 9 months ago (2014-07-15 22:52:27 UTC) #17
gmk
On Wed, Jul 16, 2014 at 12:52 AM, Alan Donovan <adonovan@google.com> wrote: > On 15 ...
9 years, 9 months ago (2014-07-16 13:33:53 UTC) #18
gri
This still doesn't quite feel right. The only two files in question are selectionset.go and ...
9 years, 9 months ago (2014-07-16 17:28:57 UTC) #19
gmk
9 years, 9 months ago (2014-07-17 16:41:42 UTC) #20
Some spices for your mulling, Robert:

The fact that the FieldSet and MethodSet functions project a field is only
a result of the factoring of this implementation.  See Patch Set 1 in this
CL for another implementation that doesn't have this property.  The
fieldsAndMethods struct only exists so that it can be stored in
SelectionSetCache -- without the cache there would be no need for it.

That said, there still might be a reason to export fieldsAndMethods and its
fields fset and mset, but I don't see it.  As a container, this struct
doesn't provide much value.  And in terms of behavior I can only imagine it
providing a Lookup method that checked both SelectionSets; but this is just
the equivalent of what LookupFieldOrMethod does (and what I expect it to
actually do, eventually).

I think FieldSet and MethodSet might still be filter functions.  Yes, they
compute a new SelectionSet with new Selections each time, but those
Selections are identical over subsequent calls.  But I still wouldn't be
averse to calling them NewFieldSet and NewMethodSet (the funcs, not the
cache methods).  After all, we use NewT for all the Type factories, but
they also create identical immutable instances for some given parameters;
or maybe you would like to rename them to NamedOf, StructOf, PointerTo,
SliceOf, etc?


On Wed, Jul 16, 2014 at 7:28 PM, <gri@golang.org> wrote:

> This still doesn't quite feel right. The only two files in question are
> selectionset.go and selectionsetcache.go, of course.
>
> The FieldSet and Method set functions simply project a field. Perhaps
> these fields should just be exposed. The type is always a SelectionSet
> anyway. They are not really filter functions anymore also. And in fact
> they do compute a new selection set (but for the empty case).
>
> Let me mull this over for a couple of days.
>
> https://codereview.appspot.com/66730052/
>
Sign in to reply to this message.

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