Commit Graph

1201 Commits

Author SHA1 Message Date
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
Robert Griesemer df6f0829a2 go.tools/go/types: complete expr and type string functions
- consolidate them in (expr|type)string[_test].go
- support for printing all ast.Expr
- fix printing of type: chan (<-chan int) (parentheses)
- more consistent names, comments, and exports

R=adonovan
CC=golang-dev
https://golang.org/cl/28680043
2013-11-18 22:38:48 -08:00
Robert Griesemer 65aa1a4fbe go.tools/go/types: String method for Initializers
Plus a couple of minor fixes.

R=adonovan
CC=golang-dev
https://golang.org/cl/28540043
2013-11-18 11:26:49 -08:00
Robert Griesemer e785f050b6 go.tools/go/types: add missing checks for short variable declarations
Fixes golang/go#6766.

R=adonovan
CC=golang-dev
https://golang.org/cl/24330044
2013-11-15 14:26:29 -08:00
Robert Griesemer 01f122e48b go.tools/go/gcimporter: fix build by adjusting test to new print output
R=adonovan, bradfitz
CC=golang-dev
https://golang.org/cl/26430049
2013-11-15 11:58:23 -08:00
Alan Donovan 45992044b5 go.tools/go/types: SelectionString: print method with selective package-qualification.
R=gri, gri
CC=golang-dev
https://golang.org/cl/26570048
2013-11-15 12:35:03 -05:00
Alan Donovan 0820934407 go.tools/go/types: add TypeString, ObjectString utilities
These are variants of Type.String(), Object.String() that
accept a 'from *Package' argument.  If provided, package
qualification is omitted when printing named types belonging
to that package.

This is useful for UIs where a package is implied by context
e.g. ssadump disassembly, oracle output.

+ Test.

R=gri, gri, gordon.klaus
CC=golang-dev
https://golang.org/cl/22190048
2013-11-15 09:20:46 -05:00
Robert Griesemer 91e5190eb9 go.tools/go/types: minor cleanups
R=adonovan
CC=golang-dev
https://golang.org/cl/26430045
2013-11-14 21:38:04 -08:00
Robert Griesemer 27563ff576 go.tools/go/types: move gcimporter to its own package
- fixed a couple of TODOs
- various cleanups along the way
- adjusted clients

Once submitted, clients of go/types that don't explicitly
specify Config.Import will need to add the extra import:

import _ "code.google.com/p/go.tools/go/gcimporter"

to install the default (gc) importer in go/types.

R=adonovan, gri
CC=golang-dev
https://golang.org/cl/26390043
2013-11-14 14:11:43 -08:00
Robert Griesemer d1184e294e go.tools/go/types: fix build
(I inadvertently submitted a modified file.)

R=adonovan
CC=golang-dev
https://golang.org/cl/22750044
2013-11-13 15:21:38 -08:00
Richard Musiol cfc002f30b go.tools/go/types: Do not throw error on division of float variables by zero.
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/26040043
2013-11-13 15:16:19 -08:00
Alan Donovan 3f686cae84 go.tools/go/types: print named types with package qualification.
Depending on the context, printing only the package name can
be ambiguous or even incorrect since it is valid only within
the environment of a given file's import specs.

(The standard library packages are mostly unique in their last
segment, but this is not the case for proprietary repos.)

R=gri, gri
CC=golang-dev
https://golang.org/cl/26300043
2013-11-13 16:03:41 -05:00
Robert Griesemer f339918a70 go.tools/go/exact: some factoring, more tests
R=adonovan
CC=golang-dev
https://golang.org/cl/25440043
2013-11-12 12:45:43 -08:00
Richard Musiol a5baa859ae go.tools/go/exact: Fix for exact.BinaryOp. It was modifying its argument.
R=golang-dev, gri, mail
CC=golang-dev
https://golang.org/cl/24570043
2013-11-12 10:06:24 -08:00
Alan Donovan d8292e2a38 go.tools/go/types: cache method set for pointer-to-named in the Named.
This change improves the complete running time of 'ssadump cmd/oracle' by ~20%.

R=gri, gri
CC=golang-dev
https://golang.org/cl/22910045
2013-11-11 17:20:27 -05:00
Robert Griesemer c798b9cca0 go.tools/go/types: check validity of import paths
This check is currently done in go/parser as well but
eventually can be removed from there (after Go 1.2).

R=adonovan
CC=golang-dev
https://golang.org/cl/22240045
2013-11-08 14:14:58 -08:00
Robert Griesemer 7b183d1766 go.tools/go/types, cmd/gotype: fix early bailout
Clients must have chance to look at panics they
are raising.

R=adonovan
CC=golang-dev
https://golang.org/cl/23820043
2013-11-08 12:52:57 -08:00
Robert Griesemer e8fe66cd57 go.tools/go/types: print initialization cycles
Also: Always report cycle at first (in source order)
variable in the cycle.

R=adonovan, gri
CC=golang-dev
https://golang.org/cl/23370043
2013-11-08 12:06:10 -08:00
Robert Griesemer 0f193b767d go.tools/go/types: simplified GcImportedTypes test
R=adonovan
CC=golang-dev
https://golang.org/cl/23340043
2013-11-08 08:56:55 -08:00
Robert Griesemer 7520cff8d3 go.tools/go/types: remove a workaround for 386 bug
R=adonovan
CC=golang-dev
https://golang.org/cl/23350043
2013-11-08 08:55:16 -08:00
Robert Griesemer 7123ca00a8 go.tools/go/types: fix bug in init cycle detection
Initialization cycles need to reported for cycles
that contain variables, even if they don't end in
a variable.

This fixes the last known issue with the existing
std library tests.

R=adonovan, gri
CC=golang-dev
https://golang.org/cl/22200049
2013-11-06 17:47:54 -08:00
Robert Griesemer eb67edd047 go.tools/go/types: add test cases for pending issues
The gc compiler is inconsistent how it handles method
"mentions" with respect to initialization cycle detection
(see issue 6703 for details). Pending a spec clarification,
this CL assumes that for a method to be "mentioned", it
must be mentioned as a method expression rather than a
method value (closer in intent to "syntactic" mention).

R=adonovan
CC=golang-dev
https://golang.org/cl/22050044
2013-11-06 09:55:03 -08:00
Alan Donovan 2e7d5a8b6b go.tools/ssa: dump types in "pkg."-unqualified form where appropriate.
Also: types.Typ[types.UnsafePointer].String() now always prints as "unsafe.Pointer".

R=gri
CC=golang-dev
https://golang.org/cl/21820044
2013-11-05 17:32:45 -05:00
Robert Griesemer 8e64946a3a go.tools/go/types: better error messages for api tests
R=adonovan
CC=golang-dev
https://golang.org/cl/22140043
2013-11-05 13:42:31 -08:00
Robert Griesemer 8b05c30f06 go.tools/go/types: track cycles through methods
R=adonovan
CC=golang-dev
https://golang.org/cl/22070043
2013-11-05 11:47:22 -08:00
Robert Griesemer b33df7e76a go.tools/go/types: track init cycles through closures
R=adonovan
CC=golang-dev
https://golang.org/cl/21790044
2013-11-05 10:51:13 -08:00
Robert Griesemer 9d1e9ed2ab go.tools/go/types: track init cycles through functions
- Info.InitOrder now provides list of Initializers
  (vars + init expr), handling n:1 decls and blank
  identifiers
- added respective API test
- cycles detected through function "mentions"

Missing: cycles through method "mentions" and via
         closures

R=adonovan
CC=golang-dev
https://golang.org/cl/21810043
2013-11-05 09:25:25 -08:00
Robert Griesemer d259ea48d1 go.tools/go/types: first cut at checking variable initialization cycles
Missing:
- dependencies via functions (incl. closures and methods)
- more tests (incl. API test)

