Commit Graph

1077 Commits

Author SHA1 Message Date
Robert Griesemer c2d7895b1e go.tools/go/types: "imported but not used" errors for dot-imports
R=adonovan, josharian
CC=golang-dev
https://golang.org/cl/13795043
2013-09-20 10:09:16 -07:00
Robert Griesemer 86e41f819a go.tools/go/types: "imported but not used" checks for packages
also:
- initial code for unused label errors
- some cleanups, better names
- additional tests

TODO: Dot-imported packages are not handled yet; i.e., they
      are always considered used for now.

R=adonovan
CC=golang-dev
https://golang.org/cl/13768043
2013-09-19 10:05:34 -07:00
Robert Griesemer a68deb25ff go.tools/go/types: "declared but not used" error for type switches
Also:
- added more tests
- removed Var.Used accessor: it's not meaningful for clients since
  it does not reflect actual use/def information
- fixed position for short variable declaration errors

R=adonovan
CC=golang-dev
https://golang.org/cl/13240051
2013-09-18 11:31:46 -07:00
Robert Griesemer f1051f2025 go.tools/go/types: 'declared but not used' checks for variables
- updated all tests to conform to stricter rules
- TODO: check for implicitly declared variables in type switches

R=adonovan
CC=golang-dev
https://golang.org/cl/13695046
2013-09-18 08:39:02 -07:00
Robert Griesemer 4acd602bea go.tools/go/types: fix a couple of std lib test failures
1. handle return statements with zero (but expected) return values
2. indices provided for array or slice composite literals must be integer constants

Added additional test cases.

R=adonovan
CC=golang-dev
https://golang.org/cl/13734043
2013-09-17 10:26:06 -07:00
Robert Griesemer cf1e27bbda go.tools/go/types: add test case for resolution of blank methods
(was bug on go/types wishlist; probably fixed a while ago)

R=adonovan
CC=golang-dev
https://golang.org/cl/13633047
2013-09-16 13:18:56 -07:00
Robert Griesemer 1928c01286 go.tools/go/types: separate package descriptor from package object
Includes changes by adonovan to make oracle work again
(former CL 13395050).

R=adonovan
CC=golang-dev
https://golang.org/cl/13672044
2013-09-13 09:52:57 -07:00
Robert Griesemer 3fee9166d4 go.tools/go/types: treat unsafe.Pointer like a pointer for receivers and embedding
Also: Better error message for receiver type errors.

R=adonovan
CC=golang-dev
https://golang.org/cl/13259044
2013-09-11 10:03:40 -07:00
Robert Griesemer 67c866ec74 go.tools/go/types: extra tests for float conversions
R=adonovan
CC=golang-dev
https://golang.org/cl/13393046
2013-09-10 14:43:23 -07:00
Robert Griesemer b591789053 go.tools/go/types: clearer documentation
(Follow-up of CL feedback.)

R=adonovan
CC=golang-dev
https://golang.org/cl/13333047
2013-09-10 14:26:49 -07:00
Alan Donovan 9a9fb35468 go.types/go/types: document primary vs. secondary Package distinction.
And: add accessor to get the primary from a secondary Package.

This change documents a surprising fact about the current
go/types resolver implementation, namely that each ast.ImportSpec
    import "fmt"
creates a new ("secondary") Package object for fmt with the
same String, Name, Path and Scope as the canonical ("primary")
fmt package, but with a different identity.

This change also adds an accessor Package.Primary() that
returns the primary package associated with a secondary
package object, if any.

IMHO the current design is wrong, and the resolver should not
create secondary packages at all.  Even if a package is
imported under a non-default name, as in
    import f "fmt"
    ...
    f.Print
