Commit Graph

385 Commits

Author SHA1 Message Date
Robert Griesemer f59b01c69b go.tools/go/types, exact: fix build for 1.2
Fixes golang/go#8192.

LGTM=bradfitz
R=bradfitz, adonovan
CC=golang-codereviews
https://golang.org/cl/105160043
2014-06-12 12:46:21 -07:00
Robert Griesemer afafa2630f go.tools/go/types: export types.Checker (cleanup)
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/109850044
2014-06-12 11:13:58 -07:00
Alan Donovan 142566e529 go/ssa: avoid "premature optimization" of dead branch removal.
Blocks dominated by "if false" should be retained in the
initial SSA form so they remain visible to subsequent source
code analysis tools.

In any case, true compilers already need a stronger version of
this optimization so they can simplify CFGs such as this:
	const x, y = ...
        switch x {case y:...}
where a branch is constant but the comparison of constants
does not occur within an expression.

LGTM=gri
R=gri
CC=golang-codereviews, pcc
https://golang.org/cl/101250043
2014-06-12 11:31:41 -04:00
Robert Griesemer 0fa48054ca go.tools/go/types: comma-ok expressions return bool rather than untyped bool
Per the current spec.

Fixes golang/go#8188.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/101200043
2014-06-11 15:03:38 -07:00
Alan Donovan 30166088e4 go/ssa: remove optimization of 'rundefers'.
The SSA builder shouldn't be in the business of
interprocedural optimization, especially in the presence of
concurrency.

This causes the instruction count to increase by 0.03%.

LGTM=gri
R=gri, pcc
CC=golang-codereviews
https://golang.org/cl/105020045
2014-06-11 16:33:25 -04:00
Peter Collingbourne cd36f52558 go.tools/go/ssa: add Max to Slice's SSA operand list
LGTM=adonovan
R=adonovan, bradfitz
CC=golang-codereviews
https://golang.org/cl/101160043
2014-06-11 16:16:19 -04:00
Alan Donovan cc02c5be36 go/ssa: s/Capture/FreeVar/g
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/109820044
2014-06-11 14:04:45 -04:00
Alan Donovan 1edc750a9c go/ssa: cleanup: make NewFunction a member of *Program.
(since it always needs this field)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/106960045
2014-06-11 14:03:40 -04:00
Alan Donovan 94d1589bd2 go.tools/go/pointer: fix objectNode() bug causing it to return nil spuriously.
It was making the unsound assumption that cgn==nil => v is one
of {Global,Function,Const,Capture} to avoid checking v's type,
which is what it now does.  This caused more expensive
constraints to be generated, which is suboptimal though not
wrong exactly.

In one benchmark, this change reduces the number of complex
constraints by about 23% of loads and 53% of stores, and
increases the number of (simple) copy constraints by about 5%.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/106940043
2014-06-11 13:19:52 -04:00
Alan Donovan 7746b67294 go.tools/go/loader: enable cgo processing of files that import "C".
Files that import "C" are not valid Go source files and
require preprocessing.  Until now, the loader has simply
hard-coded CGO_ENABLED=0 (in effect) which causes go/build to
use build tags select pure Go implementations where they exist
(e.g. in $GOROOT).  Where they don't (e.g. arbitrary user
code) this leads to masses of spurious type errors.
(Reported by Guillaume Charmes, private correspondence.)

This change causes the loader to invoke the cgo preprocessor
on such files and to load the preprocessed files instead,
using the original names.  This means that the syntax offset
position information is garbage, although thanks to //line
directives, the line numbers at least should be good.

See comment in cgo.go for details.

This CL changes the loader's default behaviour and may make it slower.
CGO_ENABLED=0 enables the old behaviour.

Tested via stdlib_test, which now loads all standard packages
using cgo, and also exercises CGO_ENABLED=0 for "net" and "os/user".

LGTM=gri
R=gri, rsc
CC=golang-codereviews, guillaume.charmes
https://golang.org/cl/86140043
2014-06-11 13:16:51 -04:00
Alan Donovan 04427c85cf go/ssa: add Node interface: common parts of Value+Instruction, plus Operands/Referrers.
Also:
- extend Parent() to all Values and add to interface:
  (Builtin/Const/Global => nil; Function => Enclosing)
- hide Function.Enclosing since it's now redundant wrt Parent()
- make (*Function).String robust for synthetics without pkg object

