aboutsummaryrefslogtreecommitdiff
path: root/test
AgeCommit message (Collapse)Author
2021-08-27cmd/compile: delay fillinMethods to deal with mutually-recursive typesDan Scales
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-26cmd/compile: fix reference to generic type needed by crawlerDan Scales
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-25cmd/compile: always accept 1.18 syntax but complain if not 1.18Robert Griesemer
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-25cmd/compile: generic SSA rules for simplifying 2 and 3 operand integer ↵Jake Ciolek
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-25cmd/compile: fix function contains no TParam in generic functionkorzhao
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-25cmd/compile: fix stencil call expression.wdvxdr
Fixes: #47878 Change-Id: I369350813726fd518b4eab2b98f43bf031a6dee6 Reviewed-on: https://go-review.googlesource.com/c/go/+/344210 Reviewed-by: Dan Scales <danscales@google.com> Trust: Dan Scales <danscales@google.com> Trust: Keith Randall <khr@golang.org> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-08-25cmd/compile: fix CheckSize() calculation for -G=3 and stencilsDan Scales
Because the Align/Width of pointer types are always set when created, CalcSize() never descends past a pointer. Therefore, we need to do CheckSize() at every level when creating type. We need to do this for types creates by types2-to-types1 conversion and also by type substitution (mostly for stenciling). We also need to do Defer/ResumeCheckSize() at the top level in each of these cases to deal with potentially recursive types. These changes fix issue #47929 and also allow us to remove the special-case CheckSize() call that causes the problem for issue #47901. Fixes #47901 Fixes #47929 Change-Id: Icd8192431c145009cd6df2f4ade6db7da0f4dd3e Reviewed-on: https://go-review.googlesource.com/c/go/+/344829 Trust: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2021-08-25test: add test that caused gofrontend compiler crashIan Lance Taylor
Updates https://gcc.gnu.org/PR101994 Change-Id: I50dcb90e315792efd7d83b496034ad33b5f199e9 Reviewed-on: https://go-review.googlesource.com/c/go/+/343874 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2021-08-25test: add test case that gofrontend miscompiledIan Lance Taylor
For #47771 Change-Id: I99dfdd48def756bde68445b50741afd6d86b6cf2 Reviewed-on: https://go-review.googlesource.com/c/go/+/344169 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2021-08-25cmd/compile: fix checkptr false positive for (*[Big]T)(ptr)[:n:n] patternCuong Manh Le
The checkptr instrumentation is currently inserted before slice operation has validated that n <= Big. So instead of panic, checkptr have false positive throws. To fix this, just insert the checkptr instrumentation after the bound checking during SSA generation. Fixes #46938 Change-Id: I9dbf84441c711842ccc883f3654ca8766ac696d8 Reviewed-on: https://go-review.googlesource.com/c/go/+/343972 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-24cmd/compile: mark ODYNAMICDOTTYPE as an expression that can panicKeith Randall
Fixes #47924 Change-Id: I4325b3c4ed9d369d9ea778478285436e1b2ab08a Reviewed-on: https://go-review.googlesource.com/c/go/+/344571 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-24cmd/compile: fix naming of types inside instantiationsDan Scales
Issues 47713 and 47877 were both due to problems with the names used for instantiated functions/methods, which must be in sync with the names used by types2. - Switched to using NameString() for writing out type arguments in instantiation names. This ensures that we are always adding the package to type names even for the local package. Previously, we were explicitly adding the package name for local packages, but that doesn't handle the case when the local type is embedded inside a pointer or slice type. By switching to NameString(), we fix #47713. - types1 and types2 write out 'interface {' differently (vs. 'interface{') and we were already handling that. But we needed to add similar code to handle 'struct {' vs 'struct{'. This fixes issue #47877. While fixing these bugs, I also moved some duplicated code (which include some of the changes above) into a common function addTargs(). I also moved InstType() name to subr.go, and renamed: MakeInstName -> MakeFuncInstSym and MakeDictName -> MakeDictSym. Also removed a couple of ".inst..inst." prefix checks which are irrelvant now, since we don't add ".inst." anymore to function instantiations. Fixes #47713 Fixes #47877 Fixes #47922 Change-Id: I19e9a073451f3ababd8ec31b6608cd79ba8cba36 Reviewed-on: https://go-review.googlesource.com/c/go/+/344613 Trust: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2021-08-24cmd/compile: change irgen to generate exprs/stmts after decls processedMatthew Dempsky
This CL changes irgen to wait until all top-level declarations have been processed before constructing any expressions or statements that reference them. This is the same approach that typecheck used. Mechanically, it splits varDecl and funcDecl (the two top-level declarations that can generate/contain code) into a part that runs immediately for constructing the ir.ONAME, and then a separate task that runs later to handle the code. It also adds an exprStmtOK flag to indicate when it's actually safe to start constructing (non-trivial) expressions and statements. Fixes #47928. Change-Id: I51942af6823aa561d341e2ffc1142948da025fa2 Reviewed-on: https://go-review.googlesource.com/c/go/+/344649 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Dan Scales <danscales@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> Reviewed-by: Dan Scales <danscales@google.com>
2021-08-24cmd/compile: reuse same node for global dictionariesDan Scales
Change stencil.go:getDictionaryValue() and reflect.go:getDictionary() to reuse any existing name node that has been created for the needed global dictionary. Otherwise, these functions may set the Def on a specific dictionary sym to two different name nodes, which means the first node will not satisfy the invariant 'n.Sym().Def.(*ir.Name) == n' (which is the assertion in this issue). Fixes #47896 Change-Id: I1e7ae1efd077a83c7878b4342feb6d28d52476cc Reviewed-on: https://go-review.googlesource.com/c/go/+/344609 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com>
2021-08-23cmd/compile: fixes for non-constant Sizeof/Alignof/OffsetofDan Scales
Includes Robert's suggested fix in validate.go to not fail on non-constant alignof/offsetof/sizeof calls. Further changes to wait on transforming these calls until stenciling time, when we can call EvalConst() to evaluate them once all the relevant types are known. Added a bunch of new tests for non-constant Sizeof/Alignof/Offsetof. Fixes #47716 Change-Id: I469af888eb9ce3a853124d919eda753971009b3e Reviewed-on: https://go-review.googlesource.com/c/go/+/344250 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com>
2021-08-23cmd/compile: do not mark arrays used for map initialization noalgMartin Möhrmann
Arrays marked noalg are created by the compiler to hold keys and values to initialize map literals. The ssa backend creates a pointer type for the array type when creating an OpAddr while processing the loop that initializes the map from the arrays. The pointer type does not inherit the noalg property but points to the noalg array type. This causes values created through reflect of types that should be equal to compare unequal because the noalg and alg type might be compared and these are not the same. A similar problem occurred in #32595 for argument arrays of defer structs. Created #47904 to track improve noalg handling to be able to reintroduce this optimization again. Fixes #47068 Change-Id: I87549342bd404b98d71a3c0f33e3c169e9d4efc8 Reviewed-on: https://go-review.googlesource.com/c/go/+/344349 Trust: Martin Möhrmann <martin@golang.org> Run-TryBot: Martin Möhrmann <martin@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-23cmd/compile: don't emit write barriers for offsets of global addresseszikaeroh
Currently, write barriers aren't emitted for global addresses, but they are emitted for addresses offset of global addresses. This CL changes IsGlobalAddr to recognize offsets of global addresses as globals too, removing write barriers for staticuint64s based addresses. The logic added is the same as used in IsStackAddr. Updates #37612 Change-Id: I537579f85b9ad02987d94f3ee0b4508b90097959 Reviewed-on: https://go-review.googlesource.com/c/go/+/342129 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Trust: Michael Knyszek <mknyszek@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-08-23cmd/compile: always remove receiver type from instantiated method valuesKeith Randall
If a type T has a method foo, then var t T var i interface{} = t.foo The type of foo is a method type, but the type of t.foo should be a standard function type. Make sure we always do that conversion. Fixes #47775 Change-Id: I464ec792196b050aba1914e070a4ede34bfd0bfa Reviewed-on: https://go-review.googlesource.com/c/go/+/343881 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dan Scales <danscales@google.com>
2021-08-23cmd/compile: copy captured dictionary var to local varKeith Randall
When starting a closure that needs a dictionary, copy the closure variable to a local variable. This lets child closures capture that dictionary variable correctly. This is a better fix for #47684, which does not cause problems like #47723. Fixes #47723 Update #47684 Change-Id: Ib5d9ffc68a5142e28daa7d0d75683e7a35508540 Reviewed-on: https://go-review.googlesource.com/c/go/+/343871 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-23cmd/compile: fixing 15.go for -G=3Dan Scales
Required two changes: - avoid creating a closure in the case where the actual receiver of an embedded method is not generic even though the base operand of the selector is generic. This is similar to the test suggested by wayne zuo - I thought it was clear in buildClosure, and easier to comment. - Propagate //go:nointerface to base generic methods and then to instantiations. Change-Id: If30c834e4223c2639b7f7e74d44e6087aa9ccd76 Reviewed-on: https://go-review.googlesource.com/c/go/+/344251 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Wayne Zuo <wdvxdr1123@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Trust: Dan Scales <danscales@google.com>
2021-08-21cmd/compile: enable -G=3 by defaultMatthew Dempsky
This CL changes cmd/compile's -G flag's default from 0 to 3, which enables use of the new types2 type checker and support for type parameters. The old type checker is still available with -gcflags=all=-G=0. The CL also updates the regress test harness to account for the change in default behavior (e.g., to expect known types2 changes/failures). However, the -G=0 mode is still being tested for now. Copy of CL 340914 by danscales@, minus the cmd/internal/objabi.AbsFile change (handled instead by CL 343731) and rebased to master branch. Updates #43651. Change-Id: I1f62d6c0a3ff245e15c5c0e8f3d922129fdd4f29 Reviewed-on: https://go-review.googlesource.com/c/go/+/343732 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2021-08-20test/typeparam: add a test case for issue46591korzhao
Fixes #46591 Change-Id: I4875092ecd7760b0cd487e793576ef7a9a569a0e Reviewed-on: https://go-review.googlesource.com/c/go/+/343970 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-08-20test: enable regabi test on arm64Cuong Manh Le
CL 324890 turned on register ABI by default on ARM64, causing neither live.go nor live_regabi.go is run on ARM64. This CL enables live_regabi.go test for ARM64. Change-Id: I0c483a38b761c5a6f1fa9a5b3324b5da64907e61 Reviewed-on: https://go-review.googlesource.com/c/go/+/343531 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-19cmd/compile: add support for //go:nointerface for -G=3Matthew Dempsky
This is used within Google's internal code repo, so getting it working is a pre-req for enabling -G=3 by default. Change-Id: Icbc570948c852ca09cdb2a59f778140f620244b2 Reviewed-on: https://go-review.googlesource.com/c/go/+/343429 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-08-18cmd/compile: only use dictionaries for conversions to type parametersKeith Randall
Conversions to regular concrete types should not be rewritten during stenciling. Fixes #47740 Change-Id: I2b45e22f962dcd2e18bd6cc876ebc0f850860822 Reviewed-on: https://go-review.googlesource.com/c/go/+/342989 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
2021-08-17all: fix typosYasuhiro Matsumoto
Change-Id: I83180c472db8795803c1b9be3a33f35959e4dcc2 Reviewed-on: https://go-review.googlesource.com/c/go/+/336889 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2021-08-17cmd/compile: fix CONVIFACE case converting interface to empty interfaceDan Scales
We need an extra case in convertToDictionary. In the case of an operand which is an interface and converting to an empty interface, we don't want to get the run-time type from the dictionary (which would be the run-time type of the interface). We want to do a type-assert to the empty interface. Change-Id: I414247210168153151272fab198bfe82ad7b1567 Reviewed-on: https://go-review.googlesource.com/c/go/+/342009 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com>
2021-08-16cmd/compile: fix panic with dead hidden closuresCuong Manh Le
Currently, for hidden closures, we always push them to compile queue during typechecking. If the hidden closure is discarded from the outer function body during deadcode, any desugaring phase after deadcode won't be applied to the closure. Thus, some un-expected OPs are passed to downstream passes, which they can't handle, the compiler goes boom! To fix this, we keep track of discarded hidden closures during deadcode pass, and won't compile them then. Fixes #47712 Change-Id: I078717d5d1f4f2fa39cbaf610cfffbb042e70ceb Reviewed-on: https://go-review.googlesource.com/c/go/+/342350 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-16cmd/compile: fix dictionaries for nested closuresKeith Randall
Capturing dictionary closure variables is ok. Fixes #47684 Change-Id: I049c87117915e0c5a172b9665bfac2f91064b2d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/342050 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-16cmd/compile: intrinsify Mul64 on riscv64Meng Zhuo
According to RISCV instruction set manual v2.2 Sec 6.1 MULHU followed by MUL will be fused into one multiply by microarchitecture Benchstat on Hifive unmatched: name old time/op new time/op delta Hash8Bytes 245ns ± 3% 186ns ± 4% -23.99% (p=0.000 n=10+10) Hash320Bytes 1.94µs ± 1% 1.31µs ± 1% -32.38% (p=0.000 n=9+10) Hash1K 5.84µs ± 0% 3.84µs ± 0% -34.20% (p=0.000 n=10+9) Hash8K 45.3µs ± 0% 29.4µs ± 0% -35.04% (p=0.000 n=10+10) name old speed new speed delta Hash8Bytes 32.7MB/s ± 3% 43.0MB/s ± 4% +31.61% (p=0.000 n=10+10) Hash320Bytes 165MB/s ± 1% 244MB/s ± 1% +47.88% (p=0.000 n=9+10) Hash1K 175MB/s ± 0% 266MB/s ± 0% +51.98% (p=0.000 n=10+9) Hash8K 181MB/s ± 0% 279MB/s ± 0% +53.94% (p=0.000 n=10+10) Change-Id: I3561495d02a4a0ad8578e9b9819bf0a4eaca5d12 Reviewed-on: https://go-review.googlesource.com/c/go/+/329970 Reviewed-by: Joel Sing <joel@sing.id.au> Run-TryBot: Joel Sing <joel@sing.id.au> TryBot-Result: Go Bot <gobot@golang.org> Trust: Meng Zhuo <mzh@golangcn.org>
2021-08-13test: change issue10441.go from "build" to "compile"Ian Lance Taylor
We use "build" for tests in the main package with a main function. We use "compile" for tests that are not in the main package. Change-Id: I9876b55a9e4672277483fd24e69058d439c66658 Reviewed-on: https://go-review.googlesource.com/c/go/+/334329 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-08-13test: add test case for CL 340609Ian Lance Taylor
The first version of CL 340609 for gofrontend passed all existing tests, but not this one. For #42076 Change-Id: I6491e2f186091bdae140b7f7befa511806a6478a Reviewed-on: https://go-review.googlesource.com/c/go/+/340950 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2021-08-13test: add test case that caused a gofrontend compiler crashIan Lance Taylor
For #47131 Change-Id: Ie2d5a2bd3dceec607544c43e6dc68bd5ea353091 Reviewed-on: https://go-review.googlesource.com/c/go/+/335172 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-08-10[dev.typeparams] cmd/compile: handle interface type parameters in type switchesKeith Randall
Change-Id: I9bba21a64d7e9f42395b6fcdf8aa3ca01cf131dc Reviewed-on: https://go-review.googlesource.com/c/go/+/340912 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
2021-08-10[dev.typeparams] cmd/compile/internal/types2: parameterized functions must ↵Robert Griesemer
have a body Add the respective check and add missing bodies to tests. Use {} as body for functions that don't return a result. Use { panic(0) } as body for functions that return a result. For #47069. Change-Id: Ia5d7525c9c036baf8a955d13bff448401e08235e Reviewed-on: https://go-review.googlesource.com/c/go/+/340911 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-09[dev.typeparams] cmd/compile: call transformArgs before early typecheckaste ↵Dan Scales
in noder In the cases where we do an early call to typecheckaste() in noder to expose CONVIFACE nodes, we need a preceding call to transformArgs(). This is needed to allow typecheckaste() to run correctly, in the case of f(g()), where g has multiple return values. I also cleaned up the code a bit and commented the code in Call(), and we do the call to typecheckaste() in several more cases. In stencil.go:stencil(), I moved the transformCall earlier for the OCALLMETH/ODOTMETH case, just as I did in my previous CL for OCALL/OFUNCINST. By doing this, transformArgs no longer needs to deal with the extra dictionary args. Therefore, I was able to simply transformArgs() to look like typecheckargs() again, and make use of RewriteMultiValue directly. Updates #47514 Change-Id: I49eb82ac05707e50c2e2fb03e39458a70491d406 Reviewed-on: https://go-review.googlesource.com/c/go/+/340531 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2021-08-09[dev.typeparams] cmd/compile: implement generic type switchesKeith Randall
Add a new dynamicType node, which is used as a case entry when the type being switched to is generic. Change-Id: Ice77c6f224b8fdd3ff574fdf4a8ea5f6c7ddbe75 Reviewed-on: https://go-review.googlesource.com/c/go/+/339429 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
2021-08-09[dev.typeparams] cmd/compile: simplify interface conversionsKeith Randall
Simplify the implementation of interface conversions in the compiler. Don't pass fields that aren't needed (the data word, usually) to the runtime. For generics, we need to put a dynamic type in an interface. The new dataWord function is exactly what we need (the type word will come from a dictionary). Change-Id: Iade5de5c174854b65ad248f35c7893c603f7be3d Reviewed-on: https://go-review.googlesource.com/c/go/+/340029 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-06[dev.typeparams] cmd/compile/internal/types2: fix make with type parameter ↵Robert Griesemer
argument For make with a type parameter argument, the structural type of the type parameter's constraint determines what make is making. Change-Id: I3b48f8ce3236b7624e0638b5f5be208c5915c987 Reviewed-on: https://go-review.googlesource.com/c/go/+/339899 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-06[dev.typeparams] cmd/compile: make sure closures inside generic funcs are ↵Dan Scales
not compiled Closures inside generic functions were being added to the g.target.Decls list during noding, just like other closures. We remove generic functions/methods from g.target.Decls, so they don't get compiled (they're only available for export and stenciling). Most closures inside generic functions/methods were similarly being removed from g.target.Decls, because they have a generic parameter. But we need to ensure no closures in generic function/methods are left remaining in g.target.Decls, since we don't want them transformed and compiled. So, we set a flag in (*irgen) that records when we are noding a top-level generic function/method, and don't add any closures to g.target.Decls when the flag is true. Updates #47514 Change-Id: Id66b4c41d307ffa8f54cab6ce3646ade81606862 Reviewed-on: https://go-review.googlesource.com/c/go/+/340258 Trust: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2021-08-05[dev.typeparams] cmd/compile/internal/types2: implement type sets with term ↵Robert Griesemer
lists This CL resolves several known issues and TODOs. - Represent type sets with term lists and using term list abstractions. - Represent Unions internally as a list of (syntactical) terms. Use term operations to print terms and detect overlapping union entries. - Compute type sets corresponding to unions lazily, on demand. - Adjust code throughout. - Adjusted error check in test/typeparam/mincheck.dir/main.go to make test pass. Change-Id: Ib36fb7e1d343c2b6aec51d304f0f7d1ad415f999 Reviewed-on: https://go-review.googlesource.com/c/go/+/338310 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-05[dev.typeparams] cmd/compile: fixing case where type arg is an interfaceDan Scales
In this case, we can't use an itab for doing a bound call, since we're converting from an interface to an interface. We do a static or dynamic type assert in new function assertToBound(). The dynamic type assert in assertToBound() is only needed if a bound is parameterized. In that case, we must do a dynamic type assert, and therefore need a dictionary entry for the type bound (see change in getGfInfo). I'm not sure if we can somehow limit this case, since using an interface as a type arg AND having the type bound of the type arg be parameterized is a very unlikely case. Had to add the TUNION case to parameterizedBy1() (which is only used for extra checking). Added a bunch of these test cases to 13.go, which now passes. Change-Id: Ic22eed637fa879b5bbb46d36b40aaad6f90b9d01 Reviewed-on: https://go-review.googlesource.com/c/go/+/339898 Trust: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2021-08-04[dev.typeparams] cmd/compile: put shape types in their own packageKeith Randall
Put shape types in the top level package called ".shape". Name them using the serialization of the shape name, instead of the .shapeN names. This allows the linker to deduplicate instantiations across packages. Not sure that this is entirely correct, as shapes in this package may reference other packages (e.g. a field of a struct). But it seems to work for now. For the added test, when you look at the resulting binary (use the -k option with run.go) it has only one instantiation of F, and 4 call sites: $ objdump -d a.exe | grep _a\.F 1053cb0: e8 8b 00 00 00 callq 139 <_a.F[.shape.*uint8]> 1053ce9: e8 52 00 00 00 callq 82 <_a.F[.shape.*uint8]> _a.F[.shape.*uint8]: 1053d90: e8 ab ff ff ff callq -85 <_a.F[.shape.*uint8]> 1053dc9: e8 72 ff ff ff callq -142 <_a.F[.shape.*uint8]> Change-Id: I627f7e50210aabe4a10d0e2717d87b75ac82e99b Reviewed-on: https://go-review.googlesource.com/c/go/+/339595 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-03[dev.typeparams] cmd/compile: make softfloat mode work with register ABICherry Mui
Previously, softfloat mode does not work with register ABI, mainly because the compiler doesn't know how to pass floating point arguments and results. According to the ABI it should be passed in FP registers, but there isn't any in softfloat mode. This CL makes it work. When softfloat is used, we define the ABI as having 0 floating point registers (because there aren't any). The integer registers are unchanged. So floating point arguments and results are passed in memory. Another option is to pass (the bit representation of) floating point values in integer registers. But this complicates things because it'd need to reorder integer argument registers. Change-Id: Ibecbeccb658c10a868fa7f2dcf75138f719cc809 Reviewed-on: https://go-review.googlesource.com/c/go/+/327274 Trust: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2021-07-31[dev.typeparams] cmd/compile: make all pointer types have the same shapeKeith Randall
Except unsafe.Pointer. It has a different Kind, which makes it trickier. Change-Id: I12582afb6e591bea35da9e43ac8d141ed19532a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/338749 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-07-30[dev.typeparams] cmd/compile: allow types with the same underlying type to ↵Keith Randall
have the same shape First baby step to sharing the underlying implementation among several types. Change-Id: I6a156176d2b7f0131a87285a03b881ce380c26ed Reviewed-on: https://go-review.googlesource.com/c/go/+/338610 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-07-29[dev.typeparams] cmd/compile: handle meth expressions on typeparamsDan Scales
Rewrite a method expression such as 'T.String' (where T is type param and String is part of its type bound Stringer) as: func(rcvr T, other params...) { return Stringer(rcvr).String(other params...) } New function buildClosure2 to create the needed closure. The conversion Stringer(rcvr) uses the dictionary in the outer function. For a method expression like 'Test[T].finish' (where finish is a method of Test[T]), we can already deal with this in buildClosure(). We just need fix transformDot() to allow the method lookup to fail, since shapes have no methods on them. That's fine, since for any instantiated receiver type, we always use the methods on the generic base type. Also removed the OMETHEXPR case in the main switch of node(), which isn't needed any (and removes one more potential unshapify). Also, fixed two small bugs with handling closures that have generic params or generic captured variables. Need to set the instInfo for the closure in the subst struct when descending into a closure during genericSubst() and was missing initializing the startItabConv and gfInfo fields in the closure info. Change-Id: I6dadedd1378477936a27c9c544c014cd2083cfb7 Reviewed-on: https://go-review.googlesource.com/c/go/+/338129 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2021-07-29[dev.typeparams] cmd/compile: implement generic .(T) operationsKeith Randall
Introduce new dynamic dottype operations which take a dynamic instead of static type to convert to. Change-Id: I5824a1fea056fe811b1226ce059e1e8da1baa335 Reviewed-on: https://go-review.googlesource.com/c/go/+/337609 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-07-28[dev.typeparams] test: rename blank functionsMatthew Dempsky
This CL renames blank functions in the test/ directory so that they don't rely on the compiler doing anything more than typechecking them. In particular, I ran this search to find files that used blank functions and methods: $ git grep -l '^func.*\b_(' | xargs grep -n '^' | grep '\.go:1:' | grep -v '// errorcheck$' I then skipped updating a few files: * blank.go * fixedbugs/issue11699.go * fixedbugs/issue29870.go These tests specifically check that blank functions/methods work. * interface/fail.go Not sure the motivation for the blank method here, but it's empty anyway. * typeparam/tparam1.go Type-checking test, but uses "-G" (to use types2 instead of typecheck). Updates #47446. Change-Id: I9ec1714f499808768bd0dcd7ae6016fb2b078e5e Reviewed-on: https://go-review.googlesource.com/c/go/+/338094 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-07-28[dev.typeparams] test/typeparam: gofmt -wMatthew Dempsky
We don't usually reformat the test directory, but all of the files in test/typeparam are syntactically valid. I suspect the misformattings here are because developers aren't re-installing gofmt with -tags=typeparams, not intentionally exercising non-standard formatting. Change-Id: I3767d480434c19225568f3c7d656dc8589197183 Reviewed-on: https://go-review.googlesource.com/c/go/+/338093 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>