1
0
mirror of https://github.com/golang/go synced 2024-11-19 16:34:49 -07:00
Commit Graph

35258 Commits

Author SHA1 Message Date
Austin Clements
252f1170e5 runtime: buffered write barrier for 386
Updates #22460.

Change-Id: I3c8e90fd6bcda7e28911036591873d63665aaca7
Reviewed-on: https://go-review.googlesource.com/92696
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-13 16:34:15 +00:00
Austin Clements
de186c63ce cmd/compile: calls can clobber g on s390x
Because a call may ultimately invoke runtime.setg, we have to assume
that g may be clobbered by any call. All of the other architectures
that use a g register already do this, but it was missing from the
s390x caller save clobber set.

Change-Id: Ia931638d42c44979839f20d71097acf31475f423
Reviewed-on: https://go-review.googlesource.com/92835
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-13 16:34:14 +00:00
Cherry Zhang
ce5fa6d5e9 cmd/internal/obj/mips: fix use of R28 on 32-bit MIPS
R28 is used as the SB register on MIPS64, and it was printed as
"RSB" on both 32-bit and 64-bit MIPS. This is confusing on MIPS32
as there R28 is just a general purpose register. Further, this
string representation is used in the assembler's frontend to parse
register symbols, and this leads to failure in parsing R28 in
MIPS32 assembly code. Change rconv to always print the register
as R28. This fixes the parsing problem on MIPS32, and this is
a reasonable representation on both MIPS32 and MIPS64.

Change-Id: I30d6c0a442fbb08ea615f32f1763b5baadcee1da
Reviewed-on: https://go-review.googlesource.com/92915
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2018-02-13 16:00:30 +00:00
Cherry Zhang
1e0ef6601d cmd/internal/obj/mips: use LR as temporary register in RET
On mips/mips64, for non-leaf function, RET is assembled as
	MOV (SP), R4       // load saved LR
	ADD $framesize, SP
	JMP (R4)

This clobbers R4 unnecessarily. Use the link register as
temporary instead.

Probably for Go 1.11.

Change-Id: I2209db7be11074ed2e0e0829cace95ebfb709e9f
Reviewed-on: https://go-review.googlesource.com/79016
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Austin Clements <austin@google.com>
2018-02-13 15:59:55 +00:00
Tobias Klauser
36951a9f63 syscall: support syscalls without error return on Linux
Add the rawSyscallNoError wrapper function which is used for Linux
syscalls that don't return an error and convert all applicable
occurences of RawSyscall to use it instead.

Fixes #22924

Change-Id: Iff1eddb54573d459faa01471f10398b3d38528dd
Reviewed-on: https://go-review.googlesource.com/84485
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-02-13 15:57:31 +00:00
Tobias Klauser
acd17e9b2b syscall: support Getwd on all BSDs
All supported BSDs provide the SYS___GETCWD syscall which can be used to
implement syscall.Getwd. With this change os.Getwd can use a single
syscall instead of falling back to the current kludge solution on the
BSDs.

This doesn't add any new exported functions to the frozen syscall
package, only ImplementsGetwd changes to true for dragonfly, freebsd,
netbsd and openbsd.

As suggested by Ian, this follows CL 83755 which did the same for
golang.org/x/sys/unix.

Also, an entry for netbsd/arm is added to mkall.sh which was used to
generate the syscall wrappers there.

Change-Id: I84da1ec61a6b8625443699a63cde556b6442ad41
Reviewed-on: https://go-review.googlesource.com/84484
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-02-13 15:41:19 +00:00
Tobias Klauser
dc27d68936 syscall: reuse BSD forkExecPipe for Solaris
The function was duplicated for Solaris. Reuse the BSD version instead.

