1
0
mirror of https://github.com/golang/go synced 2024-10-01 16:08:33 -06:00
Commit Graph

3670 Commits

Author SHA1 Message Date
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
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
Rob Pike
291b2c84b6 go.tools/cmd/vet: prepare print format checker for indexed arguments
Rewrite the checker to be more flexible and better documented, being
more explicit about parsed format vs. checked arguments.
No attempt yet to do check indexed formats; this just paves the way.
All tests still pass.

R=gri
CC=golang-dev
https://golang.org/cl/9881044
2013-05-30 14:26:22 -04:00
Alan Donovan
18f85da60d go.tools/ssa: fix breakage caused by CL 9839045 to go/types.
This removes the ast.CaseClase hack for implicit variables.

R=gri
CC=golang-dev
https://golang.org/cl/9863045
2013-05-30 13:18:07 -04: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
Alan Donovan
4e0d6858c8 go.types/ssa: inline all calls to objKind().
R=gri
CC=golang-dev
https://golang.org/cl/9740052
2013-05-30 12:13:42 -04:00
Alan Donovan
6c7ce1c2d3 go.tools/ssa: Value.Pos() method + remaining source position plumbing.
Implement Pos() method for
  Values:       Parameter, Capture, Phi.  (Not Literal, Builtin.)
  Instructions: UnOp, BinOp, Store.

'address' (an lvalue) now needs position of '*' in "*addr".

Also:
- Un-export fields Pos_ Type_ Name_ Block_ from various values/instructions.
  Define NewFunction() as a temporary measure.
  Will try to eliminate calls from clients...
- Remove Implements{Value,Member,Interface} marker methods.
  I've decided I don't like them.
- Func.addParamObj helper.
- Various comment fixes.

R=gri
CC=golang-dev
https://golang.org/cl/9740046
2013-05-30 09:59:17 -04:00
Rob Pike
d6c1c75eab go.tools/cmd/vet: say ./testvet instead of testvet
I bet "." is not in the default PATH.

R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/9867043
2013-05-29 15:00:51 -04:00
Rob Pike
f91ca66179 go.tools/cmd/vet: attempt to fix build
Can't reproduce the failure outside the builder, but attempt a fix
by changing the criterion for failure: FAIL iff the output contains "BUG".

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/9798050
2013-05-29 11:28:19 -04:00
Rob Pike
2b48cfca08 cmd/vet: use length of output from errchk to check PASS/FAIL
errchk is itself a FAIL: it doesn't exit non-zero on error!

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/9842044
2013-05-28 16:51:47 -04:00