Commit Graph

28936 Commits

Author SHA1 Message Date
Matthew Dempsky e809658d77 misc/nacl: include parser.go for cmd/compile/internal/syntax tests
Fix suggested by Minux.

Change-Id: Ia7aa8ccccc16535af4ec3ad23830ef0aa5d776ac
Reviewed-on: https://go-review.googlesource.com/27193
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Minux Ma <minux@golang.org>
2016-08-16 22:42:13 +00:00
Matthew Dempsky 504a104a2c cmd/compile/internal/syntax: match old parser errors and line numbers
This makes a bunch of changes to package syntax to tweak line numbers
for AST nodes. For example, short variable declaration statements are
now associated with the location of the ":=" token, and function calls
are associated with the location of the final ")" token. These help
satisfy many unit tests that assume the old parser's behavior.

Because many of these changes are questionable, they're guarded behind
a new "gcCompat" const to make them easy to identify and revisit in
the future.

A handful of remaining tests are too difficult to make behave
identically. These have been updated to execute with -newparser=0 and
comments explaining why they need to be fixed.

all.bash now passes with both the old and new parsers.

Change-Id: Iab834b71ca8698d39269f261eb5c92a0d55a3bf4
2016-08-16 14:32:09 -07:00
Matthew Dempsky 29cfbcfef4 cmd/compile/internal/gc: use new AST parser
Introduce a new noder type to transform package syntax's AST into gc's
Node tree. Hidden behind a new -newparser flag.

Change-Id: Id0e862ef6196c41533876afc4ec289e21d422d18
2016-08-16 14:32:09 -07:00
Matthew Dempsky 55b9234023 cmd/dist: build cmd/compile/internal/syntax
Change-Id: Ie6dd2318e031be445c0b1ae65d4c78723d5a1167
2016-08-16 14:32:09 -07:00
Matthew Dempsky d6d493fc56 cmd/compile/internal/syntax: add a Line method to interface Node
Change-Id: I64baf334a35c72336d26fa6755c67eb9d6f4e93c
2016-08-16 14:32:09 -07:00
Matthew Dempsky 4bc85b2eb8 cmd/compile/internal/syntax: refactor DeclStmt parsing
No behavior change.

Change-Id: I93c7cb7ab76b5afa74e6a1f092b7045fb96467b1
2016-08-16 14:32:09 -07:00
Matthew Dempsky 83153e7f37 cmd/compile/internal/syntax: emit errors for unexpected top-level tokens
Fixes cmd/go's TestIssue7108.

Change-Id: I8436b0e3e5a9b36649d46a9c2c741d820115a5d1
2016-08-16 14:32:09 -07:00
Matthew Dempsky 7a8201b924 cmd/compile/internal/syntax: change Read to still return the AST
If we the caller provided an error handler, still return our best
effort parsed AST tree.
2016-08-16 14:32:09 -07:00
Matthew Dempsky 38d52ef0c4 cmd/compile/internal/syntax: fix off-by-1 for implicit semicolons
pos and line already refer to the position immediately before the
returned newline character, so no need to decrement them further.

Change-Id: I1d7a32cde55a5b8a1c6fd882ec8ba532869cc858
2016-08-16 14:32:08 -07:00
Robert Griesemer f82bd3cc7d cmd/compile/internal/syntax: better error positions for scanner errors
For string/comment not terminated errors, report error at the
start of the string/comment rather than the end of the file.
2016-08-16 14:32:08 -07:00
Robert Griesemer 3c72ed3bfa cmd/compile/internal/syntax: provide LitKind to identify literals
- various minor cleanups related to literal scanning
- report newlines in character and regular string literals (plus tests)
2016-08-16 14:32:08 -07:00
Matthew Dempsky a17ec6b30c cmd/compile/internal/syntax: simplify BOM handling
Change-Id: I5e2522d34720d7687e1e9ff0831936702976a1c7
2016-08-16 14:32:08 -07:00
Matthew Dempsky 0d8ac5ecf1 cmd/compile/internal/syntax: cleanup TypeSwitchGuard handling
Fixes typeswitch3.go and at least recognizes the error in typesw.go
(albeit wrong line number and non-pretty-printed syntax.Expr output).

