1
0
mirror of https://github.com/golang/go synced 2024-10-01 12:38:31 -06:00
Commit Graph

551 Commits

Author SHA1 Message Date
Robert Griesemer
40b09326ee go.tools/go/types: enable another test case
Working now that circular interface types are handled correcly.

R=adonovan
CC=golang-dev
https://golang.org/cl/16310046
2013-10-24 09:09:10 -07:00
Alan Donovan
8636f40baf go.tools/ssa: CreateTestMainPackage: synthesize test driver as a package ("testmain") not 'main' function.
This allows us to run/analyze multiple tests.
Also it causes the production code packages to be properly initialized.

Also:
- cmd/ssadump: improved usage message (add example;
  incorporate LoadInitialPackages usage; explain how -run
  finds main).
- pointer, oracle, ssa/interp: use CreateTestMainPackage.
- ssa/builder.go: remove 'rundefers' instruction from package init,
  which no longer uses 'defer'.

R=gri
CC=golang-dev
https://golang.org/cl/15920047
2013-10-23 18:07:53 -04:00
Alan Donovan
87ced824bd go.tools/ssa: fix computation of set of types requiring method sets.
Motivation:

Previously, we assumed that the set of types for which a
complete method set (containing all synthesized wrapper
functions) is required at runtime was the set of types
used as operands to some *ssa.MakeInterface instruction.

In fact, this is an underapproximation because types can
be derived from other ones via reflection, and some of
these may need methods.  The reflect.Type API allows *T to
be derived from T, and these may have different method
sets.  Reflection also allows almost any subcomponent of a
type to be accessed (with one exception: given T, defined
'type T struct{S}', you can reach S but not struct{S}).

As a result, the pointer analysis was unable to generate
all necessary constraints before running the solver,
causing a crash when reflection derives types whose
methods are unavailable.  (A similar problem would afflict
an ahead-of-time compiler based on ssa.  The ssa/interp
interpreter was immune only because it does not require
all wrapper methods to be created before execution
begins.)

Description:

This change causes the SSA builder to record, for each
package, the set of all types with non-empty method sets that
are referenced within that package.  This set is accessed via
Packages.TypesWithMethodSets().  Program.TypesWithMethodSets()
returns its union across all packages.

The set of references that matter are:
- types of operands to some MakeInterface instruction (as before)
- types of all exported package members
- all subcomponents of the above, recursively.
This is a conservative approximation to the set of types
whose methods may be called dynamically.

We define the owning package of a type as follows:
- the owner of a named type is the package in which it is defined;
- the owner of a pointer-to-named type is the owner of that named type;
- the owner of all other types is nil.

A package must include the method sets for all types that it
owns, and all subcomponents of that type that are not owned by
another package, recursively.  Types with an owner appear in
exactly one package; types with no owner (such as struct{T})
may appear within multiple packages.
(A typical Go compiler would emit multiple copies of these
methods as weak symbols; a typical linker would eliminate
duplicates.)

Also:
- go/types/typemap: implement hash function for *Tuple.
- pointer: generate nodes/constraints for all of
  ssa.Program.TypesWithMethodSets().
  Add rtti.go regression test.
- Add API test of Package.TypesWithMethodSets().
- Set Function.Pkg to nil (again) for wrapper functions,
  since these may be shared by many packages.
- Remove a redundant logging statement.
- Document that ssa CREATE phase is in fact sequential.

Fixes golang/go#6605

R=gri
CC=golang-dev
https://golang.org/cl/14920056
2013-10-23 17:07:52 -04:00
Robert Griesemer
93ef310aab go.tools/go/types: handle interface types recurring via method signatures
Fixes golang/go#5090.

R=adonovan, gri, r, mtj
CC=golang-dev
https://golang.org/cl/14795044
2013-10-23 13:46:40 -07:00
Robert Griesemer
c8f4d650c8 go.tools/ssa/interp: make typeAssert robust against nil types
R=adonovan
CC=golang-dev
https://golang.org/cl/16180043
2013-10-23 13:45:49 -07:00
Robert Griesemer
a1886cc6ef go/tools/ssa/interp: make iface.eq robust against nil types
A future version of go/types.IsIdentical does not accept
nil types anymore.

R=adonovan
CC=golang-dev
https://golang.org/cl/16150043
2013-10-23 13:26:23 -07:00
Andrew Gerrand
36c288d6d7 go.tools/cmd/godoc: search go.tools/cmd before $GOROOT/cmd
Fixes golang/go#6527.

