Commit Graph

773 Commits

Author SHA1 Message Date
Robert Griesemer 0325defab0 go.tools/go/types: factor method set and lookup better
No functional change, just symmetric cleanup.

R=adonovan
CC=golang-dev
https://golang.org/cl/10417045
2013-06-21 13:19:41 -07:00
Robert Griesemer 2d345c1dd7 go.tools/go/types: improved LookupFieldOrMethod, ast.Nodes for Scopes
- LookupFieldOrMethod now computes if any indirection was found on the
  way to an embedded field/method: this is the only information required
  to determine if a result method is in the method set.

- Scopes now provide a link to the ast.Node responsible for them.

Also:
- don't permit unsafe.Offsetof on method values
- report ambiguities in field/method lookup errors
- added some missing checks for anonymous fields
- lots of new tests

Fixes golang/go#5499.

R=adonovan
CC=golang-dev
https://golang.org/cl/10411045
2013-06-21 08:57:26 -07:00
Robert Griesemer 9ff248b00d go.tools/go/types: simplified lookup
- much simpler lookup
- more result information
- will make tracking of pointer-ness easier

TODO: apply the same changes to method set computation

R=adonovan
CC=golang-dev
https://golang.org/cl/10379049
2013-06-19 12:29:17 -07:00
Robert Griesemer d338982a64 go.tools/go/types: use qualified names when printing types in errors
Also: Require that clean package paths are not ".".

R=adonovan, r
CC=golang-dev
https://golang.org/cl/10368047
2013-06-18 16:41:11 -07:00
Robert Griesemer 9a50e157b4 go.tools/go/types: first cut at sorted method sets
- moved single field and method lookup functionality
  from operand.go to new file lookup.go and cleaned
  up the lookup implementation

- implemented method set computation using the same
  basic structure as for field/method lookup, in new
  file methodset.go

- minor related changes

- the method set computation ignores pointer-ness of
  the receiver type at the moment (next CL)

- fixed a couple of bugs (missing pkg info for imported
  embedded types, wrong test for method expressions)

The method set computation is currently verified by
comparing a regular method lookup with a method-set
based method lookup.

R=adonovan
CC=golang-dev
https://golang.org/cl/10235049
2013-06-18 15:59:16 -07:00
Robert Griesemer 7517d8bae3 go.tools/go/types: catch cycles in function declarations
Fixes golang/go#5217.

R=adonovan
CC=golang-dev
https://golang.org/cl/10402044
2013-06-18 15:34:12 -07:00
Alan Donovan f1d4d01fed go.tools/ssa: memoize synthesis of all wrapper methods.
methodIndex() utility was split and specialized to its two
cases, *Interface vs *Named, which are logically quite
different.

We can't memoize promotion wrappers yet; we need typemap.

Terminology:
- "thunks" are now "wrappers"
- "bridge methods" are now "promotion wrappers"

Where the diff is messy it's just because of indentation.

R=gri
CC=golang-dev
https://golang.org/cl/10282043
2013-06-14 15:50:37 -04:00
Robert Griesemer 9ce6fcb502 go.tools/go/types: use []*Func instead of *Scope to hold methods
R=golang-dev, adonovan
CC=golang-dev
https://golang.org/cl/10243043
2013-06-13 11:11:53 -07:00
Robert Griesemer 5efab5e9c0 go.tools/go/types: Use []*Field instead of *Scope for struct fields
This partially reverts a previous change, using a []*Field is a better
representation for struct fields than a *Scope, after all; however
*Fields remain Objects.

Fixes golang/go#5670.

R=adonovan, axwalk
CC=golang-dev
https://golang.org/cl/10207043
2013-06-11 19:54:47 -07:00
Robert Griesemer 0d2f7d411b go.tools/go/types: fix isAssignable and IsIdentical
- Imported objects that are explicitly exported may have a nil package;
  don't use it for qualified name computation (it's not needed).
- isAssignable must check all possibilities before declaring failure.

Fixes golang/go#5675.

R=adonovan
CC=golang-dev
https://golang.org/cl/10141044
2013-06-11 10:00:00 -07:00
Robert Griesemer 63f3103b6f go.tools/go/types: call Context.Ident for selectors
Fixes golang/go#5669.

R=adonovan
CC=golang-dev
https://golang.org/cl/9714045
2013-06-10 16:42:22 -07:00
Robert Griesemer 221795b447 go.tools/go/types: Factories for all objects
R=adonovan
CC=golang-dev
https://golang.org/cl/9794044
2013-06-04 15:15:41 -04:00
Alan Donovan be28dbb86f go.types/ssa: split the load/parse/typecheck logic off into a separate package.
PLEASE NOTE: the APIs for both "importer" and "ssa" packages
will continue to evolve and both need some polishing; the key
thing is that this CL splits them.

