Commit Graph

645 Commits

Author SHA1 Message Date
Alan Donovan 95bd0c4fdf go.tools/go/types: add (*PkgName).ImportedPackage method.
It returns the value formerly returned by Pkg(), i.e. the imported package.
Pkg() now returns the package enclosing the import statement,
which is consistent with all other Objects.

Fixes golang/go#8628.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/136090043
2014-09-02 18:12:08 -04:00
Robert Griesemer a4d1505cfc go.tools/go/types: remove Strict mode from API
Also: factor out shared code assertableTo.

LGTM=adonovan
R=adonovan, gordon.klaus
CC=golang-codereviews
https://golang.org/cl/139880043
2014-08-29 09:15:36 -07:00
Robert Griesemer 4c3c0f68c5 go.tools/go/importer: use platform-specific word size in tests
Hopefully
Fixes golang/go#8366.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/138810043
2014-08-28 15:19:30 -07:00
Robert Griesemer 776a9335ce go.tools/go/types: fix typo in comment
TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/135960043
2014-08-28 14:57:53 -07:00
Robert Griesemer 289e96cc26 go.tools/go/types: no errors for x.(T) where T is an interface
Also: Added Config.Strict flag to enable type checker tests
      beyond the Go 1 specification.

Fixes golang/go#8561.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/134050043
2014-08-28 14:03:10 -07:00
Alan Donovan cd5b7ff318 go/ssa/interp: add intrinsic for runtime.environ, recently added.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/135120043
2014-08-28 16:56:49 -04:00
Robert Griesemer 5dca7d8bd1 go.tools/go/types: LookupFieldOrMethod checks method set
LookupFieldOrMethod now also decides whether a found
method is actually in the method set. Simplifies call
sites. Added corresponding API tests.

TODO (separate CL): Decide what the correct value for
the indirect result should be (as required for code
generation). For now, the result value for indirect
is unchanged from before if a field/method is found.

Fixes golang/go#8584.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/132260043
2014-08-28 13:03:13 -07:00
Robert Griesemer 87b4cd993d go.tools/go/types: don't crash dealing with unknown constants
Also: Better tracing for top-level declarations.

Fixes golang/go#8518.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/132310043
2014-08-28 12:17:30 -07:00
Robert Griesemer 7486f5904a go.tools/go/types: added TODO re: misleading error message
Fix not urgent.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/135810043
2014-08-26 10:56:22 -07:00
Alan Donovan 4aaa1f6f6c go/ssa/interp: fix intrinsics for (*runtime.Func) methods.
They changed when they were ported to Go in CL
https://golang.org/cl/124300044.

LGTM=crawshaw
R=gri, crawshaw
CC=golang-codereviews
https://golang.org/cl/136780043
2014-08-26 11:48:15 -04:00
Alan Donovan 067a2992ee go/pointer: fix runtime.startTimer intrinsic.
The test broke because the actual behaviour of time.startTimer changed in
https://golang.org/cl/129480043.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/131280043
2014-08-26 11:08:45 -04:00
Alan Donovan 845abca4e3 go/types/typeutil: Dependencies utility returns transitive closure of import graph.
(Used by forthcoming 'singlefile' command.)

+ Test.

LGTM=bwkster, gri
R=gri, bwkster
CC=golang-codereviews
https://golang.org/cl/130100043
2014-08-18 22:31:56 -04:00
Alan Donovan f13ba78920 go.tools/go/loader: make error message for massive failure (e.g. no "fmt") more concise.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/126080043
2014-08-14 12:10:34 -04:00
Alan Donovan cd6b8ab06d go.tools/go/ssa: improvements to CreateTestMainPackage.
(1) support Example functions defined in programs that don't
    import "testing".  We emit code to testmain.main() to call
    them directly, since we can't call testing.Main.

(2) expose a FindTests function which reports the set of
    Test, Example and Benchmark functions it finds.
    Certain clients need this.

Added test for logic in FindTests.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/115290048
2014-08-08 14:47:16 -04:00
Robert Griesemer 8ce35843de go.tools/go/types: handle all receiver errors in go/types
Pending parser change in CL 123010044.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/125830043
2014-08-07 12:45:28 -07:00
Alan Donovan 3bbc63016b go.tools/go/loader: report parser errors too.
Previously these were recorded in the PackageInfo, but not
reported to the user's error handler (types.Config.Error),
which is typically what prints them.

Minor subtlety: that function must now be able to handle error
values that are not of type types.Error.

+ Test (and renamed it).

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/121290043
2014-08-07 12:50:15 -04:00
Alan Donovan d3f2df4854 go.tools/go/ssa/interp: some fixes to tests
- Break out parts of coverage.go into more specific files.
- Re-enable test of nil interface-to-interface conversion.
- Update initorder test to reflect spec ambiguity and gc vs go/types variance.
- Re-enable test dependent on now-fixed bug 8189 ("value,ok" yields an untyped bool)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/119530043
2014-08-07 10:57:00 -04:00
Robert Griesemer b31dcd1655 go/types: comma-ok expressions return untyped boolean as 2nd result
Per acceptance of https://golang.org/cl/112320045/ .

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/113990043
2014-08-05 11:34:36 -07:00
Alan Donovan 149e030318 go.tools/cmd/ssadump: print packages and functions to stdout, not stderr.
And serialize the printing of each item with a mutex.
It is the formatted output of this tool, after all.

Also: minor doc tweaks.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/114620044
2014-08-01 14:44:37 -04:00
Alan Donovan 4228ee8063 go.tools/go/ssa: improve printing of anonymous functions.
Examples:
- "foo$1" becomes "pkg.foo$1"
- "init$1" (meaning the first declared "init" function) becomes "init#1",
   to distinguish it from "init$1" (meaning the first anonymous function
   within the synthetic "init" function that initializes package-level vars).

It is now an invariant that all source-level (non-synthetic)
functions have distinct names, and that all names include the
enclosing package.  Added test for this.

+ updated various clients.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/122750043
2014-07-31 17:37:41 -04:00
Alan Donovan b419465131 go.tools/go/ssa: print types package-relative in all instructions.
It was missing from the four conversions and the Make* instructions.

(Experiments with pure bytes.Buffer-based printing were not faster; various TODOs removed.)

LGTM=crawshaw
R=gri, crawshaw
CC=golang-codereviews
https://golang.org/cl/58040043
2014-07-31 16:29:47 -04:00
Alan Donovan 31c2077fe3 go.tools/go/ssa: rename promote.go and split into two files, {methods,wrappers}.go.
Also:
- move shared utilities to util.go.
- rename types.Selection vars.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/113550043
2014-07-31 16:28:34 -04:00
Alan Donovan 935700a081 go.tools/go/loader: apply DisplayPath to working directory of cgo tool.
This transforms the virtualized directory (build.Context).Dir to a physical one,
for proprietary build systems that distinguish them.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/116230043
2014-07-24 14:12:52 -04:00
Alan Donovan 9ffbf29971 go.tools/go/ssa: add hook to testmain.go for proprietary (non-'go test') build systems.
Users need only add an extra file to the package to specify
additional imports and initialization steps in testmain, to
match their build system.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/120090043
2014-07-23 15:37:37 -04:00
Alan Donovan b5528ca070 go.tools/go/pointer: add test file missing from CL 112610043 (rev 32ae05502022)
TBR=gri
R=gri
CC=adg, golang-codereviews
https://golang.org/cl/111580043
2014-07-23 12:28:56 -04:00
Alan Donovan e5d15a9781 go.tools/go/pointer: add intrinsic for time.startTimer, which is implemented in C.
Without it, no value appears to be sent on NewTicker/NewTimer channels.

+ test

Also:
- add (callgraph.Edge).{Description,Pos} convenience methods
  to simplify client code when Site==nil.

LGTM=gri
R=gri, friestein68503
CC=golang-codereviews
https://golang.org/cl/112610043
2014-07-22 18:30:06 -04:00
Alan Donovan cd61993a08 go.tools/go/types: move {Type,Object}Of methods from *loader.PackageInfo to *types.Info
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/113750044
2014-07-17 15:10:29 -04:00
Alan Donovan 514bdfb1b7 go.tools/go/ssa: improve generated code for addressable expressions.
If an expression is addressable, we compute its address then load, rather than
extracting the value of subelements.  For aggregates this avoids large copies.
Example:
        var x [2]struct{y [3]int}
        print(x[1].y[2])

