1
0
mirror of https://github.com/golang/go synced 2024-11-06 10:36:13 -07:00
Commit Graph

4929 Commits

Author SHA1 Message Date
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
Alan Donovan
86b0a65b65 go.tools/ssa: emit ChangeType when using method as function in f := T.meth.
Previously: typeOf(f).Signature.Recv == T
       Now: typeOf(f).Signature.Params.At(0) == T

Added test.

BUG=5781

R=gri
CC=golang-dev
https://golang.org/cl/10622043
2013-06-26 13:18:31 -04:00
Alan Donovan
b68a029040 go.tools/ssa: un-export Function.FullName. Use String.
R=gri
CC=golang-dev
https://golang.org/cl/10604044
2013-06-26 12:38:08 -04: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
Rob Pike
6740bb0838 go.tools/cmd/vet: delete the word "only" from a warning
No semantic change.

R=dsymonds, rsc
CC=golang-dev
https://golang.org/cl/10516043
2013-06-24 12:56:35 -07:00
Rob Pike
40caf1ff72 go.tools/cmd/cover: better usage message
R=adg, rsc
CC=golang-dev
https://golang.org/cl/10453044
2013-06-24 12:56:25 -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
Alan Donovan
8097dad724 go.tools/ssa: Select now returns received values by tuple, not interface.
Before, all values received on some channel by Select would
flow to an empty interface, creating a spurious confluence for
flow analyses.  Now, the tuple returned by Select has one
component for each 'receive' case.

Also, fixes:
- Removed workarounds for now-fixed typechecker bug in FuncLit+TypeAssert.
- sanity check that all Value Instructions have non-nil Type().
- Convert: document and sanity-check that at least one of the types is basic.

Also, other things to help clients:
- Define CallInstruction interface: common parts of Call, Go, Defer.
- Add CallCommon.Signature() method.
- Literal.Pos() is now populated.

R=gri
CC=golang-dev
https://golang.org/cl/10505043
2013-06-24 14:15:13 -04: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
Rob Pike
78d364c43e go.tools/cmd/cover: fix build
Need the ./ for the path. Quick fix to get the build green, but what really is the right answer for Windows?

R=golang-dev
CC=golang-dev
https://golang.org/cl/10359044
2013-06-21 14:47:04 -07:00
Rob Pike
c28528d489 go.tools/cmd/cover: add a test
Test the statistics work as expected for a simple program, which can be extended as needed. This is all a bit meta.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/10392050
2013-06-21 14:35:09 -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
Rob Pike
decfd079c5 go.tools/cmd/cover: skip mode line (first line of profile)
Still to do: use the mode to affect how to present the data.

R=adg, rsc
CC=golang-dev
https://golang.org/cl/10364050
2013-06-21 14:19:57 -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
Rob Pike
331c428e76 go.tools/cmd/vet: add check for shadowed variables
Experimental feature. It's too noisy yet to be enabled by default,
so it must be enabled explicitly by
        go tool vet -shadow *.go
or
        go tool vet -shadow directory
(The go command does not know about the -shadow flag.)

Fixes golang/go#5634.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/10409047
2013-06-21 11:27:53 -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
Rob Pike
33ae2b030f go.tools.cmd/cover: define a block to end at the closing brace rather than last statement
Makes for prettier output in many cases.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/10360049
2013-06-19 09:11:32 -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
Rob Pike
86c0ff156c go.tools/cmd/vet: set the package name unconditionally
A better fix than the one in CL 10400044

R=gri
CC=golang-dev
https://golang.org/cl/10376044
2013-06-18 14:12:51 -07:00
Rob Pike
ce82fb0e23 go.tools/cmd/vet: use directory for pkg.path if path is "."
Before:
        math/big/nat_test.go:688: arg r for printf verb %s of wrong type: ..Word
After:
        math/big/nat_test.go:688: arg r for printf verb %s of wrong type: big.Word

R=gri
CC=golang-dev
https://golang.org/cl/10400044
2013-06-18 14:02:01 -07:00
Rob Pike
df787c2073 go.tools/cmd/vet: check for missing printf verb
A trailing % resulted in a bad error message.
Also clean up a couple of dregs left over from the
refactoring to add indexed formats.

R=dsymonds
CC=golang-dev
https://golang.org/cl/10336044
2013-06-18 08:21:06 -07:00
Andrew Gerrand
16c6244c27 go.tools/cmd/cover: add HTML output
R=r, dsymonds
CC=golang-dev
https://golang.org/cl/10277043
2013-06-15 08:53:10 +10: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
Alan Donovan
0f26bbae8f go.tools/ssa: fix bug in code emitted for ast.TypeAssertExpr.
var x I = ...
x.(E) may fail dynamically (iff x is nil).

Added a testcase.

R=gri
CC=golang-dev
https://golang.org/cl/10237045
2013-06-13 17:31:32 -04:00
Rob Pike
3162ce0df2 go.tools/cmd/cover: record statements-per-block
This number will allow us to give a conventional meaning to "coverage":
the percentage of executable statements visited by the test.

R=adonovan
CC=golang-dev
https://golang.org/cl/10271045
2013-06-13 14:27:22 -07:00
Rob Pike
e330494adc go.tool/cmd/cover: use a struct instead of multiple variables
We are going to need one more piece of data, so rather than create
a third variable let's just put it all in one struct. The interface gets
easier too.

