1
0
mirror of https://github.com/golang/go synced 2024-10-01 11:28:34 -06:00
Commit Graph

480 Commits

Author SHA1 Message Date
Robert Griesemer
d259ea48d1 go.tools/go/types: first cut at checking variable initialization cycles
Missing:
- dependencies via functions (incl. closures and methods)
- more tests (incl. API test)

R=adonovan
CC=golang-dev
https://golang.org/cl/20510043
2013-10-31 21:47:35 -07:00
Alex Brainman
5879669d9d go.tools/dashboard/builder: ignore GOPATH setting during build (on windows)
R=golang-dev, minux.ma, adg
CC=golang-dev
https://golang.org/cl/18920046
2013-11-01 11:28:31 +11:00
Alan Donovan
74b761d099 go.tools/ssa: clarify spec of (*builder).complit().
Added test for []*map composite literals containing nested
literal subelements.  This required implementing
(reflect.Value).Map{Keys,Index} in ssa/interp.

Plus two minor fixes in ssa/interp.

R=gri
CC=golang-dev
https://golang.org/cl/20470043
2013-10-31 17:59:52 -04:00
Robert Griesemer
fb0632eb7d go.tools/go/types: Provide explicit type checker Error.
R=adonovan
CC=golang-dev
https://golang.org/cl/20400044
2013-10-31 12:01:00 -07:00
Robert Griesemer
03e3f0cf81 go.tools/cmd/gotype: make gotype use go/build
This CL makes gotype usable again. Removed -r
(recursive) mode; use go/build to determine
the correct set of Go files when processing
a directory. The -v (verbose) mode now prints
some basic stats (duration, number of files,
lines, and lines/s).

Thoroughly restructured the code.

Applying gotype -v -a . to the go/types directory:
128.94141ms (40 files, 12008 lines, 93127 lines/s)

On a 2.8 GHz Quad-Core Intel Xeon, 800 MHz DDR2 FB-DIMM,
with go/types built with the (interal) debug flag set to
false. There's still quite a bit of room for performance
improvement in all parts of the code since no tuning has
been done.

R=golang-dev, adonovan
CC=golang-dev
https://golang.org/cl/19930043
2013-10-31 10:01:58 -07:00
Alan Donovan
1518a24464 go.tools/importer: don't pass srcDir=os.Getwd to go/build.Import().
This makes imports independent of the process's working
directory.  (Perhaps this was a feature, but I haven't found a
situation in which it actually works.)

R=gri
CC=golang-dev
https://golang.org/cl/19420043
2013-10-31 10:56:33 -04:00
Alan Donovan
f4fca995ad go.tools/pointer: fix test of pts(os.Args) on Windows.
I have no way to test this.

R=crawshaw
CC=alex.brainmain, golang-dev
https://golang.org/cl/17820044
2013-10-31 10:24:00 -04:00
Brad Fitzpatrick
766a70612a godoc: add a Corpus hook to summarize a package
This lets godoc implementations provide a more efficient means
of getting this information, without reading files and parsing the
package docs.

This is especially important when the files themselves don't
actually exist and the VFS is synthesizing them on demand
(e.g. protocol buffer files -> their generated *.pb.go files).
This means corpus.Init can run quickly, without generating
every protocol file in a large corpus (or fetching it from a
cache).

In the future, this hook could also be used for caching the summaries of
regular packages.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/19440043
2013-10-30 11:34:32 -07:00
Andrew Gerrand
99890b82e7 go.tools/godoc/static: use preferred JS for Google+ buttons
R=bradfitz, dsymonds
CC=golang-dev
https://golang.org/cl/19070044
2013-10-30 13:13:42 +11:00
Alan Donovan
94c387c610 go.tools/pointer: implement (reflect.Value).Call.
The implementation follows the basic pattern of an indirect
function call (genDynamicCall).

We use the same trick as SetFinalizer so that direct calls to
(r.V).Call, which are overwhelmingly the norm, are inlined.