Change-Id: Ibc812bcf36d21f4a7ceeef7b4fb091fa9479bfa8
Reviewed-on: https://go-review.googlesource.com/81395
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-02-13 15:35:36 +00:00
Jason A. Donenfeld
04e6ae6bc3 runtime: use Android O friendly syscalls on 64-bit machines
Android O disallows open on 64-bit, so let's use openat with AT_FDCWD to
achieve the same behavior.

Android O disallows epoll_wait on 64-bit, so let's use epoll_pwait with
the last argument as NULL to achieve the same behavior.

See here:
https://android.googlesource.com/platform/bionic/+/master/libc/seccomp/arm64_app_policy.cpp
https://android.googlesource.com/platform/bionic/+/master/libc/seccomp/mips64_app_policy.cpp
https://android.googlesource.com/platform/bionic/+/master/libc/seccomp/x86_64_app_policy.cpp

Fixes #23750

Change-Id: If8d5a663357471e5d2c1f516151344a9d05b188a
Reviewed-on: https://go-review.googlesource.com/92895
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-02-13 15:33:19 +00:00
Yasuhiro Matsumoto
4dad4ab57b runtime: fix typo in comment
GitHub-Last-Rev: d6a6fa3909
GitHub-Pull-Request: golang/go#23809
Change-Id: Ife18ba2f982b5e1c30bda32d13dcd441778b986a
Reviewed-on: https://go-review.googlesource.com/93575
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-02-13 15:12:17 +00:00
Andrew Bonventre
816154b065 os: add UserCacheDir
Adds a function that returns an OS-dependent location
for user-specific cache data.

Fixes golang/go#22536

Change-Id: Ifff015452494571ad357fa2d945d66a5992c751d
Reviewed-on: https://go-review.googlesource.com/78835
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-02-13 07:01:26 +00:00
Brad Fitzpatrick
45ca9797f6 VERSION: remove erroneously committed VERSION file
This file wasn't supposed to be checked in.

Change-Id: Ib0db0a330a3e030b0e6e5fde12088df5ac610ebc
Reviewed-on: https://go-review.googlesource.com/93555
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-02-13 06:31:13 +00:00
Rob Pike
8c8bb96b92 cmd/asm: fix crash on bad symbol for TEXT
Was missing a check in validSymbol.

Fixes #23580.

Can wait for go1.11. Probably safe but the crash is only for
invalid input, so not worth the risk.

Change-Id: I51f88c5be35a8880536147d1fe5c5dd6798c29de
Reviewed-on: https://go-review.googlesource.com/90398
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-02-13 04:38:15 +00:00
Mark Rushakoff
24cdb0f965 doc: fix typo in OverflowInt godoc
Change-Id: I426310e0c05c2b4a0123299ade0fe11721d40b10
GitHub-Last-Rev: 651c0291d6
GitHub-Pull-Request: golang/go#23801
Reviewed-on: https://go-review.googlesource.com/93475
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-02-13 03:02:09 +00:00
Daniel Martí
06a795e478 go/types: use consistent receiver names
Inconsistent names are quite obvious on the godoc HTML rendering:

	type Array
	    func NewArray(elem Type, len int64) *Array
	    func (a *Array) Elem() Type
	    func (a *Array) Len() int64
	    func (t *Array) String() string
	    func (t *Array) Underlying() Type

Fix all the String and Underlying methods to be consistent with their
types. This makes these two lists of methods less consistent, but that's
not visible to the user.

This also makes the inconsistent receiver names rule in golint happy.

Change-Id: I7c84d6bae1235887233a70d5f7f61a224106e952
Reviewed-on: https://go-review.googlesource.com/91736
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-02-13 00:50:30 +00:00
Robert Griesemer
945872e5ef cmd/compile/internal/syntax: added test cases for recent fixes
R=go1.11.

Now that we have a syntax error test harness, we can add the
proper tests for the recent parser fixes.

For #20800.
For #20789.
For #23385.
For #23434.

A test for #20789 already exists in test/fixedbugs, but this
is the better location for that test. But leaving the existing
one where it is as well.