Change-Id: I38b8e923265b0e7b3c301aea2f4a901bbabc24b5
2016-08-16 14:32:08 -07:00
Robert Griesemer 573afbcdb6 cmd/compile/internal/syntax: export ImplicitOne and use to identify x++/x--
+ minor documentation improvements
2016-08-16 14:32:08 -07:00
Robert Griesemer a6a4701053 cmd/compile/internal/syntax: minor cleanups in source handling 2016-08-16 14:32:08 -07:00
Matthew Dempsky 81839a93a9 cmd/compile/internal/syntax: represent empty statements with EmptyStmt
Fixes fixedbugs/bug031.go.

Change-Id: Icc1846368802d71ade14e1a6b79cb6ee651b663e
2016-08-16 14:32:07 -07:00
Robert Griesemer 3a7da56582 cmd/compile/internal/syntax: fix many string/rune literal corner cases
+ many more test cases
2016-08-16 14:32:07 -07:00
Robert Griesemer f363ad2a55 cmd/compile/internal/syntax: fix source.getr
The source's rune reader logic was overly clever and tried to
determine if an invalid rune was due to an actual source error
or due to not enough bytes in the buffer.

Replaced with slightly optimized version of bufio Reader's
ReadRune method for now. Performance may be a tiny bit lower
but we can always optimize later.

Fixes endless loops when parsing certain source files.
Added test case to ScanError test.
2016-08-16 14:32:07 -07:00
Robert Griesemer fe52bcc8e6 cmd/compile/internal/syntax: rudimentary support for error reporting
If an ErrorHandler is provided with a syntax.ReadXXX
function, it is invoked for each error encountered.
Will need to be refined, but should enable progress
with all.bash.

Also:
- added tests for lexical errors
- fixed endless loops when encountering non-terminated
  strings and comments
2016-08-16 14:32:07 -07:00
Robert Griesemer f50329534a cmd/compile/internal/syntax: skip verbose tests in -short mode 2016-08-16 14:32:07 -07:00
Matthew Dempsky 1d8cdaf6ce cmd/compile/internal/syntax: insert implicit semicolons before EOF
Fixes test/eof.go.

Change-Id: Idaa2713bb1669ec165f3a2687fcfa2f8d8c70c74
2016-08-16 14:32:07 -07:00
Matthew Dempsky 49fb8d3cdb cmd/compile/internal/syntax: fix general comment lexing
Previously, we failed to recognize "**/" as the end of a general
comment.

Fixes ken/embed.go.

Change-Id: Ibed746da105453420ec2d184e7be1a5de15927a6
2016-08-16 14:32:06 -07:00
Robert Griesemer 9be3d08e6a cmd/compile/internal/syntax: fix lexing of ".45e1" and add token tests 2016-08-16 14:32:06 -07:00
Matthew Dempsky b3efd7d6e8 cmd/compile/internal/syntax: fix dot-import parsing
Change-Id: Iba8c9d9c01516706a2fc6ca5502401cfc063f210
2016-08-16 14:32:06 -07:00
Matthew Dempsky 1a5acb4b3a cmd/compile/internal/syntax: pragma support for new parser
Change-Id: Id4d9b40900b97708d2b4586f5a745dcb8b0eb8bd
2016-08-16 14:32:06 -07:00
Matthew Dempsky 4b1cc51518 cmd/compile/internal/syntax: simplify IfStmt
Change IfStmt's Else field from []Stmt to Stmt like in go/ast.

Change-Id: I835577beaf12b6e5895bc93041c13403143b4d2d
2016-08-16 14:32:06 -07:00
Matthew Dempsky 4f989a487d cmd/compile/internal/syntax: various tweaks
Export token constants needed by users (Break, Continue, Defer,
Fallthrough, Go, and Goto).