R=rsc
CC=golang-dev
https://golang.org/cl/14725043
2013-10-18 10:42:41 +09:00
Robert Griesemer
851a7b980a go.tools/go/types: return invalid type (rather than nil) for (*Label).Type()
R=adonovan
CC=golang-dev
https://golang.org/cl/14782043
2013-10-17 10:48:19 -07:00
Alan Donovan
8bb20b8231 go.tools/pointer: more reflection.
Support for:
        (*reflect.rtype).Field
        (*reflect.rtype).FieldByName
        reflect.MakeSlice
        runtime.SetFinalizer

Details:
- analysis locates ssa.Functions for (reflect.Value).Call
  and runtime.SetFinalizer during startup to that it can
  special-case them during genCall.  ('Call' is forthcoming.)
- The callsite.targets mechanism is only used for dynamic
  calls now.  For static calls we call callEdge during constraint
  generation; this is a minor optimisation.
- Static calls to SetFinalizer are inlined so that the call
  appears to go direct to the finalizer.  (We'll use the same
  trick for (reflect.Value).Call.)
- runtime.FuncForPC: treat as a no-op.
- Fixed pointer_test to properly deal with expectations
  that are multi-sets.
- Inlined rtypeMethodByNameConstraint.addMethod.
- More tests.

R=crawshaw
CC=golang-dev
https://golang.org/cl/14682045
2013-10-17 09:26:44 -04:00
Robert Griesemer
ac0a1222cb go.tools/go/types: fix StdSizes.Sizeof computation
Thanks to Travis Cline for finding this bug.

R=adonovan
CC=golang-dev
https://golang.org/cl/14752043
2013-10-16 10:45:58 -07:00
Robert Griesemer
d8391b87d1 go.tools/ssa/interp: use new Sizes interface (fix build)
R=adonovan
TBR=adonovan
CC=golang-dev
https://golang.org/cl/14722043
2013-10-15 15:30:03 -07:00
Robert Griesemer
5fcdb7b3ff go.tools/go/types: provide Sizes interface instead of individual sizing functions
This will make it a bit easier to create commonly used "custom" sizes for types.

With this CL, interfaces are now by default 2*WordSize (= 16) instead of 1*WordSize
as before.

Also: minor unrelated cleanups.

R=adonovan
CC=golang-dev
https://golang.org/cl/14719043
2013-10-15 14:51:52 -07:00
Francesc Campoy
fea69e5bab go.tools/present: add support for non Go code execution
R=adg, r
CC=golang-dev
https://golang.org/cl/14615043
2013-10-14 14:14:08 -07:00
Alan Donovan
2accef29d7 go.tools/ssa: implement correct control flow for recovered panic.
A function such as this:
        func one() (x int) {
                defer func() { recover() }()
                x = 1
                panic("return")
        }
that combines named return parameters (NRPs) with deferred calls
that call recover, may return non-zero values despite the
fact it doesn't even contain a return statement. (!)

This requires a change to the SSA API: all functions'
control-flow graphs now have a second entry point, called
Recover, which is the block at which control flow resumes
after a recovered panic.  The Recover block simply loads the
NRPs and returns them.

As an optimization, most functions don't need a Recover block,
so it is omitted.  In fact it is only needed for functions that
have NRPs and defer a call to another function that _may_ call
recover.

Dataflow analysis of SSA now requires extra work, since every
may-panic instruction has an implicit control-flow edge to
the Recover block.  The only dataflow analysis so far implemented
is SSA renaming, for which we make the following simplifying
assumption: the Recover block only loads the NRPs and returns.
This means we don't really need to analyze it, we can just
skip the "lifting" of such NRPs.  We also special-case the Recover
block in the dominance computation.

Rejected alternative approaches:
- Specifying a Recover block for every defer instruction (like a
   traditional exception handler).
   This seemed like excessive generality, since Go programs
   only need the same degenerate form of Recover block.
- Adding an instruction to set the Recover block immediately
   after the named return values are set up, so that dominance
   can be computed without special-casing.
   This didn't seem worth the effort.

Interpreter:
- This CL completely reimplements the panic/recover/
  defer logic in the interpreter.  It's clearer and simpler
  and closer to the model in the spec.
- Some runtime panic messages have been changed to be closer
  to gc's, since tests depend on it.