Change-Id: I5937b9b63bafd1efab467a00344302e717976171
Reviewed-on: https://go-review.googlesource.com/88336
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12 22:58:12 +00:00
Robert Griesemer
52fcac3b7c cmd/compile/internal/syntax: implement regression test harness for syntax errors
R=go1.11

Fixes #20800.

Change-Id: Ifea273521d42a543a43da2f655ace7c295650e30
Reviewed-on: https://go-review.googlesource.com/88335
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12 22:58:06 +00:00
Robert Griesemer
b890688986 cmd/compile/internal/syntax: implement comment reporting in scanner
R=go1.11

In order to collect comments in the AST and for error testing purposes,
the scanner needs to not only recognize and skip comments, but also be
able to report them if so desired. This change adds a mode flag to the
scanner's init function which controls the scanner behavior around
comments.

In the common case where comments are not needed, there must be no
significant overhead. Thus, comments are reported via a handler upcall
rather than being returned as a _Comment token (which the parser would
have to filter out with every scanner.next() call).

Because the handlers for error messages, directives, and comments all
look the same (they take a position and text), and because directives
look like comments, and errors never start with a '/', this change
simplifies the scanner's init call to only take one (error) handler
instead of 2 or 3 different handlers with identical signature. It is
trivial in the handler to determine if we have an error, directive,
or general comment.

Finally, because directives are comments, when reporting directives
the full comment text is returned now rather than just the directive
text. This simplifies the implementation and makes the scanner API
more regular. Furthermore, it provides important information about
the comment style used by a directive, which may matter eventually
when we fully implement /*line file:line:col*/ directives.

Change-Id: I2adbfcebecd615e4237ed3a832b6ceb9518bf09c
Reviewed-on: https://go-review.googlesource.com/88215
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12 22:57:57 +00:00
Robert Griesemer
670494827c cmd/compile/internal/syntax: better error recovery after missing type
R=go1.11.

This is just a copy of the fix for #23434:
https://go-review.googlesource.com/c/go/+/87898.

Test pending test harness for the syntax package.

Change-Id: I52409aebe13ec784ddd7e41190a81c7e126bdd0c
Reviewed-on: https://go-review.googlesource.com/87901
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12 22:57:56 +00:00
Robert Griesemer
be9a1774f2 cmd/compile/internal/syntax: better error msg for some 'if' statements
R=go1.11

A common error is to write '=' instead of '==' inside the condition
of a simple 'if' statement:

	if x = 0 { ... }

Highlight the fact that we have an assignment in the error message
to prevent further confusion.

Fixes #23385.

Change-Id: I1552050fd6da927bd12a1be0977bd2e98eca5885
Reviewed-on: https://go-review.googlesource.com/87316
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12 22:57:54 +00:00
Robert Griesemer
ac45cb9aa0 cmd/compile/internal/syntax: permit /*line file:line:col*/ directives
R=go1.11

This implements parsing of /*line file:line*/ and /*line file:line:col*/
directives and also extends the optional column format to regular //line
directives, per #22662.

For a line directive to be recognized, its comment text must start with
the prefix "line " which is followed by one of the following:

:line
:line:col
filename:line
filename:line:col

with at least one : present. The line and col values must be unsigned
decimal integers; everything before is considered part of the filename.

Valid line directives are:

//line :123
//line :123:8
//line foo.go:123
//line C:foo.go:123	(filename is "C:foo.go")
//line C:foo.go:123:8	(filename is "C:foo.go")
/*line ::123*/		(filename is ":")

No matter the comment format, at the moment all directives act as if
they were in //line comments, and column information is ignored.
To be addressed in subsequent CLs.

For #22662.

Change-Id: I1a2dc54bacc94bc6cdedc5229ee13278971f314e
Reviewed-on: https://go-review.googlesource.com/86037
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12 22:57:52 +00:00
Robert Griesemer
e87f2a1b70 cmd/compile/internal/syntax: remove ParseBytes from API - not needed
R=go1.11