Bug fix (and simplification): calling untag() to unbox a
reflect.Value is wrong for reflect.Values containing interfaces
(rare).  Now, we call untag for concrete types and typeFilter
for interface types, and we can use this pattern in all cases.
It corresponds to the ssa.TypeAssert operator, so we call
it typeAssert.  Added tests to cover this.

We also specialize reflect.{In,Out} when the operand is an int
literal.

+ Tests.

Also:
- make taggedValue() panic, not return nil, eliminating many checks.
  We call isTaggedValue for the one place that cares.
- pointer_test: recover from panics in Analyze() and dump the log.

R=crawshaw
CC=golang-dev
https://golang.org/cl/14426050
2013-10-29 21:57:53 -04:00
Alan Donovan
e1b710c31e go.tools/README: minor correction.
R=gri
CC=golang-dev
https://golang.org/cl/18490043
2013-10-29 13:20:58 -04:00
Alan Donovan
bac7098173 go.tools/ssa: fix crash on (new)(T) due to missing unparen() call.
Audited codebase for other occurrences, found two more.
Added test coverage for all of them.

R=gri
CC=golang-dev
https://golang.org/cl/14698043
2013-10-29 11:07:09 -04:00
Brian Gitonga Marete
4a813e4058 blog: Fix atom feed's `updated' time when there's only one article.
When computing the time for the "updated" tag of the atom feed, the
current code checks if there is more than one article and if that is
not true, it sets the time to the zero time.Time. This means that
the feed also gets the zero time in this tag when there is exactly one
article.

This trivial patch fixes this so that when there is exactly one
article, the time is set to that article's time.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/18420044
2013-10-29 15:55:27 +09:00
Brad Fitzpatrick
452c763fc7 godoc: parallelize corpus init
Massive win for high-latency network filesystems.
Also benefits the local disk/ssd case too, though.

R=golang-dev, bgarcia
CC=golang-dev
https://golang.org/cl/18650043
2013-10-28 12:51:01 -07:00
Alan Donovan
e29626539b go.tools/ssa: clarify that DebugRef relation is a function from ast.Expr to (ssa.Value, IsAddr bool), in docs and printed form.
R=gri
CC=golang-dev
https://golang.org/cl/18410043
2013-10-28 12:05:29 -04:00
Alan Donovan
7a70c382be go.tools/pointer: fix panic in reflection.
reflect.Values may point to tagged objects with
interface type, e.g. x := reflect.ValueOf(new(interface{})).Elem().
We failed to consider this when implementing Elem.

Also, (reflect.Value).Interface() must do one "unboxing"
when it encounters such tagged objects.
i.e., x.Elem().Interface() and x.Interface() are equivalent
in that case.

Also:
- add example of tagged object with interface type.
- untabify (Label).String docstring.
- added tests.

R=crawshaw
CC=golang-dev
https://golang.org/cl/18020044
2013-10-28 10:58:46 -04:00
Brian Gitonga Marete
f3120b161e blog: Make the atom feed title configurable.
The blog code is quite generic and with the replacement of template and
static files, it can be re-used. But the atom feed title is hard-coded
into the code. This patch adds a field to set the atom feed title to
the Config structure and uses it in the code where the title was
previously hard-coded.

A CL sent separately will set this Config field in the main package in
the go.blog sub-repository. (See CL 16850043 for that other patch).

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/16830043
2013-10-28 10:17:10 +02:00
Alan Donovan
aa2386290b go.tools/ssa: new Function.Syntax() returns the declaring AST (debug mode) or just the Pos/End of the function's extent (otherwise).
R=gri
CC=golang-dev
https://golang.org/cl/16980043
2013-10-27 10:55:21 -04:00
Robert Griesemer
3eb9e504e3 go.tools/go/types: update a TODO comment (not a TODO anymore)
R=adonovan
TBR=adonovan
CC=golang-dev
https://golang.org/cl/17440043
2013-10-25 15:37:03 -07:00
Robert Griesemer
b98997fdfe go.tools/go/types: enable std lib test of map key types
R=adonovan
CC=golang-dev
https://golang.org/cl/17390043
2013-10-25 14:38:52 -07:00
Robert Griesemer
65aaa0093c go.tools/go/types: check map key type when it is fully known
Fixes golang/go#6667.