- The interpreter now requires that the runtime.runtimeError
  type be part of the SSA program.  This requires that clients
  import this package prior to invoking the interpreter.
  This in turn requires (Importer).ImportPackage(path string),
  which this CL adds.
- All $GOROOT/test/recover{,1,2,3}.go tests are now passing.

NB, the bug described in coverage.go (defer/recover in a concatenated
init function) remains.  Will be fixed in a follow-up.

Fixes golang/go#6381

R=gri
CC=crawshaw, golang-dev
https://golang.org/cl/13844043
2013-10-14 15:38:56 -04:00
Alan Donovan
7aabe2e113 go.tools/ssa: build a separate Function for each init() func.
Before, we would concatenate all the init() blocks together,
resulting in incorrect treatment of a recovered panic in one
init block: the implicit return would cause the subsequent ones
to be skipped.

The result is simpler, and closer to what gc does.

The additional functions are visible in the call graph,
so some tests required updating.

R=gri
CC=crawshaw, golang-dev
https://golang.org/cl/14671044
2013-10-14 14:08:23 -04:00
Alan Donovan
d7a9805478 go.tools/pointer: use assignable not identical type predicate in reflect.{Send,SetMapIndex,etc}
Various reflect operations permit assignability conversions,
i.e. their internals behave unlike y=x.(T) which unpacks only
those interface values in x that are identical to T.

We split typeAssertConstraint y=x.(T) into two constraints:
1) typeFilter, for when T is an interface type and no
   representation change occurs.
2) unpack, for when T is a concrete type and the payload of the
   tagged object is extracted.  This constraint has an 'exact'
   parameter indicating whether to use the predicate
   IsIdentical (for type assertions) or
   IsAssignable (for reflect operators).

+ Tests.

R=crawshaw
CC=golang-dev
https://golang.org/cl/14547043
2013-10-14 13:53:41 -04:00
Alan Donovan
1ff3452afa go.tools/ssa: unexport Register.
R=gri
CC=golang-dev
https://golang.org/cl/14672043
2013-10-14 13:48:34 -04:00
Shenghou Ma
1e6b0db4b9 go.tools/godoc/static: fix & escape in codewalks
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/14426053
2013-10-13 22:22:48 -04:00
Robert Griesemer
60c505c95c go.tools/go/types: fix recorded type for append(s, "foo"...)
R=adonovan
CC=golang-dev
https://golang.org/cl/14512057
2013-10-11 14:27:44 -07:00
Alan Donovan
aff951c80f go.tools/pointer: more reflection operators.
(reflect.Value).Bytes
(reflect.Value).Elem
(reflect.Value).Index
(reflect.Value).SetBytes
(reflect.Value).Slice
reflect.PtrTo
reflect.SliceOf

+ Tests.

Also: comment out an 'info-'level print statement in the test; it was distracting.

R=crawshaw
CC=golang-dev
https://golang.org/cl/14454055
2013-10-11 15:34:19 -04:00
Robert Griesemer
271af2c149 go.tools/importer: delete BuiltinCallSignature
This functionality is now provided by go/types.

R=adonovan
CC=golang-dev
https://golang.org/cl/14489045
2013-10-11 12:26:31 -07:00
Alan Donovan
7e4be2f6bc go.tools/importer: crude fix for race condition.
Revision 8f2c714c6d97 made the 'imports' map per-typechecker,
not per package, breaking an assumption of doImport0.  This
API needs a rethink for a number of reasons, some of which are
noted in this CL.

R=gri
CC=golang-dev
https://golang.org/cl/14606044
2013-10-11 15:18:21 -04:00
Rob Pike
e4256a40f4 go.tools/cmd/cover: for range loops might contain function literals
Break the basic block at the function literal. The code to do this analysis
was already there; this CL just factors it out more nicely and uses it in
one new place. Also adds a test.

Fixes golang/go#6555.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/14601043
2013-10-11 10:32:36 -07:00
Robert Griesemer
0c45220917 go.tools/go/types: record call-site specific types of built-in functions
Given a built-in call f(args), Info.Types now maps f to the call-site
specific type of f (by looking at the argument types) if the built-in
call is not producing a constant (at typecheck time) result. If the
result is constant, the recorded type is invalid (a back-end won't
need it).

R=adonovan
CC=golang-dev
https://golang.org/cl/14598045
2013-10-11 10:04:10 -07:00
Andrew Gerrand
7b481db506 go.tools/cmd/godoc: search go.tools/cmd for command docs
Update golang/go#6527

