1
0
mirror of https://github.com/golang/go synced 2024-11-23 07:10:05 -07:00
Commit Graph

49246 Commits

Author SHA1 Message Date
Cuong Manh Le
5afa555428 cmd/compile: fix wrong check for b.Controls in isBlockMultiValueExit
b.Controls has type [2]*Value, thus len(b.Controls) > 0 is always true.
The right check should be b.Controls[0] != nil, though, this is also
always true, since when we always set control value for BlockRet and
BlockRetJmp when state.exit is called.

Though checkFunc also checks for nil control value of ret/retjmp, but
it happens later after expand_calls pass, so better to be defensive
here, just in case.

Change-Id: Ie4a292a3494dfbf5e6d872cde498703023b84d00
Reviewed-on: https://go-review.googlesource.com/c/go/+/345433
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-28 16:58:26 +00:00
Dan Scales
d7a43e8912 cmd/compile: support type C comparable
Support 'type C comparable' properly by using the same logic as for
'type T error', since ErrorType and ComparableType are entirely
analogous.

Added support for 'any' type as well, as requested by Robert. (For the
future - we can't currently have 'any' anywhere other than in a
constraint.)

Fixes #47966

Change-Id: I68bd284ced9a8bfca7d2339cd576f3cb909b1b83
Reviewed-on: https://go-review.googlesource.com/c/go/+/345174
Trust: Dan Scales <danscales@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-28 16:00:51 +00:00
Cuong Manh Le
044550ab0e runtime: add test case for checkptr alignment with nested expression
Discover while working on moving checkptr instrumentation from walk to
SSA generation.

Change-Id: I3f4a41fe4ad308b86c7c57d14b6ccc7c613e7f98
Reviewed-on: https://go-review.googlesource.com/c/go/+/345432
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-28 06:22:11 +00:00
Cuong Manh Le
010817714e cmd/compile: ignore SliceExpr.CheckPtrCall for mknode
CL 343972 added SliceExpr.CheckPtrCall field but forgot to add ignore
tag for mknode. This CL adds the missing tag.

Change-Id: Ib39bff3d456063bdc10fc17b4047b8392d373bf1
Reviewed-on: https://go-review.googlesource.com/c/go/+/345431
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-28 04:46:13 +00:00
Joe Tsai
f371b30f32 unicode/utf8: add AppendRune
AppendRune appends the UTF-8 encoding of a rune to a []byte.
It is a generally more user friendly than EncodeRune.

    EncodeASCIIRune-4     2.35ns ± 2%
    EncodeJapaneseRune-4  4.60ns ± 2%
    AppendASCIIRune-4     0.30ns ± 3%
    AppendJapaneseRune-4  4.70ns ± 2%

The ASCII case is written to be inlineable.

Fixes #47609

Change-Id: If4f71eedffd2bd4ef0d7f960cb55b41c637eec54
Reviewed-on: https://go-review.googlesource.com/c/go/+/345571
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-28 01:49:50 +00:00
Matthew Dempsky
ef4cb2f776 cmd/compile/internal/types: change NewNamed to use TypeObject
Semantically, TypeObject is the interface that go/types.TypeName would
implement, so we might as well use that instead of the more generic
Object (analog to go/types.Object) for NewNamed. In practice, this
doesn't really matter though, because we use *ir.Name for almost all
Objects anyway.

Also, remove VarObject: its last use was removed in CL 302071 (March
2021).

Change-Id: I6e987ecd419105e09f74fc8d60cadb61bcbc751f
Reviewed-on: https://go-review.googlesource.com/c/go/+/345810
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-28 01:26:53 +00:00
Robert Griesemer
5fb177163b go/types, types2: types in type switch cases must be instantiated
We already have a function that does all the right checks and it's called
varType. The only reason it wasn't used for type switch cases was that we
also have to accept the nil value. That was handled with typeOrNil. But
that function (typeOrNil) was only used for this specific purpose and I long
wished to get rid of it. It turns out that there's only one way to write the
untyped value nil, which is to actually write "nil" (maybe with parentheses).
So looking for that turned out to be simpler than using typeOrNil.

The new code does exactly that, and now we can just use varType and delete
typeOrNil. With this, there is now less code (excluding the test) and the code
is simpler and more correct.

Fixes #48008.

Change-Id: I8f2d80e61ae663c886924909f22bbfa634e7779c
Reviewed-on: https://go-review.googlesource.com/c/go/+/345790
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-28 00:51:39 +00:00
Matthew Dempsky
c81fa001a7 cmd/compile/internal/types: simplify and optimize PtrDataSize
The current implementation of PtrDataSize checks HasPointers each
call, which could lead to exponential blow-up in handling (admittedly
contrived) deeply nested structs.

To avoid the duplicate recursion, this CL incorporates the HasPointers
logic directly int PtrDataSize, and then re-defines HasPointers as
simply "PtrDataSize(t) > 0".

This CL also tightens up HasPointers/PtrDataSize to only be valid on
actual Go types. Fortunately, there was only one instance where this
wasn't already the case (escape analysis), and that's easily fixed
with an extra check for untyped types.

Change-Id: I0044bf9b558a88333aee2ccb137afb6cb4fea1db
Reviewed-on: https://go-review.googlesource.com/c/go/+/345809
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-28 00:50:13 +00:00
Matthew Dempsky
a9377183d0 cmd/compile/internal/types: unexport New and NewBasic
Now that the universe is fully initialized within package types, we
can stop exporting New and NewBasic, which are only needed for that
purpose. So this CL renames "New" to "newType" and "NewBasic" to
"newBasic".