R=adonovan
CC=golang-dev
https://golang.org/cl/20510043
2013-10-31 21:47:35 -07:00
Robert Griesemer fb0632eb7d go.tools/go/types: Provide explicit type checker Error.
R=adonovan
CC=golang-dev
https://golang.org/cl/20400044
2013-10-31 12:01:00 -07:00
Robert Griesemer 3eb9e504e3 go.tools/go/types: update a TODO comment (not a TODO anymore)
R=adonovan
TBR=adonovan
CC=golang-dev
https://golang.org/cl/17440043
2013-10-25 15:37:03 -07:00
Robert Griesemer b98997fdfe go.tools/go/types: enable std lib test of map key types
R=adonovan
CC=golang-dev
https://golang.org/cl/17390043
2013-10-25 14:38:52 -07:00
Robert Griesemer 65aaa0093c go.tools/go/types: check map key type when it is fully known
Fixes golang/go#6667.

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

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

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

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

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

R=adonovan
CC=golang-dev
https://golang.org/cl/16380043
2013-10-24 09:12:28 -07:00
Robert Griesemer 40b09326ee go.tools/go/types: enable another test case
Working now that circular interface types are handled correcly.

R=adonovan
CC=golang-dev
https://golang.org/cl/16310046
2013-10-24 09:09:10 -07:00
Alan Donovan 87ced824bd go.tools/ssa: fix computation of set of types requiring method sets.
Motivation:

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

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

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

Description:

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

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

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

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

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

Fixes golang/go#6605

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

R=adonovan, gri, r, mtj
CC=golang-dev
https://golang.org/cl/14795044
2013-10-23 13:46:40 -07:00
Robert Griesemer 851a7b980a go.tools/go/types: return invalid type (rather than nil) for (*Label).Type()
R=adonovan
CC=golang-dev
https://golang.org/cl/14782043
2013-10-17 10:48:19 -07:00
Robert Griesemer ac0a1222cb go.tools/go/types: fix StdSizes.Sizeof computation
Thanks to Travis Cline for finding this bug.

R=adonovan
CC=golang-dev
https://golang.org/cl/14752043
2013-10-16 10:45:58 -07:00
Robert Griesemer 5fcdb7b3ff go.tools/go/types: provide Sizes interface instead of individual sizing functions
This will make it a bit easier to create commonly used "custom" sizes for types.

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

Also: minor unrelated cleanups.

R=adonovan
CC=golang-dev
https://golang.org/cl/14719043
2013-10-15 14:51:52 -07:00
Robert Griesemer 60c505c95c go.tools/go/types: fix recorded type for append(s, "foo"...)
R=adonovan
CC=golang-dev
https://golang.org/cl/14512057
2013-10-11 14:27:44 -07:00
Robert Griesemer 0c45220917 go.tools/go/types: record call-site specific types of built-in functions
Given a built-in call f(args), Info.Types now maps f to the call-site
specific type of f (by looking at the argument types) if the built-in
call is not producing a constant (at typecheck time) result. If the
result is constant, the recorded type is invalid (a back-end won't
need it).

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

R=adonovan
CC=golang-dev
https://golang.org/cl/14600043
2013-10-10 11:05:46 -07:00
Robert Griesemer f54303d6cb to.tools/go/types: check invalid use of ... with built-ins
R=adonovan
CC=golang-dev
https://golang.org/cl/14531047
2013-10-10 10:46:54 -07:00
Robert Griesemer 7ca228a514 go.tools/go.types: more missing assigment checks implemented
Assignments to "comma, ok" expressions on the lhs of an
assignment are not permitted unless we have map index
"comma, ok" expression. Created new operand mode 'mapindex'
to distinguish this case. Renamed mode 'valueok' to the more
commonly used 'commaok' term, which also makes it easier to
distinguish from simply 'value'.

Added corresponding tests.

Fixes a TODO.

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