Also: Minor updates to syntax.Parse doc string.

Change-Id: I649965be9670a2f1c3de2cdb350634ed21e36ad9
Reviewed-on: https://go-review.googlesource.com/85663
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12 22:57:49 +00:00
Robert Griesemer
7ac393a3f2 go/parser: improved error message for unexpected literals
R=go1.11

This is a follow up for #11377 which reported that an error like

/tmp/xx.go:9:6: expected '(', found 'IDENT' F1

shouldn't print 'IDENT', as it's just an internal detail.
The relevant change wasn't made in the original fix, so here it is.

For #11377.

Change-Id: Ib76957d86b88e3e63646fbe4abf03a3b9d045139
Reviewed-on: https://go-review.googlesource.com/87900
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12 21:43:41 +00:00
Robert Griesemer
5408d79950 go/parser: remove newly introduced TODO (cleanup)
R=go1.11

No semantic change.

For #23434.

Change-Id: Iafdb062b0ebe6cd6e51f9a98b62b1d10f1bacc5c
Reviewed-on: https://go-review.googlesource.com/87899
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12 21:43:34 +00:00
Robert Griesemer
fc31d4e28d go/parser: improved error recovery after missing type
R=go1.11

This CL also introduces a new TODO in parser.go. To be
addressed in a separate CL to make this easier to review.

Also: Make parser's test harness easier to use by ignoring
auto-inserted (invisible) semicolons when computing error
positions. Adjusted testdata/commas.src accordingly.

Fixes #23434.