This CL also moves the initialization of Types[TBLANK] and Types[TNIL]
from typecheck.InitUniverse to types.InitTypes, which I missed in an
earlier CL. And a use of "New(TSTRING)" in test/abiutils_test.go,
which should just be "Types[TSTRING]" anyway.

Change-Id: I1d83f93e27b88be289d4f3f6c16357a20f570460
Reviewed-on: https://go-review.googlesource.com/c/go/+/345487
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-27 23:06:52 +00:00
Matthew Dempsky
82efc05403 cmd/compile: use Type.OrigSym getter/setters [generated]
Automated CL to rewrite existing code to use OrigSym getters and
setters. Afterwards, we also unexported OrigSym, and then rename the
getter to OrigSym.

[git-generate]
cd src/cmd/compile/internal

: Workaround rf issue with types2 tests.
rm types2/*_test.go

rf '
ex ./noder ./typecheck {
import "cmd/compile/internal/types"
var s *types.Sym
var t *types.Type

t.OrigSym = s -> t.SetOrigSym(s)
t.OrigSym     -> t.OrigSym_()
}
'

cd types
rf '
mv Type.OrigSym Type.origSym
mv Type.OrigSym_ Type.OrigSym
'

: Revert types2 hack.
cd ../types2
git checkout HEAD^ .

Change-Id: I8eb17098613b1575df56b8189b1615823071d3d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/345485
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-08-27 21:27:59 +00:00
Matthew Dempsky
68ecdc2c70 cmd/compile/internal/types: add Type.OrigSym getter/setters
Will be used in the next CL, so that Type.OrigSym can be unexported.

Change-Id: I085f2a886abd419343c7ec7e4ae18c19de1fbbd4
Reviewed-on: https://go-review.googlesource.com/c/go/+/345484
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-08-27 20:43:38 +00:00
Matthew Dempsky
72c003ef82 cmd/compile: unexport Type.Width and Type.Align [generated]
[git-generate]
cd src/cmd/compile/internal

: Workaround rf issue with types2 tests.
rm types2/*_test.go

: Rewrite uses. First a type-safe rewrite,
: then a second pass to fix unnecessary conversions.
rf '
ex ./abi ./escape ./gc ./liveness ./noder ./reflectdata ./ssa ./ssagen ./staticinit ./typebits ./typecheck ./walk {
  import "cmd/compile/internal/types"
  var t *types.Type
  t.Width -> t.Size()
  t.Align -> uint8(t.Alignment())
}

ex ./abi ./escape ./gc ./liveness ./noder ./reflectdata ./ssa ./ssagen ./staticinit ./typebits ./typecheck ./walk {
  import "cmd/compile/internal/types"
  var t *types.Type
  int64(uint8(t.Alignment())) -> t.Alignment()
}
'

: Rename fields to lower case.
(
cd types
rf '
mv Type.Width Type.width
mv Type.Align Type.align
'
)

: Revert types2 changes.
git checkout HEAD^ types2

Change-Id: I42091faece104c4ef619d9d4d50514fd48c8f029
Reviewed-on: https://go-review.googlesource.com/c/go/+/345480
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-27 20:43:31 +00:00
Michael Matloob
94f2a03951 cmd: update requirement on golang.org/x/mod
Commands run:
  go get golang.org/x/mod@master
  go mod vendor
  go mod tidy

This change pulls in the x/mod on master. Before it was pulled in on
the dev.cmdgo branch of x/mod, but now that the workspace changes have
been pulled into x/mod, we can change the requirement back on to the
main branch.

Change-Id: I296799a87ecc08ba17c0722e955f000426b105ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/345390
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-08-27 18:01:06 +00:00
Keith Randall
6a35e07512 cmd/compile: fix stenciling of conversions between interfaces
Conversions need to allow nil through.
We do that using a CONVIFACE instead of a DOTTYPE.

Also reorganize how nonempty interfaces are handled.
For nonempty to empty, a simple CONVIFACE suffices.
For nonempty to nonempty, we need to call the runtime to get the
new itab. Use the entry from the dictionary to identify the
target interface type (if parameterized).

Fixes #47925

Change-Id: I4ffeed964318bb3e270b06f558e6ab9c5bfc7188
Reviewed-on: https://go-review.googlesource.com/c/go/+/344830
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-27 16:41:29 +00:00
Keith Randall
4f0dedca71 cmd/compile: fix parameterized interfaces
type I[T any] interface{}

This is an interface, but it has a type parameter.
We need to distinguish that from an interface that is not parameterized.

That means when doing type substitution on an interface with
parameters, we need to make a new one.

Same for non-empty interfaces. Even if the type parameter is not
used in any method, we sill need to make a new type.

Similar case to tstruct, above.

Change-Id: I23ad9f21d2c4ef675bf3f7d84899d9e4919d05e7
Reviewed-on: https://go-review.googlesource.com/c/go/+/344578
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-27 15:03:09 +00:00
Filippo Valsorda
39eb1cc3f4 crypto/x509: drop compatibility hack for expired COMODO intermediates
The hack was there for a couple intermediates with only SGC EKUs that
issued severAuth certificates. They now all expired, so we can drop it.

https://crt.sh/?id=10066
https://crt.sh/?id=213

Change-Id: I46820024892b2f9918ce125bafbbaf9e6c5c58b3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/781225
Reviewed-on: https://go-review.googlesource.com/c/go/+/327809
Trust: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2021-08-27 13:05:08 +00:00
Michael Matloob
acdea4f9f7 all: REVERSE MERGE dev.cmdgo (220bc44) into master
This commit is a REVERSE MERGE.
It merges dev.cmdgo back into its parent branch, master.
This marks the end of development on dev.cmdgo.

Merge List:

+ 2021-08-27 220bc44a4c [dev.cmdgo] all: merge master (67f7e16) into dev.cmdgo
+ 2021-08-26 de83ef67ac [dev.cmdgo] all: merge master (5e6a7e9) into dev.cmdgo
+ 2021-08-25 de23549a39 [dev.cmdgo] cmd/go: fix calls to modFileGoVersion to pass in modFile
+ 2021-08-25 3b523caf41 [dev.cmdgo] cmd/go: clean up TODOWorkspaces instances
+ 2021-08-25 109c13b64f [dev.cmdgo] all: merge master (c2f96e6) into dev.cmdgo
+ 2021-08-12 e2e1987b31 [dev.cmdgo] cmd/link: fix TestBuildForTvOS
+ 2021-08-12 d397fc1169 [dev.cmdgo] don't give command-line-arguments a module
+ 2021-08-11 aaf914d0e6 [dev.cmdgo] cmd/go: remove modload.ModRoot function
+ 2021-08-06 3025ce2fa8 [dev.cmdgo] cmd/go: address code review comments in test cgo_path_space_quote
+ 2021-08-06 fc8e0cbbba [dev.cmdgo] cmd: update x/tools and remove copy of txtar
+ 2021-07-31 3799012990 [dev.cmdgo] cmd/go: add go mod editwork command
+ 2021-07-30 b3b53e1dad [dev.cmdgo] cmd/go: thread through modroots providing replacements
+ 2021-07-30 47694b59eb [dev.cmdgo] cmd/go: provide a more helpful missing required module error in workspaces
+ 2021-07-30 90830699ae [dev.cmdgo] cmd/go: allow expliticly setting -mod=readonly in workspace mode
+ 2021-07-30 8e2ab05dd3 Merge "[dev.cmdgo] all: merge master (9eee0ed) into dev.cmdgo" into dev.cmdgo
+ 2021-07-30 52e970b1c8 [dev.cmdgo] cmd: support space and quotes in CC and CXX
+ 2021-07-30 3a69cef65a [dev.cmdgo] cmd/internal/str: add utilities for quoting and splitting args
+ 2021-07-30 137089ffb9 [dev.cmdgo] cmd/internal/str: move package from cmd/go/internal/str
+ 2021-07-28 47cdfa95ae [dev.cmdgo] all: merge master (9eee0ed) into dev.cmdgo
+ 2021-07-28 176baafd5b [dev.cmdgo] cmd/go: sort roots when joining multiple main module roots
+ 2021-07-28 288a83dcff [dev.cmdgo] cmd/go: maintain a go.work.sum file
+ 2021-07-27 2c8acf63c2 [dev.cmdgo] cmd/go: make fewer 'go mod' commands update go.mod
+ 2021-07-27 72233d27c4 [dev.cmdgo] cmd/go: add -testsum flag to update go.sum in script tests
+ 2021-07-27 b2205eab0e [dev.cmdgo] cmd/go: add go mod initwork command
+ 2021-07-27 f05f5ceffa [dev.cmdgo] cmd/go: fold index and modFile into MainModules
+ 2021-07-26 7ce257147f [dev.cmdgo] cmd/go: add the workspace mode
+ 2021-07-26 3cd15e02ed [dev.cmdgo] cmd: pull in x/mod on the dev.cmdgo branch
+ 2021-07-22 a627fcd3c4 [dev.cmdgo] cmd/go: replace Target with MainModules, allowing for multiple targets
+ 2021-07-20 ab361499ef [dev.cmdgo] cmd/go/testdata/script: fix a small typo in modfile_flag
+ 2021-07-06 aa4da4f189 [dev.cmdgo] all: merge master (912f075) into dev.cmdgo
+ 2020-12-22 6dc2c16f95 [dev.cmdgo] codereview.cfg: add config for dev.cmdgo

Change-Id: Ic42f1273e42c90954bd61a6e4d6ca193c97bf04c
2021-08-27 08:24:13 -04:00
Michael Matloob
220bc44a4c [dev.cmdgo] all: merge master (67f7e16) into dev.cmdgo
Merge List:

+ 2021-08-27 67f7e16bcc encoding/gob: optimize decoding of []byte
+ 2021-08-27 2c60a99f72 cmd/compile/internal/syntax: make valid type parameter list in presence of errors
+ 2021-08-27 d350a66532 cmd/compile: eagerly CalcStructSize for synthetic ABI types
+ 2021-08-27 d7e2e2ec2b cmd/compile: delay fillinMethods to deal with mutually-recursive types
+ 2021-08-27 c927599783 cmd/compile: eliminate repetitive code
+ 2021-08-27 62f88b6dc8 cmd/compile: add types.RecalcSize
+ 2021-08-27 e7eee5e265 cmd/compile: remove ssagen/pgen_test.go
+ 2021-08-27 f153b6739b cmd/compile: use typecheck.InitUniverse in unit tests
+ 2021-08-26 967a8017f7 cmd/compile: move types init code into package types
+ 2021-08-26 af80af22b5 cmd/compile/internal/types2: do not declare new methods on instantiated types
+ 2021-08-26 03db2c2413 cmd/compile/internal/types2: implement TypeList.String (debugging support)
+ 2021-08-26 c9e05fdcf7 cmd/compile: fix reference to generic type needed by crawler
+ 2021-08-26 eb6a07fcf9 cmd/compile: unexport Type.Vargen
+ 2021-08-26 3836983779 cmd/compile/internal/types: unexport Type.Extra
+ 2021-08-26 1f8d4562de cmd/compile: change typecheck.iscmp into ir.Op.IsCmp

Change-Id: I95c040a0e984a13a3b12c50458148007221ee300
2021-08-27 08:06:57 -04:00
Joe Tsai
67f7e16bcc encoding/gob: optimize decoding of []byte
The reflect.Value.Slice method unfortunately allocates every time
since it needs to place the slice header on the heap.
This is silly since gob immediately stores the result back into slice.
Instead, use the reflect.Value.SetLen method.

DecodeBytesSlice  75.0µs ± 2%  35.2µs ± 6%  -53.02%

Change-Id: I3ca0529d01bf978f2b76e215f52d369f458951ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/345572
Trust: Joe Tsai <joetsai@digital-static.net>
Run-TryBot: Joe Tsai <joetsai@digital-static.net>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2021-08-27 08:01:41 +00:00
Robert Griesemer
2c60a99f72 cmd/compile/internal/syntax: make valid type parameter list in presence of errors
Make sure the parser fills in names and types for type parameter
lists, even in the case of errors.

While at it, adjust some of the test functions to accept generic
code and report all syntax errors.

Added offending source as test for types2.

Fixes #47996.

Change-Id: I449bcf5e2cb80fa2a24cdd3945f484bfca218a06
Reviewed-on: https://go-review.googlesource.com/c/go/+/345476
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-27 05:13:44 +00:00
Matthew Dempsky
d350a66532 cmd/compile: eagerly CalcStructSize for synthetic ABI types
The next CL is going to replace Type.Width with Type.Size(), but
Type.Size() isn't safe to call concurrently. So this CL calls
CalcStructSize, which *is* allowed to be used concurrently, but then
it's the caller's responsibility to ensure it's called right after
NewStruct.

Change-Id: If9cd81650ccb3a867b4449af757375fa56227901
Reviewed-on: https://go-review.googlesource.com/c/go/+/345483
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-27 03:24:35 +00:00
Dan Scales
d7e2e2ec2b cmd/compile: delay fillinMethods to deal with mutually-recursive types
We need to delay fillinMethods until we get to a top-level type, so we
know all the TFORW types have been filled in, and we can do the
substitutions required by fillinMethods.

Fixes #47710

Change-Id: I298de7e7753ed31a2c2b1ff04f35177a8afc7a66
Reviewed-on: https://go-review.googlesource.com/c/go/+/345149
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-27 01:42:38 +00:00
wangyuntao
c927599783 cmd/compile: eliminate repetitive code
Change-Id: I02c8b65f7c1c1606c9964ab6c54d5ab5f1b444a5
GitHub-Last-Rev: 3d740b9ac1
GitHub-Pull-Request: golang/go#47242
Reviewed-on: https://go-review.googlesource.com/c/go/+/334990
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-08-27 01:08:12 +00:00
Matthew Dempsky
62f88b6dc8 cmd/compile: add types.RecalcSize
This is the only case where Align is assigned outside of package
types. Rather than adding a SetAlign method, adding a RecalcSize
function is a bit more descriptive.

Change-Id: I1b3c01ebd0e41183665baa63c926592865bbbd0b
Reviewed-on: https://go-review.googlesource.com/c/go/+/345479
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-27 00:36:54 +00:00
Matthew Dempsky
e7eee5e265 cmd/compile: remove ssagen/pgen_test.go
This test was written in 2015, and hasn't had any meaningful changes
to it since. However, it's very ad hoc and pokes into internals that
it shouldn't, and it keeps getting in the way of more meaningful
refactorings. It doesn't even catch bugs; e.g., it didn't catch that
cmpstackvarlt wasn't asymmetric (CL 19778), and a bunch of its test
cases are bogus because we never actually use it to sort ir.PFUNC
nodes (assert added in this CL).

The compiler is woefully lacking in unit tests like these, but I
strongly feel this test is more of a hinderance than a help at the
moment.

Change-Id: I3ac7a3e533947aa95f325626c6eec13a43789f9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/345478
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-27 00:36:45 +00:00
Matthew Dempsky
f153b6739b cmd/compile: use typecheck.InitUniverse in unit tests
Rather than ad hoc setting up the universe, just initialize it
properly.

Change-Id: I18484b952321f55eb3e1e48fd383068a4ee75f66
Reviewed-on: https://go-review.googlesource.com/c/go/+/345475
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-27 00:36:19 +00:00
Matthew Dempsky
967a8017f7 cmd/compile: move types init code into package types
This moves the package types setup code from package typecheck into
package types itself. This is a prereq for making types.Type more
opaque, because some unit tests depend on being able to init the basic
universal types.

A few notable details of this CL:

1. Creating the builtin types requires being able to create the
ir.Name/ir.OTYPE that represents it, but package types can't depend on
package ir. So we add a callback function to handle creating the
ir.Name.

2. This CL moves ir.Pkgs.Unsafe to types.UnsafePkg. Package unsafe is
part of the language, not like the other ir.Pkgs packages that are
purely implementation details.

3. This CL also moves typecheck.FakeRecv to types.FakeRecv, addressing
an outstanding TODO.

Change-Id: I64de04ce82fbcd1bb59f547e2eea3cda52d89429
Reviewed-on: https://go-review.googlesource.com/c/go/+/345474
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-26 22:37:54 +00:00
Robert Griesemer
af80af22b5 cmd/compile/internal/types2: do not declare new methods on instantiated types
Report an error if an alias is used to declare a method on an
instantiated type.

Also, when resolving the receiver type, don't use asNamed to
avoid premature expansion of the type.

Fixes #47968.

Change-Id: Ie5acc4cfb1944deaaeeaee98707f31e256f8ef5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/345472
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-26 20:39:56 +00:00
Robert Griesemer
03db2c2413 cmd/compile/internal/types2: implement TypeList.String (debugging support)
Change-Id: Iaa203def3dac94a7d5ff6120e89315c3d7977ee1
Reviewed-on: https://go-review.googlesource.com/c/go/+/345471
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-26 20:39:50 +00:00
Dan Scales
c9e05fdcf7 cmd/compile: fix reference to generic type needed by crawler
This problem happens when you create a new local type that uses an
imported generic type (maybe just by instantiating it), and then that
local type needed to be included as part of an export. In that case, the
imported generic type is does not have a declaration in the local
package, so it is not necessarily created in types1, so the
crawler/export doesn't work.

To fix this issue, we just need to add a call to g.obj() for the base
generic type, to make sure that it will exist if needed later in the
compilation or for the crawler during export.

Fixes #47514

Change-Id: Ie756578f07ad0007de8a88ae909cf7534a22936e
Reviewed-on: https://go-review.googlesource.com/c/go/+/345411
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
2021-08-26 20:18:58 +00:00
Matthew Dempsky
eb6a07fcf9 cmd/compile: unexport Type.Vargen
This field is only used outside of packages types in two places, and
they follow the same pattern. So this CL creates a Type.Setvargen
function that they can use instead, so that Type.Vargen can be
unexported.

A bit clumsy, but it works for now.

Change-Id: I7b4f33fac635e2464df2fbc0607ab40902f6f09f
Reviewed-on: https://go-review.googlesource.com/c/go/+/345469
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-26 19:34:58 +00:00
Matthew Dempsky
3836983779 cmd/compile/internal/types: unexport Type.Extra
Not used outside of package types anymore. Let's keep it that.

Change-Id: I69b464ac94edaacd219da4210f7b8618e2beaf70
Reviewed-on: https://go-review.googlesource.com/c/go/+/345413
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-08-26 19:34:52 +00:00
Matthew Dempsky
1f8d4562de cmd/compile: change typecheck.iscmp into ir.Op.IsCmp
Change-Id: If89089cbd79b7ff030d856df3a7e6b7862c0f4ec
Reviewed-on: https://go-review.googlesource.com/c/go/+/345412
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-26 19:07:27 +00:00
Michael Matloob
de83ef67ac [dev.cmdgo] all: merge master (5e6a7e9) into dev.cmdgo
Merge List:

+ 2021-08-26 5e6a7e9b86 embed: remove reference to global variables in docs
+ 2021-08-26 166b691b65 cmd/compile/internal/types2: remove need for instance (struct)
+ 2021-08-26 d6bdae33e9 cmd/compile/internal/types2: address some TODOs (cleanup)
+ 2021-08-26 770df2e18d crypto/tls: fix typo in PreferServerCipherSuites comment
+ 2021-08-26 a6ff433d6a cmd/go: pass -gcflags after other flags generated by the go command
+ 2021-08-25 4f2620285d cmd/compile/internal/types2: fix type set printing and add test
+ 2021-08-25 0ac64f6d70 cmd/compile/internal/types2: rename IsMethodSet to IsConstraint (cleanup)
+ 2021-08-25 4068fb6c21 cmd/compile: always accept 1.18 syntax but complain if not 1.18
+ 2021-08-25 bf0bc4122f go/types, types2: don't re-evaluate context string for each function argument (optimization)
+ 2021-08-25 4158e88f64 cmd/compile/internal/syntax: fix position of type parameter field
+ 2021-08-25 647bef6c59 go/types: implement NewTypeList and use it instead of composite literals
+ 2021-08-25 6cf1d5d0fa cmd/compile: generic SSA rules for simplifying 2 and 3 operand integer arithmetic expressions
+ 2021-08-25 5baf60d472 bytes, strings: optimize Trim for single byte cutsets
+ 2021-08-25 3d667671ad cmd/compile: fix function contains no TParam in generic function
+ 2021-08-25 4f2ebfe34b cmd/compile: allow embed into any byte slice type
+ 2021-08-25 d2f002cb39 time/format: avoid growslice in time.String()/time.GoString()
+ 2021-08-25 08d4cc20ca cmd/compile: fix stencil call expression.
+ 2021-08-25 099b819085 cmd/compile: fix CheckSize() calculation for -G=3 and stencils
+ 2021-08-25 e1fcf8857e test: add test that caused gofrontend compiler crash
+ 2021-08-25 d37b8dedf7 test: add test case that gofrontend miscompiled
+ 2021-08-25 41b99dab0f os/user: don't skip TestLookupGroup if supported
+ 2021-08-25 de1c934b97 cmd/compile: fix checkptr false positive for (*[Big]T)(ptr)[:n:n] pattern
+ 2021-08-24 54cdef1f10 reflect: add MapIter.SetKey and MapIter.SetValue
+ 2021-08-24 5d863f89fe cmd/compile: simplify bad conversion check

Change-Id: I29ab927f0e47f44d82f9307c642900f75f4f678f
2021-08-26 15:04:42 -04:00
Dan Kortschak
5e6a7e9b86 embed: remove reference to global variables in docs
Refering to variable is both redundant since package scope is used, and
incorrect since global variables are not described in the spec.

Change-Id: Ib08a9f072fc800ee36549f758b68167d8f044878
Reviewed-on: https://go-review.googlesource.com/c/go/+/344214
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Alexander Rakoczy <alex@golang.org>
Run-TryBot: Alexander Rakoczy <alex@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-26 18:26:42 +00:00
Robert Griesemer
166b691b65 cmd/compile/internal/types2: remove need for instance (struct)
instance was only used to hold the instantiation position for
lazy instantiation (and encode the fact that we have a lazy
instantiation). Just use a (pointer to a) syntax.Pos instead.

We could use a syntax.Pos (no pointer) and rely on the fact
that we have a known position (or fake position, if need be)
to indicate lazy instantiation. But using a pointer leads to
a smaller Named struct.

Change-Id: I441a839a125f453ad6c501de1ce499b72a2f67a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/345177
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-26 17:19:04 +00:00
Robert Griesemer
d6bdae33e9 cmd/compile/internal/types2: address some TODOs (cleanup)
- Address some easy TODOs.
- Remove some TODOs that are not correct anymore or are unimportent.
- Simplify some code on the way.

Change-Id: I4d20de3725b3a735022afe022cbc002b2798936d
Reviewed-on: https://go-review.googlesource.com/c/go/+/345176
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-26 17:18:58 +00:00
vinckr
770df2e18d crypto/tls: fix typo in PreferServerCipherSuites comment
Fixing a typo, Deprected -> Deprecated.

Change-Id: Ie0ccc9a57ae6a935b4f67154ac097dba4c3832ec
GitHub-Last-Rev: 57337cc1bf
GitHub-Pull-Request: golang/go#47745
Reviewed-on: https://go-review.googlesource.com/c/go/+/342791
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2021-08-26 12:19:23 +00:00
Cuong Manh Le
a6ff433d6a cmd/go: pass -gcflags after other flags generated by the go command
Otherwise, any gc flags set by user using "-gcflags" won't have effect.

Fixes #47682

Change-Id: Icd365577cba1f64f6c7b8320d0c9019de9f062f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/344909
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-08-26 02:06:43 +00:00
Robert Griesemer
4f2620285d cmd/compile/internal/types2: fix type set printing and add test
Change-Id: I44ca1f889b041467d5febacaf6037cfd75859175
Reviewed-on: https://go-review.googlesource.com/c/go/+/344873
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-25 23:44:02 +00:00
Robert Griesemer
0ac64f6d70 cmd/compile/internal/types2: rename IsMethodSet to IsConstraint (cleanup)
Invert the boolean result to match the new name.

Change-Id: Ide6c649ed8ac3a5d263640309960e61a005c886e
Reviewed-on: https://go-review.googlesource.com/c/go/+/344872
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-25 23:43:58 +00:00
Robert Griesemer
4068fb6c21 cmd/compile: always accept 1.18 syntax but complain if not 1.18
This CL configures the parser to always accept 1.18 syntax
(type parameters, type instantiations, interface elements),
even when -lang is set to an earlier release.

Instead, the type checker looks for 1.18 operations and
complains if the language version is set to an earlier
release.

Doing these checks during type checking is necessary because it
it is possible to write "generic" code using pre-1.18 syntax;
for instance, an imported generic function may be implicitly
instantiated (as in imported.Max(2, 3)), or an imported constraint
interface may be embedded in an "ordinary" interface.

Fixes #47818.

Change-Id: I83ec302b3f4ba7196c0a4743c03670cfb901310d
Reviewed-on: https://go-review.googlesource.com/c/go/+/344871
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-25 23:43:53 +00:00
Robert Griesemer
bf0bc4122f go/types, types2: don't re-evaluate context string for each function argument (optimization)
Change-Id: Ie1b4d5b64350ea42484adea14df84cacd1d2653b
Reviewed-on: https://go-review.googlesource.com/c/go/+/344576
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-25 23:43:42 +00:00
Robert Griesemer
4158e88f64 cmd/compile/internal/syntax: fix position of type parameter field
Change-Id: I8bca01b935301e7bd4efa55ed21921dbf31a75b9
Reviewed-on: https://go-review.googlesource.com/c/go/+/344575
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-25 23:43:41 +00:00
Robert Griesemer
647bef6c59 go/types: implement NewTypeList and use it instead of composite literals
Also, simplify a bit of code in predicates.go.

This is a backport of changes in CL 344615 that were made in addition
to the changes of the original CL 343933; it brings go/types in sync
with types2.

Change-Id: I14cd4d4704d29894d0fbb8d129744d65e332ad22
Reviewed-on: https://go-review.googlesource.com/c/go/+/344570
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-25 23:43:40 +00:00
Jake Ciolek
6cf1d5d0fa cmd/compile: generic SSA rules for simplifying 2 and 3 operand integer arithmetic expressions
This applies the following generic integer addition/subtraction transformations:

x - (x + y) = -y
(x - y) - x = -y
y + (x - y) = x
y + (z + (x - y) = x + z

There's over 40 unique functions matching in Go. Hits 2 funcs in the runtime itself:

runtime.stackfree()
runtime.runqdrain()

Go binary size reduced by 0.05% on Linux x86_64.

StackCopy bench (perflocked Cascade Lake x86):

name                old time/op  new time/op  delta
StackCopyPtr-8      87.3ms ± 1%  86.9ms ± 0%  -0.45%  (p=0.000 n=20+20)
StackCopy-8         77.6ms ± 1%  77.0ms ± 0%  -0.76%  (p=0.000 n=20+20)
StackCopyNoCache-8  2.28ms ± 2%  2.26ms ± 2%  -0.93%  (p=0.008 n=19+20)

test/bench/go1 benchmarks (perflocked Cascade Lake x86):

name                     old time/op    new time/op    delta
BinaryTree17-8              1.88s ± 1%     1.88s ± 0%    ~     (p=0.373 n=15+12)
Fannkuch11-8                2.31s ± 0%     2.35s ± 0%  +1.52%  (p=0.000 n=15+14)
FmtFprintfEmpty-8          26.6ns ± 0%    26.6ns ± 0%    ~     (p=0.081 n=14+13)
FmtFprintfString-8         48.6ns ± 0%    50.0ns ± 0%  +2.86%  (p=0.000 n=15+14)
FmtFprintfInt-8            56.9ns ± 0%    54.8ns ± 0%  -3.70%  (p=0.000 n=15+15)
FmtFprintfIntInt-8         90.4ns ± 0%    88.8ns ± 0%  -1.78%  (p=0.000 n=15+15)
FmtFprintfPrefixedInt-8     104ns ± 0%     104ns ± 0%    ~     (p=0.905 n=14+13)
FmtFprintfFloat-8           148ns ± 0%     144ns ± 0%  -2.19%  (p=0.000 n=14+15)
FmtManyArgs-8               389ns ± 0%     390ns ± 0%  +0.35%  (p=0.000 n=12+15)
GobDecode-8                3.90ms ± 1%    3.88ms ± 0%  -0.49%  (p=0.000 n=15+14)
GobEncode-8                2.73ms ± 0%    2.73ms ± 0%    ~     (p=0.425 n=15+14)
Gzip-8                      169ms ± 0%     168ms ± 0%  -0.52%  (p=0.000 n=13+13)
Gunzip-8                   24.7ms ± 0%    24.8ms ± 0%  +0.61%  (p=0.000 n=15+15)
HTTPClientServer-8         60.5µs ± 6%    60.4µs ± 7%    ~     (p=0.595 n=15+15)
JSONEncode-8               6.97ms ± 1%    6.93ms ± 0%  -0.69%  (p=0.000 n=14+14)
JSONDecode-8               31.2ms ± 1%    30.8ms ± 1%  -1.27%  (p=0.000 n=14+14)
Mandelbrot200-8            3.87ms ± 0%    3.87ms ± 0%    ~     (p=0.652 n=15+14)
GoParse-8                  2.65ms ± 2%    2.64ms ± 1%    ~     (p=0.202 n=15+15)
RegexpMatchEasy0_32-8      45.1ns ± 0%    45.9ns ± 0%  +1.68%  (p=0.000 n=14+15)
RegexpMatchEasy0_1K-8       140ns ± 0%     139ns ± 0%  -0.44%  (p=0.000 n=15+14)
RegexpMatchEasy1_32-8      40.9ns ± 3%    40.5ns ± 0%  -0.88%  (p=0.000 n=15+13)
RegexpMatchEasy1_1K-8       215ns ± 1%     220ns ± 1%  +2.27%  (p=0.000 n=15+15)
RegexpMatchMedium_32-8      783ns ± 7%     738ns ± 0%    ~     (p=0.361 n=15+15)
RegexpMatchMedium_1K-8     24.1µs ± 6%    23.4µs ± 6%  -2.94%  (p=0.004 n=15+15)
RegexpMatchHard_32-8       1.10µs ± 1%    1.09µs ± 1%  -0.40%  (p=0.006 n=15+14)
RegexpMatchHard_1K-8       33.0µs ± 0%    33.0µs ± 0%    ~     (p=0.535 n=12+14)
Revcomp-8                   354ms ± 0%     353ms ± 0%  -0.23%  (p=0.002 n=15+13)
Template-8                 42.0ms ± 1%    41.8ms ± 2%  -0.37%  (p=0.023 n=14+15)
TimeParse-8                 181ns ± 0%     180ns ± 1%  -0.18%  (p=0.014 n=12+13)
TimeFormat-8                240ns ± 0%     242ns ± 1%  +0.69%  (p=0.000 n=12+15)
[Geo mean]                 35.2µs         35.1µs       -0.43%

name                     old speed      new speed      delta
GobDecode-8               197MB/s ± 1%   198MB/s ± 0%  +0.49%  (p=0.000 n=15+14)
GobEncode-8               281MB/s ± 0%   281MB/s ± 0%    ~     (p=0.419 n=15+14)
Gzip-8                    115MB/s ± 0%   115MB/s ± 0%  +0.52%  (p=0.000 n=13+13)
Gunzip-8                  786MB/s ± 0%   781MB/s ± 0%  -0.60%  (p=0.000 n=15+15)
JSONEncode-8              278MB/s ± 1%   280MB/s ± 0%  +0.69%  (p=0.000 n=14+14)
JSONDecode-8             62.3MB/s ± 1%  63.1MB/s ± 1%  +1.29%  (p=0.000 n=14+14)
GoParse-8                21.9MB/s ± 2%  22.0MB/s ± 1%    ~     (p=0.205 n=15+15)
RegexpMatchEasy0_32-8     709MB/s ± 0%   697MB/s ± 0%  -1.65%  (p=0.000 n=14+15)
RegexpMatchEasy0_1K-8    7.34GB/s ± 0%  7.37GB/s ± 0%  +0.43%  (p=0.000 n=15+15)
RegexpMatchEasy1_32-8     783MB/s ± 2%   790MB/s ± 0%  +0.88%  (p=0.000 n=15+13)
RegexpMatchEasy1_1K-8    4.77GB/s ± 1%  4.66GB/s ± 1%  -2.23%  (p=0.000 n=15+15)
RegexpMatchMedium_32-8   41.0MB/s ± 7%  43.3MB/s ± 0%    ~     (p=0.360 n=15+15)
RegexpMatchMedium_1K-8   42.5MB/s ± 6%  43.8MB/s ± 6%  +3.07%  (p=0.004 n=15+15)
RegexpMatchHard_32-8     29.2MB/s ± 1%  29.3MB/s ± 1%  +0.41%  (p=0.006 n=15+14)
RegexpMatchHard_1K-8     31.1MB/s ± 0%  31.1MB/s ± 0%    ~     (p=0.495 n=12+14)
Revcomp-8                 718MB/s ± 0%   720MB/s ± 0%  +0.23%  (p=0.002 n=15+13)
Template-8               46.3MB/s ± 1%  46.4MB/s ± 2%  +0.38%  (p=0.021 n=14+15)
[Geo mean]                205MB/s        206MB/s       +0.57%

Change-Id: Ibd1afdf8b6c0b08087dcc3acd8f943637eb95ac0
Reviewed-on: https://go-review.googlesource.com/c/go/+/344930
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
2021-08-25 19:45:20 +00:00
Joe Tsai
5baf60d472 bytes, strings: optimize Trim for single byte cutsets
Using the latest version of all modules known by the module proxy,
we determine that for all Trim usages (and related functionality):
* 76.6% have cutsets of len=1, and
* 13.4% have cutsets of len=2.

Given that a vast majority of usages only have a cutset of len=1,
we should more heavily optimize for that situation.
Previously, there was some optimization for cutsets of len=1,
but it's within the internal makeCutsetFunc function.
This is sub-optimal as it incurs an allocation in makeCutsetFunc
for the closure over that single byte.

This CL removes special-casing of one-byte cutsets from makeCutsetFunc
and instead distributes it directly in Trim, TrimRight, and TrimLeft.
Whether we should distribute the entire ASCII cutset logic into Trim
is a future CL that should be discussed and handled separately.
The evidence for multibyte cutsets is not as obviously compelling.

name                old time/op  new time/op  delta
bytes/TrimByte-4    84.1ns ± 2%   7.5ns ± 1%  -91.10%  (p=0.000 n=9+7)
strings/TrimByte-4  86.2ns ± 3%   8.3ns ± 1%  -90.33%  (p=0.000 n=9+10)

Fixes #46446

Change-Id: Ia0e31a8384c3ce111ae35465605bcec45df2ebec
Reviewed-on: https://go-review.googlesource.com/c/go/+/323318
Trust: Joe Tsai <joetsai@digital-static.net>
Run-TryBot: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-25 19:29:15 +00:00
korzhao
3d667671ad cmd/compile: fix function contains no TParam in generic function
Fixes #47948

Change-Id: I446a9548265d195ae4d88aff6b1361474d1b6214
Reviewed-on: https://go-review.googlesource.com/c/go/+/344910
Trust: Alexander Rakoczy <alex@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Alexander Rakoczy <alex@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-25 19:06:16 +00:00
korzhao
4f2ebfe34b cmd/compile: allow embed into any byte slice type
Fixes #47735

Change-Id: Ia21ea9a67f36a3edfef1b299ae4f3b00c306cd68
Reviewed-on: https://go-review.googlesource.com/c/go/+/342851
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Alexander Rakoczy <alex@golang.org>
2021-08-25 18:31:07 +00:00
korzhao
d2f002cb39 time/format: avoid growslice in time.String()/time.GoString()
Pre-allocate the slice of buf with enough capacity
to avoid growslice calls.

benchmark                   old ns/op     new ns/op     delta
BenchmarkTimeString-4       493           409           -17.12%
BenchmarkTimeGoString-4     309           182           -41.30%

benchmark                   old allocs     new allocs     delta
BenchmarkTimeString-4       5              3              -40.00%
BenchmarkTimeGoString-4     4              1              -75.00%

benchmark                   old bytes     new bytes     delta
BenchmarkTimeString-4       152           128           -15.79%
BenchmarkTimeGoString-4     248           80            -67.74%

Change-Id: I64eabe2ab0b3d4a846453c2e8e548a831d720b8c
Reviewed-on: https://go-review.googlesource.com/c/go/+/343971
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Alexander Rakoczy <alex@golang.org>
2021-08-25 18:27:41 +00:00