R=adonovan, r
CC=golang-dev
https://golang.org/cl/14438052
2013-10-09 14:17:25 -07:00
Robert Griesemer 5d9b86d6ce go.tools/go/types: range iteration variables are typed (not untyped)
R=adonovan
CC=golang-dev
https://golang.org/cl/14516044
2013-10-07 20:27:21 -07:00
Robert Griesemer 5d0990f591 go.tools/go/types: built-in calls of the form builtin(f())
- factor out argument extraction logic
- cleaned up error handling in builtin.go (no need for goto's anymore)
- lots of additional test cases
- various cleanups, better documentation

Fixes golang/go#5795.

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

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/14283043
2013-10-04 11:46:57 +10:00
Robert Griesemer b9b3bed16e go.tools/go/types: fix build (gc export format changed)
Revision f280b8a485fd of the std library changed the
gc export format: anonymous fields may be qualified
with a package.

R=rsc
TBR=rsc
CC=golang-dev
https://golang.org/cl/14312043
2013-10-02 16:53:34 -07:00
Robert Griesemer a32c2633d0 go.tools/go/types: complete checking of append built-in
R=adonovan
CC=golang-dev
https://golang.org/cl/14238043
2013-10-01 18:14:15 -07:00
Robert Griesemer 35e395da09 go.tools/go/types: more flexible error checking
- permit ERROR markers to be in full or line comments
- don't require ""s in /* ERROR "foo" */
- enable more std tests
- some minor cleanups

R=adonovan
CC=golang-dev
https://golang.org/cl/14169044
2013-09-30 21:47:05 -07:00
Robert Griesemer c92471fb85 go.tools/go/types: improved error messages for invalid labels
In general, if a break or continue label is not found, we don't
know if a correspondingly named label was not declared, was declared
but is not visible, or will be declared (and won't be visible).
Complain about "invalid" rather than "not declared" label.

Added more tests.

R=adonovan
CC=golang-dev
https://golang.org/cl/14149043
2013-09-30 14:03:33 -07:00
Robert Griesemer 3daa579643 go.tools/go/types: implement label checks
R=adonovan
CC=golang-dev
https://golang.org/cl/14036046
2013-09-30 11:05:30 -07:00
Robert Griesemer 0730d79f0f go.tools/go/types: check unlabeled break, continue statements
This CL temporarily removes some preliminary label checks.
They will be implemented completely in a subsequent CL.

R=adonovan
CC=golang-dev
https://golang.org/cl/14055043
2013-09-27 13:43:11 -07:00
Robert Griesemer 27b698bc2a go.tools/go/types: x.f is addressable if x is addressable or x.f contains an indirection
Fixes golang/go#6487.

R=adonovan
CC=golang-dev
https://golang.org/cl/14047043
2013-09-27 09:33:00 -07:00
Robert Griesemer ca3d62b66d go.tools/go/types: fix incorrect argument to fmt.Printf
(found by r using the vet tool)

R=adonovan
CC=golang-dev
https://golang.org/cl/14013043
2013-09-26 20:34:35 -07:00
Russ Cox 577fe73c91 go.tools/go/types: fix build for Go 1.1 users
Fixes golang/go#6485.

R=gri
CC=golang-dev
https://golang.org/cl/13901045
2013-09-26 12:45:44 -04:00
Robert Griesemer a6c151c04d go.tools/go/types: (panic(0)) (parenthesized) is a terminating statement
R=adonovan
CC=golang-dev
https://golang.org/cl/13913043
2013-09-25 10:19:24 -07:00
Robert Griesemer 9d1c551b43 go.tools/go/types: check 3-index slice expressions
R=adonovan
CC=golang-dev
https://golang.org/cl/13881043
2013-09-25 10:15:40 -07:00
Robert Griesemer dfaa5cc0c1 go.tools/go/types: test case for issue 6413
Fixes golang/go#6413.

R=adonovan
CC=golang-dev
https://golang.org/cl/13840047
2013-09-24 12:51:45 -07:00
Robert Griesemer bce88d26ea go.tools/go/types: improved operand printing in error messages
Also:
- removed operand.val hack for built-in encoding; added id field
- minor cleanups

R=adonovan
CC=golang-dev
https://golang.org/cl/13840046
2013-09-24 12:22:04 -07:00
Robert Griesemer 0e6d095d11 go.tools/go/types: better error messages for invald expression statements
Also: removed some dynamic print formats.

R=adonovan
CC=golang-dev
https://golang.org/cl/13849043
2013-09-23 15:39:11 -07:00
Robert Griesemer a05da76c7b go.tools/go/types: represent built-ins as Objects (rather than types)
This change affects the API: Func objects now always have a *Signature
as type (never a *Builtin). Instead, built-ins now appear as *Builtin
objects. Only the built-in name is exposed, other fields are now private
to go/types.

Several bugs are fixed:
- correctly checking for built-ins permitted in statement context
- expression statements that are calls are not type-checked twice anymore
- go/defer statements report call types and provide good error messages now

This CL will briefly break the build until CL 13848043 is submitted.

R=adonovan
CC=golang-dev
https://golang.org/cl/13813043
2013-09-23 15:14:17 -07:00
Robert Griesemer 26a4f47422 go.tools/go/types: enable more std lib tests
R=adonovan
CC=golang-dev
https://golang.org/cl/13798043
2013-09-20 10:09:40 -07:00
Robert Griesemer c2d7895b1e go.tools/go/types: "imported but not used" errors for dot-imports
R=adonovan, josharian
CC=golang-dev
https://golang.org/cl/13795043
2013-09-20 10:09:16 -07:00
Robert Griesemer 86e41f819a go.tools/go/types: "imported but not used" checks for packages
also:
- initial code for unused label errors
- some cleanups, better names
- additional tests

TODO: Dot-imported packages are not handled yet; i.e., they
      are always considered used for now.

R=adonovan
CC=golang-dev
https://golang.org/cl/13768043
2013-09-19 10:05:34 -07:00
Robert Griesemer a68deb25ff go.tools/go/types: "declared but not used" error for type switches
Also:
- added more tests
- removed Var.Used accessor: it's not meaningful for clients since
  it does not reflect actual use/def information
- fixed position for short variable declaration errors

R=adonovan
CC=golang-dev
https://golang.org/cl/13240051
2013-09-18 11:31:46 -07:00
Robert Griesemer f1051f2025 go.tools/go/types: 'declared but not used' checks for variables
- updated all tests to conform to stricter rules
- TODO: check for implicitly declared variables in type switches

R=adonovan
CC=golang-dev
https://golang.org/cl/13695046
2013-09-18 08:39:02 -07:00
Robert Griesemer 4acd602bea go.tools/go/types: fix a couple of std lib test failures
1. handle return statements with zero (but expected) return values
2. indices provided for array or slice composite literals must be integer constants

Added additional test cases.

R=adonovan
CC=golang-dev
https://golang.org/cl/13734043
2013-09-17 10:26:06 -07:00
Robert Griesemer cf1e27bbda go.tools/go/types: add test case for resolution of blank methods
(was bug on go/types wishlist; probably fixed a while ago)

R=adonovan
CC=golang-dev
https://golang.org/cl/13633047
2013-09-16 13:18:56 -07:00
Robert Griesemer 1928c01286 go.tools/go/types: separate package descriptor from package object
Includes changes by adonovan to make oracle work again
(former CL 13395050).

R=adonovan
CC=golang-dev
https://golang.org/cl/13672044
2013-09-13 09:52:57 -07:00
Robert Griesemer 3fee9166d4 go.tools/go/types: treat unsafe.Pointer like a pointer for receivers and embedding
Also: Better error message for receiver type errors.

R=adonovan
CC=golang-dev
https://golang.org/cl/13259044
2013-09-11 10:03:40 -07:00
Robert Griesemer 67c866ec74 go.tools/go/types: extra tests for float conversions
R=adonovan
CC=golang-dev
https://golang.org/cl/13393046
2013-09-10 14:43:23 -07:00
Robert Griesemer b591789053 go.tools/go/types: clearer documentation
(Follow-up of CL feedback.)

R=adonovan
CC=golang-dev
https://golang.org/cl/13333047
2013-09-10 14:26:49 -07:00
Alan Donovan 9a9fb35468 go.types/go/types: document primary vs. secondary Package distinction.
And: add accessor to get the primary from a secondary Package.

This change documents a surprising fact about the current
go/types resolver implementation, namely that each ast.ImportSpec
    import "fmt"
creates a new ("secondary") Package object for fmt with the
same String, Name, Path and Scope as the canonical ("primary")
fmt package, but with a different identity.

This change also adds an accessor Package.Primary() that
returns the primary package associated with a secondary
package object, if any.

IMHO the current design is wrong, and the resolver should not
create secondary packages at all.  Even if a package is
imported under a non-default name, as in
    import f "fmt"
    ...
    f.Print
we should just regard f as a reference to the existing package
"fmt", not as the defining identifier for a secondary package.
What we would lose by such a change (the connection of the two
f's in 'f.Print' and 'import f "fmt"') seems a small price to
pay.

This CL is thus just a minimal change to permit clients to
make progress under the status quo.

R=r, gri, crawshaw
CC=golang-dev
https://golang.org/cl/13626043
2013-09-10 14:11:17 -04:00
Robert Griesemer 6688b01dc1 go.tools/go/types: fix unsafe.Pointer conversions
Make compliant with gc. Spec is not very clear.
Also: Fix error handling (don't destroy x before
using it in error message).

Fixes golang/go#6326.

R=adonovan
CC=golang-dev
https://golang.org/cl/13632043
2013-09-09 16:41:46 -07:00
Robert Griesemer 932a87ce16 go.tools/go/types: fix ... parameter passing
Also: exclude test case from std test to fix build.

Fixes golang/go#6344.

R=adonovan
CC=golang-dev
https://golang.org/cl/13630043
2013-09-09 15:20:14 -07:00
Chris Manghane 95e4181bb5 go.tools/go/vcs: apply fix to issue 5801.
No semantic difference from https://golang.org/cl/12343043/

R=bradfitz
CC=golang-dev
https://golang.org/cl/13383044
2013-09-09 12:49:08 -07:00
Rob Pike 6fb9ae0ed5 go.tools/go/vcs: use same regular expression for code.google.com as cmd/go
No semantic change.

R=golang-dev, bradfitz, dsymonds
CC=golang-dev
https://golang.org/cl/13373043
2013-08-29 14:32:06 +10:00
Rob Pike b38e3512f0 go.tools/go/vcs: support cloned repos in code.google.com
R=golang-dev, bradfitz, dsymonds
CC=golang-dev
https://golang.org/cl/13241047
2013-08-29 13:50:05 +10:00
David Symonds cec37cabd4 go/vcs: add proper error handling to test.
Fix a couple of error messages to report better messages.

R=adg
CC=golang-dev
https://golang.org/cl/13146043
2013-08-21 13:55:33 +10:00
Chris Manghane d64ad45594 go.tools/go/vcs: add logging functionality and create/log at revision
Add support for logging commands for Mercurial and Subversion as well as the ability to create/log a repo at a certain revision.

- Exported Cmd.LogCmd
- Exported Cmd.CreateAtRev
- Exported Cmd.Log
- Exported Cmd.LogAtRev

R=adg
CC=golang-dev
https://golang.org/cl/13060044
2013-08-20 20:10:15 -07:00
Andrew Gerrand 4e1a4d9fde go.tools/go/types: fix bad function comparison
Issue found by vet -nilfunc.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12816044
2013-08-20 15:26:04 +10:00
Dave Cheney 41a15a3013 go.tools/go/vcs: do not delete $TMPDIR during test runs
The test would nuke the entire contents of os.TempDir on completion.

This change corrects the code to use ioutil.TempDir.

R=r, adg
CC=golang-dev
https://golang.org/cl/12796045
2013-08-19 16:22:31 +10:00
Chris Manghane dfa65ded17 go.tools: add go/vcs
go/vcs exposes cmd/go/vcs.go from the `go get` command.

- Exported global variables `Verbose` and `ShowCmd` to replace `buildV` and `buildX` from cmd/go/main.go.
- Moved environment building code (envForDir, mergeEnvLists)from cmd/go/main.go to env.go
- Exported Cmd and its methods: Create, Download, Ping, TagSync, and Tags
- Exported ByCmd and FromDir functions for constructing Cmd
- Exported TagCmd
- Exported RepoRoot
- Exported RepoRootForImport* functions for constructing RepoRoot

R=golang-dev, adg, cmang, bradfitz
CC=golang-dev
https://golang.org/cl/12058054
2013-08-15 09:00:02 -07:00
Robert Griesemer ae874abc7a go.tools/go/types: *interface types have no methods
Fixes golang/go#5918.

R=adonovan
CC=golang-dev
https://golang.org/cl/12909043
2013-08-14 11:02:10 -07:00
Robert Griesemer d13d94afe7 go.tools/go/types: do rounding in constant numeric conversions
- cleaned up surrounding code
- adjusted error message positions for too few/many argument errors
- added more conversion tests
- added all tests under test/ken to std tests

R=adonovan, r
TBR=adonovan
CC=golang-dev
https://golang.org/cl/12711043
2013-08-12 14:57:08 -07:00
Robert Griesemer 508ae115ae go.tools/go/types: added missing test for file scopes
R=adonovan, r
CC=golang-dev
https://golang.org/cl/12671044
2013-08-08 20:54:28 -07:00
Robert Griesemer 2449594308 go.tools/go.types: retain ast.Node links on demand only
- support Info.Scopes mapping that maps ast.Nodes
  to the respective *Scope
- remove old node link from *Scope
- added corresponding API test

Also: re-enable debug mode (the faster version was
only important for the go api tool, which  has its
own version now).

R=adonovan, r
CC=golang-dev
https://golang.org/cl/12552047
2013-08-08 20:27:15 -07:00
Robert Griesemer 875ff2496f go.tools/go/types: support for fake imports of package "C"
Also:
- cleaner method set printing
- disable debug mode internally (50% faster)

R=adonovan, bradfitz
CC=golang-dev
https://golang.org/cl/12578043
2013-08-07 14:09:50 -07:00
Robert Griesemer 56b9e46247 go.tools/go/types: fewer guarantees in case of type errors
Provide fewer guarantees regarding the collected result
type information in types.Info if there are type errors.

Specifically, don't record nil objects in the Objects map
in case of a declaration error; instead, simply omit them.

R=adonovan
TBR=adonovan
CC=golang-dev
https://golang.org/cl/12553043
2013-08-06 11:27:05 -07:00
Rob Pike 75920173e4 go.tools/go/types: don't put an interface nil into the Objects map
If a method cannot type check, we end up with the interface variable
m to hold <*Func, nil>. Don't put that in the map because it defeats
the usual != nil check.

R=gri, dsymonds
CC=golang-dev
https://golang.org/cl/12506043
2013-08-06 16:19:10 +10:00
Robert Griesemer b956928b06 go.tools/go/types: Fix for broken IsAssignableTo.
Was broken by CL 12378043.

- factored out some error checking code
- adjusted error positions

R=adonovan
TBR=adonovan
CC=golang-dev
https://golang.org/cl/12401043
2013-08-05 13:54:22 -07:00
David Symonds 1dce9cc7c7 go/types: exclude a couple of files from the stdlib test that don't parse on Windows.
They use stuff in syscall that doesn't exist on Windows, and this test does not
parse build tags (not that we make that easy) to automatically skip them.

R=golang-dev, r, gri
CC=golang-dev
https://golang.org/cl/12453043
2013-08-05 13:54:22 +10:00
Robert Griesemer 3209d6ad73 go.tools/go/types: fix interface vs interface type assertion
R=adonovan
CC=golang-dev
https://golang.org/cl/12378043
2013-08-02 14:37:19 -07:00
Robert Griesemer e06b897351 go.tools/go/types: mark imported named types as 'complete'
Fixes "illegal cycle" error for: go tool vet -v pkg/unicode.

R=adonovan
CC=golang-dev
https://golang.org/cl/12355043
2013-08-02 09:33:37 -07:00
Robert Griesemer 4ceda807d5 go.tools/go/types: add mode to typecheck pkg-level decls only
This is useful for situations where one only cares about
exports, for instance (as in the goapi checker).

R=adonovan, bradfitz
CC=golang-dev
https://golang.org/cl/12292043
2013-08-01 16:37:56 -07:00
Alan Donovan 61a33ecd43 go.tools/go/types: fix: the type of a method value should not have a reciever
e.g.
type T int
func (T) f() {}
var t T
_ = t.f  // method value: should have signature "func()", no receiver

Also:
- ssa: add sanity check that helped diagnose this.

R=gri
CC=golang-dev
https://golang.org/cl/12283043
2013-08-01 15:38:41 -04:00
Robert Griesemer caf3fc90ed go.tools/go/types: test against test/fixedbugs
Fixed several bugs:
- lhs blank identifier may be parenthesized: (_) = 0 is ok
- constant shift counts in non-constant shifts must be >= 0
- init functions must have a body

Classified currently failing tests:
- 10 classes of errors not checked at the moment

R=adonovan, r
CC=golang-dev
https://golang.org/cl/11952046
2013-07-31 20:08:18 -07:00
Robert Griesemer ae07aa6055 go.tools/go/types: return typed bool for comma-ok expressions
Also: determine default types for assignments of the form: _ = x .

R=adonovan
CC=golang-dev
https://golang.org/cl/12186043
2013-07-31 12:49:34 -07:00
Robert Griesemer e5cfd92deb go.tools/go/types: record comma-ok results as tuples
- added corresponding api tests
- support tuple comparison with IsIdentical

This CL will require some adjustments to SSA.

R=adonovan
CC=golang-dev
https://golang.org/cl/12024046
2013-07-31 09:33:46 -07:00
Robert Griesemer 1e79a68ff5 go.tools/go/types: check fallthrough statements
R=adonovan
CC=golang-dev
https://golang.org/cl/12041049
2013-07-30 16:00:57 -07:00
Alan Donovan 2f6855ad75 go.tools/ssa: avoid calling go/types.NewSelection, and eliminate it.
Also: s/LookupMethod/Method/

R=gri
CC=golang-dev
https://golang.org/cl/12058052
2013-07-30 16:36:58 -04:00
Robert Griesemer 4ae33302a4 go.tools/go/types: map keys must be comparable
R=adonovan
CC=golang-dev
https://golang.org/cl/12102044
2013-07-30 13:15:28 -07:00
Robert Griesemer 33d57bf48f go.tools/go/types: report identifier for methods with blank names
R=adonovan
CC=golang-dev
https://golang.org/cl/12123045
2013-07-30 12:47:40 -07:00
Robert Griesemer e7c7afbb1a go.tools/go/types: enable (previously broken) shift tests
R=adonovan
CC=golang-dev
https://golang.org/cl/12109044
2013-07-30 11:10:28 -07:00
Robert Griesemer 7a1a18283b go.tools/go/types: constant shifts always produce integers (bug fix)
R=adonovan
CC=golang-dev
https://golang.org/cl/12025044
2013-07-30 10:28:57 -07:00
Robert Griesemer 30c6d6350d go.tools/go/types: check type-checker against $GOROOT/test
R=adonovan
CC=golang-dev
https://golang.org/cl/12070044
2013-07-30 09:00:25 -07:00
Alan Donovan 0ba53b54bd go.tools/ssa: add debug info for x.f where Selection.Kind()==FieldVal.
Also:
- Implement Program.FuncValue for interface methods (+ test).
- go/types.Object.String(): don't package-qualify names unless
  they are package level objects---otherwise you see "main.x" for
  locals, struct fields, etc.
- go/types.Func.String(): don't assume Type() is *Signature;
  it could be *Builtin.

R=gri
CC=golang-dev
https://golang.org/cl/12058045
2013-07-29 17:10:11 -04:00
Robert Griesemer 90aa993096 go.tools/go/types: provide package for imported methods
Fixes golang/go#5815.

R=adonovan
CC=golang-dev
https://golang.org/cl/12048043
2013-07-29 13:22:46 -07:00
Robert Griesemer bb34185432 go.tools/go/types: more implicit conversion tests
Also: Fixed grammar in selection.go comment.

R=adonovan
CC=golang-dev
https://golang.org/cl/11962043
2013-07-29 13:07:46 -07:00
Alan Donovan fb0642f5fb go.tools/ssa: fix a package-level var initialization order bug.
buildDecl was visiting all decls in source order, but the spec
calls for visiting all vars and init() funcs in order, then
all remaining functions.  These two passes are now called
buildInit(), buildFuncDecl().

+ Test.

Also:
- Added workaround to gcimporter for Func with pkg==nil.
- Prog.concreteMethods has been merged into Pkg.values.
- Prog.concreteMethod() renamed declaredFunc().
- s/mfunc/obj/ (name cleanup from recent gri CL)

R=gri
CC=golang-dev
https://golang.org/cl/12030044
2013-07-29 14:24:09 -04:00
Robert Griesemer 64ea46e0bc go.tools/go/types: replace Method w/ Selection
A Method corresponds to a MethodVal Selection;
so the explicit Method object is not needed anymore.

- moved Selection code into separate file
- implemented Selection.String()
- improved and more consistent documentation

R=adonovan
CC=golang-dev
https://golang.org/cl/11950043
2013-07-26 22:27:48 -07:00
Robert Griesemer 4ea4ce9e03 go.tools/go/types: added missing implicit conversion checks
R=adonovan, r
CC=golang-dev
https://golang.org/cl/11934047
2013-07-26 18:21:14 -07:00
Robert Griesemer 41fb587948 go.tools/go/types: implement Info.Selections
Should make it easier for clients to deal with
selector expressions.

Removed Field type: The respective information
is now reported in Info.Selections.

R=adonovan
CC=golang-dev
https://golang.org/cl/11942043
2013-07-26 13:55:14 -07:00
Alan Donovan 118786e3d6 go.tools/ssa: combine CallCommon.{Recv,Func} as Value.
Also:
- add types.Func.FullName() (e.g. "fmt.Println", "(main.S).f")
- remove rogue print stmt.
- fix bad docstrings.

R=gri
CC=golang-dev
https://golang.org/cl/11936044
2013-07-26 14:06:26 -04:00
Robert Griesemer bf6a1e674e go.tools/go/types: unsafe.Offsetof must deref named pointers to structs
R=adonovan
CC=golang-dev
https://golang.org/cl/11889043
2013-07-26 09:53:47 -07:00
Alan Donovan 4da31df1c8 go.tools/ssa: (another) major refactoring of method-set logic.
We now use LookupFieldOrMethod for all SelectorExprs, and
simplify the logic to discriminate the various cases.

We inline static calls to promoted/indirected functions,
dramatically reducing the number of functions created.

More tests are needed, but I'd like to submit this as-is.

In this CL, we:
- rely less on Id strings.  Internally we now use
  *types.Method (and its components) almost everywhere.
- stop thinking of types.Methods as objects. They don't
  have stable identities. (Hopefully they will become
  plain-old structs soon.)
- eliminate receiver indirection wrappers:
  indirection and promotion are handled together by makeWrapper.
- Handle the interactions of promotion, indirection and
  abstract methods much more cleanly.
- support receiver-bound interface method closures.
- break up builder.selectField so we can re-use parts
  (emitFieldSelection).
- add importer.PackageInfo.classifySelector utility.
- delete interfaceMethodIndex()
- delete namedTypeMethodIndex()
- delete isSuperInterface() (replaced by types.IsAssignable)
- call memberFromObject on each declared concrete method's
  *types.Func, not on every Method frem each method set, in the
  CREATE phase for packages loaded by gcimporter.

go/types:
- document Func, Signature.Recv() better.
- use fmt in {Package,Label}.String
- reimplement Func.String to be prettier and to include method
  receivers.

API changes:
- Function.method now holds the types.Method (soon to be
  not-an-object) for synthetic wrappers.
- CallCommon.Method now contains an abstract (interface)
  method object; was an abstract method index.
- CallCommon.MethodId() gone.
- Program.LookupMethod now takes a *Method not an Id string.

R=gri
CC=golang-dev
https://golang.org/cl/11674043
2013-07-26 11:22:34 -04:00
Robert Griesemer c98ff05fdd go.tools/go/types: faster scopes, cleanups around method lookups
R=adonovan
CC=golang-dev
https://golang.org/cl/11787043
2013-07-24 20:02:54 -07:00
Robert Griesemer 6dbbc59ae0 go.tools/go/types: simplify handling of blank _ identifiers
Also: Fixes a couple of places where scopes instead
      of objsets were used (missed in previous CL).

R=adonovan
CC=golang-dev
https://golang.org/cl/11419047
2013-07-24 12:39:11 -07:00
Robert Griesemer d0657ebb0d go.tools/go/types: record lhs identifier in switch lhs := rhs.(type)
Added testcase.

R=adonovan
CC=golang-dev
https://golang.org/cl/11742043
2013-07-24 12:38:51 -07:00
Alan Donovan d4f2f2d7fa go.tools/ssa: repair treatment of typeswitch after recent go/types changes.
Now, in a "switch y := x.(type)", there is no object for the
outer y, only implicit objects, one per case (including
default).

Also: don't set obj=nil for blank idents (workaround suggested by gri).

R=gri
CC=golang-dev
https://golang.org/cl/11564046
2013-07-24 14:03:53 -04:00
Robert Griesemer c5b1cc4227 go.tool/go/types: ignore invalid anonymous fields
Fixes go tool vet breakage when applied to files
with incomplete type information for anonymous
fields.

R=adonovan
CC=golang-dev
https://golang.org/cl/11773043
2013-07-24 10:49:44 -07:00
Robert Griesemer 407e159412 go.tools/go/types: fix typo in self test
R=adonovan
CC=golang-dev
https://golang.org/cl/11749044
2013-07-24 09:26:39 -07:00
Robert Griesemer 66e7552830 go.tools/go/types: simplified and faster Scope
- implemented objset for tracking duplicates of fields and methods
  which permitted a simpler and faster scope implementation in turn
- related cleanups and internal renames
- fixed a couple of identifier reporting bugs

Speed of type-checking itself increased by almost 10%
(from ~71Kloc/s to ~78Kloc/s on one machine, measured
via go test -run=Self).

R=adonovan
CC=golang-dev
https://golang.org/cl/11750043
2013-07-23 21:21:37 -07:00
Robert Griesemer 2f54663e0e go.tools/go/types: fix build: ignore self-test if it fails
R=adonovan
CC=golang-dev
https://golang.org/cl/11398045
2013-07-23 20:52:41 -07:00
Robert Griesemer cc55bd9129 go.tools/go/types: add self test
R=adonovan
CC=golang-dev
https://golang.org/cl/11739043
2013-07-23 18:30:06 -07:00
Robert Griesemer 09d04edfcf go.tools/go/types: declare typeswitch local variable in correct scope
R=adonovan
CC=golang-dev
https://golang.org/cl/11534044
2013-07-23 14:18:38 -07:00
Robert Griesemer 7bc647b29a go.tools/go/types: internal cleanups
- more consistent naming of some internal data types and methods
- better factoring of some error reporting code
- cleanup around association of methods with receiver base types
- more tests

R=adonovan
CC=golang-dev
https://golang.org/cl/11726043
2013-07-23 13:42:04 -07:00
Robert Griesemer 2bff3a03e7 go.tools/go/types: clean up method type checking
- treat receivers like ordinary parameters when checking signatures;
  concentrate all respective checks in one place
- continue to type-check methods even if receiver base type does not
  satisfy receiver type criteria (comes for free)
- don't ignore blank _ methods anymore
- various related cleanups

As a consequence, the resolving needs one less internal phase.

R=adonovan
CC=golang-dev
https://golang.org/cl/11591045
2013-07-22 20:42:10 -07:00
Robert Griesemer d722d82c52 go.tools/go/type: hook up interface method receivers
Also:
- Renamed Object.SameName -> Object.SameId
- Exported Object.Id

R=adonovan
CC=golang-dev
https://golang.org/cl/11567046
2013-07-19 16:26:32 -07:00
Robert Griesemer b0ae7702cb go.tools/go/types: record Field/Method object for f in selector expressions x.f
TODO(gri) This needs tests.

R=adonovan
CC=golang-dev
https://golang.org/cl/11519046
2013-07-19 14:46:28 -07:00
Robert Griesemer f4540b7193 go.tools/go/types: set correct Method recv type in NewMethodSet
R=adonovan
CC=golang-dev
https://golang.org/cl/11602043
2013-07-19 13:00:02 -07:00
Robert Griesemer 35f4fd1cd1 go.tools/go/types: use *Var instead of *Field for struct fields
Temporarily remove Field objects in favor of Vars for struct fields.
In forthcoming CL, Fields will play the symmetric role to Methods, and
serve as lookup results including index information.

R=adonovan
CC=golang-dev
https://golang.org/cl/11594043
2013-07-19 11:01:51 -07:00
Robert Griesemer 40a278e5ee go.tools/go/types: rename Context -> Config (more apt name)
Also: Various minor cleanups.

R=adonovan, r
CC=golang-dev
https://golang.org/cl/11445044
2013-07-18 17:07:44 -07:00
Robert Griesemer 6d85cc17dd go.tools/go/types: request type Info via maps instead of callbacks
Allmost all uses of go/types that wanted the type
information computed, installed callback functions
that stored the information in maps. Most of the
time this is the only thing that could be done because
there is no guarantee that types are completely set
up before the end of type-checking.

This CL removes the respective Context callbacks in favor
of corresponding maps that collect the desired information
on demand, grouped together in an optional Info struct.

R=adonovan
CC=golang-dev
https://golang.org/cl/11530044
2013-07-18 13:09:03 -07:00
Robert Griesemer 78c8226b42 go.tools/go/types: don't modify lhs untyped types in constant shifts
Also: fix TestCheck (don't fail if there are no errors in -list mode)

Fixes golang/go#5895.

R=adonovan
CC=golang-dev
https://golang.org/cl/11535043
2013-07-18 10:48:03 -07:00
Robert Griesemer 8901caa2b3 go.tools/go/types: Method sets for all types
- fixed method set computation
- lazily compute it for a type on demand
- lazy allocation of various temporary maps

Also:
- removed Interface.IsEmpty, Scope.IsEmpty
  (these convenience functions didn't carry their weight)
- cosmetic changes

Next:
- consolidate various lookup APIs
- use lazily computed method sets for various checks
  instead of individual lookups

R=adonovan
CC=golang-dev
https://golang.org/cl/11385044
2013-07-16 22:18:08 -07:00
Alan Donovan 80ec883f7b go.tools/ssa: several small clean-ups.
- removed a number of obsolete TODO(gri) comments.
- bring ssa.DefaultType back into sync with types.defaultType.
- re-enable types.Package.Path()!="" assertion.
- use Path() (not reflect pointer) in sort routine.
- make interp.checkInterface use types.MissingMethod.
- un-export ssa.MakeId function.
- inline pointer() into all callers, and delete.
- enable two more interp_tests: $GOROOT/test/{method3,cmp}.go
- add links to bugs to other interp_tests.
- add runtime.NumCPU to ssa/interp/externals.go

R=gri
CC=golang-dev
https://golang.org/cl/11353043
2013-07-16 12:23:55 -04:00
Robert Griesemer 0117ba266d go.tools/go/types: cleanup parameter passing
- now represent ...T parameter type as []T (rather than T)
- simplified call checking
- added missing check and test for x... arguments (x must be slice)

This CL will temporarily break ssa and ssa/interp.

R=adonovan, axwalk
CC=golang-dev
https://golang.org/cl/11317043
2013-07-16 09:12:33 -07:00
Robert Griesemer f1a889124d go.tools/go/types: cleanups
Objects:
- provide IsExported, SameName, uniqueName methods
- clean up a lot of dependent code

Scopes:
- don't add children to Universe scope (!)
- document Node, WriteTo

Types:
- remove Deref in favor of internal function deref

ssa, ssa/interp:
- introduced local deref, adjusted code
- fixed some "Underlying" bugs (pun intended)

R=adonovan
CC=golang-dev
https://golang.org/cl/11232043
2013-07-12 21:09:33 -07:00
Robert Griesemer a3301d1bc6 go.tools/go/types: more test cases for types.Eval
R=adonovan
CC=golang-dev
https://golang.org/cl/11229043
2013-07-12 13:51:24 -07:00
Robert Griesemer 32ed9615b3 go.tools/go/types: implement New, Eval and EvalNode
Eval and EvalNode permit the evaluation of an expression
or type literal string (or AST node in case of EvalNode)
within a given context (package and scope).

Also:
- track nested (children) scopes for all scopes
- provide a mechanism to iterate over nested scopes
- permit recursive printing of scopes

TODO: more tests

R=adonovan
CC=golang-dev
https://golang.org/cl/10748044
2013-07-12 11:03:34 -07:00
Robert Griesemer 5ec27f6da9 go.tools/go/types: export IsAssignableTo
Tested implictly since its simply calling the
internal isAssignableTo which is used in every
assignment when testing the std library.

R=adonovan
CC=golang-dev
https://golang.org/cl/11189043
2013-07-11 14:23:23 -07:00
Robert Griesemer 424b1fda00 go.tools/go/types: only print underlying type in Object.String for type objects
R=adonovan
CC=golang-dev
https://golang.org/cl/11161045
2013-07-11 13:19:12 -07:00
Robert Griesemer ed5ac0e6f1 go.tools/go/types: provide Object.String method
R=adonovan
CC=golang-dev
https://golang.org/cl/11178043
2013-07-11 12:57:56 -07:00
Robert Griesemer 1f28df4b6c go.tools/go/types: reuse code for m:n assignments
- more test cases

R=adonovan
CC=golang-dev
https://golang.org/cl/10952044
2013-07-11 10:54:52 -07:00
Robert Griesemer 59f09dcb8c go.tools/go/types: report test errors immediately in -list mode
This way, errors reported before a crash are visible.

R=adonovan, r
CC=golang-dev
https://golang.org/cl/10802044
2013-07-10 22:19:43 -07:00
Robert Griesemer 3a75f78acd go.tools/go/types: cleanup init expr checks
- factored our arity checks
- started more systematic tests for const/var decls
- better error messages
- fixed several corner case errors

R=adonovan
CC=golang-dev
https://golang.org/cl/11137043
2013-07-10 20:10:24 -07:00
Alan Donovan 4df74776da go.tools/ssa: de-dup the creation of method sets, using typemap.
Yields a ~20% improvement in SSA construction time.

Also: better names for promotion wrapper functions.

R=gri
CC=golang-dev
https://golang.org/cl/11050043
2013-07-10 18:01:11 -04:00
Alan Donovan 26d93d2e47 go.tools/go.types/typemap: a map whose keys are types.
go/types.Type has an equivalence relation (IsIdentical) that
is not consistent with the equivalence relation implemented by
Go's == operator for Types.  Therefore extra work is required
to build a map whose keys are types.  This package does that
work.

Has simple unit test.  More tests might be good.

R=gri
CC=golang-dev
https://golang.org/cl/9649044
2013-07-10 17:57:07 -04:00
Robert Griesemer 8cd6c3be05 go.tools/go/types: check for non-func init declarations
R=adonovan
CC=golang-dev
https://golang.org/cl/11075043
2013-07-09 21:13:37 -07:00
Robert Griesemer b8f13c4c9b go.tools/go/types: assignment checking cleanup (round 2)
- consolited remainign assignment check routines
- removed more dead code
- fixed incorrect scope hierarchy in case of errors for some statements
- fixed scope of key iteration variable for range clauses

R=adonovan
CC=golang-dev
https://golang.org/cl/10694044
2013-07-09 09:45:09 -07:00
Robert Griesemer 1aa0484f4b go.tools/go/types: report correct type for untyped conversion arguments
Fixes golang/go#5849.

R=adonovan
CC=golang-dev
https://golang.org/cl/11007043
2013-07-08 13:51:20 -07:00
Robert Griesemer cc52b8b7f8 go.tools/go/types: clean up assignment checks (round 1)
Various bug fixes:
- don't allow := to redeclare non-variables
- don't permit a comma-ok expression as a two-value function return

Lots of dead code removed.

Fixes golang/go#5500.

R=adonovan
CC=golang-dev
https://golang.org/cl/10792044
2013-07-08 09:40:30 -07:00
Robert Griesemer 4ca3d7e9da go.tools/go/types: remove defers from critical paths
Various minor cleanups.

R=adonovan
CC=golang-dev
https://golang.org/cl/10925043
2013-07-03 20:51:39 -07:00
Robert Griesemer f052654314 go.tools/go/types: remove iota from all parameter lists (cleanup)
Instead of passing around iota everywhere, keep track of the
current value in the checker, and update it when entering
different declarations. This is less explicit, but the improvement
over all code is so significant that it is worth it.

R=adonovan
CC=golang-dev
https://golang.org/cl/10814044
2013-07-03 10:06:09 -07:00
Robert Griesemer b58f98e9c2 go.tools/go/types: fix more cycle errors, lots of refactoring
- moved ident and typ expr checking into typexpr.go
- as a result, fewer parameters are needed for expr checking
- forward-chain type decls of the form type ( A B; B C; C *A) etc.
  so that cycles are getting the right types in all cases
- fixed several corner case bugs, added more test cases

R=adonovan
CC=golang-dev
https://golang.org/cl/10773043
2013-07-02 16:39:30 -07:00
Robert Griesemer 69c297407f go.tools/go/types: fix nil assignment
Fixes golang/go#5800.

R=adonovan
CC=golang-dev
https://golang.org/cl/10709044
2013-06-27 13:26:13 -07:00
Robert Griesemer a0160af20b go.tools/go/types: tests for cycles in type decls
Fixed one aspect of issue 5090. Fixing it completely
requires a bit more work around the representation of
interface types.

R=adonovan
CC=golang-dev
https://golang.org/cl/10678045
2013-06-27 12:43:20 -07:00
Robert Griesemer feb0ab2b10 go.tools/go/types: -files flag for testing one-off packages
Removed special case for testdata/test.go file in favor of
a simpler, more flexible, and explicit flag for one-off test
packages.

R=adonovan
CC=golang-dev
https://golang.org/cl/10618044
2013-06-26 13:01:16 -07:00
Robert Griesemer 22b7915ff5 go.tools/go/types: factored out code for calls and selectors
No other changes.

R=adonovan
CC=golang-dev
https://golang.org/cl/10573043
2013-06-25 15:40:28 -07:00
Robert Griesemer 25da72adcd go.tools/go/types: initialize local x early in case of bailout panic
- added respective test case

Fixes golang/go#5770.

R=adonovan
CC=golang-dev
https://golang.org/cl/10531043
2013-06-24 21:29:47 -07:00
Robert Griesemer 124e603d87 go.tools/go/types: imported structs may contain _ fields
Don't report import errors due to (multiple) _ fields
in imported structs.

Fixes golang/go#5758.

R=adonovan
CC=golang-dev
https://golang.org/cl/10529043
2013-06-24 17:38:41 -07:00
Robert Griesemer c13bb422de go.tools/go/types: fix nil-ptr deref in gcimporter
Also: Make error handling more explicit.

Possibly a fix for issue 5758.

R=adonovan
CC=golang-dev
https://golang.org/cl/10520043
2013-06-24 11:49:02 -07:00
Robert Griesemer bd55eef6ec go.tools/go/types: handle p.x with p of type P *S
R=adonovan
CC=golang-dev
https://golang.org/cl/10459044
2013-06-24 09:58:27 -07:00
Robert Griesemer cf8ec1591f go.tools/go/exact: more consistent handling of unknown values
R=adonovan
CC=golang-dev
https://golang.org/cl/10431046
2013-06-21 19:56:40 -07:00
Robert Griesemer 628104465d go.tools/go/types: fix logic error in MissingMethod and type assert code
R=adonovan
CC=golang-dev
https://golang.org/cl/10448046
2013-06-21 14:30:47 -07:00
Robert Griesemer 0325defab0 go.tools/go/types: factor method set and lookup better
No functional change, just symmetric cleanup.

R=adonovan
CC=golang-dev
https://golang.org/cl/10417045
2013-06-21 13:19:41 -07:00
Robert Griesemer 2d345c1dd7 go.tools/go/types: improved LookupFieldOrMethod, ast.Nodes for Scopes
- LookupFieldOrMethod now computes if any indirection was found on the
  way to an embedded field/method: this is the only information required
  to determine if a result method is in the method set.

- Scopes now provide a link to the ast.Node responsible for them.

Also:
- don't permit unsafe.Offsetof on method values
- report ambiguities in field/method lookup errors
- added some missing checks for anonymous fields
- lots of new tests

Fixes golang/go#5499.

R=adonovan
CC=golang-dev
https://golang.org/cl/10411045
2013-06-21 08:57:26 -07:00
Robert Griesemer 9ff248b00d go.tools/go/types: simplified lookup
- much simpler lookup
- more result information
- will make tracking of pointer-ness easier

TODO: apply the same changes to method set computation

R=adonovan
CC=golang-dev
https://golang.org/cl/10379049
2013-06-19 12:29:17 -07:00
Robert Griesemer d338982a64 go.tools/go/types: use qualified names when printing types in errors
Also: Require that clean package paths are not ".".

R=adonovan, r
CC=golang-dev
https://golang.org/cl/10368047
2013-06-18 16:41:11 -07:00
Robert Griesemer 9a50e157b4 go.tools/go/types: first cut at sorted method sets
- moved single field and method lookup functionality
  from operand.go to new file lookup.go and cleaned
  up the lookup implementation

- implemented method set computation using the same
  basic structure as for field/method lookup, in new
  file methodset.go

- minor related changes

- the method set computation ignores pointer-ness of
  the receiver type at the moment (next CL)

- fixed a couple of bugs (missing pkg info for imported
  embedded types, wrong test for method expressions)

The method set computation is currently verified by
comparing a regular method lookup with a method-set
based method lookup.

R=adonovan
CC=golang-dev
https://golang.org/cl/10235049
2013-06-18 15:59:16 -07:00
Robert Griesemer 7517d8bae3 go.tools/go/types: catch cycles in function declarations
Fixes golang/go#5217.

R=adonovan
CC=golang-dev
https://golang.org/cl/10402044
2013-06-18 15:34:12 -07:00
Alan Donovan f1d4d01fed go.tools/ssa: memoize synthesis of all wrapper methods.
methodIndex() utility was split and specialized to its two
cases, *Interface vs *Named, which are logically quite
different.

We can't memoize promotion wrappers yet; we need typemap.

Terminology:
- "thunks" are now "wrappers"
- "bridge methods" are now "promotion wrappers"

Where the diff is messy it's just because of indentation.

R=gri
CC=golang-dev
https://golang.org/cl/10282043
2013-06-14 15:50:37 -04:00
Robert Griesemer 9ce6fcb502 go.tools/go/types: use []*Func instead of *Scope to hold methods
R=golang-dev, adonovan
CC=golang-dev
https://golang.org/cl/10243043
2013-06-13 11:11:53 -07:00
Robert Griesemer 5efab5e9c0 go.tools/go/types: Use []*Field instead of *Scope for struct fields
This partially reverts a previous change, using a []*Field is a better
representation for struct fields than a *Scope, after all; however
*Fields remain Objects.

Fixes golang/go#5670.

R=adonovan, axwalk
CC=golang-dev
https://golang.org/cl/10207043
2013-06-11 19:54:47 -07:00
Robert Griesemer 0d2f7d411b go.tools/go/types: fix isAssignable and IsIdentical
- Imported objects that are explicitly exported may have a nil package;
  don't use it for qualified name computation (it's not needed).
- isAssignable must check all possibilities before declaring failure.

Fixes golang/go#5675.

R=adonovan
CC=golang-dev
https://golang.org/cl/10141044
2013-06-11 10:00:00 -07:00
Robert Griesemer 63f3103b6f go.tools/go/types: call Context.Ident for selectors
Fixes golang/go#5669.

R=adonovan
CC=golang-dev
https://golang.org/cl/9714045
2013-06-10 16:42:22 -07:00
Robert Griesemer 221795b447 go.tools/go/types: Factories for all objects
R=adonovan
CC=golang-dev
https://golang.org/cl/9794044
2013-06-04 15:15:41 -04:00
Alan Donovan be28dbb86f go.types/ssa: split the load/parse/typecheck logic off into a separate package.
PLEASE NOTE: the APIs for both "importer" and "ssa" packages
will continue to evolve and both need some polishing; the key
thing is that this CL splits them.

The go.types/importer package contains contains the Importer,
which takes care of the mechanics of loading a set of packages
and type-checking them.  It exposes for each package a
PackageInfo containing:
- the package's ASTs (i.e. the input to the typechecker)
- the types.Package object
- the memoization of the typechecker callbacks for identifier
  resolution, constant folding and expression type inference.

Method-set computation (and hence bridge-method creation) is
now moved to after creation of all packages: since they are no
longer created in topological order, we can't guarantee the
needed delegate methods exist yet.

ssa.Package no longer has public TypeOf, ObjectOf, ValueOf methods.
The private counterparts are valid only during the build phase.

Also:
- added to go/types an informative error (not crash) for an
  importer() returning nil without error.
- removed Package.Name(), barely needed.
- changed Package.String() slightly.
- flag what looks like a bug in makeBridgeMethod. Will follow up.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/9898043
2013-05-31 16:14:13 -04:00
Robert Griesemer 710a117e33 go.tools/go/types: don't use nil fields and methods
The change for fields is in anticipation of fields
becoming a *Scope.

Pointed out by adonovan.

R=adonovan
CC=golang-dev
https://golang.org/cl/9874049
2013-05-31 12:02:33 -07:00
Robert Griesemer e5f49b1c9f go.tools/go/types: typecheck call arguments even if the call doesn't typecheck
This provides better partial type information in case of type errors.

R=r
CC=golang-dev
https://golang.org/cl/9835049
2013-05-31 11:22:00 -07:00
Robert Griesemer 3cad037e2f go.tools/go/types: replace ObjSet with improved Scope
- First step towards unified use of scopes. Will enable
  further simplifications.

- Removed various ForEach iterators in favor of the existing
  accessor methods, for a thinner API.

- Renamed outer/Outer to parent/Parent for scopes.

- Removed check.lookup in favor of Scope.LookupParent.

R=adonovan
CC=golang-dev
https://golang.org/cl/9862044
2013-05-30 21:58:14 -07:00
Robert Griesemer faef64e271 go.tools/go/types: support for Context.ImplicitObj callbacks
Also:
- more cleanup of new identifier resolution code
- removed residue Object.Pos() code
- two separate, equally formatted error messages for redeclaration
  errors for easier tool support
- initial support for labels
- enabled several disabled tests

Thic CL will break go.tools/ssa/interp, but the pending
CL 9863045 fixes that.

Fixes golang/go#5504.

R=adonovan
CC=golang-dev
https://golang.org/cl/9839045
2013-05-30 09:50:44 -07:00
Robert Griesemer b52cce75f3 adonovan: first round of cleanups: remove 'resolve' internal flag and respective dead code
No other changes besides documentation updates for now.

R=golang-dev, adonovan
CC=golang-dev
https://golang.org/cl/9780045
2013-05-28 11:39:15 -07:00
Robert Griesemer 5c2bbcb0fd go.tools/go/types: enable resolution of objects in type checker
R=adonovan
CC=golang-dev
https://golang.org/cl/9838043
2013-05-28 10:25:11 -07:00
Robert Griesemer 3df6f127f0 go.tools/go/types: resolve objects in type checker
By setting resolve = true in check.go, the type checker
will do all identifier resolution during type checking
time and ignore (and not depend on) parser objects. This
permits the type checker to run easily on ASTs that are
not generated with invariants guaranteed by the parser.

There is a lot of new code; much of it slightly modified
copies of old code. There is also a lot of duplication.
After removing the dead code resulting from resolve = true
permanently (and removing the flag as well), it will be
easier to perform a thorough cleanup. As is, there are
too many intertwined code paths.

For now resolve = false. To be enabled in a successor CL.

R=adonovan
CC=golang-dev
https://golang.org/cl/9606045
2013-05-28 10:06:37 -07:00
Robert Griesemer 08ee2985d7 go.tools/go.types: check for redeclarations across package files
Fixes golang/go#5506.

R=adonovan
CC=golang-dev
https://golang.org/cl/9600044
2013-05-20 14:29:57 -07:00
Rob Pike 87334f402b go.tools: bring up to date
Repo was copied from old point.  Bad r.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/9504043
2013-05-17 14:02:47 -07:00
Rob Pike 01f8cd246d go.tools: add go/types, ssa, and cmd/vet
They will be deleted from their current homes once this has landed.
Changes made to import paths to make the code compile, and to find
errchk in the right place in cmd/vet's Makefile.
TODO in a later CL: tidy up vet.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/9495043
2013-05-17 13:20:39 -07:00