The go.types/importer package contains contains the Importer,
which takes care of the mechanics of loading a set of packages
and type-checking them.  It exposes for each package a
PackageInfo containing:
- the package's ASTs (i.e. the input to the typechecker)
- the types.Package object
- the memoization of the typechecker callbacks for identifier
  resolution, constant folding and expression type inference.

Method-set computation (and hence bridge-method creation) is
now moved to after creation of all packages: since they are no
longer created in topological order, we can't guarantee the
needed delegate methods exist yet.

ssa.Package no longer has public TypeOf, ObjectOf, ValueOf methods.
The private counterparts are valid only during the build phase.

Also:
- added to go/types an informative error (not crash) for an
  importer() returning nil without error.
- removed Package.Name(), barely needed.
- changed Package.String() slightly.
- flag what looks like a bug in makeBridgeMethod. Will follow up.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/9898043
2013-05-31 16:14:13 -04:00
Robert Griesemer 710a117e33 go.tools/go/types: don't use nil fields and methods
The change for fields is in anticipation of fields
becoming a *Scope.

Pointed out by adonovan.

R=adonovan
CC=golang-dev
https://golang.org/cl/9874049
2013-05-31 12:02:33 -07:00
Robert Griesemer e5f49b1c9f go.tools/go/types: typecheck call arguments even if the call doesn't typecheck
This provides better partial type information in case of type errors.

R=r
CC=golang-dev
https://golang.org/cl/9835049
2013-05-31 11:22:00 -07:00
Robert Griesemer 3cad037e2f go.tools/go/types: replace ObjSet with improved Scope
- First step towards unified use of scopes. Will enable
  further simplifications.

- Removed various ForEach iterators in favor of the existing
  accessor methods, for a thinner API.

- Renamed outer/Outer to parent/Parent for scopes.

- Removed check.lookup in favor of Scope.LookupParent.

R=adonovan
CC=golang-dev
https://golang.org/cl/9862044
2013-05-30 21:58:14 -07:00
Robert Griesemer faef64e271 go.tools/go/types: support for Context.ImplicitObj callbacks
Also:
- more cleanup of new identifier resolution code
- removed residue Object.Pos() code
- two separate, equally formatted error messages for redeclaration
  errors for easier tool support
- initial support for labels
- enabled several disabled tests

Thic CL will break go.tools/ssa/interp, but the pending
CL 9863045 fixes that.

Fixes golang/go#5504.

R=adonovan
CC=golang-dev
https://golang.org/cl/9839045
2013-05-30 09:50:44 -07:00
Robert Griesemer b52cce75f3 adonovan: first round of cleanups: remove 'resolve' internal flag and respective dead code
No other changes besides documentation updates for now.

R=golang-dev, adonovan
CC=golang-dev
https://golang.org/cl/9780045
2013-05-28 11:39:15 -07:00
Robert Griesemer 5c2bbcb0fd go.tools/go/types: enable resolution of objects in type checker
R=adonovan
CC=golang-dev
https://golang.org/cl/9838043
2013-05-28 10:25:11 -07:00
Robert Griesemer 3df6f127f0 go.tools/go/types: resolve objects in type checker
By setting resolve = true in check.go, the type checker
will do all identifier resolution during type checking
time and ignore (and not depend on) parser objects. This
permits the type checker to run easily on ASTs that are
not generated with invariants guaranteed by the parser.

There is a lot of new code; much of it slightly modified
copies of old code. There is also a lot of duplication.
After removing the dead code resulting from resolve = true
permanently (and removing the flag as well), it will be
easier to perform a thorough cleanup. As is, there are
too many intertwined code paths.

For now resolve = false. To be enabled in a successor CL.

R=adonovan
CC=golang-dev
https://golang.org/cl/9606045
2013-05-28 10:06:37 -07:00
Robert Griesemer 08ee2985d7 go.tools/go.types: check for redeclarations across package files
Fixes golang/go#5506.

R=adonovan
CC=golang-dev
https://golang.org/cl/9600044
2013-05-20 14:29:57 -07:00
Rob Pike 87334f402b go.tools: bring up to date
Repo was copied from old point.  Bad r.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/9504043
2013-05-17 14:02:47 -07:00
Rob Pike 01f8cd246d go.tools: add go/types, ssa, and cmd/vet
They will be deleted from their current homes once this has landed.
Changes made to import paths to make the code compile, and to find
errchk in the right place in cmd/vet's Makefile.
TODO in a later CL: tidy up vet.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/9495043
2013-05-17 13:20:39 -07:00