go.tools/oracle: callgraph: fix crash caused by sparse node numbering.

Revision 0ea4058a1ca3 caused the node numbering to become
sparse, violating a precondition of
(*callgraphResult).toSerial.  Now we renumber the callgraph
nodes always, not just the qpos != nil case.

Fixes issue 8171

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://codereview.appspot.com/103240044
go.tools/go/types: fix float32 conversions

Pending CL 93550043.
For submission after the 1.3 release.

Fixes issue 8066.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://codereview.appspot.com/95580045
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 issue 7964.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://codereview.appspot.com/91450043
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://codereview.appspot.com/103080044

Committer: Robert Griesemer <gri@golang.org>
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 issue 7839

LGTM=gri
R=gri
CC=golang-codereviews, pcc
https://codereview.appspot.com/93780044
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://codereview.appspot.com/95240043
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://codereview.appspot.com/87580044
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://codereview.appspot.com/86140043
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://codereview.appspot.com/106940043
go/ssa: cleanup: make NewFunction a member of *Program.

(since it always needs this field)

LGTM=gri
R=gri
CC=golang-codereviews
https://codereview.appspot.com/106960045
go/ssa: s/Capture/FreeVar/g

LGTM=gri
R=gri
CC=golang-codereviews
https://codereview.appspot.com/109820044
go.tools/go/ssa: add Max to Slice's SSA operand list

LGTM=adonovan
R=adonovan, bradfitz
CC=golang-codereviews
https://codereview.appspot.com/101160043

Committer: Alan Donovan <adonovan@google.com>
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://codereview.appspot.com/105020045
go.tools/go/types: comma-ok expressions return bool rather than untyped bool

Per the current spec.

Fixes issue 8188.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://codereview.appspot.com/101200043
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://codereview.appspot.com/101250043
go.tools/go/types: export types.Checker (cleanup)

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://codereview.appspot.com/109850044
go.tools/go/types, exact: fix build for 1.2

Fixes issue 8192.

LGTM=bradfitz
R=bradfitz, adonovan
CC=golang-codereviews
https://codereview.appspot.com/105160043
go.tools/go/types: remove PackageObj Selection - not needed

LGTM=gri
R=gri
CC=golang-codereviews
https://codereview.appspot.com/105920043
go.tools/present: allow intentionally empty parameters

Fixes issue 7613.

LGTM=r
R=adg, r
CC=golang-codereviews
https://codereview.appspot.com/105070043

Committer: Rob Pike <r@golang.org>
go.tools/present: correctly test empty argument

Updates issue 7613.

LGTM=r
R=r
CC=golang-codereviews
https://codereview.appspot.com/105130046

Committer: Rob Pike <r@golang.org>