LGTM=gri
R=gri
CC=golang-codereviews, khr
https://golang.org/cl/87580044
2014-06-11 13:14:06 -04:00
Alan Donovan 74117bcfd8 go/pointer: use sparse bit vectors to represent points-to sets in solver.
This optimization reduces solve time (typically >90% of the
total) by about 78% when analysing real programs.  It also
makes the solver 100% deterministic since all iterations are
ordered.

Also:
- remove unnecessary nodeid parameter to solve() method.
- don't add a fieldInfo for singleton tuples (cosmetic fix).
- inline+simplify "worklist" type.
- replace "constraintset" type by a slice.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/95240043
2014-06-11 13:12:15 -04:00
Alan Donovan fec252214b go.tools/ssa: create thunks for method expressions T.f.
Until now, the same Function was used to represent a method
(T)func() and the "method expression" function func(T) formed
from it. So the SSA code for this:

    var buf bytes.Buffer
    f := Buffer.Bytes
    f(buf)
    buf.Bytes()

would involve an implicit cast (ChangeType) on line 2.
However, compilers based on go/ssa may want to use different
calling conventions for them, like gccgo does (see issue
7839).  This change decouples them by using an anonymous
function called a "thunk", rather like this:

    f := func(r *bytes.Buffer) []byte { return r.Bytes() }

Thunks are similar to method wrappers; both are created by
makeWrapper.

"Interface method wrappers" were a special case of thunks for
direct calls (no indirection/fields) of interface methods.
They are now subsumed by thunks and have been deleted.  Now
that only the needed thunks are built, we don't need to
populate the concrete method sets of interface types at all,
so (*Program).Method and LookupMethod return nil for them.
This results in a slight reduction in function count (>1%) and
instruction count (<<1%).

Details:

go/ssa:
- API: ChangeType no longer supports func/method conversions.
- API: (*Program).FuncValue now returns nil for abstract
  (interface) methods.
- API: (*Function).RelString simplified.
  "$bound" is now a suffix not a prefix, and the receiver
  type is rendered package-relative.
- API: Function.Object is now defined for all wrappers too.
- API: (*Program).Method and LookupMethod return nil for
  abstract methods.
- emitConv no longer permits (non-identical)
  Signature->Signature conversions.  Added assertion.
- add and use isInterface helper
- sanity: we check packages after Build, not Create, otherwise
  cross-package refs might fail.

go/pointer:
- update tests for new function strings.
- pointer_test: don't add non-pointerlike probes to analysis.
  (The error was checked, but too late, causing a panic.)
- fixed a minor bug: if a test probe print(x) was the sole
  reference to x, no nodes were generated for x.
- (reflect.Type).MethodByName: updated due to ssa API changes.
  Also, fixed incorrect testdata/funcreflect.go expectation
  for MethodByName on interfaces.

oracle:
- fix for new FuncValue semantics.
- a "pointsto" query on an I.f thunk now returns an error.

Fixes golang/go#7839

LGTM=gri
R=gri
CC=golang-codereviews, pcc
https://golang.org/cl/93780044
2014-06-11 13:10:26 -04:00
Peter Collingbourne 9fc9dd9a01 go.tools/go/types: dup check interface keys in composite map literals correctly
Specifically, take into account the key type.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/103080044
2014-06-11 10:01:51 -07:00
Robert Griesemer 3827909f21 go.tools/go/types: compute correct initialization order
- Replaced check.initDependencies with check.initOrder;
  this is the only semantic change, it affects only the
  value of Info.InitOrder.
- Added additional init order test cases and adjusted
  existing tests.
- Moved orderedSetObjects from resolver.go to ordering.go.

Fixes golang/go#7964.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/91450043
2014-06-11 09:15:31 -07:00
Robert Griesemer 459aaad458 go.tools/go/types: fix float32 conversions
Pending CL 93550043.
For submission after the 1.3 release.

Fixes golang/go#8066.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/95580045
2014-06-11 09:12:52 -07:00
Peter Collingbourne afea1b1755 go.tools/go/ssa: fix range iteration over values of pointer to named array type
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/107800045
2014-06-05 17:19:58 -04:00
Alan Donovan 43c97eab79 go.tools/go/pointer: fix solver nontermination bug due to reflective type construction cycles.
Programs such as this cause the PtrTo solver to attempt to
enumerate an infinite set of types {T, *T, ..., *******T, etc}.

        t := reflect.TypeOf(T{})
        for {
                t = reflect.PtrTo(t)
        }