Fix parsing of Continue statements: previously they would be parsed as
a BranchStmt with Break as the token.

Change aNode, aDecl, aStmt, aExpr, etc.'s tag methods to take a
pointer receiver to prevent accidents like trying to type assert from
syntax.Expr to syntax.ListExpr instead of *syntax.ListExpr.

Relocate pointer fields to the end of AST nodes so the GC can
short-circuit scanning objects.

Change-Id: Ib7505e75726816e260b9b29a2f726f76bf1a38b4
2016-08-16 14:32:02 -07:00
Robert Griesemer d5bb1db3ec cmd/compile/internal/syntax: don't allocate a string for each keyword
$ go test -run StdLib -fast
parsed 1074061 lines (2828 files) in 571.1019ms (1880681 lines/s)
allocated 263.676Mb (461.696Mb/s)
PASS
2016-08-16 10:48:20 -07:00
Robert Griesemer c7cc983097 cmd/compile/internal/syntax: implement buffered reading from io.Reader
No performance impact:

$ go test -run StdLib -fast
parsed 1073074 lines (2823 files) in 575.606804ms (1864248 lines/s)
allocated 263.956Mb (458.570Mb/s)
PASS
2016-08-16 10:48:01 -07:00
Robert Griesemer a85b9c5467 cmd/compile/internal/syntax: fast Go syntax trees, initial commit.
Syntax tree nodes, scanner, parser, basic printers.

Builds syntax trees for entire Go std lib at a rate of ~1.8M lines/s
in warmed up state (MacMini, 2.3 GHz Intel Core i7, 8GB RAM):

$ go test -run StdLib -fast
parsed 1074617 lines (2832 files) in 579.66364ms (1853863 lines/s)
allocated 282.212Mb (486.854Mb/s)
PASS
2016-08-16 10:45:05 -07:00
Josh Bleecher Snyder 9d2b988e4a cmd/compile: accept literals in samesafeexpr
This only triggers a few places in the stdlib,
but it helps a lot when it does.

Before:

runtime.mapassign1 t=1 size=2400 args=0x20 locals=0xe0

After:

runtime.mapassign1 t=1 size=2352 args=0x20 locals=0xd8

name           old time/op  new time/op  delta
MapPop100-8    19.8µs ±11%  18.4µs ± 9%  -7.16%  (p=0.000 n=20+19)
MapPop1000-8    367µs ±17%   335µs ±11%  -8.63%  (p=0.000 n=19+19)
MapPop10000-8  7.29ms ±15%  6.86ms ±12%  -5.84%  (p=0.020 n=20+20)

Change-Id: I9faf32f95a6ba6a6d5d0818eab32cc271e01d10a
Reviewed-on: https://go-review.googlesource.com/26666
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-16 17:28:07 +00:00
Cherry Zhang e6f1a886bc cmd/compile: fix uint<->float conversion on 386
The frontend rewriting lowers them to runtime calls on 386. It
matches explicitly uint32, but missed uint.

Fixes #16738.

Change-Id: Iece7a45edf74615baca052a53273c208f057636d
Reviewed-on: https://go-review.googlesource.com/27085
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-16 17:20:11 +00:00
Keith Randall 1faea596e4 cmd/compile: add size hint to map literal allocations
Might as well tell the runtime how large the map is going to be.
This avoids grow work and allocations while the map is being built.

Will wait for 1.8.

Fixes #15880
Fixes #16279

Change-Id: I377e3e5ec1e2e76ea2a50cc00810adda20ad0e79
Reviewed-on: https://go-review.googlesource.com/23558
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2016-08-16 17:19:48 +00:00
Josh Bleecher Snyder 35e25ef62e cmd/internal/obj/x86: minor code cleanup
Update #16415

Change-Id: I83e0966931ada2f1ed02304685bb45effdd71268
Reviewed-on: https://go-review.googlesource.com/26665
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-16 17:19:07 +00:00
Josh Bleecher Snyder e85265e8c2 cmd/compile: optimize bool to int conversion
This CL teaches SSA to recognize code of the form