R=adonovan
CC=golang-dev
https://golang.org/cl/17360043
2013-10-25 14:32:14 -07:00
Robert Griesemer
1e05a58b11 go.tools/go/types: consistently use 'elem' instead of 'elt'
This is simply a rename of unexported struct fields.
No other changes.

R=adonovan
CC=golang-dev
https://golang.org/cl/17330043
2013-10-25 13:59:40 -07:00
Robert Griesemer
cf08eefe7f go.tools/go/types: test cases for comparisons
- better error messages
- in contrast to a long-standing TODO, comparisons
  between interface and non-interface types always
  worked correctly

R=adonovan
CC=golang-dev
https://golang.org/cl/17310043
2013-10-25 13:16:45 -07:00
Alan Donovan
d644aa1fcd go.tools/ssa/interp: enable $GOROOT/test/switch.go test
(now that go/types can handle it)

R=gri
TBR=gri
CC=golang-dev
https://golang.org/cl/16970043
2013-10-24 22:38:10 -04:00
Alan Donovan
9f640c2abb go.tools/ssa: record lvalue/rvalue distinction precisely in DebugRef.
A DebugRef associates a source expression E with an ssa.Value
V, but until now did not record whether V was the value or the
address of E.  So, we would guess from the "pointerness" of
the Value, leading to confusion in some cases, e.g.

   type N *N
   var n N
   n = &n  // lvalue and rvalue are both pointers

Now we explicitly record 'IsAddress bool' in DebugRef, and
plumb this everywhere: through (*Function).ValueForExpr and
(*Program).VarValue, all the way to forming the pointer
analysis query.

Also:
- VarValue now treats each reference to a global distinctly,
  just like it does for other vars.  So:
    var g int
    func f() {
   	g = 1     // VarValue(g) == Const(1:int), !isAddress
        print(g)  // VarValue(g) == Global(g), isAddress
    }
- DebugRefs are not emitted for references to predeclared
  identifiers (nil, built-in).
- DebugRefs no longer prevent lifting of an Alloc var into a
  register; now we update or discard the debug info.
- TestValueForExpr: improve coverage of ssa.EnclosingFunction
  by putting expectations in methods and init funcs, not just
  normal funcs.
- oracle: fix golden file broken by recent
  (*types.Var).IsField change.

R=gri
CC=golang-dev
https://golang.org/cl/16610045
2013-10-24 18:31:50 -04:00
Robert Griesemer
69f5b543df go.tools/go/types: check for duplicate types in type switches
R=adonovan
CC=golang-dev
https://golang.org/cl/16860043
2013-10-24 15:20:03 -07:00
Alan Donovan
96bdcd22e3 go.tools/go/types: add Var.IsField() accessor, and print "field" not "var".
R=gri
CC=golang-dev
https://golang.org/cl/16780043
2013-10-24 17:07:11 -04:00
Robert Griesemer
c20165988a go.tools/go/types: no duplicate checking in expr switches for now
See also issue 4524.

R=adonovan
CC=golang-dev
https://golang.org/cl/16700045
2013-10-24 14:02:14 -07:00
Robert Griesemer
ad46727525 go.tools/go/types: handle blank _ methods in interface types
The spec does not exclude blank _ method names in interfaces
from the uniqueness criteria; i.e., at most one blank method
may appear in an interface type.

Arguably the spec is vague (and possibly incorrect) here.
gccgo handles it the same way. gc crashes with an internal
compiler error.

R=adonovan
CC=golang-dev
https://golang.org/cl/16380043
2013-10-24 09:12:28 -07:00
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