The indirectType function comment uses the phrase 'layed out'. In the
context of that phrase, where something is being placed or sprawled,
the word should be 'laid'. 'Layed' is a misspelling of 'laid'.
Change-Id: I05ecb97637276e2252c47e92a0bd678130714889
GitHub-Last-Rev: 6ee67371b42c12ceaf4c6c245319748008ac7e7b
GitHub-Pull-Request: golang/go#27444
Reviewed-on: https://go-review.googlesource.com/132779 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Michael Munday [Fri, 25 May 2018 16:54:58 +0000 (17:54 +0100)]
cmd/compile: implement OnesCount{8,16,32,64} intrinsics on s390x
This CL implements the math/bits.OnesCount{8,16,32,64} functions
as intrinsics on s390x using the 'population count' (popcnt)
instruction. This instruction was released as the 'population-count'
facility which uses the same facility bit (45) as the
'distinct-operands' facility which is a pre-requisite for Go on
s390x. We can therefore use it without a feature check.
The s390x popcnt instruction treats a 64 bit register as a vector
of 8 bytes, summing the number of ones in each byte individually.
It then writes the results to the corresponding bytes in the
output register. Therefore to implement OnesCount{16,32,64} we
need to sum the individual byte counts using some extra
instructions. To do this efficiently I've added some additional
pseudo operations to the s390x SSA backend.
Unlike other architectures the new instruction sequence is faster
for OnesCount8, so that is implemented using the intrinsic.
Helps to avoid "leaking param" with assignments showed above.
The implementation is based on somewhat similiar xs=xs[a:b]
special case that is ignored by the escape analysis.
We may figure out more generalized version of this,
but this one looks like a safe step into that direction.
Phil Pearl [Sun, 2 Sep 2018 16:03:34 +0000 (17:03 +0100)]
strings: simplify Join using Builder
The existing implementation has a bunch of special cases and
suffers an additional allocation for longer arrays. We can replace
this code with a simple implementation using Builder, improve
performance and reduce complexity.
Giovanni Bajo [Sat, 19 May 2018 07:42:52 +0000 (09:42 +0200)]
test: relax whitespaces matching in codegen tests
The codegen testsuite uses regexp to parse the syntax, but it doesn't
have a way to tell line comments containing checks from line comments
containing English sentences. This means that any syntax error (that
is, non-matching regexp) is currently ignored and not reported.
There were some tests in memcombine.go that had an extraneous space
and were thus effectively disabled. It would be great if we could
report it as a syntax error, but for now we just punt and swallow the
spaces as a workaround, to avoid the same mistake again.
Fixes #25452
Change-Id: Ic7747a2278bc00adffd0c199ce40937acbbc9cf0
Reviewed-on: https://go-review.googlesource.com/113835
Run-TryBot: Giovanni Bajo <rasky@develer.com>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
crypto/x509: revert change of article in SystemCertPool docs
The words 'the returned' were changed to 'a returned' in 8201b92aae7ba51ed2e2645c1f7815bfe845db72 when referring to the value
returned by SystemCertPool. Brad Fitz pointed out after that commit was
merged that it makes the wording of this function doc inconsistent with
rest of the stdlib since 'a returned' is not used anywhere, but 'the
returned' is frequently used.
Than McIntosh [Fri, 27 Jul 2018 11:21:24 +0000 (07:21 -0400)]
test: improve runtime/pprof tests for gccgo
In the CPU profile tests for gccgo, check to make sure that the
runtime's sigprof handler itself doesn't appear in the profile. Add a
"skip if gccgo" guard to one testpoint.
Updates #26595
Change-Id: I92a44161d61f17b9305ce09532134edd229745a7
Reviewed-on: https://go-review.googlesource.com/126316
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Alex Brainman [Sun, 26 Aug 2018 06:45:10 +0000 (16:45 +1000)]
internal/poll: advance file position in windows sendfile
Some versions of Windows (Windows 10 1803) do not set file
position after TransmitFile completes. So just use Seek
to set file position before returning from sendfile.
Giovanni Bajo [Fri, 31 Aug 2018 00:15:26 +0000 (02:15 +0200)]
cmd/compile: in prove, fix fence-post implications for unsigned domain
Fence-post implications of the form "x-1 >= w && x > min ⇒ x > w"
were not correctly handling unsigned domain, by always checking signed
limits.
This bug was uncovered once we taught prove that len(x) is always
>= 0 in the signed domain.
In the code being miscompiled (s[len(s)-1]), prove checks
whether len(s)-1 >= len(s) in the unsigned domain; if it proves
that this is always false, it can remove the bound check.
Notice that len(s)-1 >= len(s) can be true for len(s) = 0 because
of the wrap-around, so this is something prove should not be
able to deduce.
But because of the bug, the gate condition for the fence-post
implication was len(s) > MinInt64 instead of len(s) > 0; that
condition would be good in the signed domain but not in the
unsigned domain. And since in CL105635 we taught prove that
len(s) >= 0, the condition incorrectly triggered
(len(s) >= 0 > MinInt64) and things were going downfall.
Fixes #27251
Fixes #27289
Change-Id: I3dbcb1955ac5a66a0dcbee500f41e8d219409be5
Reviewed-on: https://go-review.googlesource.com/132495 Reviewed-by: Keith Randall <khr@golang.org>
Dina Garmash [Thu, 30 Aug 2018 20:59:29 +0000 (16:59 -0400)]
doc: fix os.Pipe() call in the example.
Short variable declarations example passes an fd argument to os.Pipe call.
However, os.Pipe() takes no arguments and returns 2 Files and an error:
https://golang.org/src/os/pipe_linux.go?s=319:360#L1
Fixes: #27384
Change-Id: I0a709f51e0878c57185d901b899d209f001dfcce
Reviewed-on: https://go-review.googlesource.com/132284 Reviewed-by: Robert Griesemer <gri@golang.org>
Rhys Hiltner [Fri, 31 Aug 2018 03:09:08 +0000 (20:09 -0700)]
doc: recommend benchstat for performance commits
The benchstat tool computes statistics about benchmarks, including
whether any differences are statistically significant. Recommend its use
in commit messages of performance-related changes rather than the
simpler benchcmp tool.
Rodolfo Rodriguez [Fri, 31 Aug 2018 00:14:09 +0000 (18:14 -0600)]
fmt: add Println example
Change-Id: Ifd509c0c6a6ea41094b6ae1f4931414325b152fd
Reviewed-on: https://go-review.googlesource.com/132475
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Robert Griesemer [Tue, 21 Aug 2018 23:02:51 +0000 (16:02 -0700)]
go/types: better names for internal helper functions (cleanup)
Internal helper functions for type-checking type expressions were
renamed to make it clearer when they should be used:
typExpr (w/o def) -> typ
typExpr (w/ def) -> definedType
typ -> indirectType
typExprInternal -> typInternal
The rename emphasizes that in most cases Checker.typ should be used
to compute the types.Type from an ast.Type. If the type is defined,
definedType should be used. For composite type elements which are
not "inlined" in memory, indirectType should be used.
In the process, implicitly changed several uses of indirectType
(old: typ) to typ (old: typExpr) by not changing the respective
function call source. These implicit changes are ok in those
places because either call is fine where we are not concerned
about composite type elements. But using typ (old: typExpr) is
more efficient than using indirectType (old: typ).
Change-Id: I4ad14d5357c5f94b6f1c33173de575c4cd05c703
Reviewed-on: https://go-review.googlesource.com/130595 Reviewed-by: Alan Donovan <adonovan@google.com>
Robert Griesemer [Tue, 21 Aug 2018 19:01:32 +0000 (12:01 -0700)]
go/types: remove explicit path parameter from most type-checker functions (cleanup)
Now that most of the type-checker is using the object-coloring mechanism
to detect cycles, remove the explicit path parameter from the functions
that don't rely on it anymore.
Some of the syntactic-based resolver code (for aliases, interfaces)
still use an explicit path; leaving those unchanged for now.
The function cycle was moved from typexpr.go (where it is not used
anymore) to resolver.go (where it's still used). It has not changed.
Fixes #25773.
Change-Id: I2100adc8d66d5da9de9277dee94a1f08e5a88487
Reviewed-on: https://go-review.googlesource.com/130476 Reviewed-by: Alan Donovan <adonovan@google.com>
Robert Griesemer [Tue, 21 Aug 2018 16:50:58 +0000 (09:50 -0700)]
go/types: track local cycles using same mechanism as for global objects
For Go 1.11, cycle tracking of global (package-level) objects was changed
to use a Checker-level object path rather than relying on the explicit
path parameter that is passed around to some (but not all) type-checker
functions.
This change now uses the same mechanism for the detection of local
type cycles (local non-type objects cannot create cycles by definition
of the spec).
As a result, local alias cycles are now correctly detected as well
(issue #27106).
The path parameter that is explicitly passed around to some type-checker
methods is still present and will be removed in a follow-up CL.
Also:
- removed useCycleMarking flag and respective dead code
- added a couple more tests
- improved documentation
Fixes #27106.
Updates #25773.
Change-Id: I7cbf304bceb43a8d52e6483dcd0fa9ef7e1ea71c
Reviewed-on: https://go-review.googlesource.com/130455
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
Andrew Bonventre [Thu, 30 Aug 2018 21:47:04 +0000 (15:47 -0600)]
cmd/compile: make math/bits.RotateLeft* an intrinsic on amd64
Previously, pattern matching was good enough to achieve good performance
for the RotateLeft* functions, but the inlining cost for them was much
too high. Make RotateLeft* intrinsic on amd64 as a stop-gap for now to
reduce inlining costs.
This should be done (or at least looked at) for other architectures
as well.
Updates golang/go#17566
Change-Id: I6a106ff00b6c4e3f490650af3e083ed2be00c819
Reviewed-on: https://go-review.googlesource.com/132435
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Leigh McCulloch [Thu, 30 Aug 2018 21:45:21 +0000 (21:45 +0000)]
crypto/x509: clarify docs for SystemCertPool
The sentence in the docs for SystemCertPool that states that mutations
to a returned pool do not affect any other pool is ambiguous as to who
the any other pools are, because pools can be created in multiple ways
that have nothing to do with the system certificate pool. Also the use
of the word 'the' instead of 'a' early in the sentence implies there is
only one shared pool ever returned.
Kevin Burke [Thu, 30 Aug 2018 21:39:45 +0000 (15:39 -0600)]
fmt: remove spelling mistake in example
"someting" is misspelled and the error handling both clobbers the
error that occurs and distracts from the point of the example, which
is to demonstrate how Printf works. It's better to just panic with the
error.
Change-Id: I5fb0a4a1a8b4772cbe0302582fa878d95e3a4060
Reviewed-on: https://go-review.googlesource.com/132376 Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Agniva De Sarker [Fri, 3 Aug 2018 15:21:25 +0000 (20:51 +0530)]
cmd/dist: wait for run jobs to finish in case of a compiler error
Instead of calling run synchronously, we pass it through bgrun
and immediately wait for it to finish. This pushes all jobs
to execute through the bgwork channel and therefore causes
them to exit cleanly in case of a compiler error.
Fixes #25981
Change-Id: I789a85d23fabf32d144ab85a3c9f53546cb7765a
Reviewed-on: https://go-review.googlesource.com/127776
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Rebecca Stambler [Thu, 30 Aug 2018 20:01:15 +0000 (16:01 -0400)]
go/types: fix crash following misuse of [...]T in composite literal
The type-checker currently crashes when checking code such as:
_ = map[string][...]int{"": {1, 2, 3}}
In this case, the type checker reports an error for map[string][...]int,
then proceeds to type-check the values of the map literal using a hint
type of [...]int. When type-checking the inner composite (array) literal,
the length of the open array type is computed from the elements,
then the array type is recorded, but the literal has no explicit type
syntax against which to record the type, so this code causes the
type-checker to panic. Add a nil check before calling
check.recordTypeAndValue to avoid that.
Updates #22467
Change-Id: Ic4453ba485b7b88ede2a89f209365eda9e032abc
Reviewed-on: https://go-review.googlesource.com/132355 Reviewed-by: Alan Donovan <adonovan@google.com>
Andrei Tudor Călin [Thu, 30 Aug 2018 04:55:05 +0000 (06:55 +0200)]
net: refactor readerAtEOF splice test
Refactor TestSplice/readerAtEOF to handle cases where we disable
splice on older kernels better.
If splice is disabled, net.splice and poll.Splice do not get to
observe EOF on the reader, because poll.Splice returns immediately
with EINVAL. The test fails unexpectedly, because the splice operation
is reported as not handled.
This change refactors the test to handle the aforementioned case
correctly, by not calling net.splice directly, but using a higher
level check.
Fixes #27355.
Change-Id: I0d5606b4775213f2dbbb84ef82ddfc3bab662a31
Reviewed-on: https://go-review.googlesource.com/132096
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
ianzapolsky [Thu, 30 Aug 2018 18:57:16 +0000 (12:57 -0600)]
fmt: add an example for Errorf
The errors package has an example for Errorf, but the fmt
package does not. Copy the Errorf example from errors to
fmt. Move existing Stringer example into separate file, so as
not to break the assumption that the entire file will be
presented as the example.
Erin Masatsugu [Thu, 30 Aug 2018 18:27:07 +0000 (18:27 +0000)]
bytes: add example for Buffer.Len
Change-Id: Ide50aba940727a7b32cd33dea5315050f1a34717
Reviewed-on: https://go-review.googlesource.com/132237
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
David Timm [Thu, 30 Aug 2018 18:25:53 +0000 (12:25 -0600)]
net/http: add example for http.HandleFunc
Change-Id: Id0e2fb2abad5b776ac0ed76e55e36c6b774b5b7a
Reviewed-on: https://go-review.googlesource.com/132278
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Cherry Zhang [Wed, 29 Aug 2018 16:09:34 +0000 (12:09 -0400)]
cmd/compile: don't clobber dead slots in runtime.wbBufFlush
runtime.wbBufFlush must not modify its arguments, because the
argument slots are also used as spill slots in runtime.gcWriteBarrier.
So, GOEXPERIMENT=clobberdead must not clobber them.
Updates #27326.
Change-Id: Id02bb22a45201eecee748d89e7bdb3df7e4940e4
Reviewed-on: https://go-review.googlesource.com/131957 Reviewed-by: Keith Randall <khr@golang.org>
Cherry Zhang [Wed, 29 Aug 2018 15:55:55 +0000 (11:55 -0400)]
cmd/compile: only clobber dead slots at call sites
We now have safepoints at nearly all the instructions. When
GOEXPERIMENT=clobberdead is on, it inserts clobbers nearly at
every instruction. Currently this doesn't work. (Maybe the stack
maps at non-call safepoints are still imprecise. I haven't
investigated.) For now, only use call-based safepoints if the
experiment is on.
Updates #27326.
Change-Id: I72cda9b422d9637cc5738e681502035af7a5c02d
Reviewed-on: https://go-review.googlesource.com/131956 Reviewed-by: Keith Randall <khr@golang.org>
Rebecca Stambler [Thu, 30 Aug 2018 15:33:19 +0000 (11:33 -0400)]
go/types: handle nil pointer when panic is written outside of a function
The current implementation crashes when someone writes a panic outside of
a function, which makes sense since that is broken code. This fix allows
one to type-check broken code.
Updates #22467
Change-Id: I81b90dbd918162a20c60a821340898eaf02e648d
Reviewed-on: https://go-review.googlesource.com/132235 Reviewed-by: Alan Donovan <adonovan@google.com>
Than McIntosh [Wed, 18 Jul 2018 14:19:35 +0000 (10:19 -0400)]
cmd/link: move ElfType field in sym.Symbol to cold section
The sym.Symbol 'ElfType' field is used only for symbols corresponding
to things in imported shared libraries, hence is not needed in the
common case. Relocate it to sym.AuxSymbol so as to shrink the main
Symbol struct.
Updates #26186
Change-Id: I803efc561c31a0ca1d93eca434fda1c862a7b2c5
Reviewed-on: https://go-review.googlesource.com/125479 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Than McIntosh [Tue, 17 Jul 2018 19:36:30 +0000 (15:36 -0400)]
cmd/link: move Plt, Got fields in sym.Symbol to cold section
The sym.Symbol 'Plt' and 'Got' field are used only with cgo and/or
external linking and are not needed for most symbols. Relocate them to
sym.AuxSymbol so as to shrink the main Symbol struct.
Updates #26186
Change-Id: I170d628a760be300a0c1f738f0998970e91ce3d6
Reviewed-on: https://go-review.googlesource.com/125478 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Than McIntosh [Tue, 17 Jul 2018 18:38:34 +0000 (14:38 -0400)]
cmd/link: move Localentry field in sym.Symbol to cold section
The sym.Symbol 'Localentry' field is used only with cgo and/or
external linking on MachoPPC. Relocate it to sym.AuxSymbol since it is
infrequently used, so as to shrink the main Symbol struct.
Updates #26186
Change-Id: I5872aa3f059270c2a091016d235a1a732695e411
Reviewed-on: https://go-review.googlesource.com/125477 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Than McIntosh [Tue, 17 Jul 2018 15:02:57 +0000 (11:02 -0400)]
cmd/link: split out Extname into cold portion of sym.Symbol
Create a new "AuxSymbol" struct into which 'cold' or 'infrequently
set' symbol fields are located. Move the Extname field from the
main Symbol struct to AuxSymbol.
Updates #26186
Change-Id: I9e795fb0cc48f978e2818475fa073ed9f2db202d
Reviewed-on: https://go-review.googlesource.com/125476 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
runtime/pprof: compute memory profile block size using sampled values
Fixes #26638.
Change-Id: I3c18d1298d99af8ea8c00916303efd2b5a5effc7
Reviewed-on: https://go-review.googlesource.com/126336 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Alberto Donizetti [Wed, 29 Aug 2018 14:46:19 +0000 (16:46 +0200)]
bytes: note that NewBuffer's initial size can change
bytes.NewBuffer's documentation says it can be used to set the initial
size of the buffer. The current wording is:
> It can also be used to size the internal buffer for writing.
This may led users to believe that the buffer (its backing array) is
fixed in size and won't grow, which isn't true (subsequent Write calls
will expand the backing array as needed).
Change the doc to make it clearer that NewBuffer just sets the initial
size of the buffer.
Fixes #27242
Change-Id: I2a8cb5bee02ca2c1657ef59e2cf1434c7a9bd397
Reviewed-on: https://go-review.googlesource.com/132035 Reviewed-by: Dominik Honnef <dominik@honnef.co> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Daniel Martí [Wed, 29 Aug 2018 13:06:31 +0000 (07:06 -0600)]
text/template: fix newline counting in raw strings
lexRawQuote already uses the next method, which keeps track of newlines
on a character by character basis. Adding up newlines in emit again
results in the newlines being counted twice, which can mean bad position
information in error messages.
Fix that, and add a test.
Fixes #27319.
Change-Id: Id803be065c541412dc808d388bc6d8a86a0de41e
Reviewed-on: https://go-review.googlesource.com/131996
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Zheng Xu [Wed, 29 Aug 2018 06:55:03 +0000 (14:55 +0800)]
build: support frame-pointer for arm64
Supporting frame-pointer makes Linux's perf and other profilers much more useful
because it lets them gather a stack trace efficiently on profiling events. Major
changes include:
1. save FP on the word below where RSP is pointing to (proposed by Cherry and Austin)
2. adjust some specific offsets in runtime assembly and wrapper code
3. add support to FP in goroutine scheduler
4. adjust link stack overflow check to take the extra word into account
5. adjust nosplit test cases to enable frame sizes which are 16 bytes aligned
Than McIntosh [Tue, 28 Aug 2018 15:27:07 +0000 (11:27 -0400)]
cmd/compile: remove var sorting from DWARF inline generation
When generation DWARF inline info records, the current implementation
includes a sorting pass that reorders a subprogram's child variable
DIEs based on class (param/auto) and name. This sorting is no longer
needed, and can cause problems for a debugger (if we want to use the
DWARF info for creating a call to an optimized function); this patch
removes it.
Ordering of DWARF subprogram variable/parameter DIEs is still
deterministic with this change, since it is keyed off the order in
which vars appear in the pre-inlining function "Dcl" list.
Alessandro Arzilli [Thu, 23 Aug 2018 12:01:59 +0000 (14:01 +0200)]
cmd/link: move type name mangling after deadcode elimination
Moves type name mangling after deadcode elimination. The motivation for
doing this is to create a space between deadcode elimination and type name
mangling where DWARF generation for types and variables can exist, to fix
issue #23733.
Dave Brophy [Tue, 28 Aug 2018 18:13:40 +0000 (18:13 +0000)]
fmt: fix incorrect format of whole-number floats when using %#v
This fixes the unwanted behaviour where printing a zero float with the
#v fmt verb outputs "0" - e.g. missing the trailing decimal. This means
that the output would be interpreted as an int rather than a float when
parsed as Go source. After this change the the output is "0.0".
Fixes #26363
Change-Id: Ic5c060522459cd5ce077675d47c848b22ddc34fa
GitHub-Last-Rev: adfb061363f0566acec134c81be9a3dcb1f4cac8
GitHub-Pull-Request: golang/go#26383
Reviewed-on: https://go-review.googlesource.com/123956 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Than McIntosh [Fri, 6 Jul 2018 16:45:03 +0000 (12:45 -0400)]
cmd/link: improve comments for relocsym
This patch contains the remnants of CL (122482), which was intended to
reduce memory allocation in 'relocsym'. Another CL (113637) went in
first that included pretty much all of the code changes in 122482,
however there are some changes to comments that are worth preserving.
Change-Id: Iacdbd2bfe3b7ca2656596570f06ce9a646211913
Reviewed-on: https://go-review.googlesource.com/122482 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Than McIntosh [Mon, 27 Aug 2018 15:49:38 +0000 (11:49 -0400)]
cmd/link: fix a few typos in comments
Comment changes to fix typos, no code changes.
Change-Id: I6c915f183025587fc479d14f5d2c885767348b1b
Reviewed-on: https://go-review.googlesource.com/131615 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Eric Ponce [Sun, 26 Aug 2018 17:32:07 +0000 (19:32 +0200)]
math: add Round and RoundToEven examples
Change-Id: Ibef5f96ea588d17eac1c96ee3992e01943ba0fef
Reviewed-on: https://go-review.googlesource.com/131496
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Alberto Donizetti [Wed, 22 Aug 2018 12:01:22 +0000 (14:01 +0200)]
cmd/compile: prevent overflow in walkinrange
In the compiler frontend, walkinrange indiscriminately calls Int64()
on const CTINT nodes, even though Int64's return value is undefined
for anything over 2⁶³ (in practise, it'll return a negative number).
This causes the introduction of bad constants during rewrites of
unsigned expressions, which make the compiler reject valid Go
programs.
This change introduces a preliminary check that Int64() is safe to
call on the consts on hand. If it isn't, walkinrange exits without
doing any rewrite.
Daniel Martí [Sun, 26 Aug 2018 12:24:33 +0000 (06:24 -0600)]
encoding/json: fix handling of nil anonymous structs
Given the following types:
type S2 struct{ Field string }
type S struct{ *S2 }
Marshalling a value of type T1 should result in "{}", as there's no way
to access any value of T2.Field. This is how Go 1.10 and earlier
versions behave.
However, in the recent refactor golang.org/cl/125417 I broke this logic.
When the encoder found an anonymous struct pointer field that was nil,
it no longer skipped the embedded fields underneath it. This can be seen
in the added test:
Daniel Martí [Sun, 26 Aug 2018 14:35:24 +0000 (08:35 -0600)]
encoding/json: get rid of the stream_test.go TODOs
TestRawMessage now passes without the need for the RawMessage field to
be a pointer. The TODO dates all the way back to 2010, so I presume the
issue has since been fixed.
TestNullRawMessage tested the decoding of a JSON null into a
*RawMessage. The existing behavior was correct, but for the sake of
completeness a non-pointer RawMessage field has been added too. The
non-pointer field behaves differently, as one can read in the docs:
To unmarshal JSON into a value implementing the Unmarshaler
interface, Unmarshal calls that value's UnmarshalJSON method,
including when the input is a JSON null.
Daniel Martí [Sat, 25 Aug 2018 15:29:01 +0000 (16:29 +0100)]
encoding/json: remove a branch in the structEncoder loop
Encoders like map and array can use the much cheaper "i > 0" check to
see if we're not writing the first element. However, since struct fields
support omitempty, we need to keep track of that separately.
This is much more expensive - after calling the field encoder itself,
and retrieving the field via reflection, this branch was the third most
expensive piece of this field loop.
Instead, hoist the branch logic outside of the loop. The code doesn't
get much more complex, since we just delay the writing of each byte
until the next iteration. Yet the performance improvement is noticeable,
even when the struct types in CodeEncoder only have 2 and 7 fields,
respectively.
name old time/op new time/op delta
CodeEncoder-4 5.39ms ± 0% 5.31ms ± 0% -1.37% (p=0.010 n=4+6)
name old speed new speed delta
CodeEncoder-4 360MB/s ± 0% 365MB/s ± 0% +1.39% (p=0.010 n=4+6)
Daniel Martí [Sat, 25 Aug 2018 14:49:11 +0000 (15:49 +0100)]
encoding/json: avoid some more pointer receivers
A few encoder struct types, such as map and slice, only encapsulate
other prepared encoder funcs. Using pointer receivers has no advantage,
and makes calling these methods slightly more expensive.
Not a huge performance win, but certainly an easy one. The struct types
used in the benchmark below contain one slice field and one pointer
field.
name old time/op new time/op delta
CodeEncoder-4 5.48ms ± 0% 5.39ms ± 0% -1.66% (p=0.010 n=6+4)
name old speed new speed delta
CodeEncoder-4 354MB/s ± 0% 360MB/s ± 0% +1.69% (p=0.010 n=6+4)
Keith Randall [Wed, 8 Aug 2018 03:59:04 +0000 (20:59 -0700)]
reflect: use a bigger object when we need a finalizer to run
If an object is allocated as part of a tinyalloc, then other live
objects in the same tinyalloc chunk keep the finalizer from being run,
even if the object that has the finalizer is dead.
Make sure the object we're setting the finalizer on is big enough
to not trigger tinyalloc allocation.
Keith Randall [Tue, 31 Jul 2018 19:40:20 +0000 (12:40 -0700)]
cmd/compile: unify compilation of compiler tests
Before this CL we would build&run each test file individually.
Building the test takes most of the time, a significant fraction of a
second. Running the tests are really fast.
After this CL, we build all the tests at once, then run each
individually. We only have to run the compiler&linker once (or twice,
for softfloat architectures) instead of once per test.
While we're here, organize these tests to fit a bit more into the
standard testing framework.
This is just the organizational CL that changes the testing framework
and migrates 2 tests. Future tests will follow.
R=go1.12
Update #26469
Change-Id: I1a1e7338c054b51f0c1c4c539d48d3d046b08b7d
Reviewed-on: https://go-review.googlesource.com/126995
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>