// b is a boolean value, i is an int of some flavor
if b {
	i = 1
} else {
	i = 0
}

and use b's underlying 0/1 representation for i
instead of generating jumps.

Unfortunately, it does not work on the obvious code:

func bool2int(b bool) int {
	if b {
		return 1
	}
	return 0
}

This is left for future work.
Note that the existing phiopt optimizations also don't work for:

func neg(b bool) bool {
	if b {
		return false
	}
	return true
}

In the meantime, runtime authors and the like can use:

func bool2int(b bool) int {
	var i int
	if b {
		i = 1
	} else {
		i = 0
	}
	return i
}

This compiles to:

"".bool2int t=1 size=16 args=0x10 locals=0x0
	0x0000 00000 (x.go:25)	TEXT	"".bool2int(SB), $0-16
	0x0000 00000 (x.go:25)	FUNCDATA	$0, gclocals·23e8278e2b69a3a75fa59b23c49ed6ad(SB)
	0x0000 00000 (x.go:25)	FUNCDATA	$1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
	0x0000 00000 (x.go:32)	MOVBLZX	"".b+8(FP), AX
	0x0005 00005 (x.go:32)	MOVBQZX	AL, AX
	0x0008 00008 (x.go:32)	MOVQ	AX, "".~r1+16(FP)
	0x000d 00013 (x.go:32)	RET

The extraneous MOVBQZX is #15300.

This optimization also helps range and slice.
The compiler must protect against pointers pointing
to the end of a slice/string. It does this by increasing
a pointer by either 0 or 1 * elemsize, based on a condition.
This CL optimizes away a jump in that code.

This CL triggers 382 times while compiling the standard library.

Updating code to utilize this optimization is left for future CLs.

Updates #6011

Change-Id: Ia7c1185f8aa223c543f91a3cd6d4a2a09c691c70
Reviewed-on: https://go-review.googlesource.com/22711
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2016-08-16 17:14:52 +00:00
Robert Griesemer c7b9bd7456 cmd/compile: don't crash when exporting self-recursive interfaces
For #16369.

Change-Id: I4c9f5a66b95558adcc1bcface164b9b2b4382d2f
Reviewed-on: https://go-review.googlesource.com/24979
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-08-16 17:07:03 +00:00
David Crawshaw 56752eb2b8 reflect: clear tflag on new types
Fixes #16722

Change-Id: I50a0e69d3e79d13bc1860cd983267c3db087a4b8
Reviewed-on: https://go-review.googlesource.com/27119
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-16 16:58:15 +00:00
Keith Randall d251030fa6 cmd/compile: don't fold >32bit constants into a MULQ
Don't fold constant factors into a multiply
beyond the capacity of a MULQ instruction (32 bits).

Fixes #16733

Change-Id: Idc213c6cb06f7c94008a8cf9e60a9e77d085fd89
Reviewed-on: https://go-review.googlesource.com/27160
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-16 16:46:48 +00:00
Josh Bleecher Snyder 562d06fc23 cmd/compile: inline _, ok = i.(T)
We already inlined

_, ok = e.(T)
_, ok = i.(E)
_, ok = e.(E)

The only ok-only variants not inlined are now

_, ok = i.(I)
_, ok = e.(I)

These call getitab, so are non-trivial.

Change-Id: Ie45fd8933ee179a679b92ce925079b94cff0ee12
Reviewed-on: https://go-review.googlesource.com/26658
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2016-08-16 15:24:33 +00:00
Michael Pratt e6e26eeb29 cmd/internal/obj: convert Aconv to a stringer
Now that assembler opcodes have their own type, they can have a true
stringer, rather than explicit calls to Aconv, which makes for nicer
format strings.

Change-Id: Ic77f5f8ac38b4e519dcaa08c93e7b732226f7bfe
Reviewed-on: https://go-review.googlesource.com/25045
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2016-08-16 15:03:07 +00:00
Josh Bleecher Snyder 5693bee0f1 cmd/compile/internal/big: re-vendor
Pick up a bunch of changes and fixes.