we should just regard f as a reference to the existing package
"fmt", not as the defining identifier for a secondary package.
What we would lose by such a change (the connection of the two
f's in 'f.Print' and 'import f "fmt"') seems a small price to
pay.

This CL is thus just a minimal change to permit clients to
make progress under the status quo.

R=r, gri, crawshaw
CC=golang-dev
https://golang.org/cl/13626043
2013-09-10 14:11:17 -04:00
Robert Griesemer 6688b01dc1 go.tools/go/types: fix unsafe.Pointer conversions
Make compliant with gc. Spec is not very clear.
Also: Fix error handling (don't destroy x before
using it in error message).

Fixes golang/go#6326.

R=adonovan
CC=golang-dev
https://golang.org/cl/13632043
2013-09-09 16:41:46 -07:00
Robert Griesemer 932a87ce16 go.tools/go/types: fix ... parameter passing
Also: exclude test case from std test to fix build.

Fixes golang/go#6344.

R=adonovan
CC=golang-dev
https://golang.org/cl/13630043
2013-09-09 15:20:14 -07:00
Chris Manghane 95e4181bb5 go.tools/go/vcs: apply fix to issue 5801.
No semantic difference from https://golang.org/cl/12343043/

R=bradfitz
CC=golang-dev
https://golang.org/cl/13383044
2013-09-09 12:49:08 -07:00
Rob Pike 6fb9ae0ed5 go.tools/go/vcs: use same regular expression for code.google.com as cmd/go
No semantic change.

R=golang-dev, bradfitz, dsymonds
CC=golang-dev
https://golang.org/cl/13373043
2013-08-29 14:32:06 +10:00
Rob Pike b38e3512f0 go.tools/go/vcs: support cloned repos in code.google.com
R=golang-dev, bradfitz, dsymonds
CC=golang-dev
https://golang.org/cl/13241047
2013-08-29 13:50:05 +10:00
David Symonds cec37cabd4 go/vcs: add proper error handling to test.
Fix a couple of error messages to report better messages.

R=adg
CC=golang-dev
https://golang.org/cl/13146043
2013-08-21 13:55:33 +10:00
Chris Manghane d64ad45594 go.tools/go/vcs: add logging functionality and create/log at revision
Add support for logging commands for Mercurial and Subversion as well as the ability to create/log a repo at a certain revision.

- Exported Cmd.LogCmd
- Exported Cmd.CreateAtRev
- Exported Cmd.Log
- Exported Cmd.LogAtRev

R=adg
CC=golang-dev
https://golang.org/cl/13060044
2013-08-20 20:10:15 -07:00
Andrew Gerrand 4e1a4d9fde go.tools/go/types: fix bad function comparison
Issue found by vet -nilfunc.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12816044
2013-08-20 15:26:04 +10:00
Dave Cheney 41a15a3013 go.tools/go/vcs: do not delete $TMPDIR during test runs
The test would nuke the entire contents of os.TempDir on completion.

This change corrects the code to use ioutil.TempDir.

R=r, adg
CC=golang-dev
https://golang.org/cl/12796045
2013-08-19 16:22:31 +10:00
Chris Manghane dfa65ded17 go.tools: add go/vcs
go/vcs exposes cmd/go/vcs.go from the `go get` command.

- Exported global variables `Verbose` and `ShowCmd` to replace `buildV` and `buildX` from cmd/go/main.go.
- Moved environment building code (envForDir, mergeEnvLists)from cmd/go/main.go to env.go
- Exported Cmd and its methods: Create, Download, Ping, TagSync, and Tags
- Exported ByCmd and FromDir functions for constructing Cmd
- Exported TagCmd
- Exported RepoRoot
- Exported RepoRootForImport* functions for constructing RepoRoot

R=golang-dev, adg, cmang, bradfitz
CC=golang-dev
https://golang.org/cl/12058054
2013-08-15 09:00:02 -07:00
Robert Griesemer ae874abc7a go.tools/go/types: *interface types have no methods
Fixes golang/go#5918.

R=adonovan
CC=golang-dev
https://golang.org/cl/12909043
2013-08-14 11:02:10 -07:00
Robert Griesemer d13d94afe7 go.tools/go/types: do rounding in constant numeric conversions
- cleaned up surrounding code
- adjusted error message positions for too few/many argument errors
- added more conversion tests
- added all tests under test/ken to std tests

R=adonovan, r
TBR=adonovan
CC=golang-dev
https://golang.org/cl/12711043
2013-08-12 14:57:08 -07:00
Robert Griesemer 508ae115ae go.tools/go/types: added missing test for file scopes
R=adonovan, r
CC=golang-dev
https://golang.org/cl/12671044
2013-08-08 20:54:28 -07:00
Robert Griesemer 2449594308 go.tools/go.types: retain ast.Node links on demand only
- support Info.Scopes mapping that maps ast.Nodes
  to the respective *Scope
- remove old node link from *Scope
- added corresponding API test

Also: re-enable debug mode (the faster version was
only important for the go api tool, which  has its
own version now).

R=adonovan, r
CC=golang-dev
https://golang.org/cl/12552047
2013-08-08 20:27:15 -07:00
Robert Griesemer 875ff2496f go.tools/go/types: support for fake imports of package "C"
Also:
- cleaner method set printing
- disable debug mode internally (50% faster)

R=adonovan, bradfitz
CC=golang-dev
https://golang.org/cl/12578043
2013-08-07 14:09:50 -07:00
Robert Griesemer 56b9e46247 go.tools/go/types: fewer guarantees in case of type errors
Provide fewer guarantees regarding the collected result
type information in types.Info if there are type errors.

Specifically, don't record nil objects in the Objects map
in case of a declaration error; instead, simply omit them.

R=adonovan
TBR=adonovan
CC=golang-dev
https://golang.org/cl/12553043
2013-08-06 11:27:05 -07:00
Rob Pike 75920173e4 go.tools/go/types: don't put an interface nil into the Objects map
If a method cannot type check, we end up with the interface variable
m to hold <*Func, nil>. Don't put that in the map because it defeats
the usual != nil check.

R=gri, dsymonds
CC=golang-dev
https://golang.org/cl/12506043
2013-08-06 16:19:10 +10:00
Robert Griesemer b956928b06 go.tools/go/types: Fix for broken IsAssignableTo.
Was broken by CL 12378043.

- factored out some error checking code
- adjusted error positions

R=adonovan
TBR=adonovan
CC=golang-dev
https://golang.org/cl/12401043
2013-08-05 13:54:22 -07:00
David Symonds 1dce9cc7c7 go/types: exclude a couple of files from the stdlib test that don't parse on Windows.
They use stuff in syscall that doesn't exist on Windows, and this test does not
parse build tags (not that we make that easy) to automatically skip them.

R=golang-dev, r, gri
CC=golang-dev
https://golang.org/cl/12453043
2013-08-05 13:54:22 +10:00
Robert Griesemer 3209d6ad73 go.tools/go/types: fix interface vs interface type assertion
R=adonovan
CC=golang-dev
https://golang.org/cl/12378043
2013-08-02 14:37:19 -07:00
Robert Griesemer e06b897351 go.tools/go/types: mark imported named types as 'complete'
Fixes "illegal cycle" error for: go tool vet -v pkg/unicode.

R=adonovan
CC=golang-dev
https://golang.org/cl/12355043
2013-08-02 09:33:37 -07:00
Robert Griesemer 4ceda807d5 go.tools/go/types: add mode to typecheck pkg-level decls only
This is useful for situations where one only cares about
exports, for instance (as in the goapi checker).

R=adonovan, bradfitz
CC=golang-dev
https://golang.org/cl/12292043
2013-08-01 16:37:56 -07:00
Alan Donovan 61a33ecd43 go.tools/go/types: fix: the type of a method value should not have a reciever
e.g.
type T int
func (T) f() {}
var t T
_ = t.f  // method value: should have signature "func()", no receiver

Also:
- ssa: add sanity check that helped diagnose this.

R=gri
CC=golang-dev
https://golang.org/cl/12283043
2013-08-01 15:38:41 -04:00
Robert Griesemer caf3fc90ed go.tools/go/types: test against test/fixedbugs
Fixed several bugs:
- lhs blank identifier may be parenthesized: (_) = 0 is ok
- constant shift counts in non-constant shifts must be >= 0
- init functions must have a body

Classified currently failing tests:
- 10 classes of errors not checked at the moment

R=adonovan, r
CC=golang-dev
https://golang.org/cl/11952046
2013-07-31 20:08:18 -07:00
Robert Griesemer ae07aa6055 go.tools/go/types: return typed bool for comma-ok expressions
Also: determine default types for assignments of the form: _ = x .

R=adonovan
CC=golang-dev
https://golang.org/cl/12186043
2013-07-31 12:49:34 -07:00
Robert Griesemer e5cfd92deb go.tools/go/types: record comma-ok results as tuples
- added corresponding api tests
- support tuple comparison with IsIdentical

This CL will require some adjustments to SSA.

R=adonovan
CC=golang-dev
https://golang.org/cl/12024046
2013-07-31 09:33:46 -07:00
Robert Griesemer 1e79a68ff5 go.tools/go/types: check fallthrough statements
R=adonovan
CC=golang-dev
https://golang.org/cl/12041049
2013-07-30 16:00:57 -07:00
Alan Donovan 2f6855ad75 go.tools/ssa: avoid calling go/types.NewSelection, and eliminate it.
Also: s/LookupMethod/Method/

R=gri
CC=golang-dev
https://golang.org/cl/12058052
2013-07-30 16:36:58 -04:00
Robert Griesemer 4ae33302a4 go.tools/go/types: map keys must be comparable
R=adonovan
CC=golang-dev
https://golang.org/cl/12102044
2013-07-30 13:15:28 -07:00
Robert Griesemer 33d57bf48f go.tools/go/types: report identifier for methods with blank names
R=adonovan
CC=golang-dev
https://golang.org/cl/12123045
2013-07-30 12:47:40 -07:00
Robert Griesemer e7c7afbb1a go.tools/go/types: enable (previously broken) shift tests
R=adonovan
CC=golang-dev
https://golang.org/cl/12109044
2013-07-30 11:10:28 -07:00
Robert Griesemer 7a1a18283b go.tools/go/types: constant shifts always produce integers (bug fix)
R=adonovan
CC=golang-dev
https://golang.org/cl/12025044
2013-07-30 10:28:57 -07:00
Robert Griesemer 30c6d6350d go.tools/go/types: check type-checker against $GOROOT/test
R=adonovan
CC=golang-dev
https://golang.org/cl/12070044
2013-07-30 09:00:25 -07:00
Alan Donovan 0ba53b54bd go.tools/ssa: add debug info for x.f where Selection.Kind()==FieldVal.
Also:
- Implement Program.FuncValue for interface methods (+ test).
- go/types.Object.String(): don't package-qualify names unless
  they are package level objects---otherwise you see "main.x" for
  locals, struct fields, etc.
- go/types.Func.String(): don't assume Type() is *Signature;
  it could be *Builtin.

R=gri
CC=golang-dev
https://golang.org/cl/12058045
2013-07-29 17:10:11 -04:00
Robert Griesemer 90aa993096 go.tools/go/types: provide package for imported methods
Fixes golang/go#5815.

R=adonovan
CC=golang-dev
https://golang.org/cl/12048043
2013-07-29 13:22:46 -07:00
Robert Griesemer bb34185432 go.tools/go/types: more implicit conversion tests
Also: Fixed grammar in selection.go comment.

R=adonovan
CC=golang-dev
https://golang.org/cl/11962043
2013-07-29 13:07:46 -07:00
Alan Donovan fb0642f5fb go.tools/ssa: fix a package-level var initialization order bug.
buildDecl was visiting all decls in source order, but the spec
calls for visiting all vars and init() funcs in order, then
all remaining functions.  These two passes are now called
buildInit(), buildFuncDecl().

+ Test.

Also:
- Added workaround to gcimporter for Func with pkg==nil.
- Prog.concreteMethods has been merged into Pkg.values.
- Prog.concreteMethod() renamed declaredFunc().
- s/mfunc/obj/ (name cleanup from recent gri CL)

R=gri
CC=golang-dev
https://golang.org/cl/12030044
2013-07-29 14:24:09 -04:00
Robert Griesemer 64ea46e0bc go.tools/go/types: replace Method w/ Selection
A Method corresponds to a MethodVal Selection;
so the explicit Method object is not needed anymore.

- moved Selection code into separate file
- implemented Selection.String()
- improved and more consistent documentation

R=adonovan
CC=golang-dev
https://golang.org/cl/11950043
2013-07-26 22:27:48 -07:00
Robert Griesemer 4ea4ce9e03 go.tools/go/types: added missing implicit conversion checks
R=adonovan, r
CC=golang-dev
https://golang.org/cl/11934047
2013-07-26 18:21:14 -07:00
Robert Griesemer 41fb587948 go.tools/go/types: implement Info.Selections
Should make it easier for clients to deal with
selector expressions.

Removed Field type: The respective information
is now reported in Info.Selections.

R=adonovan
CC=golang-dev
https://golang.org/cl/11942043
2013-07-26 13:55:14 -07:00
Alan Donovan 118786e3d6 go.tools/ssa: combine CallCommon.{Recv,Func} as Value.
Also:
- add types.Func.FullName() (e.g. "fmt.Println", "(main.S).f")
- remove rogue print stmt.
- fix bad docstrings.

R=gri
CC=golang-dev
https://golang.org/cl/11936044
2013-07-26 14:06:26 -04:00
Robert Griesemer bf6a1e674e go.tools/go/types: unsafe.Offsetof must deref named pointers to structs
R=adonovan
CC=golang-dev
https://golang.org/cl/11889043
2013-07-26 09:53:47 -07:00
Alan Donovan 4da31df1c8 go.tools/ssa: (another) major refactoring of method-set logic.
We now use LookupFieldOrMethod for all SelectorExprs, and
simplify the logic to discriminate the various cases.

We inline static calls to promoted/indirected functions,
dramatically reducing the number of functions created.

More tests are needed, but I'd like to submit this as-is.

In this CL, we:
- rely less on Id strings.  Internally we now use
  *types.Method (and its components) almost everywhere.
- stop thinking of types.Methods as objects. They don't
  have stable identities. (Hopefully they will become
  plain-old structs soon.)
- eliminate receiver indirection wrappers:
  indirection and promotion are handled together by makeWrapper.
- Handle the interactions of promotion, indirection and
  abstract methods much more cleanly.
- support receiver-bound interface method closures.
- break up builder.selectField so we can re-use parts
  (emitFieldSelection).
- add importer.PackageInfo.classifySelector utility.
- delete interfaceMethodIndex()
- delete namedTypeMethodIndex()
- delete isSuperInterface() (replaced by types.IsAssignable)
- call memberFromObject on each declared concrete method's
  *types.Func, not on every Method frem each method set, in the
  CREATE phase for packages loaded by gcimporter.

go/types:
- document Func, Signature.Recv() better.
- use fmt in {Package,Label}.String
- reimplement Func.String to be prettier and to include method
  receivers.

API changes:
- Function.method now holds the types.Method (soon to be
  not-an-object) for synthetic wrappers.
- CallCommon.Method now contains an abstract (interface)
  method object; was an abstract method index.
- CallCommon.MethodId() gone.
- Program.LookupMethod now takes a *Method not an Id string.

R=gri
CC=golang-dev
https://golang.org/cl/11674043
2013-07-26 11:22:34 -04:00
Robert Griesemer c98ff05fdd go.tools/go/types: faster scopes, cleanups around method lookups
R=adonovan
CC=golang-dev
https://golang.org/cl/11787043
2013-07-24 20:02:54 -07:00
Robert Griesemer 6dbbc59ae0 go.tools/go/types: simplify handling of blank _ identifiers
Also: Fixes a couple of places where scopes instead
      of objsets were used (missed in previous CL).

R=adonovan
CC=golang-dev
https://golang.org/cl/11419047
2013-07-24 12:39:11 -07:00
Robert Griesemer d0657ebb0d go.tools/go/types: record lhs identifier in switch lhs := rhs.(type)
Added testcase.

R=adonovan
CC=golang-dev
https://golang.org/cl/11742043
2013-07-24 12:38:51 -07:00
Alan Donovan d4f2f2d7fa go.tools/ssa: repair treatment of typeswitch after recent go/types changes.
Now, in a "switch y := x.(type)", there is no object for the
outer y, only implicit objects, one per case (including
default).

Also: don't set obj=nil for blank idents (workaround suggested by gri).

R=gri
CC=golang-dev
https://golang.org/cl/11564046
2013-07-24 14:03:53 -04:00
Robert Griesemer c5b1cc4227 go.tool/go/types: ignore invalid anonymous fields
Fixes go tool vet breakage when applied to files
with incomplete type information for anonymous
fields.

R=adonovan
CC=golang-dev
https://golang.org/cl/11773043
2013-07-24 10:49:44 -07:00
Robert Griesemer 407e159412 go.tools/go/types: fix typo in self test
R=adonovan
CC=golang-dev
https://golang.org/cl/11749044
2013-07-24 09:26:39 -07:00
Robert Griesemer 66e7552830 go.tools/go/types: simplified and faster Scope
- implemented objset for tracking duplicates of fields and methods
  which permitted a simpler and faster scope implementation in turn
- related cleanups and internal renames
- fixed a couple of identifier reporting bugs

Speed of type-checking itself increased by almost 10%
(from ~71Kloc/s to ~78Kloc/s on one machine, measured
via go test -run=Self).

R=adonovan
CC=golang-dev
https://golang.org/cl/11750043
2013-07-23 21:21:37 -07:00
Robert Griesemer 2f54663e0e go.tools/go/types: fix build: ignore self-test if it fails
R=adonovan
CC=golang-dev
https://golang.org/cl/11398045
2013-07-23 20:52:41 -07:00
Robert Griesemer cc55bd9129 go.tools/go/types: add self test
R=adonovan
CC=golang-dev
https://golang.org/cl/11739043
2013-07-23 18:30:06 -07:00
Robert Griesemer 09d04edfcf go.tools/go/types: declare typeswitch local variable in correct scope
R=adonovan
CC=golang-dev
https://golang.org/cl/11534044
2013-07-23 14:18:38 -07:00
Robert Griesemer 7bc647b29a go.tools/go/types: internal cleanups
- more consistent naming of some internal data types and methods
- better factoring of some error reporting code
- cleanup around association of methods with receiver base types
- more tests

R=adonovan
CC=golang-dev
https://golang.org/cl/11726043
2013-07-23 13:42:04 -07:00
Robert Griesemer 2bff3a03e7 go.tools/go/types: clean up method type checking
- treat receivers like ordinary parameters when checking signatures;
  concentrate all respective checks in one place
- continue to type-check methods even if receiver base type does not
  satisfy receiver type criteria (comes for free)
- don't ignore blank _ methods anymore
- various related cleanups

As a consequence, the resolving needs one less internal phase.

R=adonovan
CC=golang-dev
https://golang.org/cl/11591045
2013-07-22 20:42:10 -07:00
Robert Griesemer d722d82c52 go.tools/go/type: hook up interface method receivers
Also:
- Renamed Object.SameName -> Object.SameId
- Exported Object.Id

R=adonovan
CC=golang-dev
https://golang.org/cl/11567046
2013-07-19 16:26:32 -07:00
Robert Griesemer b0ae7702cb go.tools/go/types: record Field/Method object for f in selector expressions x.f
TODO(gri) This needs tests.

R=adonovan
CC=golang-dev
https://golang.org/cl/11519046
2013-07-19 14:46:28 -07:00
Robert Griesemer f4540b7193 go.tools/go/types: set correct Method recv type in NewMethodSet
R=adonovan
CC=golang-dev
https://golang.org/cl/11602043
2013-07-19 13:00:02 -07:00
Robert Griesemer 35f4fd1cd1 go.tools/go/types: use *Var instead of *Field for struct fields
Temporarily remove Field objects in favor of Vars for struct fields.
In forthcoming CL, Fields will play the symmetric role to Methods, and
serve as lookup results including index information.

R=adonovan
CC=golang-dev
https://golang.org/cl/11594043
2013-07-19 11:01:51 -07:00
Robert Griesemer 40a278e5ee go.tools/go/types: rename Context -> Config (more apt name)
Also: Various minor cleanups.

R=adonovan, r
CC=golang-dev
https://golang.org/cl/11445044
2013-07-18 17:07:44 -07:00
Robert Griesemer 6d85cc17dd go.tools/go/types: request type Info via maps instead of callbacks
Allmost all uses of go/types that wanted the type
information computed, installed callback functions
that stored the information in maps. Most of the
time this is the only thing that could be done because
there is no guarantee that types are completely set
up before the end of type-checking.

This CL removes the respective Context callbacks in favor
of corresponding maps that collect the desired information
on demand, grouped together in an optional Info struct.

R=adonovan
CC=golang-dev
https://golang.org/cl/11530044
2013-07-18 13:09:03 -07:00
Robert Griesemer 78c8226b42 go.tools/go/types: don't modify lhs untyped types in constant shifts
Also: fix TestCheck (don't fail if there are no errors in -list mode)

Fixes golang/go#5895.

R=adonovan
CC=golang-dev
https://golang.org/cl/11535043
2013-07-18 10:48:03 -07:00
Robert Griesemer 8901caa2b3 go.tools/go/types: Method sets for all types
- fixed method set computation
- lazily compute it for a type on demand
- lazy allocation of various temporary maps

Also:
- removed Interface.IsEmpty, Scope.IsEmpty
  (these convenience functions didn't carry their weight)
- cosmetic changes

Next:
- consolidate various lookup APIs
- use lazily computed method sets for various checks
  instead of individual lookups

R=adonovan
CC=golang-dev
https://golang.org/cl/11385044
2013-07-16 22:18:08 -07:00
Alan Donovan 80ec883f7b go.tools/ssa: several small clean-ups.
- removed a number of obsolete TODO(gri) comments.
- bring ssa.DefaultType back into sync with types.defaultType.
- re-enable types.Package.Path()!="" assertion.
- use Path() (not reflect pointer) in sort routine.
- make interp.checkInterface use types.MissingMethod.
- un-export ssa.MakeId function.
- inline pointer() into all callers, and delete.
- enable two more interp_tests: $GOROOT/test/{method3,cmp}.go
- add links to bugs to other interp_tests.
- add runtime.NumCPU to ssa/interp/externals.go

R=gri
CC=golang-dev
https://golang.org/cl/11353043
2013-07-16 12:23:55 -04:00
Robert Griesemer 0117ba266d go.tools/go/types: cleanup parameter passing
- now represent ...T parameter type as []T (rather than T)
- simplified call checking
- added missing check and test for x... arguments (x must be slice)

This CL will temporarily break ssa and ssa/interp.

R=adonovan, axwalk
CC=golang-dev
https://golang.org/cl/11317043
2013-07-16 09:12:33 -07:00
Robert Griesemer f1a889124d go.tools/go/types: cleanups
Objects:
- provide IsExported, SameName, uniqueName methods
- clean up a lot of dependent code

Scopes:
- don't add children to Universe scope (!)
- document Node, WriteTo

Types:
- remove Deref in favor of internal function deref

ssa, ssa/interp:
- introduced local deref, adjusted code
- fixed some "Underlying" bugs (pun intended)

R=adonovan
CC=golang-dev
https://golang.org/cl/11232043
2013-07-12 21:09:33 -07:00
Robert Griesemer a3301d1bc6 go.tools/go/types: more test cases for types.Eval
R=adonovan
CC=golang-dev
https://golang.org/cl/11229043
2013-07-12 13:51:24 -07:00
Robert Griesemer 32ed9615b3 go.tools/go/types: implement New, Eval and EvalNode
Eval and EvalNode permit the evaluation of an expression
or type literal string (or AST node in case of EvalNode)
within a given context (package and scope).

Also:
- track nested (children) scopes for all scopes
- provide a mechanism to iterate over nested scopes
- permit recursive printing of scopes

TODO: more tests

R=adonovan
CC=golang-dev
https://golang.org/cl/10748044
2013-07-12 11:03:34 -07:00
Robert Griesemer 5ec27f6da9 go.tools/go/types: export IsAssignableTo
Tested implictly since its simply calling the
internal isAssignableTo which is used in every
assignment when testing the std library.

R=adonovan
CC=golang-dev
https://golang.org/cl/11189043
2013-07-11 14:23:23 -07:00
Robert Griesemer 424b1fda00 go.tools/go/types: only print underlying type in Object.String for type objects
R=adonovan
CC=golang-dev
https://golang.org/cl/11161045
2013-07-11 13:19:12 -07:00
Robert Griesemer ed5ac0e6f1 go.tools/go/types: provide Object.String method
R=adonovan
CC=golang-dev
https://golang.org/cl/11178043
2013-07-11 12:57:56 -07:00
Robert Griesemer 1f28df4b6c go.tools/go/types: reuse code for m:n assignments
- more test cases

R=adonovan
CC=golang-dev
https://golang.org/cl/10952044
2013-07-11 10:54:52 -07:00
Robert Griesemer 59f09dcb8c go.tools/go/types: report test errors immediately in -list mode
This way, errors reported before a crash are visible.

R=adonovan, r
CC=golang-dev
https://golang.org/cl/10802044
2013-07-10 22:19:43 -07:00
Robert Griesemer 3a75f78acd go.tools/go/types: cleanup init expr checks
- factored our arity checks
- started more systematic tests for const/var decls
- better error messages
- fixed several corner case errors

R=adonovan
CC=golang-dev
https://golang.org/cl/11137043
2013-07-10 20:10:24 -07:00
Alan Donovan 4df74776da go.tools/ssa: de-dup the creation of method sets, using typemap.
Yields a ~20% improvement in SSA construction time.

Also: better names for promotion wrapper functions.

R=gri
CC=golang-dev
https://golang.org/cl/11050043
2013-07-10 18:01:11 -04:00
Alan Donovan 26d93d2e47 go.tools/go.types/typemap: a map whose keys are types.
go/types.Type has an equivalence relation (IsIdentical) that
is not consistent with the equivalence relation implemented by
Go's == operator for Types.  Therefore extra work is required
to build a map whose keys are types.  This package does that
work.

Has simple unit test.  More tests might be good.

R=gri
CC=golang-dev
https://golang.org/cl/9649044
2013-07-10 17:57:07 -04:00
Robert Griesemer 8cd6c3be05 go.tools/go/types: check for non-func init declarations
R=adonovan
CC=golang-dev
https://golang.org/cl/11075043
2013-07-09 21:13:37 -07:00
Robert Griesemer b8f13c4c9b go.tools/go/types: assignment checking cleanup (round 2)
- consolited remainign assignment check routines
- removed more dead code
- fixed incorrect scope hierarchy in case of errors for some statements
- fixed scope of key iteration variable for range clauses

R=adonovan
CC=golang-dev
https://golang.org/cl/10694044
2013-07-09 09:45:09 -07:00
Robert Griesemer 1aa0484f4b go.tools/go/types: report correct type for untyped conversion arguments
Fixes golang/go#5849.

R=adonovan
CC=golang-dev
https://golang.org/cl/11007043
2013-07-08 13:51:20 -07:00
Robert Griesemer cc52b8b7f8 go.tools/go/types: clean up assignment checks (round 1)
Various bug fixes:
- don't allow := to redeclare non-variables
- don't permit a comma-ok expression as a two-value function return

Lots of dead code removed.

Fixes golang/go#5500.

R=adonovan
CC=golang-dev
https://golang.org/cl/10792044
2013-07-08 09:40:30 -07:00
Robert Griesemer 4ca3d7e9da go.tools/go/types: remove defers from critical paths
Various minor cleanups.

R=adonovan
CC=golang-dev
https://golang.org/cl/10925043
2013-07-03 20:51:39 -07:00
Robert Griesemer f052654314 go.tools/go/types: remove iota from all parameter lists (cleanup)
Instead of passing around iota everywhere, keep track of the
current value in the checker, and update it when entering
different declarations. This is less explicit, but the improvement
over all code is so significant that it is worth it.

R=adonovan
CC=golang-dev
https://golang.org/cl/10814044
2013-07-03 10:06:09 -07:00
Robert Griesemer b58f98e9c2 go.tools/go/types: fix more cycle errors, lots of refactoring
- moved ident and typ expr checking into typexpr.go
- as a result, fewer parameters are needed for expr checking
- forward-chain type decls of the form type ( A B; B C; C *A) etc.
  so that cycles are getting the right types in all cases
- fixed several corner case bugs, added more test cases

R=adonovan
CC=golang-dev
https://golang.org/cl/10773043
2013-07-02 16:39:30 -07:00
Robert Griesemer 69c297407f go.tools/go/types: fix nil assignment
Fixes golang/go#5800.

R=adonovan
CC=golang-dev
https://golang.org/cl/10709044
2013-06-27 13:26:13 -07:00
Robert Griesemer a0160af20b go.tools/go/types: tests for cycles in type decls
Fixed one aspect of issue 5090. Fixing it completely
requires a bit more work around the representation of
interface types.

R=adonovan
CC=golang-dev
https://golang.org/cl/10678045
2013-06-27 12:43:20 -07:00
Robert Griesemer feb0ab2b10 go.tools/go/types: -files flag for testing one-off packages
Removed special case for testdata/test.go file in favor of
a simpler, more flexible, and explicit flag for one-off test
packages.

R=adonovan
CC=golang-dev
https://golang.org/cl/10618044
2013-06-26 13:01:16 -07:00
Robert Griesemer 22b7915ff5 go.tools/go/types: factored out code for calls and selectors
No other changes.

R=adonovan
CC=golang-dev
https://golang.org/cl/10573043
2013-06-25 15:40:28 -07:00
Robert Griesemer 25da72adcd go.tools/go/types: initialize local x early in case of bailout panic
- added respective test case

Fixes golang/go#5770.

R=adonovan
CC=golang-dev
https://golang.org/cl/10531043
2013-06-24 21:29:47 -07:00
Robert Griesemer 124e603d87 go.tools/go/types: imported structs may contain _ fields
Don't report import errors due to (multiple) _ fields
in imported structs.

Fixes golang/go#5758.

R=adonovan
CC=golang-dev
https://golang.org/cl/10529043
2013-06-24 17:38:41 -07:00
Robert Griesemer c13bb422de go.tools/go/types: fix nil-ptr deref in gcimporter
Also: Make error handling more explicit.

Possibly a fix for issue 5758.

R=adonovan
CC=golang-dev
https://golang.org/cl/10520043
2013-06-24 11:49:02 -07:00
Robert Griesemer bd55eef6ec go.tools/go/types: handle p.x with p of type P *S
R=adonovan
CC=golang-dev
https://golang.org/cl/10459044
2013-06-24 09:58:27 -07:00
Robert Griesemer cf8ec1591f go.tools/go/exact: more consistent handling of unknown values
R=adonovan
CC=golang-dev
https://golang.org/cl/10431046
2013-06-21 19:56:40 -07:00
Robert Griesemer 628104465d go.tools/go/types: fix logic error in MissingMethod and type assert code
R=adonovan
CC=golang-dev
https://golang.org/cl/10448046
2013-06-21 14:30:47 -07:00
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