The fix is to bound the depth of reflectively created types at
about 4 map/chan/slice/pointer constructors.

+ test.

LGTM=gri
R=gri
CC=crawshaw, golang-codereviews
https://golang.org/cl/102030044
2014-05-30 16:27:51 -04:00
Robert Griesemer 8df7a779db go.tools/go/types: package name must not be blank
Fixes golang/go#8077.

LGTM=adonovan
R=golang-codereviews, adonovan
CC=golang-codereviews
https://golang.org/cl/91640043
2014-05-22 13:45:29 -07:00
Robert Griesemer 2afc128b30 go.tools/go/types: interfaces may not have blank methods
Fixes golang/go#8050.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/96520047
2014-05-22 13:10:53 -07:00
Robert Griesemer 2fcf90cfac go.tools/go/types: re-disable float_lit2.go std test
go/types doesn't correctly round the largest possible
float32 literal values and fails. Instead of relying
on Rat.Float64 and float32 conversion, we need a
Rat.Float32 implementation with correct rounding.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/96540045
2014-05-21 09:55:02 -07:00
Robert Griesemer 11314ad3ea go.tools/go/types: enable float_lit2.go test
Pending CL 91590047 which fixes that test.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/91630043
2014-05-21 08:54:23 -07:00
Robert Griesemer 33097bf3ed go.tools/go/types: exclude newly added std test (fix build)
TBR=adonovan

TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/99410045
2014-05-20 13:27:11 -07:00
Rob Pike a8c8f48be3 go.tools/all: the the thes are too frequent, it's clear that that's not what we want
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/98380043
2014-05-19 09:48:30 -07:00
Rob Pike 6f17d00f0d go.tools: fix various minor issues found by go vet
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/96360048
2014-05-19 08:47:28 -07:00
Alan Donovan 18c694293a go.tools/go/ssa: fix incorrect indentation in SSA printout.
Very long instructions caused the printf width spec to go
negative, which causes right-padding, often several lines'
worth.

Also: print the basic block comment once on the RHS. It's too
verbose to print it each time we mention the block.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/97490046
2014-05-16 12:37:17 -04:00
Robert Griesemer 51d8ee0ff8 go.tools/go/types: report init dependencies via method values
- one-line fix
- comprehensive set of test cases added

Fixes golang/go#7963.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/100320043
2014-05-09 13:57:38 -07:00
Alan Donovan 4700b7a612 go/callgraph: fix asymptote trap in DeleteSyntheticNodes.
The previous implementation would cause the graph to contain
many duplicate edges resulting in very large cross products,
so that for some inputs (and random map iteration orders) the
running time of DeleteSyntheticNodes was many minutes---more
than the pointer analysis!

Duplicate edges can arise from an interface call that
dispatches to several different wrapper functions each
wrapping the same declared method.

For example, in the callgraph for go/types, a call to
Object.Pos() dispatches to the synthetic functions (*Type).Pos
and (*Var).Pos, each of which wrap (*object).Pos().  After
DeleteSyntheticNodes, Object.Pos() appeared to call
(*object).Pos() twice.

This change builds the set of all edges and avoids adding
edges already in the set.