Change-Id: I050592d11d5f984f71185548394c000eea509205
Reviewed-on: https://go-review.googlesource.com/87898
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12 21:43:28 +00:00
Robert Griesemer
ea006a8513 go/scanner: don't eat \r in comments if that shortens the comment
For consistent formatting across platforms we strip \r's from
comments. This happens in the go/scanner which already does
this for raw string literals where it is mandated by the spec.
But if a (sequence of) \r appears in a regular (/*-style) comment
between a * and a /, removing that (sequence of) \r shortens that
text segment to */ which terminates the comment prematurely.

Don't do it.

As an aside, a better approach would be to not touch comments,
(and raw string literals for that matter) in the scanner and
leave the extra processing to clients. That is the approach
taken by the cmd/compile/internal/syntax package. However, we
probably can't change the semantics here too much, so just do
the minimal change that doesn't produce invalid comments. It's
an esoteric case after all.

Fixes #11151.

Change-Id: Ib4dcb52094f13c235e840c9672e439ea65fef961
Reviewed-on: https://go-review.googlesource.com/87498
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12 21:43:22 +00:00
Robert Griesemer
c5f3a8b107 go/parser: more robust error handling for 'if' headers
R=go1.11

To fix this, this CL borrows code from the new syntax
package which has a better tuned parser at this point.

Fixes #11377.

Change-Id: Ib9212c945903d6f62abcc59ef5a5767d4ef36981
Reviewed-on: https://go-review.googlesource.com/87495
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12 21:43:15 +00:00
Robert Griesemer
29461ccc7f go/parser: simplify code to read from an io.Reader (cleanup)
ioutil.ReadAll didn't exist when we wrote that parser code
originally (in 2009). Now it does, so use it. This may also
make that code path slightly more efficient.

Also, now that we are guaranteed to have a fast path for reading
from an io.Reader (and thus an io.ReadCloser), simplify setup
code for parser.ParseFile calls in srcimporter.Importer.ParseFiles.

Remove the associated TODO since we cannot reproduce any significant
performance differences when running go test -run ImportStdLib for
the case where we used to read directly from a file (even before the
change to the parser).

Fixes #19281.

Change-Id: I816459d092bb9e27fdc85089b8f21d57ec3fd79a
Reviewed-on: https://go-review.googlesource.com/85395
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-02-12 21:43:10 +00:00
Robert Griesemer
ea012d100b go/importer: use named receiver types for methods of named interfaces
R=go1.11

Once approved, this change must be ported to golang.org/x/tools/go/gcimporter15.

Fixes #13829.

Change-Id: I26a0094d2bfd38b97f2b64bae84b9f428fc9cdf1
Reviewed-on: https://go-review.googlesource.com/85318
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-02-12 21:43:04 +00:00
Austin Clements
01b8f5d7cf runtime: remove legacy comments and code from arm morestack
CL 137410043 deleted support for split stacks, which means morestack
no longer needed to save its caller's frame or argument size or its
caller's argument pointer. However, this commit failed to update the
comment or delete the line that computed the caller's argument
pointer. Clean these up now.

Change-Id: I65725d3d42c86e8adb6645d5aa80c305d473363d
Reviewed-on: https://go-review.googlesource.com/92437
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-12 21:41:34 +00:00
Austin Clements
dfbf568c9f runtime: use NOFRAME on mips and mips64
This replaces frame size -4/-8 with the NOFRAME flag in mips and
mips64 assembly.

This was automated with:

sed -i -e 's/\(^TEXT.*[A-Z]\),\( *\)\$-[84]/\1|NOFRAME,\2$0/' $(find -name '*_mips*.s')

Plus a manual fix to mkduff.go.

The go binary is identical on both architectures before and after this
change.

Change-Id: I0310384d1a584118c41d1cd3a042bb8ea7227efb
Reviewed-on: https://go-review.googlesource.com/92044
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-12 21:41:32 +00:00
Austin Clements
beeabbcb25 runtime: use NOFRAME on arm64
This replaces frame size -8 with the NOFRAME flag in arm64 assembly.

This was automated with:

sed -i -e 's/\(^TEXT.*[A-Z]\),\( *\)\$-8/\1|NOFRAME,\2$0/' $(find -name '*_arm64.s')

Plus a manual fix to mkduff.go.

The go binary is identical before and after this change.

Change-Id: I0310384d1a584118c41d1cd3a042bb8ea7227efa
Reviewed-on: https://go-review.googlesource.com/92043
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-12 21:41:31 +00:00
Austin Clements
a046caa1e8 runtime, sync/atomic: use NOFRAME on arm
This replaces frame size -4 with the NOFRAME flag in arm assembly.

This was automated with:

sed -i -e 's/\(^TEXT.*[A-Z]\),\( *\)\$-4/\1|NOFRAME,\2$0/' $(find -name '*_arm.s')

Plus three manual comment changes found by:

grep '\$-4' $(find -name '*_arm.s')

The go binary is identical before and after this change.

Change-Id: I0310384d1a584118c41d1cd3a042bb8ea7227ef9
Reviewed-on: https://go-review.googlesource.com/92042
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-12 21:41:30 +00:00
Austin Clements
39f42c59e6 cmd/vet: teach asmdecl check about NOFRAME
Change-Id: I3f71228e391f122f9cc5656ca6835fdf51a424b7
Reviewed-on: https://go-review.googlesource.com/92435
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-12 21:41:29 +00:00
Austin Clements
e940358fc9 cmd/internal/obj/mips: support NOFRAME
This passes toolstash -cmp with one exception: assembly functions that
were declared with a frame size of -4 (or -8) used to record
locals=0xfffffffffffffffc in the object file and now record
locals=0x0. This doesn't affect anything.

Change-Id: I0d15e81770e54222ae329ce4496da06016736771
Reviewed-on: https://go-review.googlesource.com/92041
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-12 21:41:27 +00:00
Austin Clements
75b56a0895 cmd/internal/obj/arm64: support NOFRAME
In addition, this makes the arm64 prologue code generation much closer
to the pattern used on other platforms.

This passes toolstash -cmp with one exception: assembly functions that
were declared with a frame size of -8 used to record
locals=0xfffffffffffffff8 in the object file and now record
locals=0x0. This doesn't affect anything.

Change-Id: I0d15e81770e54222ae329ce4496da06016736770
Reviewed-on: https://go-review.googlesource.com/92040
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-12 21:41:26 +00:00
Austin Clements
99e37e98b4 cmd/internal/obj/arm: support NOFRAME
This adds support on arm for the NOFRAME symbol attribute used by
ppc64 and s390x in preference to using a frame size of -4. This is
modeled on ppc64's implementation of NOFRAME.

This passes toolstash -cmp.

Change-Id: I0d15e81770e54222ae329ce4496da0601673677f
Reviewed-on: https://go-review.googlesource.com/92039
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-12 21:41:24 +00:00
Austin Clements
8a064c6008 runtime: fix silly frame sizes on arm and arm64
"-8" is not a sensible frame size on arm and we're about to start
rejecting it. Replace it with -4.

Likewise, "-4" is not a sensible frame size on arm64 and we're about
to start rejecting it. Replace it with -8.

Finally, clean up some places we're weirdly inconsistent about using 0
versus -8.

Change-Id: If85e229993d5f7f1f0cfa9852b4e294d053bd784
Reviewed-on: https://go-review.googlesource.com/92038
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-12 21:41:23 +00:00
Austin Clements
495174302f cmd/internal/obj/arm64: omit stack check for no-frame leafs
For leaf functions with zero-sized frames, there's no point in doing a
stack check, so omit it.

This aligns arm64 with other architectures.

Change-Id: I1fb483d62f1736af10c5110815d3f5a875a46d7f
Reviewed-on: https://go-review.googlesource.com/92037
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-12 21:41:22 +00:00
Austin Clements
a7f73c436d cmd/compile: eliminate NoFramePointer
The NoFramePointer function flag is no longer used, so this CL
eliminates it. This cleans up some confusion between the compiler's
NoFramePointer flag and obj's NOFRAME flag. NoFramePointer was
intended to eliminate the saved base pointer on x86, but it was
translated into obj's NOFRAME flag. On x86, NOFRAME does mean to omit
the saved base pointer, but on ppc64 and s390x it has a more general
meaning of omitting *everything* from the frame, including the saved
LR and ppc64's "fixed frame". Hence, on ppc64 and s390x there are far
fewer situations where it is safe to set this flag.

Change-Id: If68991310b4d00638128c296bdd57f4ed731b46d
Reviewed-on: https://go-review.googlesource.com/92036
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-12 21:41:21 +00:00
Austin Clements
9b331189c1 cmd/internal/obj/x86: adjust SP correctly for tail calls
Currently, tail calls on x86 don't adjust the SP on return, so it's
important that the compiler produce a zero-sized frame and disable the
frame pointer. However, these constraints aren't necessary. For
example, on other architectures it's generally necessary to restore
the saved LR before a tail call, so obj simply makes this work.
Likewise, on x86, there's no reason we can't simply make this work.

Hence, this CL adjusts the compiler to use the same tail call
convention for x86 that we use on LR machines by producing a RET with
a target, rather than a JMP with a target. In fact, obj already
understands this convention for x86 except that it's buggy with
non-zero frame sizes. So we also fix this bug obj. As a result of
these fixes, the compiler no longer needs to mark wrappers as
NoFramePointer since it's now perfectly fine to save the frame
pointer.

In fact, this eliminates the only use of NoFramePointer in the
compiler, which will enable further cleanups.

This also fixes what is very nearly, but not quite, a code generation
bug. NoFramePointer becomes obj.NOFRAME in the object file, which on
ppc64 and s390x means to omit the saved LR. Hence, on these
architectures, NoFramePointer (and NOFRAME) is only safe to set on
leaf functions. However, on *most* architectures, wrappers aren't
necessarily leaf functions because they may call DUFFZERO. We're saved
on ppc64 and s390x only because the compiler doesn't have the rules to
produce DUFFZERO calls on these architectures. Hence, this only works
because the set of LR architectures that implement NOFRAME is disjoint
from the set where the compiler produces DUFFZERO operations. (I
discovered this whole mess when I attempted to add NOFRAME support to
arm.)

Change-Id: Icc589aeb86beacb850d0a6a80bd3024974a33947
Reviewed-on: https://go-review.googlesource.com/92035
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-02-12 21:41:19 +00:00
Robert Griesemer
caf96f7dae go/types: use check.lookup consistently where possible (cleanup)
This CL converts the last call to scope.LookupParent with no position
information to a check.lookup call that respects position information
provided by Eval (there's one more LookupParent call that cannot be
converted, see the respective comment in the code).

In this case, the lookup is needed to determine the variable on the
LHS of an assignment, for adjustment of its `used` information.

Outside a types.Eval call, i.e., during normal type-checking, there
is no difference between this new code and the old code.

While in a types.Eval call, it's important to use the correct position
to look up the relevant variable. If token.NoPos were used, one might
find another variable with the same name, declared later in the scope.

Caveat: Types.Eval only accepts expressions, and it's currently not
possible to evaluate assignments (except via function literals, but
then the scope is different). That is, this change is a fix for a
potential future bug, and for now a no-op.

Change-Id: I28db1fe1202c07e3f7b3fadfd185728afb9b2ae7
Reviewed-on: https://go-review.googlesource.com/85199
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-02-12 21:40:31 +00:00
Robert Griesemer
38f9d75195 go/types: correctly determine if panic call refers to built-in
R=go1.11

The terminating statement check for functions that declare result
parameters was using the wrong scope to look up calls to `panic`
which in esoteric cases lead to a false positive.

Instead of looking up a panic call again at a time when correct
scope information would have to be recomputed, collect calls to
predeclared panic in a set when type-checking that call.

Fixes #23218.

Change-Id: I35eaf010e5cb8e43696efba7d77cefffb6f3deb2
Reviewed-on: https://go-review.googlesource.com/85198
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-02-12 21:40:26 +00:00
Robert Griesemer
d5e47fdc92 go/types: perform delayed tests even for types.Eval
R=go1.11

types.Eval historically never evaluated any delayed tests, which
included verification of validity of map keys, but also function
literal bodies.

Now, embedded interfaces are also type-checked in a delayed fashion,
so it becomes imperative to do all delayed checks for eval (otherwise
obviously incorrect type expressions are silently accepted).

Enabling the delayed tests also removes the restriction that function
literals were not type-checked.

Also fixed a bug where eval wouldn't return a type-checking error
because check.handleBailout was using the wrong err variable.

Added tests that verify that method set computation is using the
right types when evaluating interfaces with embedded types.

For #18395.
For #22992.

Change-Id: I574fa84568b5158bca4b4ccd4ef5abb616fbf896
Reviewed-on: https://go-review.googlesource.com/84898
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-02-12 21:40:19 +00:00
Robert Griesemer
cf12fef5c6 go/types: don't associate methods with alias type names
R=go1.11

The existing code associated methods with receiver base type
names before knowing if a type name denoted a locally defined
type. Sometimes, methods would be incorrectly associated with
alias type names and consequently were lost down the road.

This change first collects all methods with non-blank names
and in a follow-up pass resolves receiver base type names to
valid non-alias type names with which the methods are then
associated.

Fixes #23042.

Change-Id: I7699e577b70aadef6a2997e882beb0644da89fa3
Reviewed-on: https://go-review.googlesource.com/83996
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-02-12 21:40:14 +00:00
Robert Griesemer
973393c293 go/types: accept iotas inside closures of const init expressions
R=go1.11

Fixes #22345.

Change-Id: I7cf22d17bdd0143efb6ee48981e649ffe797aed9
Reviewed-on: https://go-review.googlesource.com/83579
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-02-12 21:40:08 +00:00
Robert Griesemer
ff6d7c2b27 go/types: delay type-checking of function literals
R=go1.11

Functions (at the package level) were collected and their bodies
type-checked after all other package-level objects were checked.
But function literals where type-checked right away when they were
encountered so that they could see the correct, partially populated
surrounding scope, and also to mark variables of the surrounding
function as used.

This approach, while simple, breaks down in esoteric cases where
a function literal appears inside the declaration of an object
that its body depends on: If the body is type-checked before the
object is completely set up, the literal may use incomplete data
structures, possibly leading to spurious errors.

This change postpones type-checking of function literals to later;
after the current expression or statement, but before any changes
to the enclosing scope (so that the delayed type-checking sees the
correct scope contents).

The new mechanism is general and now is also used for other
(non-function) delayed checks.

Fixes #22992.

Change-Id: Ic95f709560858b4bdf8c645be70abe4449f6184d
Reviewed-on: https://go-review.googlesource.com/83397
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-02-12 21:40:02 +00:00
Robert Griesemer
574fc66b17 go/types: add lookup method to context and factor out LookupParent calls
R=go1.11

Also: Moved Checker.pos field into context where it belongs.

This is a cleanup/code factoring.

For #22992.

Change-Id: If9d4f0af537cb181f73735e709ebc8258b2a1378
Reviewed-on: https://go-review.googlesource.com/83017
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-02-12 21:39:56 +00:00
Robert Griesemer
dd448957fd go/types: correctly compute method set of some recursive interfaces
R=go1.11.

The existing algorithm for type-checking interfaces breaks down in
complex cases of recursive types, e.g.:

	package issue21804

	type (
		_ interface{ m(B) }
		A interface{ a(D) }
		B interface{ A }
		C interface{ B }
		D interface{ C }
	)

	var _ A = C(nil)

The underlying problem is that the method set of C is computed by
following a chain of embedded interfaces at a point when the method
set for one of those interfaces is not yet complete. A more general
problem is largely avoided by topological sorting of interfaces
depending on their dependencies on embedded interfaces (but not
method parameters).

This change fixes this problem by fundamentally changing how
interface method sets are computed: Instead of determining them
based on recursively type-checking embedded interfaces, the new
approach computes the method sets of interfaces separately,
based on syntactic structure and name resolution; and using type-
checked types only when readily available (e.g., for local types
which can at best refer to themselves, and imported interfaces).

This approach avoids cyclic dependencies arising in the method
sets by separating the collection of embedded methods (which
fundamentally cannot have cycles in correct programs) and type-
checking of the method's signatures (which may have arbitrary
cycles).

As a consequence, type-checking interfaces can rely on the
pre-computed method sets which makes the code simpler: Type-
checking of embedded interface types doesn't have to happen
anymore during interface construction since we already have
all methods and now is delayed to the end of type-checking.
Also, the topological sort of global interfaces is not needed
anymore.

Fixes #18395.

Change-Id: I0f849ac9568e87a32c9c27bbf8fab0e2bac9ebb1
Reviewed-on: https://go-review.googlesource.com/79575
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-02-12 20:39:59 +00:00
Andrew Bonventre
4c4ce3dc79 all: restore changes from faulty merge/revert
This reverts commit 3b6abd8a45.

Change-Id: I8ca100501c1844af78a547989786d14dac6b494a
Reviewed-on: https://go-review.googlesource.com/93456
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-02-12 20:13:59 +00:00
Andrew Bonventre
3b6abd8a45 Revert "[release-branch.go1.10] all: merge master into release-branch.go1.10"
This reverts commit b83d7f7253.

Reason for revert: wrong branch

Change-Id: I28ebb121f7b3e331729e8a6a00961b876f3dd0f2
Reviewed-on: https://go-review.googlesource.com/93455
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-02-12 20:10:09 +00:00