R=adonovan
CC=golang-dev
https://golang.org/cl/10271044
2013-06-13 12:50:30 -07:00
Alan Donovan
341a07a3aa go.tools/ssa: small changes accumulated during gri's vacation. :)
Method sets:
- Simplify CallCommon.
  Avoid the implicit copy when calling a T method on a *T
  receiver.  This simplifies clients.  Instead we generate
  "indirection wrapper" functions that do this (like gc does).
  New invariant:
  m's receiver type is exactly T for all m in MethodSet(T)
- MakeInterface no longer holds the concrete type's MethodSet.
  We can defer its computation this way.
- ssa.Type now just wraps a types.TypeName object.
  MethodSets are computed as needed, not eagerly.

Position info:
- new CanonicalPos utility maps ast.Expr to canonical
  token.Pos, as returned by {Instruction,Value}.Pos() methods.
- Don't set posn for implicit operations (e.g. varargs array alloc)
- Set position info for ChangeInterface and Slice instructions.

Cosmetic:
- add Member.Token() method
- simplify isPointer
- Omit words "interface", "slice" when printing MakeInterface,
  MakeSlice; the type is enough.
- Comments on PathEnclosingInterval.
- Remove Function.FullName() where implicit String() suffices.

Also:
- Exposed NewLiteral to clients.
- Added ssa.Instruction.Parent() *Function
  Added ssa.BasicBlock.Parent() *Function.
  Added Sanity checks for above.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/10166045
2013-06-13 14:43:35 -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
Rob Pike
0ca15cc618 go.tools/cmd/cover: add -o outputfile option
Makes it easier to get error output when run from the go tool.

R=adonovan
CC=golang-dev
https://golang.org/cl/10190043
2013-06-11 10:18:55 -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
Rob Pike
73612ddbfd go.tools/cmd/cover: handle empty select
Putting a coverage counter inside select{} is invalid Go.

R=adonovan
CC=golang-dev
https://golang.org/cl/10175043
2013-06-10 15:58:32 -07:00
Rob Pike
ba51e7a586 go.tools/cmd/cover: make -mode=atomic work again
It was broken by a previous simplification. The import was missing.

R=adonovan
CC=golang-dev
https://golang.org/cl/10117045
2013-06-10 10:58:08 -07:00
Rob Pike
ab78c3fa10 go.tools/cmd/cover: new tool
This is just the tool proper; stitching into "go test" will be a separate CL.
Tests are missing - they'll come once it's integrated - but it can handle,
perhaps correctly, all of src/pkg/...

The basic approach is to rewrite the source to add annotations that will
track coverage; the rewritten source must of course be compiled and
run after this tool has done its job.

R=adonovan
CC=golang-dev
https://golang.org/cl/10102043
2013-06-06 23:51:51 -07:00
Rob Pike
3402cf10ab go.tools/cmd/vet: verify printf for String and Error implementers
Fixes golang/go#5624.

R=adonovan
CC=gobot, golang-dev, gri
https://golang.org/cl/9657048
2013-06-06 16:05:14 -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
fc4c97d1f1 go.tools/ssa: refactoring: eliminate Builder from API.
Details:
- builder is now un-exported and is now a per-package entity.
- Package.nTo1Vars is now part of builder, where it belongs.
- CREATE phase code split out into its own file, create.go
- Context type is gone; it had become trivial after the
  Importer refactoring.
- importer.PackageInfo.Imports() now encapsulates iteration
  over imports.

Typical usage is now:
  prog := ssa.NewProgram(imp.Fset, mode)
  prog.CreatePackages(imp)
  prog.BuildAll()

Builder.BuildPackage(Package) is now Package.Build()
Builder.BuildAllPackages() is now Program.BuildAll()

R=iant, gri
CC=golang-dev
https://golang.org/cl/9970044
2013-06-03 16:46:57 -04:00
Alan Donovan
4d628a0312 go.tools/ssa: refactoring to make Builder stateless.
A Builder is now just a Program and a Context.

Details of this CL:
- Builder.imp field removed.
- Builder.globals split up into Package.values and Prog.Builtins.
- Builder.packages  moved to Prog.packages.
- Builder.PackageFor moved to Program.Package(types.Object)
- Program.Lookup() func replaces Builder.globals map.
- also: keep Package.info field around until end of BuildPackage.

Planned follow-ups to eliminate Builder from API:
- split NewBuilder up into NewProgram and Program.CreatePackages(...)
- move Builder.BuildAllPackages -> Program.BuildAll(Context)
- move Builder.BuildPackage -> Package.Build(Context)

R=gri, iant
CC=golang-dev
https://golang.org/cl/9966044
2013-06-03 14:15:19 -04:00
Alan Donovan
1f2812fe9b go.tools/ssa: fix bug in makeBridgeMethod for promoted interfaces.
The method index was hard-coded to zero, which works some of
the time.  Apparently I just forgot to implement the
method-table lookup...

Added regression test.

R=gri
CC=golang-dev
https://golang.org/cl/9916043
2013-05-31 16:36:03 -04:00
Rob Pike
838e9a8987 go.tools/cmd/vet: check indexed arguments in printf
Refactor the printf parser to be easier to understand.

R=gri
CC=golang-dev
https://golang.org/cl/9909043
2013-05-31 16:31:01 -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