Also, document findings.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/96100043
2014-05-08 14:03:06 -04:00
Alan Donovan c212b356b8 go.tools/go/types: add API test of Selection mechanism.
Also: fixed a crash in (*Selection).String() for FieldVal of a
non-function type.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/93830043
2014-05-07 18:35:43 -04:00
Robert Griesemer 9f1412014f go.tools/go/types: added test case for channel make
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/95910044
2014-05-05 10:12:50 -07:00
Robert Griesemer 30b1abe2f7 go.tools: fix various typos
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/97920045
2014-05-02 14:38:08 -07:00
Alan Donovan 6e03bb4eb4 go.tools: remove dead code
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/90320043
2014-04-25 15:08:13 -04:00
Alan Donovan 8e263c554d go.tools/go/types: fix incorrect receiver in (*Selection).Type().
Method expressions T.f are reported as having type (T)func(T),
i.e. T appears twice, as a receiver and a regular parameter.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/96780044
2014-04-25 12:08:31 -04:00
Alan Donovan 7d1d69032b go.tools/go/ssa: don't attempt fusion on single-pred blocks with φ-nodes
During block optimization, degenerate conditional logic such
as "false && x" may result in single-predecessor blocks
containing φ-nodes.  (Ideally such φ-nodes would be replaced
by their sole operand, but that requires Referrers information
which isn't computed until later.)  It is obviously not safe
to fuse such blocks, so now we don't.

Fixes golang/go#7840

LGTM=gri
R=gri
CC=golang-codereviews, pcc
https://golang.org/cl/90620043
2014-04-24 09:08:21 -04:00
Robert Griesemer 4bc2f4e34b go.tools/go/types: fix doc comment
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/90100043
2014-04-21 16:35:40 -07:00
Peter Collingbourne feafa74756 go.tools/go/types: address and slice operations are not addressable
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/89380044
2014-04-21 11:38:43 -07:00
Peter Collingbourne 998b73a2e9 go.tools/go/types: result of make and new builtins are not addressable
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/89390045
2014-04-21 11:20:54 -07:00
Alan Donovan 379e0e7704 go.tools/go/types: x,y:=0,0 is a Use (not Def) of x if it is already defined.
+ test.

Fixes golang/go#7827

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/89600045
2014-04-21 14:05:25 -04:00
Alan Donovan 1ae1c63748 go.tools/go/ssa/interp: add wrappers for Sysctl{,Uint32} intrinsics on FreeBSD
(Speculative fix---I can't test it directly.)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/89320043
2014-04-18 15:58:12 -04:00
Andrew Wilkins f8200537d8 go.tools/go/gccgoimporter: use gccgo -dumpversion
GccgoInstallation.InitFromDriver currently parses
the output of gccgo -### to get the gcc version,
target triple, and library paths. At least with
Ubuntu's stock libgo5 package, the search path for
.gox files derived from the version is incorrect.

gccgo uses the DEFAULT_TARGET_VERSION macro when
constructing the search path; this value can be
retrieved from gccgo via the "-dumpversion" flag.

Fixes golang/go#7772.

LGTM=iant, gri
R=golang-codereviews, iant, gri
CC=golang-codereviews
https://golang.org/cl/88150043
2014-04-17 13:40:42 -07:00
Robert Griesemer 1961019b8c go.tools/go/exact: tweaked documentation
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/88630043
2014-04-16 13:07:59 -07:00
Alan Donovan 9531aca448 go.tools/go/pointer: add TODO comment.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/87810046
2014-04-15 15:41:02 -04:00
Alan Donovan 5421af34cc go.tools/go/types: fix typo in comment.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/88200044
2014-04-15 15:39:24 -04:00
Alan Donovan bc722df585 go.tools/go/ssa/interp: minor cleanup
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/88080044
2014-04-15 15:37:32 -04:00
Alan Donovan 647d17e45f go.tools/go/ssa/interp: add no-op intrinsic sync.runtime_registerPoolCleanup
Also, compute correct index of struct field sync.Pool.New, which just changed.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/87780043
2014-04-14 17:53:58 -04:00
Robert Griesemer b5d07c813b go.tools/go/types: tweak test exceptions
Per feedback from rsc.

LGTM=rsc, adonovan
R=adonovan, rsc
CC=golang-codereviews
https://golang.org/cl/86310043
2014-04-10 10:39:00 -07:00
Robert Griesemer 8caaaf224f go.tools/go/types: exclude broken test case (fix build)
TBR=adonovan

TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/86260043
2014-04-09 15:32:36 -07:00
Alan Donovan 7ef831a4e6 go.tools/go/ssa: perform nil check when taking value of interface method.
+ test.

Fixes golang/go#7269

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/84650046
2014-04-09 18:00:57 -04:00
Alan Donovan b12fe1707c go.tools/go/loader: slashify the name of packages found by walking the file tree.
Otherwise on Windows the enumerated package "net\\http" will
be distinct from the imported package "net/http" leading to
strange errors.  (A similar bug was fixed in go/ssa/stdlib_test.go.)

Fixes golang/go#7189

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/86170043
2014-04-09 15:47:42 -04:00
Robert Griesemer 0b23073b5c go.tools/go/types: type-check interfaces in reverse dependency order
Side-effect: Because interfaces are now type-checked in reverse order,
cycle errors in interface declarations appear at the "end" rather than
at the "beginning" of the cycle in the source code. This is harmless.
Eventually we may want to do dependency order determination and thus
cycle detection for all types before fully type-checking them, which
might simplify some code and also produce consistently positioned cycle
errors again.

Fixes golang/go#7158.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/83640043
2014-04-02 11:42:29 -07:00