R=r, dsymonds
CC=golang-dev
https://golang.org/cl/14526053
2013-10-11 10:36:50 +09:00
Andrew Gerrand
ce4c627192 go.tools/cmd/cover: move docs to separate doc.go
The doc.go files will be copied into the binary distributions'
source tree that "godoc cover" works.

R=r
CC=golang-dev
https://golang.org/cl/14599045
2013-10-11 09:13:58 +09:00
Alan Donovan
f5b337da55 go.tools/cmd/cover: preserve comments, as other build tools may need "// +build" directives.
Also: fix a crash when a file already contains 'import "sync/atomic"'.

R=r, gri
CC=golang-dev
https://golang.org/cl/14441052
2013-10-10 15:29:24 -04:00
Robert Griesemer
579c61d653 go.tools/go/types: more robust handling of ... errors with built-ins
Catch ... errors earlier and in case of error, type-check all
arguments anyway for better type reporting and fewer "declared
but not used" errors.

R=adonovan
CC=golang-dev
https://golang.org/cl/14600043
2013-10-10 11:05:46 -07:00
Robert Griesemer
f54303d6cb to.tools/go/types: check invalid use of ... with built-ins
R=adonovan
CC=golang-dev
https://golang.org/cl/14531047
2013-10-10 10:46:54 -07:00
Alan Donovan
548052f0fa go.tools/importer: honor the client's TypeChecker.{Import,Error} values.
This requires us to make a copy of (not clobber) the supplied
config, and retain their Import hook separately so that it can
be wrapped by Importer.doImport.

Fixes bug 6562.

R=gri
CC=golang-dev
https://golang.org/cl/14523054
2013-10-10 13:34:24 -04:00
Alan Donovan
e1e9089196 go.tools/importer: change type of print{,ln} built-ins.
Before: func(any, ...interface{}).
After:  func(any, ...any)

They are no longer variadic, so you can't write print(x, y...).

(Recall that print(1) and print(interface{}(1)) behave
differently and that this is useful.)

Fixes bug 6560

R=gri
CC=golang-dev
https://golang.org/cl/14455054
2013-10-10 13:33:29 -04:00
Alan Donovan
9cce4759bb go.tools/importer: expose CreatePackage method.
The new method is functionally identical to typeCheck, and
obviates the LoadMainPackage method.

Updated all clients.

Fixes bug 6561.

R=gri
CC=golang-dev
https://golang.org/cl/14494051
2013-10-10 12:37:49 -04:00
Robert Griesemer
7ca228a514 go.tools/go.types: more missing assigment checks implemented
Assignments to "comma, ok" expressions on the lhs of an
assignment are not permitted unless we have map index
"comma, ok" expression. Created new operand mode 'mapindex'
to distinguish this case. Renamed mode 'valueok' to the more
commonly used 'commaok' term, which also makes it easier to
distinguish from simply 'value'.

Added corresponding tests.

Fixes a TODO.

R=adonovan
CC=golang-dev
https://golang.org/cl/14526049
2013-10-10 09:02:54 -07:00
Robert Griesemer
f50f6c858a go.tools/go/types: nil is not a constant + misc. cleanups
- removed support for nil constants from go/exact
- instead define a singleton Nil Object (the nil _value_)
- in assignments, follow more closely spec wording
  (pending spec CL 14415043)
- removed use of goto in checker.unary
- cleanup around handling of isRepresentable for
  constants, with better error messages
- fix missing checks in checker.convertUntyped
- added isTyped (== !isUntyped) and isInterface predicates
- fixed hasNil predicate: unsafe.Pointer also has nil
- adjusted ssa per adonovan
- implememted types.Implements (wrapper arounfd types.MissingMethod)
- use types.Implements in vet (and fix a bug)

R=adonovan, r
CC=golang-dev
https://golang.org/cl/14438052
2013-10-09 14:17:25 -07:00
Alan Donovan
9c8d9fe736 go.tools/pointer: support reflect.Method{,ByName}.
R=crawshaw
CC=golang-dev
https://golang.org/cl/14589043
2013-10-09 16:35:59 -04:00
Rob Pike
3edc3b18a9 go.tools/README: update to make truthful
The old README was misleading, saying the packages were not of interest.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/14516051
2013-10-09 11:47:05 -07:00
Alan Donovan
e590cdbdf8 go.tools/ssa: doc tweaks + a sanity check.
R=gri
CC=golang-dev
https://golang.org/cl/14454053
2013-10-09 12:47:30 -04:00
Alan Donovan
2299ac6bf3 go.tools/pointer: make sole callsite available to intrinsics in non-shared contours.
This information can be used to specialize such calls, e.g.
- report location of unsound calls (done for reflect.NewAt)
- exploit argument information (done for constant 'dir' parameter to reflect.ChanOf)