Was:
t0 = local [3]struct{x [5]int} (x)                 *[3]struct{x [5]int}
t1 = *t0                                            [3]struct{x [5]int}
t2 = t1[1:int]                                         struct{x [5]int}
t3 = t2.x [#0]                                                   [5]int
t4 = t3[2:int]                                                      int

Now:
t1 = &t0[1:int]                                       *struct{x [5]int}
t2 = &t1.x [#0]                                                 *[5]int
t3 = &t2[2:int]                                                    *int
t4 = *t3                                                            int

Also:
- make emitFieldSelections responsible for calling emitDebugRef, as
  one of its two calls was forgetting to do it.
- relax the specification of (*Program).VarValue because not all
  subexpressions are materalized as values now.
- fix up the objlookup.go test expectations to match.

go/ssa/interp test runs 10% faster.

Thanks to Peter Collingbourne for pointing this out.

LGTM=pcc
R=pcc, gri
CC=golang-codereviews
https://golang.org/cl/109710043
2014-07-17 15:06:09 -04:00
Alan Donovan b2ea2e8560 go.tools/go/ssa: permit "for range x"
+ test

Also: don't generate init() functions for packages loaded from export data.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/111200043
2014-07-15 17:34:50 +01:00
Robert Griesemer e078800d1f go/types: permit "for range x"
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/110630044
2014-07-15 08:54:09 -07:00
Alan Donovan f2db24a319 go.tools/go/loader: use new types.TypeAndValue mode predicates.
PackageInfo:
- deleted IsType
- inlined + deleted: ValueOf, TypeCaseVar, ImportSpecPkg
- on failure, TypeOf accessor now returns nil (was: panic)

go/ssa: avoid extra map lookups by using Uses or Defs directly when safe to do so,
and keeping the TypeAndValue around in expr0().

LGTM=gri
R=gri, pcc
CC=golang-codereviews
https://golang.org/cl/107650043
2014-07-11 10:50:09 +01:00
Robert Griesemer 961ab3ca8d go.tools/go/types: provide TypeAndValue predicates
LGTM=adonovan
R=adonovan, pcc
CC=golang-codereviews
https://golang.org/cl/110880043
2014-07-10 16:59:50 -07:00
Alan Donovan a16d58355f go.tools: various doc fixes.
LGTM=crawshaw
R=gri, crawshaw
CC=golang-codereviews
https://golang.org/cl/91420044
2014-07-10 07:24:52 -04:00
Alan Donovan 400db89b86 go/types: fix incorrect InitOrder in packages created from multiple calls to (*Checker).Files.
The InitOrder needs to be reset.

+ Test.

This bug manifested itself in duplicate HTML in the godoc -analysis view,
e.g. "f((x)" or "funcfunc f()"

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/107660044
2014-07-10 06:30:01 -04:00
Peter Collingbourne 661e836afb go.tools/go/ssa: introduce a sanity check for dead referrers
This extends the sanity checker to identify and report referrers
which do not appear in the function's instruction lists, and fixes two
bugs in the lifting algorithm which were caught by the sanity check.

LGTM=adonovan
R=adonovan
CC=axwalk, golang-codereviews
https://golang.org/cl/110210045
2014-07-10 06:27:25 -04:00
Peter Collingbourne 4329a10ae7 go.tools/go: separate interface construction from method set construction
We introduce a method (*Interface).Complete(), which is intended
to be called from clients after all embedded interfaces have been
fully defined. For importers, this will definitely be the case
after the import has finished, so each importer have been updated
to do so, with the exception of the gcimporter, which does not use
embedded interfaces, therefore Complete() can be called immediately
after construction.

Building the method set separately from the constructor type caused
some problems with go/importer, which copies the types.Interface
object, leading to there existing two almost-identical interface
types referenced from interface method receivers, only one of which
has been completed. To avoid this situation, the importer has been
modified to construct the interface object only once.

Fixes golang/go#8177.

LGTM=gri
R=gri, dave, gordon.klaus, adonovan
CC=golang-codereviews
https://golang.org/cl/105060044
2014-07-09 20:00:49 -07:00
Robert Griesemer 32c9809768 go.tools/go/types: const decls with invalid init expr must not panic
Make sure const objects always have a valid (possibly unknown) value.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/106530044
2014-07-08 13:33:43 -07:00
Alan Donovan 79e0c7b71e go.tools/go/pointer: eliminate TODOs regarding sound treatment of unsafe.Pointer.
Ain't gonna happen.

Also, don't emit a warning when this happens.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/110030044
2014-07-08 10:11:36 -04:00
Gordon Klaus 3abe688aea undo CL 107160049 / 9abbb23a14f6
This method was deemed unfit for the API.  See the original CL for discussion.

««« original CL description
go.tools/go/loader: Add Program.FilePath convenience method for getting the full path of a source file.

LGTM=gri
R=gri, adonovan
CC=golang-codereviews
https://golang.org/cl/107160049

»»»

LGTM=gri
R=gri, adonovan
CC=golang-codereviews
https://golang.org/cl/107570043
2014-07-07 14:02:32 -07:00
Peter Collingbourne 87301fe3a6 go.tools/go/types: type the append([]byte, string...) builtin more correctly
This builtin is a little weird in this form as it is (to my knowledge)
the only function that takes a variadic argument of non-slice
type. The language provides no syntax to express this, so we pick
a stringification for such arguments that does not appear in the
language. Specifically, use T... instead of ...T to distinguish it
from the normal case where the type is a slice.

This change lets the go/ssa package produce more efficient IR by
avoiding an extra conversion of the second argument.

LGTM=gri
R=gri
CC=adonovan, golang-codereviews
https://golang.org/cl/108230044
2014-06-27 16:00:54 -07:00
Peter Collingbourne 969a226d69 go.tools/go/types: correctly type the copy([]byte, string) builtin
LGTM=gri
R=gri, adonovan
CC=golang-codereviews
https://golang.org/cl/104340046
2014-06-26 16:50:12 -07:00
Robert Griesemer f38fc6a97a go.tools/go/types: add test cases for parenthesized receivers
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/101510043
2014-06-26 09:48:58 -07:00
Aram Hăvărneanu 6cd21e820b go.tools/go/loader: fix Solaris build
Also fix one test that failed on Plan 9.

LGTM=0intro, dave
R=golang-codereviews, 0intro, dave
CC=golang-codereviews
https://golang.org/cl/101370053
2014-06-24 20:47:16 +10:00
Gordon Klaus 3309b0d879 go.tools/go/loader: Add Program.FilePath convenience method for getting the full path of a source file.
LGTM=gri
R=gri, adonovan
CC=golang-codereviews
https://golang.org/cl/107160049
2014-06-23 15:13:07 -07:00
Alan Donovan 5c5c4f4888 go/pointer: fix crash: valueNode(*FreeVar) was allocating 1 node, even for multi-word types.
+ regression test.

Fixes golang/go#8172

Also: return error (not panic) when called with empty input.

LGTM=gri
R=crawshaw, gri
CC=golang-codereviews, jon
https://golang.org/cl/104270043
2014-06-19 15:30:51 -04:00
Alan Donovan 02dba5d1e6 go.tools/go/pointer: fix crash in constraint generation of ssa.Convert to a named unsafe.Pointer type.
+ test.

Fixes golang/go#8231.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/106060046
2014-06-18 18:02:07 -04:00
Alan Donovan f4ab48cb83 go.tools/go/ssa: remove obsolete comment.
This was a cryptic prediction of the bug you fixed. :)

LGTM=pcc
R=pcc
CC=golang-codereviews
https://golang.org/cl/103470048
2014-06-18 18:00:03 -04:00
Alex Brainman a20078a082 go.tools/go/loader: skip TestCgoOption on windows
windows std packages do not use cgo.

LGTM=minux
R=golang-codereviews, minux
CC=golang-codereviews
https://golang.org/cl/102460043
2014-06-18 11:28:36 +10:00
Peter Collingbourne 02990bd494 go.tools/go/gccgoimporter: keep track of package and import priority
Clients such as compilers need this information in order
to correctly link against imported packages.

This also adds support for the condensed import data format
where the priority information is stored as a suffix of the
condensed import data, as well as support for archive files.

LGTM=gri
R=gri
CC=golang-codereviews, iant
https://golang.org/cl/78740043
2014-06-17 10:56:47 -07:00
Peter Collingbourne 4a6efa0a34 go.tools/go/ssa: add a flag for selecting bare init functions
Bare init functions omit calls to dependent init functions and the
use of an init guard. They are useful in cases where the client uses
a different calling convention for init functions, or cases where
it is easier for a client to analyze bare init functions.

LGTM=adonovan
R=adonovan
CC=golang-codereviews, iant
https://golang.org/cl/78780043
2014-06-16 21:34:51 -04:00
Alan Donovan f032426134 go.tools/go/pointer: suppress logging by default
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/102490043
2014-06-16 16:31:30 -04:00
Alan Donovan 9b38eafe60 go/pointer: implement pointer equivalence via hash-value numbering, a pre-solver optimization.
This reduces solver time by about 40%.
See hvn.go for detailed description.

Also in this CL:
- Update package docs.
- Added various global opt/debug options for maintainer convenience.
- Added logging of phase timing.
- Added stdlib_test, disabled by default, that runs the analysis
  on all tests in $GOROOT.
- include types when dumping solution

LGTM=crawshaw
R=crawshaw, dannyb
CC=golang-codereviews
https://golang.org/cl/96650048
2014-06-16 15:46:07 -04:00
Alan Donovan 47c0a8f0c3 go.tools/go/types: give Label objects a non-nil Package() too.
New invariant: all user-defined objects have an associated package.
Added a check of this invariant to stdlib_test.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/104170043
2014-06-16 12:31:46 -04:00
Alan Donovan 6db8a00c75 go.tools/go/ssa: write zero value when storing a composite literal in-place if necessary
Previously, statements such as:

type T struct { a, b int }
[...]
x = T{}
x = T{b: 1}

would only affect the aggregate members mentioned in the composite
literal and leave the other members unchanged. This change causes us
to write a zero value to the target in cases where the target is not
already known to hold a zero value and the number of initializers in
the composite literal differs from the number of elements in its type.

Author: Peter Collingbourne.  (hg clpatch got confused)

LGTM=pcc
R=pcc
CC=golang-codereviews
https://golang.org/cl/107980045
2014-06-16 12:29:30 -04:00
Andrew Gerrand a94a6a54d1 go.tools/go/types/typeutil: use reflect instead of unsafe
Godoc depends on this package.
Packages that use unsafe cannot be deployed to App Engine.
Packages that use reflect can.
This package needn't use unsafe, so don't.

LGTM=adonovan, rsc
R=rsc, adonovan
CC=golang-codereviews
https://golang.org/cl/105960043
2014-06-14 12:45:55 +10:00
Alan Donovan de23e2b0c2 go/ssa: make Builtin capable of representing non-spec-defined intrinsics.
Also, define ssa:wrapnilchk intrinsic to check and gracefully
fail when a T method is dynamically invoked via a nil *T receiver.
+ Test.

A follow-up CL will add another intrinsic, ssa:memclr.

+ minor cleanups.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/101170044
2014-06-13 17:34:07 -04:00
Alan Donovan 38cb4c0966 go.tools/go/ssa: record ast.CallExpr.Rparen as Alloc.Pos() for varargs arrays.
+ pointer analysis test-case.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/108980043
2014-06-13 17:12:28 -04:00
Peter Collingbourne ce1e99a260 go.tools/go/ssa: emit a recover block if the function's results are unnamed
It is easier for clients to recover from panics if the recover block
is always present. Otherwise, the client has to work around the lack
of a recover block by synthesizing a zero value return.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/87210044
2014-06-13 13:08:35 -04:00
Alan Donovan f0ff511183 go/loader: make (*Config).Load() robust against I/O, scanner and parser errors.
Before, Load() would just fail.  Now, it gathers all frontend
errors (not just the first go/types error) in PackageInfo.Errors.

There are still cases where Load() can fail hard, e.g. errors in x_test.go
files.  That case is trickier to fix and remains a TODO item.

Also, make godoc display all scanner/parser/type errors in the source view.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/108940043
2014-06-13 11:32:46 -04:00
Alan Donovan d014be43ae go.tools/go/types: remove PackageObj Selection - not needed
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/105920043
2014-06-12 18:05:33 -04:00
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
Robert Griesemer d7048bec64 go.tools/go/types: simplified init dependency data structures
Preparation for fixing issue 7158.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/83160045
2014-04-02 09:01:28 -07:00
Robert Griesemer 3d9dcf408f go.tools/go/types: comment fixes - no code changes
TBR=adonovan

TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/80430045
2014-03-31 16:48:42 -07:00
Robert Griesemer 4f89dd6aed go.tools/go/importer: record low-level encoding format
This avoids confusion when trying to read correctly
encoded export data that happens to be encoded in
a different format (debug vs product).

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/82090043
2014-03-31 09:49:52 -07:00
Robert Griesemer 250eb11b9b go.tools/go/gccgoimporter: backported some changes from godex implementation
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/82000043
2014-03-28 14:24:35 -07:00
Robert Griesemer 069e8474de go.tools/go/types: print meaningful panic for unknown expressions
LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/81310045
2014-03-27 15:47:04 -07:00
Robert Griesemer 33f2a1701b go.tools/go/types: minor internal cleanup
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/80960046
2014-03-27 10:03:51 -07:00
Alan Donovan 2414677bb9 go.tools/go/loader: add Config.ParserMode configuration parameter.
Existing tools use the default value of zero; their behaviour is unchanged.
(*Config).ParseFile is used only from tests.

LGTM=crawshaw, rsc, gri
R=crawshaw, gri, rsc
CC=golang-codereviews
https://golang.org/cl/79290044
2014-03-27 12:50:26 -04:00
Robert Griesemer a781b00b0d go.tools/go/types: avoid spurious "declared but not used" errors in case of other errors
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/76810044
2014-03-20 11:28:26 -07:00
Robert Griesemer 6256e2d81b go.tools/go/types: use package-local type names in errors referring to operands
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/77670043
2014-03-19 09:36:06 -07:00
Robert Griesemer 62216e60bb go.tools/go/types: use unqualified names for local objects in error messages
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/77590043
2014-03-18 13:37:09 -07:00
Alan Donovan e3dc58c6e0 go.tools/go/loader: use the build.Context's I/O hooks, if any.
Also, add loader.Config.DisplayPath hook, which allows the
filename returned by build.Context.Import() to be transformed
prior to attaching to the AST.  This allows a virtual file
system to be used without leaking into the user interface.

Eliminate parsePackageFiles hook; I don't think we need it any
more.  The test that was using it has been rewritten to use
the build.Context hooks.

LGTM=gri
R=gri, crawshaw
CC=daniel.morsing, golang-codereviews, rsc
https://golang.org/cl/75520046
2014-03-14 16:17:53 -04:00
Robert Griesemer 71b6dfeb19 go.tools/go/types: correct a comment (was pointing at wrong issue)
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/76160044
2014-03-14 10:34:06 -07:00
Robert Griesemer c4ca0e2489 go.tools/go/types: don't change dot-imported object's parents
With this CL, an Object.Parent() Scope is always the scope in
which the object was originally declared. For dot-imported
objects, that is the package scope of the package from which
the objects are imported (not the file scope into which they
are imported).

Also:

- Changed Scope.Insert to be agnostic regarding blank
identifiers - blank identifiers must be handled outside.

- Fixed handling of blank labels: they are never declared.

Fixes golang/go#7537.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/75570043
2014-03-13 13:22:44 -07:00
Alan Donovan 4f7b2f8882 go.tools/go/types: add Scope.comment as a debugging aid.
e.g. file foo.go scope {...}
     package math scope {...}
     function f scope {...}
     if scope {...}

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/74320043
2014-03-12 14:12:09 -04:00
Alan Donovan 98ed3d3c76 go.tools/go/pointer: node renumbering
This change renumbers nodes so that addressable ones
  (that may appear in a points-to set) all have lower
  numbers than non-addressable ones----initially at least:
  reflection, SetFinalizer, etc add new nodes during
  solving.

  This improves the efficiency of sparse PTS
  representations (to be added later).  The largest int in
  a PTS is now about 20% of the previous max.

  Overview:
  - move constraint stuff into constraint.go.
  - add two methods to constraint:
    (1) renumber(): renumbers all nodeids.  The
        implementations are very repetitive but simple.  I
        thought hard about other ways (mixins, reflection)
        but decided this one was fine.
	(2) indirect(): report the set of nodeids whose
        points-to relations depend on the solver, not just
        the initial constraint graph.
        (This method is currently unused and is logically
        part of a forthcoming change to implement PE/LE
        presolver optimizations. (Perhaps I should comment
        it out/remove it for now.)
  - split up the population of the intrinsics map by file.
  - delete analysis.probes (unused field)
  - remove state="..." from panic message; unnecessary.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/73320043
2014-03-11 18:37:19 -04:00
Robert Griesemer 52c6f24392 go.tools/go/types: short var decls require new variables
This appears to be a regression. Added fix and test case.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/74190043
2014-03-11 15:31:12 -07:00
Alan Donovan ba9c801433 go.tools: various comments + doc tweaks.
No functional changes.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/74270043
2014-03-11 18:24:39 -04:00
Alan Donovan be96a2037f go.tools/go/loader: fix broken test.
(The previous figure was based on an unclean workspace.)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/74210043
2014-03-11 17:04:45 -04:00
Alan Donovan cd987a3c83 go.tools/go/loader: allow loading of multiple test packages.
Now that go/types permits files to be added to a package
      incrementally (fixing bug 7114), this CL extends the loader
      to load and augment multiple test packages at once.

      TESTED:
      - go/loader/stdlib_test runs the type-checker on the entire
        standard library loaded from source in a single gulp, with
        each package augmented by tests.
      - Manually tested on:
        % ssadump -test -run unicode encoding/ascii85
            Both sets of tests are run (and pass).

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/61060043
2014-03-11 15:41:57 -04:00
Robert Griesemer 2b8dd19c64 go.tools/go/types: enable incremental adding of package files
With this CL, it is now possible to type-check additional
package files to an already type-checked package through
repeated calls to Checker.Files.

Fixes golang/go#7114.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/72730043
2014-03-10 15:25:56 -07:00
Robert Griesemer c5d02e0e94 go.tools/go/types: factor resolveFiles
Another step towards resolvinng issue 7114.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/72550044
2014-03-07 14:40:14 -08:00
Robert Griesemer f06b7e1853 go.tools/go/types: remove need for global initializer map
Another step towards resolving issue 7114.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/72260043
2014-03-07 11:03:08 -08:00
Robert Griesemer 4f1c486d35 go.tools/go/types: towards permitting adding additional package files incrementally
Another small step towards resolving issue 7114.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/72230043
2014-03-06 15:53:37 -08:00
Robert Griesemer d14a9d31e6 go.tools/go/types: support for "soft" errors
Provide an extra field, "Soft" in types.Error.
A client may want to filter out soft errors and
only abort if there are "hard" errors.

Qualified a first set of errors as "soft".

Fixes golang/go#7360.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/71800043
2014-03-05 15:19:38 -08:00
Robert Griesemer 5d3ec72759 go.tools/go/types: implement shadowed return parameter restriction
Also:
- slightly better error messages for return statements
- more AST validity checking of parameter lists
- use secondary error message for clarifying message in type switch errors

Fixes golang/go#7469.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/71780044
2014-03-05 15:05:34 -08:00
Robert Griesemer e3ab342481 go.tools/go/types: report correctly rounded constant values
Also:
- better documentation of exact.Float64Val
- minor rearrangement in go/importer (unrelated)

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/70200047
2014-03-05 10:23:33 -08:00
Robert Griesemer fccaf8c467 go.tools/go/types: adjust tests for better parser error positions
The parser may return error positions referring to positions
immediately after rather than at a token position. Provide
mechanism to identify those positions in test cases.

Also: Don't compute position strings for each token in test
cases. Should speed up Check test.

Pending CL 70190046 in main repo.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/71330043
2014-03-04 14:32:55 -08:00
Alan Donovan 5536d2ae3e go/loader: convert directory separators to slash when enumerating packages.
(On Windows the two are not the same.)

Fixes golang/go#7189.

Also: remove exception for code.google.com subtree; this was
an artifact of my unusual setup.

LGTM=gri
R=alex.brainman, gri
CC=golang-codereviews
https://golang.org/cl/70060048
2014-03-04 13:48:09 -05:00
Alan Donovan 53324e8992 go/ssa/interp: add syscall.Sysctl to Darwin.
This fixes a recent test breakge now that os.init calls it
(on Darwin).

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/68000048
2014-03-04 13:34:45 -05:00
Robert Griesemer ddcdb3637a go.tools/go/types: built-in calls returning constants don't count as function calls
Fixes golang/go#7457.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/69890052
2014-03-04 09:26:21 -08:00
Alan Donovan d503a640d7 go.tools/go/ssa: name anon funcs by their enclosing func.
Before, they were named func@line:col which made them easy to find in the source if you know the file, but hard if you don't, and it made tests fragile.

Now, they are named outer$1, outer$2, etc, which makes them
more informative in a UI since "outer" has meaning.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/65630048
2014-02-28 10:18:55 -05:00
Alan Donovan c509cf123c go.tools/go/pointer: recover from panic in Analyse and return an error.
This is to avoid an internal error in pointer analysis from
bringing down a long-lived application such as godoc.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/68930046
2014-02-27 14:13:52 -05:00
Robert Griesemer d15a452238 go.tools/go/types: move new switch test case in the right place (cleanup)
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/69000047
2014-02-27 10:46:04 -08:00
Alan Donovan ced954c167 go.tools/go/types: split Info.Objects map into Defs and Uses.
An identifier X in anonymous struct field struct{X} is both a
definition of a field (*Var) and reference to a type
(*TypeName).  Now that we have split the map, we can capture
both of these aspects.

Interestingly, every client but one was going to extra effort
to iterate over just the uses or just the defs; this
simplifies them.

Also, fix two bug related to tagless switches:
- An entry was being recorded in the Object map for a piece of
  synthetic syntax.
- The "true" identifier was being looked up in the current scope,
  which allowed perverse users to locally redefine it.  Now
  we use the bool (not untyped boolean) constant true, per the
  consequent clarification of the spec (issue 7404).

+ tests.

Fixes golang/go#7276

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/68270044
2014-02-27 13:21:59 -05:00
Robert Griesemer 3ff8e6554d go/types: simplify tracking of side effects for len/cap
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/67190043
2014-02-24 10:14:33 -08:00
Alan Donovan 99b2441d95 go.tools/oracle: optionally restrict 'callgraph' query to a single package.
If a -pos argument is specified, a 'callgraph' query reports only the
functions within the query package.  This produces a far more manageable
amount of information, and because we don't need to package-qualify the
names, the result is easier to read.

Added tests:
- callgraph query with/without -pos
  (The test driver was extended to allow "nopos" queries.)
- callers and callees queries don't return wrappers

Also, in go/callgraph:
- (*Node).String, (*Edge).String
- (*Graph).DeleteSyntheticNodes eliminates synthetic wrapper functions,
  preserving topology.  Used in all four oracle "call*" queries.
- (*Graph).DeleteNode

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/66240044
2014-02-21 10:46:02 -05:00
Alan Donovan 49eaa56ed1 go.tools/go/*: fix breakage caused by removal of types.NewPackage parameter.
(This fixes the build, but one test is failing.)

TBR=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/66730043
2014-02-20 20:11:00 -05:00
Alan Donovan 01263f0a00 go.tools/go/ssa: fix breakage caused by removal of types.NewPackage parameter.
TBR=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/66600045
2014-02-20 19:49:38 -05:00
Robert Griesemer 9111cead20 go.tools/go/types: internal cleanups
- clearer separation between package-level and object-level state
- lazy allocation of various package-level maps
- NewPackage automatically allocates a package scope
- steps towards enabling incremental checking of extra (test) files
  after the (non-test) package is type-checked (not yet exposed)

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/66230044
2014-02-20 14:52:21 -08:00
Alan Donovan 829d52f2e8 go.tools/go/callgraph: simplifications to API.
1) We remove context sensitivity from API.  The pointer analysis is
   not sufficiently context-sensitive for the context information to
   be worth exposing.  (The actual analysis precision still benefits
   from being context-sensitive, though.)  Since all clients would
   discard the context info, we now do that for them.
2) Make the graph doubly-linked.  Edges are now shared by the Nodes
   at both ends of the edge so it's possible to navigate more easily
   (e.g. to the callers).
3) Graph and Node are now concrete, not interfaces.

Less code in every file!

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/66460043
2014-02-20 11:57:48 -05:00
Alan Donovan 28104d2c91 go.tools/go/pointer: remove context-sensitivity from API.
Previously, each {Indirect,}Query would return a set of Pointers, one per context; now it returns (at most) one Pointer combining information from all contexts.

The old API was more faithful to the implementation concepts, but the analysis is not sufficiently context-sensitive that it makes sense: all existing clients simply throw away the context information---so now we do that for them.

(I may remove the context-sensitivity from the callgraph too, but I'll benchmark that first to see if it reduces precision.)

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/66130044
2014-02-20 11:35:09 -05:00
Alan Donovan 0eac03b836 go.tools/go/types: include import path in (*Package).String()
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/66120045
2014-02-19 17:55:30 -05:00
Robert Griesemer 9d6717b260 go.tools/go/importer: handle predeclared types consistently
- pre-poluate typIndex and typList using a predefined list of types
- no need to handle basic types explicitly anymore
- removed basicTag
- go/types: exported UniverseByte and UniverseRune for now

LGTM=adonovan
R=adonovan
CC=cmang, golang-codereviews
https://golang.org/cl/65920044
2014-02-19 13:27:11 -08:00
Alan Donovan aaa5866ea1 go.tools/go/loader: rename backdoor so only tests can use it.
Also: add copyright message.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/64040044
2014-02-19 13:52:19 -05:00
Alan Donovan 03ca00ddd4 go.tools/go/types/typeutil: new package for type utilities.
Contains the members formerly known as:
- ssa.IntuitiveMethodSet
- typemap.M (now: Map)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/65670043
2014-02-19 13:32:36 -05:00
Alan Donovan 42022f89d4 go.tools/go/loader: add file missing from rev ebef51b726fc
(CL https://golang.org/cl/62540043)

TBR=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/65530046
2014-02-19 13:28:12 -05:00
Alan Donovan 0c9517ddba go.tools/go/pointer: assert that input program is complete.
Fixes golang/go#7257

LGTM=crawshaw
R=daniel.morsing, crawshaw
CC=golang-codereviews
https://golang.org/cl/65730045
2014-02-19 13:08:06 -05:00
Alan Donovan ed45af74ff go.tools/go/loader: add AllowTypeErrors flag.
If this flag is set, (*Config).Load will not return an
error even if some packages had type errors.  Each individual
PackageInfo can be queried for its error state, now exposed as
TypeError.

In addition, each PackageInfo exposes whether it is
"transitively error-free".  ssa.Create skips packages without
this flag since it is required for SSA construction.

+ Test.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/62000045
2014-02-18 19:43:14 -05:00
Alan Donovan 5f96644dbf go.tools/pointer: opt: type-based label tracking reduces solver time by up to 75%.
Observation: not all alias facts are interesting.
- A channel-peers query also cares about pointers of kind chan.
- An oracle "points-to" query on an expression of kind map
  only cares about maps.
- We always care about func, interface and reflect.Value,
  since they're needed for sound analysis of dynamic dispatch.

We needn't bother collecting alias information for
uninteresting pointers, and this massively reduces the number
of labels flowing in to the constraint system.
The only constraints that create new labels are addressOf
and offsetAddr; both are now selectively emitted by type.

We compute the set of type kinds to track, based on the
{Indirect,}Query types.  (We could enable tracking at an
even finer grain if we want.)

This requires that we can see all the {Indirect,}Query
value types a priori, which is not the case for the PrintCalls
mechanism used in the tests, so I have rewritten the latter
to use {Indirect,}Query instead.

This reduces the solver-phase time for the entire standard
library and tests from >8m to <2m.  Similar speedups are
obtained on small and medium-sized programs.

Details:
- shouldTrack inspects the flattened form of a type to see if
  it contains fields we must track.  It memoizes the result.
- added precondition checks to (*Config).Add{,Indirect}Query.
- added (*ssa.Program).LookupMethod convenience method.
- added Example of how to use the Query mechanism.
- removed code made dead by a recent invariant:
  the only pointerlike Const value is nil.
- don't generate constraints for any functions in "reflect".
  (we had forgotten to skip synthetic wrappers too).
- write PTA warnings to the log.
- add annotations for more intrinsics.

LGTM=gri, crawshaw
R=crawshaw, gri
CC=golang-codereviews
https://golang.org/cl/62540043
2014-02-18 12:40:44 -08:00
Alan Donovan 675033b4f3 go.tools/go/ssa: fix nondeterministic computation of necessary method sets.
Method Signatures (types.Signatures with a non-nil receiver) behave
like ordinary func Signatures in the hash function/equivalence relation
used by typemap.M, which leads to surprising incomplete traversal
over the type graph if an M is used to remember types already
visited.

This change avoids ever putting method Signatures in a typemap.

% go test -v code.google.com/p/go.tools/go/ssa
now repeatedly shows the exact same number of functions and
instructions.

(We should discuss how to avoid this problem more generally.)

Also:
- recur over the params/results of all the methods of
  each type when computing necessary method sets.
- there's no longer any need to treat declarations of unexported
  methods as a root for traversal.  Added test case.
- enable SourceImports flag in stdlib_test, which was dropped
  during a recent refactoring (d'oh).
- doc tweaks

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/65450043
2014-02-18 12:39:29 -08:00
Alan Donovan a75195d091 go.tools/go/ssa/interp: fix tests broken by recent runtime changes.
This CL adds no-op stubs for intrinsics now required by tests:
 	 runtime.Goexit
	 sync.runtime_Sem{acquire,release}
        sync/atomic.AddUint{32,64}
 	Goexit needs more thought; for now I've disabled the interpreted
       tests of the "testing" package to make the build green again.

TBR=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/65480044
2014-02-18 15:37:24 -05:00
Alan Donovan 8c7a4539cd go.tools/pointer: implement (*reflect.rtype).MethodByName for abstract methods.
+ test.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/25810043
2014-02-12 12:45:55 -05:00
Alan Donovan d10dca34ca go.tools/ssa/interp: add several standard library packages to test suite.
- Add math.{Log,Ldexp} to externals
- Test now uses FromArgs
- Scan all initial packages for tests, don't assume Created[0] exists.
  (It doesn't if we import a package that has only in-package tests.)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/62010044
2014-02-11 20:35:18 -05:00
Alan Donovan b2557286bb go.tools/go/ssa/interp: improve "no such method" error.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/59740043
2014-02-11 18:15:10 -05:00
Alan Donovan 08fadac071 go.tools/go/loader: simplify command-line syntax.
Previously, each word could be a package import path or a
comma-separated list of *.go file names.  Now, if the
first word ends with ".go", all words are assumed to be
Go source files.  This makes it impossible to specify
two ad-hoc packages from source files, but no-one needs that.

FromArgs also takes a boolean indicating whether tests
are wanted or not.

Also: ssadump: add -test flag to set that boolean.
For the oracle it's always true.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/61470047
2014-02-11 16:52:16 -05:00
Alan Donovan 1f29e74bfa go.tools/go/types: remove Type.MethodSet() method.
Method-set caching is now performed externally using a MethodSetCache (if desired), not by the Types themselves.

This a minor deoptimization due to the extra maps, but avoids a situation in which method-sets are computed and frozen prematurely. (See b/7114)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/61430045
2014-02-11 16:49:27 -05:00
Robert Griesemer fc1d9c5505 go.tools/go/types: adjust 3-index slice tests
The parser is now checking the presence of the 2nd and 3rd
index of 3-index slice expressions. See also:

https://golang.org/cl/58950045/
http://golang.org/issue/7305

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/58500045
2014-02-11 13:40:59 -08:00
Alan Donovan ee92efc193 go.tools/ssa: tweaks to CreateTestMainPackage.
Move mutation of program to the final step.
+ 2 assertions;
+ switches.go: comment fix.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/61510044
2014-02-11 15:59:20 -05:00
Alan Donovan ddfef020d1 go.tools/go/ssa/interp: add missing case to fake reflect function.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/61410049
2014-02-11 15:36:41 -05:00
Alan Donovan b3dbe56610 go.tools/go/ssa: support 3-operand x[lo:hi:max] slices.
+ very basic test ($GOROOT/test/slice3.go needs unsafe.Pointer)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/60030043
2014-02-05 17:54:51 -05:00
Robert Griesemer c37c5f6f46 go.tools/go/types: internal cleanup (resolve a TODO)
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/59560046
2014-02-04 11:06:00 -08:00
Robert Griesemer 20efc5ba73 go.tools/go/types: use init cycle tracking for all const and var cycles
Also rename types.Assertable -> types.AssertableTo per adonovan.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/59680044
2014-02-03 16:02:56 -08:00
Gordon Klaus 3e68d08251 go.tools/go/types: export Comparable and Assertable, simplify Implements
The "static bool" parameter to Implements was confusing; typically we think about interface implementation and type assertion as separate but related concepts, but here they were merged.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/58540044
2014-02-03 11:21:01 -08:00
Robert Griesemer ed1b894ade go.tools/go/types: print cyles of recursive type declarations
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/59140043
2014-02-03 10:34:06 -08:00
Robert Griesemer caced9f304 go.tools/go/ssa: remove windows test exclusion
Issue 7189 was likely fixed with revision ed6ecfe1bc4e .

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/59230044
2014-01-31 15:31:10 -08:00
Robert Griesemer 91159eb214 go.tools/go/types: don't type-check methods twice
- Centralize "visited" check in check.objDecl.
- Assert that object-specific declX functions
are only called with objects that have no
type associated with them, yet.
- Added test case.

Thanks to Richard Musiol (neelance@gmail.com) for
finding the bug and providing an easy test case.

For a discussion of the bug see the issue.

Fixes golang/go#7245.

TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/59210043
2014-01-31 15:12:05 -08:00
Alex Brainman 269daf307c go.tools/go/ssa: skip broken TestStdlib on windows
Update golang/go#7189

LGTM=dave
R=golang-codereviews, dave
CC=golang-codereviews
https://golang.org/cl/49640049
2014-01-31 17:46:15 +11:00
Alex Brainman 69f7b061bd go.tools/go/ssa: stop if error in TestStdlib
Update golang/go#7189

LGTM=dave
R=golang-codereviews, dave
CC=golang-codereviews
https://golang.org/cl/58910043
2014-01-31 17:30:37 +11:00
Robert Griesemer 9cd9226d63 go.tools/go/types: fix type cycle tracking
Fixes golang/go#7236.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/58430043
2014-01-30 09:46:03 -08:00
Robert Griesemer bf4d636dc9 go.tools/go/types: cleanup handling of forward chains of underlying types
- consistently set underlying types of incoming named types in typInternal
- use underlying() helper function to resolve forward chains
- related consistency cleanups

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/53870044
2014-01-29 14:24:54 -08:00
Robert Griesemer c4535ece1b go.tools/go/types: various cleanups - no semantic changes
- split resolver.go into resolver.go and decl.go
- renamed types.go -> type.go
- renamed objects.go -> object.go

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/58010043
2014-01-29 10:53:49 -08:00
Alan Donovan 744d7e68b1 go.tools/go/ssa: use bytes.Buffer instead of io.Writer.
This is (a) more efficient and (b) avoids the need for
constant error handling, since buffer writes can't fail.

Also:
- added WriteFunction and WritePackage functions,
  similar to types.WriteFoo.
- *Function and *Package now implement io.WriterTo.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/57930044
2014-01-28 17:48:10 -05:00
Robert Griesemer 83cdd9ba10 go.tools/go/types: export ConvertibleTo
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/57950043
2014-01-28 14:28:10 -08:00
Alan Donovan d0efad3082 go.tools/go/ssa: use types.WriteSignature
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/57930043
2014-01-28 17:04:41 -05:00
Alan Donovan 64ec206bfd go.tools/go/types: combine Info.{Types,Values} maps.
This results in significant improvement to type-checking time:
it reduces by 4% the entire running time of ssa/stdlib_test
(GOMAXPROCS=8, n=7).

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/57770043
2014-01-28 16:46:24 -05:00
Robert Griesemer e5e20e3af5 go.tools/go/types: make WriteType cycle-resistent
Also:
- expose WriteSignature
- s/identicalInternal/identical/g

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/57860043
2014-01-28 13:42:46 -08:00
Robert Griesemer 7dbf7c000d go.tools/go/types: internal cleanup - nil out objmap when done with it
Also: print package path with quotes.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/55520046
2014-01-28 12:56:33 -08:00
Robert Griesemer ebfa4efbc4 go.tools/go/types: cleanup: more consistent exported predicate names
Renamed predicates:
IsIdentical -> Identical
IsAssignableTo -> AssignableTo
Signature.IsVariadic -> Signature.Variadic
Object.IsExported -> Object.Exported

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/53370043
2014-01-28 10:57:56 -08:00
Robert Griesemer aea9f68811 go.tools/go/types: set array type even if length is invalid
This avoids some follow-up errors due to invalid
array declarations.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/57640043
2014-01-28 09:40:12 -08:00
Robert Griesemer ffc6416213 go.tools/go/types: print local types unqualified in error/debugging output
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/57630044
2014-01-28 09:22:53 -08:00
Alan Donovan 4dcb74e810 go.tools/go/ssa/interp: implement reflection over callstack (now that we have access to it).
+ tests.

Fixes golang/go#6041

Also: move global var _sizes to a field of interpreter.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/56530046
2014-01-27 15:39:17 -05:00
Alan Donovan fbb3d81367 go.tools/ssa/interp: add intrinsics for (*sync.Pool).{Get,Put}.
Since Put() makes a dynamic function call, this CL includes a long-overdue change to supply a *frame (and thus the call
stack and the interpreter) to intrinsics too.

This fixes the tests that were broken by (sound) revision e4a4cb47c141.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/57350043
2014-01-27 13:11:16 -05:00
Alan Donovan 87b29f65dc go.tools/go/ssa/interp: fix broken import paths.
Fixes golang/go#7166

R=gri
CC=golang-codereviews
https://golang.org/cl/55710045
2014-01-22 17:19:25 -05:00
Alan Donovan 0dcaae1610 go.tools/go/loader: permit Create* methods to specify the ad-hoc package's path
CL 49530047 made the (over-)simplifying assumption that the
Path of an ad-hoc (Created) package should default to its
Name, i.e. package declaration.

With this change, the Name is still always computed from the
package declaration (by go/types) but the Path may be
specified by the loader.Config.  If "", the value of the Name
is used, which is not globally unique.

R=gri, axwalk
CC=golang-codereviews
https://golang.org/cl/55180043
2014-01-22 09:59:19 -05:00
Robert Griesemer 074bd4ac9c go.tools/go/types: cleanup: remove unnecessary receiver
R=adonovan
CC=golang-codereviews
https://golang.org/cl/53810044
2014-01-17 11:17:43 -08:00
Alan Donovan 2845638157 go.tools/go/ssa: simplify builder.exprN now that go/types emits correct types.
(Follow-up to fix of issue 7060.)

Also: comment fixes.

R=gri
CC=golang-codereviews
https://golang.org/cl/47670043
2014-01-17 09:38:25 -05:00
Robert Griesemer 2d6b34a0f5 go.tools/go/types: report rhs type for comma-ok expressions
Fixes golang/go#7060.

R=adonovan
CC=golang-codereviews
https://golang.org/cl/53520043
2014-01-16 19:33:51 -08:00
Robert Griesemer 0b4b877c72 go.tools/go/types: remove size from Basic
More localized computation of sizes.

R=adonovan
CC=golang-codereviews
https://golang.org/cl/53460043
2014-01-16 14:47:26 -08:00
Robert Griesemer 9b91992c8c go.tools/go/loader: add missing argument to fmt.Errorf call
R=adonovan
CC=golang-codereviews
https://golang.org/cl/53360043
2014-01-16 13:20:02 -08:00
Robert Griesemer 184bc0cc8c go.tools/go/gccgoimporter: remove dead code
R=adonovan
CC=golang-codereviews
https://golang.org/cl/53340043
2014-01-16 13:19:39 -08:00
Robert Griesemer e4a00b5ce3 go.tools/go/importer: fix format string
R=adonovan
CC=golang-codereviews
https://golang.org/cl/52360045
2014-01-16 13:17:46 -08:00
Alan Donovan 9cfde22948 go.tools/ssa/interp: rewrite initorder test.
Correct, this time.

R=gri
CC=golang-codereviews
https://golang.org/cl/52930043
2014-01-16 14:08:04 -05:00
Alan Donovan b856247075 go.tools/call: rename package to go/callgraph
Was:		Now:
call.Graph	callgraph.Graph
call.GraphNode	callgraph.Node
call.Edge	callgraph.Edge

Though call.Graph was cute, the original naming was a mistake:
'call' is too useful a var name to waste on a package.

R=gri, crawshaw
CC=golang-codereviews
https://golang.org/cl/53190043
2014-01-16 14:04:19 -05:00
Alan Donovan 3fc0fc1310 go.tools: rename packages.
Was:		Now:
ssa		go/ssa
importer	go/loader
pointer		go/pointer

Next CL: call -> go/callgraph (requires more care)

R=gri, crawshaw
CC=golang-codereviews
https://golang.org/cl/52960043
2014-01-16 09:33:58 -05:00
Robert Griesemer e1c6a8ff95 go.tools/go/types: init order depends on source order
Apply sorting consistently to object->decl maps.

Fixes golang/go#7131.

R=adonovan
CC=golang-codereviews
https://golang.org/cl/52890043
2014-01-15 15:15:32 -08:00
Robert Griesemer 5d7773006a go.tools/go/types: minor cleanups
- remove TODO in exact.go
- use testing.Verbose() rather than local verbose flag

R=adonovan
CC=golang-codereviews
https://golang.org/cl/52500043
2014-01-14 21:04:35 -08:00
Peter Collingbourne a0cc29953e go.tools/go/types: introduce Func.Scope()
The goal is to allow clients to distinguish function-local objects
from package-local objects and identify the specific function by
examining its scope. For example, a compiler may need to mangle
object names according to the outer function name.

R=gri
CC=golang-codereviews, golang-dev
https://golang.org/cl/52280043
2014-01-14 14:47:27 -08:00
Peter Collingbourne 0c15485ecc go.tools/go/types: use WordSize as function pointer size
Both gc and gccgo appear to use this size, so it seems appropriate
to use it here.

R=gri
CC=golang-codereviews, golang-dev, iant, rsc
https://golang.org/cl/52290043
2014-01-14 14:10:09 -08:00
Robert Griesemer 179e0b3699 go.tools/go/types: only report constants with constant types
The issue is addressed with the change in conversions.go.

Also:
- added corresponding API test
- made names for untyped ints, bools consistent with others
- use *Basic with names byte/rune instead of uint8/int32 for better output
- minor cleanups

Fixes golang/go#6949.

R=adonovan
CC=golang-codereviews
https://golang.org/cl/50520043
2014-01-10 15:21:51 -08:00
Robert Griesemer df3357d07f go.tools/go/types: simplify variable usage error detection
Now that inner functions are processed "in line", usage errors
can be detected immediately after each function is processed.

R=adonovan
CC=golang-codereviews
https://golang.org/cl/49900044
2014-01-09 10:45:42 -08:00
Robert Griesemer 4e620158a2 go.tools/go/types: use correct outer scope state for inner functions
Inner function bodies must be type-checked "in-place" for
them to see the correct state of the surrounding scopes.

Fixes golang/go#7035.

R=adonovan
CC=golang-codereviews
https://golang.org/cl/49350043
2014-01-09 08:40:32 -08:00
Peter Collingbourne 893253274d go.tools/go/gccgoimporter: importer for gccgo export data
This can import all of the standard library, and has been tested
by using gotype to type check libgo with gccgo's export data (this
would be nice to automate, but I can't see a good way to do it,
not least because system-specific source files cause errors which
I needed to identify manually).

It includes a builtin export locator. Unfortunately I can't see a
more reliable way to locate the builtin export files than to parse
the output of 'gccgo -###'.

R=gri, iant, gri
CC=golang-codereviews, golang-dev
https://golang.org/cl/31860043
2014-01-08 09:00:50 -08:00
Robert Griesemer a9b6519df8 go.tools/go.types: cleanups
- if a named type was imported before, read it again
  and throw it away in favor of the existing type
  (the old code did the same, but more circuitously)

- better tag name for int64 values

R=adonovan
CC=golang-codereviews
https://golang.org/cl/47650044
2014-01-08 08:58:00 -08:00
Robert Griesemer ff72a95f05 go.tools/go/gcimporter: correct package for imported methods
R=adonovan
CC=golang-codereviews
https://golang.org/cl/48630044
2014-01-07 14:46:10 -08:00
Robert Griesemer b6eef48120 go.tools/go/types: adjust comments for godoc
R=adonovan
CC=golang-codereviews
https://golang.org/cl/38560045
2014-01-07 10:03:15 -08:00
Robert Griesemer 822669c658 go.tools/importer: fix field package for anonymous fields
Anonymous field names are emitted as "" in the export data
since the actual name can be reconstructed easily from the
field's type name. But "" names are not exported names and
thus the respective qualified name emits complete package
information even if the actual field name is exported. Fix
the package upon import.

R=adonovan
CC=golang-codereviews
https://golang.org/cl/42090044
2014-01-03 14:08:12 -08:00
Robert Griesemer df08273253 go.tools/gcimporter: use imported package info for anonymous fields
The package of a struct field is independent of the type of the
struct field - the old code was technically not correct. That said,
it does not seem possible (or very difficult) to create a test case
because for exported anonymous fields that field package doesn't matter
(it's not needed for name identity), and non-exported anonymous fields
cannot be accessed from an imported package.

R=adonovan
CC=golang-codereviews
https://golang.org/cl/47560043
2014-01-03 11:37:20 -08:00
Robert Griesemer 6770b5cdca go.tools/go/importer: more cleanups
R=adonovan
CC=golang-codereviews
https://golang.org/cl/34660046
2014-01-03 09:12:32 -08:00
Robert Griesemer 10f0067eb1 go.tools/go.types: cleanups
Per feedback for CL 37250044.

R=adonovan
CC=golang-codereviews
https://golang.org/cl/47150043
2014-01-02 10:07:48 -08:00
Robert Griesemer 30645c4bc6 go.tools/go/importer: fine-tuning of export format, test against std lib
(TBR adonovan)

- provide version string rather than version number (more flexible)
- match naming of tag constants with documentation (forth-coming)
- more formats for constant values (1-byte booleans, short 64bit
  values, support for floating point numbers +123p+45)
- more regular format for signatures: always print with type tag;
  this permits (future) sharing of identical signatures and possibly
  large export data size reduction
- test export and import of all type-checked std library packages
- compare import of all std library packages against corresponding
  import of gc-generated export data and verify that the packages
  match 100% (except for floating point values which are exact when
  coming from go/types, and possibly inexact when coming from gc)

On average, export data generated by the importer is ~28% of the size
of the gc-generated export data for corresponding packages of the std
library:

        package 		size	gc size

        archive/tar		2945	12030	24%
        archive/zip		4122	15796	26%
        bufio			1776	6171	28%
        bytes			2540	8006	31%
        compress/bzip2		146	419	34%
        compress/flate		2305	6356	36%
        compress/gzip		4262	17917	23%
        compress/lzw		336	832	40%
        compress/zlib		2503	9814	25%
        container/heap		255	527	48%
        container/list		653	2971	21%
        container/ring		246	707	34%
        crypto			368	1015	36%
        crypto/aes		219	499	43%
        crypto/cipher		809	1875	43%
        crypto/des		254	636	39%
        crypto/dsa		3324	15609	21%
        crypto/ecdsa		3833	18567	20%
        crypto/elliptic		3801	17417	21%
        crypto/hmac		205	459	44%
        crypto/md5		206	413	49%
        crypto/rand		3070	15047	20%
        crypto/rc4		180	443	40%
        crypto/rsa		4205	17941	23%
        crypto/sha1		208	414	50%
        crypto/sha256		272	555	49%
        crypto/sha512		274	555	49%
        crypto/subtle		247	1157	21%
        crypto/tls		13769	48330	28%
        crypto/x509		10716	40556	26%
        crypto/x509/pkix	5670	24616	23%
        database/sql		4227	15957	26%
        database/sql/driver	1239	2806	44%
        debug/dwarf		5165	12066	42%
        debug/elf		14205	36401	39%
        debug/goobj		992	2495	39%
        debug/gosym		1808	4798	37%
        debug/macho		4560	13173	34%
        debug/pe		3694	10530	35%
        encoding		261	387	67%
        encoding/ascii85	368	1541	23%
        encoding/asn1		479	1661	28%
        encoding/base32		608	2636	23%
        encoding/base64		610	2636	23%
        encoding/binary		1006	3591	28%
        encoding/csv		2287	8405	27%
        encoding/gob		9161	30565	29%
        encoding/hex		384	1331	28%
        encoding/json		6564	23334	28%
        encoding/pem		208	529	39%
        encoding/xml		7964	27220	29%
        errors			52	277	18%
        expvar			955	2978	32%
        flag			2475	18028	13%
        fmt			1141	3141	36%
        go/ast			11595	41019	28%
        go/build		3736	13920	26%
        go/doc			2647	9523	27%
        go/format		1310	5010	26%
        go/parser		4346	18525	23%
        go/printer		1737	6442	26%
        go/scanner		2360	8598	27%
        go/token		2290	7599	30%
        hash			215	595	36%
        hash/adler32		217	391	55%
        hash/crc32		399	1475	27%
        hash/crc64		324	1327	24%
        hash/fnv		338	3964	8%
        html			80	253	31%
        html/template		7981	37471	21%
        image			4270	18894	22%
        image/color		845	3154	26%
        image/color/palette	121	319	37%
        image/draw		947	4807	19%
        image/gif		1468	6611	22%
        image/jpeg		971	4534	21%
        image/png		880	4432	19%
        index/suffixarray	3702	13960	26%
        io			2049	6117	33%
        io/ioutil		2845	12060	23%
        log			2416	10241	23%
        log/syslog		3102	12208	25%
        math			2361	6008	39%
        math/big		3648	12250	29%
        math/cmplx		473	1542	30%
        math/rand		786	2002	39%
        mime			180	595	30%
        mime/multipart		2761	9338	29%
        net			10593	34352	30%
        net/http		24542	84065	29%
        net/http/cgi		12859	50970	25%
        net/http/cookiejar	2845	12429	22%
        net/http/fcgi		12331	49111	25%
        net/http/httptest	18953	75243	25%
        net/http/httputil	13994	54386	25%
        net/http/pprof		12153	49039	24%
        net/mail		1803	8599	20%
        net/rpc			18503	69044	26%
        net/rpc/jsonrpc		1063	2737	38%
        net/smtp		11775	46821	25%
        net/textproto		2684	8678	30%
        net/url			767	2886	26%
        os			5712	20293	28%
        os/exec			4705	18350	25%
        os/signal		125	330	37%
        os/user			234	720	32%
        path			231	770	30%
        path/filepath		2236	9721	23%
        reflect			4518	13467	33%
        regexp			3608	11167	32%
        regexp/syntax		2184	5157	42%
        runtime			1563	3407	45%
        runtime/cgo		36	66	54%
        runtime/debug		1714	8010	21%
        runtime/pprof		485	1358	35%
        runtime/race		38	43	88%
        sort			748	2658	28%
        strconv			949	2573	36%
        strings			1846	6220	29%
        sync			712	1970	36%
        sync/atomic		1089	2506	43%
        syscall			38975	79396	49%
        testing			3734	13626	27%
        testing/iotest		332	2378	13%
        testing/quick		4411	16434	26%
        text/scanner		1821	5349	34%
        text/tabwriter		1593	4937	32%
        text/template		6882	33329	20%
        text/template/parse	3946	12760	30%
        time			3031	9703	31%
        unicode			3148	8676	36%
        unicode/utf16		163	760	21%
        unicode/utf8		475	1122	42%

        total			463641	1644936	28%

R=adonovan
TBR=adonovan
CC=golang-codereviews
https://golang.org/cl/37250044
2013-12-20 16:43:31 -08:00
Robert Griesemer e405e03b16 go.tools/go/types: complete set of Interface accessors
Also: Provide GcCompatibilityMode for printing types
(intended for testing with gc-generated export data
only).

(TBR adonovan)

R=adonovan
TBR=adonovan
CC=golang-codereviews
https://golang.org/cl/44780043
2013-12-20 16:35:31 -08:00
Robert Griesemer e2acb64f86 go.tools/go/types: submit missed file (fix build)
R=adonovan
CC=golang-codereviews
https://golang.org/cl/38130044
2013-12-20 15:51:04 -08:00
Robert Griesemer d4da60d38f go.tools/gc/importer: fix struct tags and parameter names
R=iant
CC=golang-codereviews
https://golang.org/cl/42280046
2013-12-20 15:17:16 -08:00
Robert Griesemer 4e3127283a go.tools/go/gcimporter: adjust for new .a file format
R=rsc, r
CC=golang-dev
https://golang.org/cl/41510044
2013-12-18 10:53:59 -08:00
Robert Griesemer 53dfbf8a00 go.tools: fix build
Missed a couple of places with previous CL.

R=adonovan
TBR=adonovan
CC=golang-dev
https://golang.org/cl/40850046
2013-12-17 16:21:23 -08:00
Robert Griesemer 74d33a9c33 go.tools/go/types: use types.ChanDir instead of ast.ChanDir
Clearer code and fewer dependencies on go/ast.

R=adonovan
CC=golang-dev
https://golang.org/cl/43630043
2013-12-17 15:45:01 -08:00
Robert Griesemer a02c76070b go/importer: fix build (disable tests that won't run on builders)
R=adonovan
TBR=adonovan
CC=golang-dev
https://golang.org/cl/43010043
2013-12-16 14:44:22 -08:00
Robert Griesemer 5eb4fdc120 go.tools/go/importer: simplified exporter/importer
By using a simple (graph-based) serialization algorithm
and binary encoding, a significantly more compact export
data format is achieved than what the current compilers
use. Furthermore, the exporter and importer are completely
symmetric algorithms that are compact, and much easier to
change/expand.

R=adonovan
CC=golang-dev
https://golang.org/cl/42960043
2013-12-16 14:28:17 -08:00
Robert Griesemer 91abc02562 go.tools/go/types: print interface methods in sorted order
Required for testing code of clients.

R=adonovan
CC=golang-dev
https://golang.org/cl/35940049
2013-12-16 13:53:08 -08:00
Robert Griesemer 3df3227c35 go.tools/go/exact: fix bug introduced with CL 41170043
R=adonovan
CC=golang-dev
https://golang.org/cl/37820052
2013-12-12 14:18:40 -08:00
Robert Griesemer e2828468ff go.tools/go/exact: serialization support and better unknown handling
- fixed various imprecise doc strings
- consistent handling of unknown values

R=adonovan
CC=golang-dev
https://golang.org/cl/41170043
2013-12-12 13:43:00 -08:00
Robert Griesemer 4728c2f3f6 go.tools/go/types: turn off internal debug mode
- much improved performance
- enable when testing changes

R=adonovan
CC=golang-dev
https://golang.org/cl/36480049
2013-12-12 13:32:36 -08:00
Robert Griesemer 693727787e go.tools/go/types/typemap: fix formatting verb
(%p is trouble if the interface value is not a pointer)

R=adonovan
CC=golang-dev
https://golang.org/cl/41440043
2013-12-12 12:12:32 -08:00
Alan Donovan 036b7d3489 go.tools/types: skip "imported but not used" check if IgnoreFuncBodies.
Obviously in that mode, we can't correctly diagnose such
errors, so we shouldn't attempt it (and emit false positives).

R=gri
CC=golang-dev
https://golang.org/cl/41080043
2013-12-11 21:12:08 -05:00
Robert Griesemer 11cfd4a636 go.toools/go/types: clearer comment (per adonovan)
R=adonovan
CC=golang-dev
https://golang.org/cl/40860045
2013-12-11 10:48:17 -08:00
Robert Griesemer d6902b2ad5 go/tools/go/gcimporter: avoid possible endless loops in case of errors
R=adonovan
CC=golang-dev
https://golang.org/cl/39630045
2013-12-09 15:43:31 -08:00
Peter Collingbourne 7dcd8ded7c go.tools/go/types: handle embedded interfaces in NewInterface
R=gri
CC=golang-dev
https://golang.org/cl/39040043
2013-12-09 13:37:24 -08:00
Robert Griesemer ff84d756df go.tools/go/types: avoid spurious error in a common case
R=adonovan
CC=golang-dev
https://golang.org/cl/36900043
2013-12-03 17:51:54 -08:00
Robert Griesemer 14cf5b0a28 go.tools/go/types: fun with Hilbert: a const arithmetic test
This test generates a program that declares the constant
elements of an n*n Hilbert matrix, its inverse, and the
constant elements of the explicit product of the two.
The product should be the identity matrix; that check is
also expressed as a constant expression. Type-checking
verifies that the product is indeed the identity matrix
by asserting the result of the identity check (using the
assert built-in which is available for type-check tests).

The test is run for n = 5. Other values can be tested via
the -H flag, say: go test -run=Hilbert -H=100

The generated program can be written to a file for testing
the constant arithmetic of a compiler: go test -out=test.go

Because of the mathematically precise constant arithmetic
of go/types, this test should always succeed and is only
limited by the size of the matrix. It does run successfully
from n = 0 to values larger than 100.

The Hilbert matrix is famous for being ill-conditioned and
thus exposes arithmetic imprecision very quickly. The gc
compiler only produces a correct result for n = 0 (trivially),
and n = 1 at the moment.

R=adonovan, rsc
CC=golang-dev
https://golang.org/cl/35840043
2013-12-03 13:36:57 -08:00
Robert Griesemer 62a3fc7538 go.tools/go/types: clean up internal iota in all cases
R=dsymonds
CC=golang-dev
https://golang.org/cl/33570043
2013-11-26 17:48:47 -08:00
Robert Griesemer 3d343e42d1 go.tools/go/types: constants must have constant types
R=adonovan
CC=golang-dev
https://golang.org/cl/33210043
2013-11-26 12:42:52 -08:00
Robert Griesemer bbf45e5e0c go.tools/go/types: missing assignment checks when assigning to _
R=adonovan, gri
CC=golang-dev
https://golang.org/cl/31340044
2013-11-26 09:34:12 -08:00
Robert Griesemer b9c2c88573 go.tools/go/types: add Package.SetImports
R=adonovan, neelance
CC=golang-dev
https://golang.org/cl/32500043
2013-11-26 09:19:17 -08:00
Richard Musiol 397114a391 go.tools/go/gcimporter: ImportData has no need for *bufio.Reader, can get just io.Reader.
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/31620043
2013-11-24 12:48:45 -08:00
Robert Griesemer 8c9bb9c1e3 go.tools/go/types: various cleanups
- use unpack also for assignments
- run benchmarks only requested (-b flag)

R=adonovan
CC=golang-dev
https://golang.org/cl/31190044
2013-11-22 20:34:07 -08:00
Robert Griesemer 007f41d43e go.tools/go/types: more benchmarks, clearer results
The benchmarks don't permit clear-cut apples-to-apples
comparisons since they depend on the very source code
they are testing. But they do give an indication of
the approximate performance - as a sanity test.

Using 3 different code bases makes it apparent that
there's some difference in performance per code base;
i.e., the lines/s speed varies pretty strongly. This
may be due to setup costs, or other issues. We should
investigate eventually.

R=adonovan
CC=golang-dev
https://golang.org/cl/30650043
2013-11-21 21:08:29 -08:00
Robert Griesemer ef434a14da go.tools/go/types: record correct type for parenthesized x.(T) in comma-ok expressions
Fixes golang/go#6796.

R=adonovan
CC=golang-dev
https://golang.org/cl/30070044
2013-11-21 09:11:57 -08:00
Richard Musiol 88e2928490 go.tools/go/types: Do not throw error on division of complex variables by zero.
See http://play.golang.org/p/DrgLKnHaUW
Seems like division of a variable by zero should only throw an error if the variable is an integer.

R=golang-dev, mtj, gri
CC=golang-dev, gri
https://golang.org/cl/29500047
2013-11-20 13:42:30 -08:00
Robert Griesemer b4286c4c1b go.tools/go/types: missing checks for select statements
Also: Use defer to make sure scopes are always closed
even in case of early exits via bailout (and don't cause
an imbalanced scope error in debug mode).

R=adonovan, gri
CC=golang-dev
https://golang.org/cl/29300043
2013-11-19 13:58:01 -08:00
Robert Griesemer 849643aaaf go.tools: cleanups (added copyrights to astutil, clearer logic in go/types)
R=adonovan
CC=golang-dev
https://golang.org/cl/29110043
2013-11-19 09:07:02 -08:00