Change-Id: If4101f7185d433a4c89096bc786ee5de8eeabac0
Reviewed-on: https://go-review.googlesource.com/27123
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-16 14:51:21 +00:00
Josh Bleecher Snyder 6f74c0774c runtime: move printing of extra newline
No functional changes, makes vet happy.

Updates #11041

Change-Id: I59f3aba46d19b86d605508978652d76a1fe7ac7b
Reviewed-on: https://go-review.googlesource.com/27125
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-16 14:37:17 +00:00
Josh Bleecher Snyder 297d1d736e net/http: use keyed composite literal
Makes vet happy.

Updates #11041

Change-Id: I23ca413c03ff387359440af8114786cd7880a048
Reviewed-on: https://go-review.googlesource.com/27124
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-16 14:37:02 +00:00
Josh Bleecher Snyder 302dd7b71e crypto/cipher, math/big: fix example names
Fixes (legit) vet warnings.
Fix some verb tenses while we're here.

Updates #11041

Change-Id: I27e995f55b38f4cf584e97a67b8545e8247e83d6
Reviewed-on: https://go-review.googlesource.com/27122
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-08-16 14:36:32 +00:00
Josh Bleecher Snyder 6d2db0986f crypto/tls: fix WriteTo method signature
Give *recordingConn the correct WriteTo signature
to be an io.WriterTo. This makes vet happy.
It also means that it'll report errors,
which were previously being ignored.

Updates #11041

Change-Id: I13f171407d63f4b62427679bff362eb74faddca5
Reviewed-on: https://go-review.googlesource.com/27121
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-16 14:36:19 +00:00
Josh Bleecher Snyder 12292754d3 net: change t.Error to t.Errorf
Caught by vet.

Updates #11041

Change-Id: I4dbb2eeaf633eea5976074840064edc2349e01d8
Reviewed-on: https://go-review.googlesource.com/27120
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-08-16 14:35:55 +00:00
Josh Bleecher Snyder 88858fa58f container/list: silence vet warnings
container/list/list_test.go:274: self-assignment of e1 to e1
container/list/list_test.go:274: self-assignment of e4 to e4
container/list/list_test.go:282: self-assignment of e1 to e1
container/list/list_test.go:286: self-assignment of e1 to e1
container/list/list_test.go:286: self-assignment of e4 to e4

Updates #11041

Change-Id: Ibd90cf6a924e93497908f437b814c3fc82937f4a
Reviewed-on: https://go-review.googlesource.com/27114
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-16 14:35:37 +00:00
Cherry Zhang 4c4ca83120 cmd/compile: remove nil check in accessing PAUTOHEAP variable
CL 23393 introduces PAUTOHEAP, and access of PAUTOHEAP variable is
rewritten to indirection of a PAUTO variable. Mark this variable
non-nil, so this indirection does not introduce extra nil checks.

Change-Id: I31853eed5e60238b6c5bc0546e2e9ab340dcddd9
Reviewed-on: https://go-review.googlesource.com/26831
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2016-08-16 14:32:13 +00:00
Josh Bleecher Snyder 40cf4ad0ef all: fix "result not used" vet warnings
For tests, assign to _.
For benchmarks, assign to a sink.

Updates #11041

Change-Id: I87c5543245c7bc74dceb38902f4551768dd37948
Reviewed-on: https://go-review.googlesource.com/27116
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-16 14:15:10 +00:00
Josh Bleecher Snyder c70bdd3788 cmd/compile: fix bad generated format strings in test
We were generating format strings containing
a lone %. Vet legitimately complains:

cmd/compile/internal/gc/constFold_test.go:339: unrecognized printf verb ' '

The fix doesn't make for very readable code,
but it is simple and obviously correct.

Updates #11041

Change-Id: I90bd2d1d140887f5229752a279f7e46921472fbb
Reviewed-on: https://go-review.googlesource.com/27115
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-16 14:14:51 +00:00