+ tests.

R=crawshaw
CC=golang-dev
https://golang.org/cl/14517046
2013-10-09 12:41:55 -04:00
Alan Donovan
cd908f1108 go.tools/ssa/interp: capture stdout/err of target programs and check for "BUG".
The $GOROOT/tests may print "BUG" on failure but do not
necessarily exit zero, so we must capture their output too.

Details:
- make plan9 use unix's valueToBytes function (now in externals.go)
- direct the target's syscall.Write and print/println built-ins to a new utility, write().  This may capture the output into a global variable.

R=gri, r
CC=golang-dev
https://golang.org/cl/14550044
2013-10-08 14:35:39 -04:00
Alan Donovan
068f017092 go.tools/ssa: s/Ret/Return/g
R=gri
CC=golang-dev
https://golang.org/cl/14526044
2013-10-08 12:31:39 -04:00
Alan Donovan
8ae5d36d2a go.tools: clear DeclarationErrors flag; it's redundant w.r.t go/types checking.
R=gri
CC=golang-dev
https://golang.org/cl/14147043
2013-10-08 10:34:36 -04:00
Tw
da6f00a60b go.tools/blog: replace "\\" with "/" in path string to be compatible with windows platform
Fixes golang/go#6539

The problem happens on my win7,
for example, the path is "/content\\foo.article".
It leads to the wrong link in generated html page.
So I think we should replace all"\\" with "/" in path string at first.

R=golang-dev, dsymonds, mirtchovski, dave, adg, alex.brainman
CC=golang-dev
https://golang.org/cl/14023043
2013-10-08 16:55:56 +11:00
Robert Griesemer
5d9b86d6ce go.tools/go/types: range iteration variables are typed (not untyped)
R=adonovan
CC=golang-dev
https://golang.org/cl/14516044
2013-10-07 20:27:21 -07:00
Dominik Honnef
d5044c7ed2 go.tools/cmd/vet: Update canonical method check for new xml.Marshaler/Unmarshaler interfaces
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14484043
2013-10-07 11:10:36 -07:00
Chris Manghane
1d4de00292 go.tools/dashboard: clone main repo from local path if it already exists locally.
R=adg, minux.ma
CC=golang-dev
https://golang.org/cl/14462049
2013-10-07 09:06:32 -07:00
Alan Donovan
eb632ebaca go.tools/ssa/interp: enable tests of builtin(f()) where f has multiple results.
R=gri
CC=golang-dev
https://golang.org/cl/14408043
2013-10-04 16:52:12 -04:00
Robert Griesemer
5d0990f591 go.tools/go/types: built-in calls of the form builtin(f())
- factor out argument extraction logic
- cleaned up error handling in builtin.go (no need for goto's anymore)
- lots of additional test cases
- various cleanups, better documentation

Fixes golang/go#5795.

R=adonovan
CC=golang-dev
https://golang.org/cl/14312044
2013-10-04 13:32:21 -07:00
Matt Reiferson
6af036a659 go.tools/vcs: allow compilation with go 1.0
It would be nice to be able to use this package
as a dependency (or other go utilities in the
ecosystem that depend on this package) in
environments which have not (or cannot) for
whatever reason upgraded to newer versions of
golang.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/14283043
2013-10-04 11:46:57 +10:00
Andrew Gerrand
c8494e30f9 go.tools/godoc/redirect: remove redundant redirect rules
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14365043
2013-10-04 09:49:25 +10:00
Andrew Gerrand
0ccb6234c3 undo CL 14368043 / 7750fc1a6bd2
Not the right approach.

««« original CL description
go.tools/godoc: reverse reversed redirects

Make godoc work again for go spec and memory model doc.

TBR=rsc
CC=golang-dev
https://golang.org/cl/14368043
»»»

R=gri
CC=golang-dev
https://golang.org/cl/14370043
2013-10-04 09:48:07 +10:00