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

Issue 7058060: code review 7058060: go/types: Moving from *ast.Objects to types.Objects (st... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 3 months ago by gri
Modified:
11 years, 3 months ago
Reviewers:
adonovan
CC:
golang-dev
Visibility:
Public.

Description

go/types: Moving from *ast.Objects to types.Objects (step 1). The existing type checker was relying on augmenting ast.Object fields (empty interfaces) for its purposes. While this worked for some time now, it has become increasingly brittle. Also, the need for package information for Fields and Methods would have required a new field in each ast.Object. Rather than making them bigger and the code even more subtle, in this CL we are moving away from ast.Objects. The types packge now defines its own objects for different language entities (Const, Var, TypeName, Func), and they implement the types.Object interface. Imported packages create a Package object which holds the exported entities in a types.Scope of types.Objects. For type-checking, the current package is still using ast.Objects to make this transition manageable. In a next step, the type- checker will also use types.Objects instead, which opens the door door to resolving ASTs entirely by the type checker. As a result, the AST and type checker become less entangled, and ASTs can be manipulated "by hand" or programmatically w/o having to worry about scope and object invariants that are very hard to maintain. (As a consequence, a future parser can do less work, and a future AST will not need to define objects and scopes anymore. Also, object resolution which is now split across the parser, the ast, (ast.NewPackage), and even the type checker (for composite literal keys) can be done in a single place which will be simpler and more efficient.) Change details: - Check now takes a []*ast.File instead of a map[string]*ast.File. It's easier to handle (I deleted code at all use sites) and does not suffer from undefined order (which is a pain for testing). - ast.Object.Data is now a *types.Package rather then an *ast.Scope if the object is a package (obj.Kind == ast.Pkg). Eventually this will go away altogether. - Instead of an ast.Importer, Check now uses a types.Importer (which returns a *types.Package). - types.NamedType has two object fields (Obj Object and obj *ast.Object); eventually there will be only Obj. The *ast.Object is needed during this transition since a NamedType may refer to either an imported (using types.Object) or locally defined (using *ast.Object) type. - ast.NewPackage is not used anymore - there's a local copy for package-level resolution of imports. - struct fields now take the package origin into account. - The GcImporter is now returning a *types.Package. It cannot be used with ast.NewPackage anymore. If that functionality is still used, a copy of the old GcImporter should be made locally (note that GcImporter was part of exp/types and it's API was not frozen). - dot-imports are not handled for the time being (this will come back).

Patch Set 1 #

Patch Set 2 : diff -r 1399878c6731 https://code.google.com/p/go #

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

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

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

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

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

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

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

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

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

Patch Set 12 : diff -r c8c8cc10a3da https://code.google.com/p/go #

Patch Set 13 : diff -r d96fe1298b88 https://code.google.com/p/go #

Patch Set 14 : diff -r d96fe1298b88 https://code.google.com/p/go #

Patch Set 15 : diff -r d96fe1298b88 https://code.google.com/p/go #

Patch Set 16 : diff -r d96fe1298b88 https://code.google.com/p/go #

Patch Set 17 : diff -r d96fe1298b88 https://code.google.com/p/go #

Patch Set 18 : diff -r d96fe1298b88 https://code.google.com/p/go #

Patch Set 19 : diff -r d96fe1298b88 https://code.google.com/p/go #

Patch Set 20 : diff -r e59c2b6934af https://code.google.com/p/go #

Patch Set 21 : diff -r e59c2b6934af https://code.google.com/p/go #

Patch Set 22 : diff -r e59c2b6934af https://code.google.com/p/go #

Patch Set 23 : diff -r 16fa351dc8b6 https://code.google.com/p/go #

Patch Set 24 : diff -r 16fa351dc8b6 https://code.google.com/p/go #

Patch Set 25 : diff -r fc9545bf5a1f https://code.google.com/p/go #

Patch Set 26 : diff -r fc9545bf5a1f https://code.google.com/p/go #

Patch Set 27 : diff -r fc9545bf5a1f https://code.google.com/p/go #

Patch Set 28 : diff -r fc9545bf5a1f https://code.google.com/p/go #

Patch Set 29 : diff -r 886debcfcd43 https://code.google.com/p/go #

Patch Set 30 : diff -r 886debcfcd43 https://code.google.com/p/go #

Total comments: 1

Patch Set 31 : diff -r 592fc248d9e5 https://code.google.com/p/go #

Unified diffs Side-by-side diffs Delta from patch set Stats (+599 lines, -240 lines) Patch
M src/pkg/exp/gotype/gotype.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 5 chunks +6 lines, -13 lines 0 comments Download
M src/pkg/go/ast/scope.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +5 lines, -8 lines 0 comments Download
M src/pkg/go/types/api.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2 chunks +20 lines, -3 lines 0 comments Download
M src/pkg/go/types/check.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 7 chunks +17 lines, -35 lines 0 comments Download
M src/pkg/go/types/check_test.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 3 chunks +8 lines, -10 lines 0 comments Download
M src/pkg/go/types/conversions.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/go/types/errors.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1 chunk +10 lines, -1 line 0 comments Download
M src/pkg/go/types/expr.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 7 chunks +32 lines, -22 lines 0 comments Download
M src/pkg/go/types/gcimporter.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 25 chunks +77 lines, -62 lines 0 comments Download
M src/pkg/go/types/gcimporter_test.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 2 chunks +28 lines, -6 lines 0 comments Download
A src/pkg/go/types/objects.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1 chunk +120 lines, -0 lines 0 comments Download
M src/pkg/go/types/operand.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 5 chunks +30 lines, -23 lines 0 comments Download
M src/pkg/go/types/predicates.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 6 chunks +29 lines, -8 lines 0 comments Download
A src/pkg/go/types/resolve.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 1 chunk +146 lines, -0 lines 0 comments Download
M src/pkg/go/types/resolver_test.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 3 chunks +17 lines, -12 lines 0 comments Download
M src/pkg/go/types/types.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 4 chunks +13 lines, -10 lines 0 comments Download
M src/pkg/go/types/types_test.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2 chunks +4 lines, -3 lines 0 comments Download
M src/pkg/go/types/universe.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 3 chunks +36 lines, -23 lines 0 comments Download

Messages

Total messages: 8
gri
Hello adonovan@google.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go
11 years, 3 months ago (2013-01-11 01:08:51 UTC) #1
gri
PTAL. Fixed various types in CL desc. On Thu, Jan 10, 2013 at 5:08 PM, ...
11 years, 3 months ago (2013-01-11 01:15:45 UTC) #2
adonovan
Very brief comments so far: - The implementsObject unexported field of types.Var makes composite literals ...
11 years, 3 months ago (2013-01-11 19:39:26 UTC) #3
gri
On Fri, Jan 11, 2013 at 11:39 AM, <adonovan@google.com> wrote: > - The implementsObject unexported ...
11 years, 3 months ago (2013-01-11 19:57:22 UTC) #4
gri
Hello adonovan@google.com (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 3 months ago (2013-01-11 21:34:34 UTC) #5
adonovan
LGTM Still cleaning up the debris on my end though. :)
11 years, 3 months ago (2013-01-11 21:48:05 UTC) #6
gri
*** Submitted as https://code.google.com/p/go/source/detail?r=e088d9c306df *** go/types: Moving from *ast.Objects to types.Objects (step 1). The existing ...
11 years, 3 months ago (2013-01-11 21:53:44 UTC) #7
adonovan
11 years, 3 months ago (2013-01-11 22:00:03 UTC) #8
Message was sent while issue was closed.
https://codereview.appspot.com/7058060/diff/31057/src/pkg/go/types/types.go
File src/pkg/go/types/types.go (right):

https://codereview.appspot.com/7058060/diff/31057/src/pkg/go/types/types.go#n...
src/pkg/go/types/types.go:95: type QualifiedName struct {
Would be good to document the (logical) equivalence relation here, and explain
that Pkg is never nil.
Sign in to reply to this message.

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