summaryrefslogtreecommitdiff
path: root/src/cmd/compile
Commit message (Collapse)AuthorAgeFilesLines
* cmd/compile: enable more lenient type inference for untyped argumentsRobert Griesemer2023-05-182-4/+6
| | | | | | | | | | | | | | | | | This enables the implementation for proposal #58671, which is a likely accept. By enabling it early we get a bit extra soak time for this feature. The change can be reverted trivially, if need be. For #58671. Change-Id: Id6c27515e45ff79f4f1d2fc1706f3f672ccdd1ab Reviewed-on: https://go-review.googlesource.com/c/go/+/495955 Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/compile: build compiler with PGOCherry Mui2023-05-172-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reapplies CL 451292, which is reverted at CL 495475. The failure is fixed at CL 495595. Build the compiler with PGO. As go build -pgo=auto is enabled by default, we just need to store a profile in the compiler's directory. The profile is collected from building all std and cmd packages on Linux/AMD64 machine, using profile.sh. This improves the compiler speed. On Linux/AMD64, name old time/op new time/op delta Template 138ms ± 5% 136ms ± 4% -1.44% (p=0.005 n=36+39) Unicode 147ms ± 4% 140ms ± 4% -4.99% (p=0.000 n=40+39) GoTypes 780ms ± 3% 778ms ± 4% ~ (p=0.172 n=39+39) Compiler 105ms ± 5% 99ms ± 7% -5.64% (p=0.000 n=40+40) SSA 5.83s ± 6% 5.80s ± 6% ~ (p=0.556 n=40+40) Flate 89.0ms ± 5% 87.0ms ± 6% -2.18% (p=0.000 n=40+40) GoParser 172ms ± 4% 167ms ± 4% -2.72% (p=0.000 n=39+40) Reflect 333ms ± 4% 333ms ± 3% ~ (p=0.426 n=40+39) Tar 128ms ± 4% 126ms ± 4% -1.82% (p=0.000 n=39+39) XML 173ms ± 4% 170ms ± 4% -1.39% (p=0.000 n=39+40) [Geo mean] 253ms 248ms -2.13% The profile is pretty transferable. Using the same profile, we see a bigger win on Darwin/ARM64, name old time/op new time/op delta Template 71.0ms ± 2% 68.3ms ± 2% -3.90% (p=0.000 n=20+20) Unicode 71.8ms ± 2% 66.8ms ± 2% -6.90% (p=0.000 n=20+20) GoTypes 444ms ± 1% 428ms ± 1% -3.53% (p=0.000 n=19+20) Compiler 48.9ms ± 3% 45.6ms ± 3% -6.81% (p=0.000 n=20+20) SSA 3.25s ± 2% 3.09s ± 1% -5.03% (p=0.000 n=19+20) Flate 44.0ms ± 2% 42.3ms ± 2% -3.72% (p=0.000 n=19+20) GoParser 76.7ms ± 1% 73.5ms ± 1% -4.15% (p=0.000 n=18+19) Reflect 172ms ± 1% 165ms ± 1% -4.13% (p=0.000 n=20+19) Tar 63.1ms ± 1% 60.4ms ± 2% -4.24% (p=0.000 n=19+20) XML 83.2ms ± 2% 79.2ms ± 2% -4.79% (p=0.000 n=20+20) [Geo mean] 127ms 121ms -4.73% Change-Id: Ifbe35e48b3ea3b29430249b4667d2df8a2515aeb Reviewed-on: https://go-review.googlesource.com/c/go/+/495596 Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
* cmd/compile: don't inline from norace packages in race modeCherry Mui2023-05-172-1/+26
| | | | | | | | | | | | | | | | | | | In race mode (or other instrumentation mode), if the caller is in a regular package and the callee is in a norace (or noinstrument) package, don't inline. Otherwise, when the caller is instumented it will also affect the inlined callee. An example is sync.(*Mutex).Unlock, which is typically not inlined but with PGO it can be inlined into a regular function, which is then get instrumented. But the rest of the sync package, in particular, the Lock function is not instrumented, causing the race detector to signal false race. Change-Id: Ia78bb602c6da63a34ec2909b9a82646bf20873f3 Reviewed-on: https://go-review.googlesource.com/c/go/+/495595 Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* go/types, types2: permit partially instantiated functions as function argumentsRobert Griesemer2023-05-163-51/+148
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This CL changes Checker.genericExprList such that it collects partially instantiated generic functions together with their (partial) type argument (and corresponding) expression lists, instead of trying to infer the missing type arguments in place or to report an error. Special care is being taken to explictly record expression types where needed (because we can't use one of the usual expr evaluators which takes care of that), or to track the correct instance expression for later recording with Checker.arguments. The resulting generic expression list is passed to Checker.arguments which is changed to accept explicit partial type argument (and corresponding) expression lists. The provided type arguments are fed into type inference, matching up with their respective type parameters (which were collected already, before this CL). If type inference is successful, the instantiated functions are recorded as needed. For now, the type argument expression lists are collected and passed along but not yet used. We may use them eventually for better error reporting. Fixes #59958. For #59338. Change-Id: I26db47ef3546e64553da49d62b23cd3ef9e2b549 Reviewed-on: https://go-review.googlesource.com/c/go/+/494116 Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Griesemer <gri@google.com>
* go/types, types2: remove superfluous argument test in Checker.argumentsRobert Griesemer2023-05-161-11/+0
| | | | | | | | | | | | | | | | | | | | | | | | There's only two places which call Checker.arguments: Checker.callExpr and Checker.builtin. Both ensure that the passed argument list doesn't contain type expressions, so we don't need that extra check at the start of Checker.arguments. The remaining check causes Checker.arguments to exit early if any of the passed arguments is invalid. This reduces the number of reported errors in rare cases but is executed all the time. If the extra errors are a problem, it would be better to not call Checker.arguments in the first place, or only do the extra check before Checker.arguments reports an error. Removing this code for now. Removes a long-standing TODO. Change-Id: Ief654b680eb6b6a768bb1b4c621d3c8169953f17 Reviewed-on: https://go-review.googlesource.com/c/go/+/495395 Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
* cmd/compile: call phiElimValue from removePhiArgJakub Ciolek2023-05-164-8/+2
| | | | | | | | | | | | | | | | | With the exception of the shortcircuit pass, removePhiArg is always unconditionally followed by phiElimValue. Move the phiElimValue inside removePhiArg. Resolves a TODO. See CL 357964 for more info. Change-Id: I8460b35864f4cd7301ba86fc3dce08ec8041da7f Reviewed-on: https://go-review.googlesource.com/c/go/+/465435 Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Jakub Ciolek <jakub@ciolek.dev>
* cmd/compile/internal/noder: suppress unionType consistency checkMatthew Dempsky2023-05-161-12/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | In the types1 universe, we only need to represent value types. For interfaces, this means we only need to worry about pure interfaces. A pure interface can embed a union type, but the overall union must be equivalent to "any". In go.dev/cl/458619, we changed the types1 reader to return "any", but to incorporate a consistency check to make sure this is valid. Unfortunately, a pure interface can actually still reference impure interfaces, and in general this is hard to check precisely without reimplementing a lot of types2 data structures and logic into types1. We haven't had any other reports of this check failing since 1.20, so it seems simplest to just suppress for now. Fixes #60117. Change-Id: I5053faafe2d1068c6d438b2193347546bf5330cd Reviewed-on: https://go-review.googlesource.com/c/go/+/495455 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com>
* Revert "cmd/compile: build compiler with PGO"Cherry Mui2023-05-162-21/+0
| | | | | | | | | | | | | This reverts CL 451292. Reason for revert: causes the racecompile builder failure. https://build.golang.org/log/32d2fc21bd6e3bd415495d04befe806c0f10ea8b Change-Id: I5863437d4b814712b1280a1c21ba86009c332645 Reviewed-on: https://go-review.googlesource.com/c/go/+/495475 Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
* cmd/compile: build compiler with PGOCherry Mui2023-05-162-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Build the compiler with PGO. As go build -pgo=auto is enabled by default, we just need to store a profile in the compiler's directory. The profile is collected from building all std and cmd packages on Linux/AMD64 machine, using profile.sh. This improves the compiler speed. On Linux/AMD64, name old time/op new time/op delta Template 138ms ± 5% 136ms ± 4% -1.44% (p=0.005 n=36+39) Unicode 147ms ± 4% 140ms ± 4% -4.99% (p=0.000 n=40+39) GoTypes 780ms ± 3% 778ms ± 4% ~ (p=0.172 n=39+39) Compiler 105ms ± 5% 99ms ± 7% -5.64% (p=0.000 n=40+40) SSA 5.83s ± 6% 5.80s ± 6% ~ (p=0.556 n=40+40) Flate 89.0ms ± 5% 87.0ms ± 6% -2.18% (p=0.000 n=40+40) GoParser 172ms ± 4% 167ms ± 4% -2.72% (p=0.000 n=39+40) Reflect 333ms ± 4% 333ms ± 3% ~ (p=0.426 n=40+39) Tar 128ms ± 4% 126ms ± 4% -1.82% (p=0.000 n=39+39) XML 173ms ± 4% 170ms ± 4% -1.39% (p=0.000 n=39+40) [Geo mean] 253ms 248ms -2.13% The profile is pretty transferable. Using the same profile, we see a bigger win on Darwin/ARM64, name old time/op new time/op delta Template 71.0ms ± 2% 68.3ms ± 2% -3.90% (p=0.000 n=20+20) Unicode 71.8ms ± 2% 66.8ms ± 2% -6.90% (p=0.000 n=20+20) GoTypes 444ms ± 1% 428ms ± 1% -3.53% (p=0.000 n=19+20) Compiler 48.9ms ± 3% 45.6ms ± 3% -6.81% (p=0.000 n=20+20) SSA 3.25s ± 2% 3.09s ± 1% -5.03% (p=0.000 n=19+20) Flate 44.0ms ± 2% 42.3ms ± 2% -3.72% (p=0.000 n=19+20) GoParser 76.7ms ± 1% 73.5ms ± 1% -4.15% (p=0.000 n=18+19) Reflect 172ms ± 1% 165ms ± 1% -4.13% (p=0.000 n=20+19) Tar 63.1ms ± 1% 60.4ms ± 2% -4.24% (p=0.000 n=19+20) XML 83.2ms ± 2% 79.2ms ± 2% -4.79% (p=0.000 n=20+20) [Geo mean] 127ms 121ms -4.73% Change-Id: I44735b3f7fd6903efbbe6b19c05dee874bea4c89 Reviewed-on: https://go-review.googlesource.com/c/go/+/451292 Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/compile: add more information to the bisect-verbose reportDavid Chase2023-05-162-5/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | running on cmd/compile/internal/testdata/inlines now shows: ``` --- change set #1 (enabling changes causes failure) b/b.go:16:6: loop variable i now per-iteration (loop inlined into b/b.go:10) b/b.go:16:6: loop variable i now per-iteration ./b/b.go:16:6: loop variable b.i now per-iteration (loop inlined into a/a.go:18) ./b/b.go:16:6: loop variable b.i now per-iteration (loop inlined into ./main.go:37) ./b/b.go:16:6: loop variable b.i now per-iteration (loop inlined into ./main.go:38) --- ``` and ``` --- change set #2 (enabling changes causes failure) ./main.go:27:6: loop variable i now per-iteration ./main.go:27:6: loop variable i now per-iteration (loop inlined into ./main.go:35) --- ``` Still unsure about the utility of mentioning the inlined occurrence, but better than mysteriously repeating the line over and over again. Change-Id: I357f5d419ab4928fa316f4612eec3b75e7f8ac34 Reviewed-on: https://go-review.googlesource.com/c/go/+/494296 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: David Chase <drchase@google.com>
* cmd/compile: make memcombine pass a bit more robust to reassociation of exprsKeith Randall2023-05-161-24/+17
| | | | | | | | | | | | | | | Be more liberal about expanding the OR tree. Handle any tree shape instead of a fully left or right associative tree. Also remove tail feature, it isn't ever needed. Change-Id: If16bebef94b952a604d6069e9be3d9129994cb6f Reviewed-on: https://go-review.googlesource.com/c/go/+/494056 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Ryan Berger <ryanbberger@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com>
* cmd/compile/internal/walk: delete statement that don't needcuiweixie2023-05-161-1/+0
| | | | | | | | | Change-Id: I7253aed4808a06379caebf0949aec0f305245d23 Reviewed-on: https://go-review.googlesource.com/c/go/+/494835 Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: xie cui <523516579@qq.com>
* cmd/compile: enhance tighten pass for memory valueseric fang2023-05-162-7/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [This is a roll-forward of CL 458755, which was reverted due to make.bash being broken on GOAMD64=v3. But it turned out that the problem was caused by wrong bswap/load rewrite rules, and it was fixed in CL 492616.] This CL enhances the tighten pass. Previously if a value has memory arg, then the tighten pass won't move it, actually if the memory state is consistent among definition and use block, we can move the value. This CL optimizes this case. This is useful for the following situation: b1: x = load(...mem) if(...) goto b2 else b3 b2: use(x) b3: some_op_not_use_x For the micro-benchmark mentioned in #56620, the performance improvement is about 15%. There's no noticeable performance change in the go1 benchmark. Fixes #56620 Change-Id: I36ea68bed384986cd3ae81cb9e6efe84bb213adc Reviewed-on: https://go-review.googlesource.com/c/go/+/492895 Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Eric Fang <eric.fang@arm.com>
* cmd/compile: update rules to generate more prefixed instructionsLynn Boger2023-05-153-141/+159
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This modifies some existing rules to allow more prefixed instructions to be generated when using GOPPC64=power10. Some rules also check if PCRel is available, which is currently supported for linux/ppc64le and linux/ppc64 (internal linking only). Prior to p10, DS-offset loads and stores had a 16 bit size limit for the offset field. If the offset of the data for load or store was beyond this range then an indexed load or store would be selected by the rules. In p10 the assembler can generate prefixed instructions in this case, but does not if an indexed instruction was selected during the lowering pass. This allows many more cases to use prefixed loads or stores, reducing function sizes and improving performance in some cases where the code change happens in key loops. For example in strconv BenchmarkAppendQuoteRune before: 12c5e4: 15 00 10 06 pla r10,1425660 12c5e8: fc c0 40 39 12c5ec: 00 00 6a e8 ld r3,0(r10) 12c5f0: 10 00 aa e8 ld r5,16(r10) After this change: 12a828: 15 00 10 04 pld r3,1433272 12a82c: b8 de 60 e4 12a830: 15 00 10 04 pld r5,1433280 12a834: c0 de a0 e4 Performs better in the second case. A testcase was added to verify that the rules correctly select a load or store based on the offset and whether power10 or earlier. Change-Id: I4335fed0bd9b8aba8a4f84d69b89f819cc464846 Reviewed-on: https://go-review.googlesource.com/c/go/+/477398 Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Archana Ravindar <aravind5@in.ibm.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com> Reviewed-by: Paul Murphy <murp@ibm.com>
* reflect: do not escape Value.TypeCherry Mui2023-05-121-5/+13
| | | | | | | | | | | | | | | | | | | Types are either static (for compiler-created types) or heap allocated and always reachable (for reflection-created types, held in the central map). So there is no need to escape types. With CL 408826 reflect.Value does not always escape. Some functions that escapes Value.typ would make the Value escape without this CL. Had to add a special case for the inliner to keep (*Value).Type still inlineable. Change-Id: I7c14d35fd26328347b509a06eb5bd1534d40775f Reviewed-on: https://go-review.googlesource.com/c/go/+/413474 Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/compile: remove post-inlining PGO graph dumpMichael Pratt2023-05-122-100/+0
| | | | | | | | | | | | | | | | | | | The RedirectEdges logic is fragile and not quite complete (doesn't update in-edges), which adds overhead to maintaining this package. In my opinion, the post-inlining graph doesn't provide as much value as the pre-inlining graph. Even the latter I am not convinced should be in the compiler rather than an external tool, but it is comparatively easier to maintain. Drop it for now. Perhaps we'll want it back in the future for tracking follow-up optimizations, but for now keep things simple. Change-Id: I3133a2eb97893a14a6770547f96a3f1796798d17 Reviewed-on: https://go-review.googlesource.com/c/go/+/494655 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Michael Pratt <mpratt@google.com>
* cmd/compile/internal/pgo: remove node weights from IRNodeMichael Pratt2023-05-121-66/+32
| | | | | | | | | | | | | | | | | | | | | | | Actual PGO operation doesn't use these weights at all. They are theoretically used when printing a dot graph for debugging, but that doesn't actually work because these weights are always zero. These fields are initialized by looking for a NodeMap entry with key {CallerName: sym, CalleeName: "", CallSiteOffset: 0}. These entries will never exist, as we never put entries in NodeMap without CalleeName. Since they aren't really used and don't work, just remove them entirely, which offers nice simplification. This leaves IRNode with just a single field. I keep the type around as a future CL will make the *ir.Func optional, allowing nodes with a name but no IR. Change-Id: I1646654cad1d0779ce071042768ffad2a7e6ff49 Reviewed-on: https://go-review.googlesource.com/c/go/+/494616 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Michael Pratt <mpratt@google.com>
* go/types: minor refactoring of missingMethod following CL 494615Rob Findley2023-05-121-4/+7
| | | | | | | | | | Make the refactoring suggested by gri@ in that CL. Change-Id: I6c363f3ba5aaa3c616d3982d998b989de7046a86 Reviewed-on: https://go-review.googlesource.com/c/go/+/494617 Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* go/types, types2: call recordInstance in instantiateSignatureRobert Griesemer2023-05-121-19/+12
| | | | | | | | | | | | | This matches the pattern we use for type instantiations and factors out the recordInstance and associated assert calls. Change-Id: Ib7731c0e619aca42f418cb2d9a153785aaf014cb Reviewed-on: https://go-review.googlesource.com/c/go/+/494457 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Griesemer <gri@google.com>
* go/types, types2: be sure to type-check wrong methods in missingMethodRob Findley2023-05-121-0/+4
| | | | | | | | | | | | | | | | In the case of a wrong method, we were not ensuring that it was type-checked before passing it to funcString. Formatting the missing method error message requires a fully set-up signature. Fixes #59848 Change-Id: I1467e036afbbbdd00899bfd627a945500dc709c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/494615 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
* cmd/compile/internal/pgo/internal/graph: delete dead codeMichael Pratt2023-05-112-329/+0
| | | | | | | | | | | | We don't use large swaths of this package. Delete the code. We can always bring it back later if needed. Change-Id: I6b39a73ed9c48d2d5b37c14763d7bb7956f3ef43 Reviewed-on: https://go-review.googlesource.com/c/go/+/494438 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
* cmd/compile/internal/pgo: move pprof graph to internal packageMichael Pratt2023-05-112-8/+9
| | | | | | | | | | | | | | | | | graph.go is a simplified fork of github.com/google/pprof/internal/graph, which is used as an intermediate data structure to construct the final graph exported by package pgo (IRGraph). Exporting both is a bit confusing as the former is unused outside of the package. Since the naming is also similar, move graph.go to its own package entirely. Change-Id: I2bccb3ddb6c3f63afb869ea9cf34d2a261cad058 Reviewed-on: https://go-review.googlesource.com/c/go/+/494437 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Michael Pratt <mpratt@google.com>
* cmd/compile: remove "WORK IN PROGRESS" from package pgoMichael Pratt2023-05-111-2/+0
| | | | | | | | | | | | Work continues on PGO, but the existing support is certainly working. Change-Id: Ic6724b9b3f174f24662468000d771f7651bb18b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/494435 Auto-Submit: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Commit-Queue: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/compile: remove go:wasmimport restrictionJohan Brandhorst-Satzkorn2023-05-111-4/+0
| | | | | | | | | | | | | | | Removes the package restriction on go:wasmimport, allowing the use of it globally and in user code. Fixes #59149 Change-Id: Ib26f628dc8dafb31388005b50449e91b47dab447 Reviewed-on: https://go-review.googlesource.com/c/go/+/489255 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Eli Bendersky <eliben@google.com> Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
* cmd/compile: remove debugging option InlineSCCOnePass from inlinerThan McIntosh2023-05-112-19/+8
| | | | | | | | | | | | | | | | Delete the "InlineSCCOnePass" debugging flag and the inliner fallback code that kicks in if it is used. The change it was intended to guard has been working on tip for some time, no need for the fallback any more. Updates #58905. Change-Id: I2e1dbc7640902d9402213db5ad338be03deb96c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/492015 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* internal/bisect: copy parser changes from CL 494177Russ Cox2023-05-111-22/+24
| | | | | | | | | | | x/tools/cmd/bisect is changing to emit hex skips for robustness. Update this copy of internal/bisect to understand them. Change-Id: Ie9445714e8e9fb594e656db2f94dcde9b6ce82d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/494178 Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* internal/abi: common up some offset/size functionsDavid Chase2023-05-101-7/+8
| | | | | | | | | Change-Id: I92eeed20af35c7dec309457a80b8fd44eb70b57f Reviewed-on: https://go-review.googlesource.com/c/go/+/467876 Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com>
* cmd/compile: add ability to print extra information in bisect outputRuss Cox2023-05-105-41/+45
| | | | | | | | Change-Id: I619c21ab9754f67b69215cfed238a3e489c7fbcf Reviewed-on: https://go-review.googlesource.com/c/go/+/493955 Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org>
* go/types, types2: move xlist next to targs in Checker.arguments signatureRobert Griesemer2023-05-102-6/+6
| | | | | | | | | | | | | | | | | targs and xlist belong together (xlist contains the type expressions for each of the type arguments). Also, in builtins.go, rename xlist to alist2 to avoid some confusion. Preparation for adding more parameters to the Checker.arguments signature. Change-Id: I960501cfd2b88410ec0d581a6520a4e80fcdc56a Reviewed-on: https://go-review.googlesource.com/c/go/+/494121 Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
* cmd/compile: add De Morgan's rewrite ruleStefan2023-05-102-0/+182
| | | | | | | | | | | | | | | Adds rules that rewrites statements such as ~P&~Q as ~(P|Q) and ~P|~Q as ~(P&Q), removing an extraneous instruction. Change-Id: Icedb97df741680ddf9799df79df78657173aa500 GitHub-Last-Rev: f22e2350c95e9052e990b2351c3c2b0af810e381 GitHub-Pull-Request: golang/go#60018 Reviewed-on: https://go-review.googlesource.com/c/go/+/493175 Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Stefan M <st3f4nm4d4@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
* go/types, types2: control type inference in Checker.funcInst via infer argumentRobert Griesemer2023-05-102-12/+30
| | | | | | | | | | | | | | | | | | | | | If the infer argument is true, funcInst behaves as before. If infer is false and there are not enough type arguments, rather then inferring the missing arguments and instantiating the function, funcInst returns the found type arguments. This permits the use of funcInst (and all the checks it does) to collect the type arguments for partially instantiated generic functions used as arguments to other functions. For #59338. Change-Id: I049034dfde52bd7ff4ae72964ff1708e154e5042 Reviewed-on: https://go-review.googlesource.com/c/go/+/494118 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
* go/types, types2: explicitly look for nil type arguments in inferRobert Griesemer2023-05-101-7/+13
| | | | | | | | | | | | | | | | | | | Don't assume we have all type arguments if the number of type arguments matches the number of type parameters. Instead, look explicitly for nil type arguments in the provided targs. Preparation for type inference with type arguments provided for type parameters of generic function arguments passed to other functions. For #59338. Change-Id: I00918cd5ed06ae3277b4e41a3641063e0f53fef0 Reviewed-on: https://go-review.googlesource.com/c/go/+/494115 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* all: fix a lot of commentscui fliter2023-05-107-7/+7
| | | | | | | | | | | | | Fix comments, including duplicate is, wrong phrases and articles, misspellings, etc. Change-Id: I8bfea53b9b275e649757cc4bee6a8a026ed9c7a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/493035 Reviewed-by: Benny Siegert <bsiegert@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
* cmd/compile: remove FS debug hash formRuss Cox2023-05-093-26/+20
| | | | | | | | | | | | | | | | | The FS form was only necessary for reliable hashes in tests, and for that we can use -trimpath. Another potential concern would be temporary work directory names leaking into the names of files generated by cgo and the like, but we already make sure to avoid those to ensure reproducible builds: the compiler never sees those paths. So the FS form is not necessary for that either. Change-Id: Idae2c6acb22ab64dfb33bb053244d23fbe153830 Reviewed-on: https://go-review.googlesource.com/c/go/+/493737 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
* cmd/compile: use more of internal/bisect in HashDebugRuss Cox2023-05-095-187/+132
| | | | | | | | | | | | | | Using more of internal/bisect gives us more that will be deleted from base/hashdebug.go when we have updated the tools that need the old protocol. It is also cheaper: there is no allocation to make a decision about whether to enable, and no locking unless printing is needed. Change-Id: I43ec398461205a1a9e988512a134ed6b3a3b1587 Reviewed-on: https://go-review.googlesource.com/c/go/+/493736 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
* cmd/compile: standardize on outer-to-inner for pos listsRuss Cox2023-05-094-29/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The call sites that cared all reversed inner-to-outer to outer-to-inner already. The ones that didn't care left it alone. No one explicitly wanted inner-to-outer. Also change to a callback-based interface, so that call sites aren't required to accumulate the results in a slice (the main reason for that before was to reverse the slice!). There were three places where these lists were printed: 1. -d=ssa/genssa/dump, explicitly reversing to outer-to-inner 2. node dumps like -W, leaving the default inner-to-outer 3. file positions for HashDebugs, explicitly reversing to outer-to-inner It makes no sense that (1) and (2) would differ. The reason they do is that the code for (2) was too lazy to bother to fix it to be the right way. Consider this program: package p func f() { g() } func g() { println() } Both before and after this change, the ssa dump for f looks like: # x.go:3 00000 (3) TEXT <unlinkable>.f(SB), ABIInternal 00001 (3) FUNCDATA $0, gclocals·g2BeySu+wFnoycgXfElmcg==(SB) 00002 (3) FUNCDATA $1, gclocals·g2BeySu+wFnoycgXfElmcg==(SB) v4 00003 (-4) XCHGL AX, AX # x.go:4 # x.go:8 v5 00004 (+8) PCDATA $1, $0 v5 00005 (+8) CALL runtime.printlock(SB) v7 00006 (-8) CALL runtime.printnl(SB) v9 00007 (-8) CALL runtime.printunlock(SB) # x.go:5 b2 00008 (5) RET 00009 (?) END Note # x.go:4 (f) then # x.go:8 (g, called from f) between v4 and v5. The -W node dumps used the opposite order: before walk f . AS2 Def tc(1) # x.go:4:3 . INLMARK # +x.go:4:3 . PRINTN tc(1) # x.go:8:9,x.go:4:3 . LABEL p..i0 # x.go:4:3 Now they match the ssa dump order, and they use spaces as separators, to avoid potential problems with commas in some editors. before walk f . AS2 Def tc(1) # x.go:4:3 . INLMARK # +x.go:4:3 . PRINTN tc(1) # x.go:4:3 x.go:8:9 . LABEL p..i0 # x.go:4:3 I'm unaware of any argument for the old order other than it was easier to compute without allocation. The new code uses recursion to reverse the order without allocation. Now that the callers get the results outer-to-inner, most don't need any slices at all. This change is particularly important for HashDebug, which had been using a locked temporary slice to walk the inline stack without allocation. Now the temporary slice is gone. Change-Id: I5cb6d76b2f950db67b248acc928e47a0460569f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/493735 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Russ Cox <rsc@golang.org>
* internal/godebug: add bisect supportRuss Cox2023-05-091-3/+3
| | | | | | | | | | | | | | | | | | | | CL 491875 introduces a new bisect command, which we plan to document for use by end users to debug semantic changes in the compiler and in GODEBUGs. This CL adds bisect support to GODEBUGs, at least the ones used via internal/godebug. Support for runtime-internal GODEBUGs like panicnil will take a bit more work in followup CLs. The new API in internal/bisect to support stack-based bisecting should be easily reusable in non-GODEBUG settings as well, once we finalize and export the API. Change-Id: I6cf779c775329aceb3f3b2b2b2f221ce8a67deee Reviewed-on: https://go-review.googlesource.com/c/go/+/491975 Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org>
* cmd/compile/loopvar: adjust logging messagesDavid Chase2023-05-092-14/+20
| | | | | | | | | | | | | | | | | Michael Stapelberg thought the former messages had upside potential, Russ and I agreed. Also slightly tweaked the json logging, not sure if anyone will use it but it should at least be okay. Change-Id: Iaab75114dd5f5d8f011fab22d32b57abc0272815 Reviewed-on: https://go-review.googlesource.com/c/go/+/493135 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: David Chase <drchase@google.com> Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Michael Stapelberg <stapelberg@google.com>
* go/types, types2: infer minimum default type for untyped argumentsRobert Griesemer2023-05-083-24/+65
| | | | | | | | | | | | | | | This implements the proposal #58671. Must be explicitly enabled and requires proposal approval. For #58671. Change-Id: I150e78f4f3282d6b7cf9d90feeb5f1c5a36d8c38 Reviewed-on: https://go-review.googlesource.com/c/go/+/492835 Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Griesemer <gri@google.com>
* go/types, types2: move functions for untyped constants into const.goRobert Griesemer2023-05-082-293/+307
| | | | | | | | | | | | | No changes to the moved functions. Generate const.go for go/types. Change-Id: I5ac412cecd9f618676a01138aed36428bbce3311 Reviewed-on: https://go-review.googlesource.com/c/go/+/493715 Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/compile/internal/types2: pass pos argument to Checker.overflowRobert Griesemer2023-05-081-7/+7
| | | | | | | | | | | | | | This matches the go/types version of Checker.overflow. Preparation for generating this function (and others) for go/types. Change-Id: I84117203247011bd2e96c9cf53fd5a443e528bbf Reviewed-on: https://go-review.googlesource.com/c/go/+/493558 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Griesemer <gri@google.com>
* go/types, types2: remove genericMultiExpr (inline it in genericExprList)Robert Griesemer2023-05-082-31/+30
| | | | | | | | | | | | Also, remove named return values for exprList, genericExprList. Change-Id: I099abff4572530dd0c3b39c92d6b9a4662d95c2d Reviewed-on: https://go-review.googlesource.com/c/go/+/493557 Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* math: optimize math.Abs on mipsxJunxian Zhu2023-05-086-1/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit optimized math.Abs function implementation on mipsx. Tested on loongson 3A2000. goos: linux goarch: mipsle pkg: math │ oldmath │ newmath │ │ sec/op │ sec/op vs base │ Acos-4 282.6n ± 0% 282.3n ± 0% ~ (p=0.140 n=7) Acosh-4 506.1n ± 0% 451.8n ± 0% -10.73% (p=0.001 n=7) Asin-4 272.3n ± 0% 272.2n ± 0% ~ (p=0.808 n=7) Asinh-4 529.7n ± 0% 475.3n ± 0% -10.27% (p=0.001 n=7) Atan-4 208.2n ± 0% 207.9n ± 0% ~ (p=0.134 n=7) Atanh-4 503.4n ± 1% 449.7n ± 0% -10.67% (p=0.001 n=7) Atan2-4 310.5n ± 0% 310.5n ± 0% ~ (p=0.928 n=7) Cbrt-4 359.3n ± 0% 358.8n ± 0% ~ (p=0.121 n=7) Ceil-4 203.9n ± 0% 204.0n ± 0% ~ (p=0.600 n=7) Compare-4 23.11n ± 0% 23.11n ± 0% ~ (p=0.702 n=7) Compare32-4 19.09n ± 0% 19.12n ± 0% ~ (p=0.070 n=7) Copysign-4 33.20n ± 0% 34.02n ± 0% +2.47% (p=0.001 n=7) Cos-4 422.5n ± 0% 385.4n ± 1% -8.78% (p=0.001 n=7) Cosh-4 628.0n ± 0% 545.5n ± 0% -13.14% (p=0.001 n=7) Erf-4 193.7n ± 2% 192.7n ± 1% ~ (p=0.430 n=7) Erfc-4 192.8n ± 1% 193.0n ± 0% ~ (p=0.245 n=7) Erfinv-4 220.7n ± 1% 221.5n ± 2% ~ (p=0.272 n=7) Erfcinv-4 221.3n ± 1% 220.4n ± 2% ~ (p=0.738 n=7) Exp-4 471.4n ± 0% 435.1n ± 0% -7.70% (p=0.001 n=7) ExpGo-4 470.6n ± 0% 434.0n ± 0% -7.78% (p=0.001 n=7) Expm1-4 243.1n ± 0% 243.4n ± 0% ~ (p=0.417 n=7) Exp2-4 463.1n ± 0% 427.0n ± 0% -7.80% (p=0.001 n=7) Exp2Go-4 462.4n ± 0% 426.2n ± 5% -7.83% (p=0.001 n=7) Abs-4 37.000n ± 0% 8.039n ± 9% -78.27% (p=0.001 n=7) Dim-4 18.09n ± 0% 18.11n ± 0% ~ (p=0.094 n=7) Floor-4 151.9n ± 0% 151.8n ± 0% ~ (p=0.190 n=7) Max-4 116.7n ± 1% 116.7n ± 1% ~ (p=0.842 n=7) Min-4 116.6n ± 1% 116.6n ± 0% ~ (p=0.464 n=7) Mod-4 1244.0n ± 0% 980.9n ± 0% -21.15% (p=0.001 n=7) Frexp-4 199.0n ± 0% 146.7n ± 0% -26.28% (p=0.001 n=7) Gamma-4 516.4n ± 0% 479.3n ± 1% -7.18% (p=0.001 n=7) Hypot-4 169.8n ± 0% 117.8n ± 2% -30.62% (p=0.001 n=7) HypotGo-4 170.8n ± 0% 117.5n ± 0% -31.21% (p=0.001 n=7) Ilogb-4 160.8n ± 0% 109.5n ± 0% -31.90% (p=0.001 n=7) J0-4 1.359µ ± 0% 1.305µ ± 0% -3.97% (p=0.001 n=7) J1-4 1.386µ ± 0% 1.334µ ± 0% -3.75% (p=0.001 n=7) Jn-4 2.864µ ± 0% 2.758µ ± 0% -3.70% (p=0.001 n=7) Ldexp-4 202.9n ± 0% 151.7n ± 0% -25.23% (p=0.001 n=7) Lgamma-4 234.0n ± 0% 234.3n ± 0% ~ (p=0.199 n=7) Log-4 444.1n ± 0% 407.9n ± 0% -8.15% (p=0.001 n=7) Logb-4 157.8n ± 0% 121.6n ± 0% -22.94% (p=0.001 n=7) Log1p-4 354.8n ± 0% 315.4n ± 0% -11.10% (p=0.001 n=7) Log10-4 453.9n ± 0% 417.9n ± 0% -7.93% (p=0.001 n=7) Log2-4 245.3n ± 0% 209.1n ± 0% -14.76% (p=0.001 n=7) Modf-4 126.6n ± 0% 126.6n ± 0% ~ (p=0.126 n=7) Nextafter32-4 112.5n ± 0% 112.5n ± 0% ~ (p=0.853 n=7) Nextafter64-4 141.7n ± 0% 141.6n ± 0% ~ (p=0.331 n=7) PowInt-4 878.8n ± 1% 758.3n ± 1% -13.71% (p=0.001 n=7) PowFrac-4 1.809µ ± 0% 1.615µ ± 0% -10.72% (p=0.001 n=7) Pow10Pos-4 18.10n ± 0% 18.12n ± 0% ~ (p=0.464 n=7) Pow10Neg-4 17.09n ± 0% 17.09n ± 0% ~ (p=0.263 n=7) Round-4 68.36n ± 0% 68.33n ± 0% ~ (p=0.325 n=7) RoundToEven-4 78.40n ± 0% 78.40n ± 0% ~ (p=0.934 n=7) Remainder-4 894.0n ± 1% 753.4n ± 1% -15.73% (p=0.001 n=7) Signbit-4 18.09n ± 0% 18.09n ± 0% ~ (p=0.761 n=7) Sin-4 389.8n ± 1% 389.8n ± 0% ~ (p=0.995 n=7) Sincos-4 416.0n ± 0% 415.9n ± 0% ~ (p=0.361 n=7) Sinh-4 634.6n ± 4% 585.6n ± 1% -7.72% (p=0.001 n=7) SqrtIndirect-4 8.035n ± 0% 8.036n ± 0% ~ (p=0.523 n=7) SqrtLatency-4 8.039n ± 0% 8.037n ± 0% ~ (p=0.218 n=7) SqrtIndirectLatency-4 8.040n ± 0% 8.040n ± 0% ~ (p=0.652 n=7) SqrtGoLatency-4 895.7n ± 0% 896.6n ± 0% +0.10% (p=0.004 n=7) SqrtPrime-4 5.406µ ± 0% 5.407µ ± 0% ~ (p=0.592 n=7) Tan-4 406.1n ± 0% 405.8n ± 1% ~ (p=0.435 n=7) Tanh-4 627.6n ± 0% 545.5n ± 0% -13.08% (p=0.001 n=7) Trunc-4 146.7n ± 1% 146.7n ± 0% ~ (p=0.755 n=7) Y0-4 1.359µ ± 0% 1.310µ ± 0% -3.61% (p=0.001 n=7) Y1-4 1.351µ ± 0% 1.301µ ± 0% -3.70% (p=0.001 n=7) Yn-4 2.829µ ± 0% 2.729µ ± 0% -3.53% (p=0.001 n=7) Float64bits-4 14.08n ± 0% 14.07n ± 0% ~ (p=0.069 n=7) Float64frombits-4 19.09n ± 0% 19.10n ± 0% ~ (p=0.755 n=7) Float32bits-4 13.06n ± 0% 13.07n ± 1% ~ (p=0.586 n=7) Float32frombits-4 13.06n ± 0% 13.06n ± 0% ~ (p=0.853 n=7) FMA-4 606.9n ± 0% 606.8n ± 0% ~ (p=0.393 n=7) geomean 201.1n 185.4n -7.81% Change-Id: I6d41a97ad3789ed5731588588859ac0b8b13b664 Reviewed-on: https://go-review.googlesource.com/c/go/+/484675 Reviewed-by: Rong Zhang <rongrong@oss.cipunited.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Than McIntosh <thanm@google.com>
* go/types, types2: factor out maximum type computationRobert Griesemer2023-05-052-9/+24
| | | | | | | | | | | | | | For untyped constant binary operations we need to determine the "maximum" (untyped) type which includes both constant types. Factor out this functionality. Change-Id: If42bd793d38423322885a3063a4321bd56443b36 Reviewed-on: https://go-review.googlesource.com/c/go/+/492619 Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/compile: allow more inlining of functions that construct closuresThan McIntosh2023-05-052-19/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [This is a roll-forward of CL 479095, which was reverted due to a bad interaction between inlining and escape analysis, then later fixed first with an attempt in CL 482355, then again in CL 484859, and then one more time with CL 492135.] Currently, when the inliner is determining if a function is inlineable, it descends into the bodies of closures constructed by that function. This has several unfortunate consequences: - If the closure contains a disallowed operation (e.g., a defer), then the outer function can't be inlined. It makes sense that the *closure* can't be inlined in this case, but it doesn't make sense to punish the function that constructs the closure. - The hairiness of the closure counts against the inlining budget of the outer function. Since we currently copy the closure body when inlining the outer function, this makes sense from the perspective of export data size and binary size, but ultimately doesn't make much sense from the perspective of what should be inlineable. - Since the inliner walks into every closure created by an outer function in addition to starting a walk at every closure, this adds an n^2 factor to inlinability analysis. This CL simply drops this behavior. In std, this makes 57 more functions inlinable, and disallows inlining for 10 (due to the basic instability of our bottom-up inlining approach), for an net increase of 47 inlinable functions (+0.6%). This will help significantly with the performance of the functions to be added for #56102, which have a somewhat complicated nesting of closures with a performance-critical fast path. The downside of this seems to be a potential increase in export data and text size, but the practical impact of this seems to be negligible: │ before │ after │ │ bytes │ bytes vs base │ Go/binary 15.12Mi ± 0% 15.14Mi ± 0% +0.16% (n=1) Go/text 5.220Mi ± 0% 5.237Mi ± 0% +0.32% (n=1) Compile/binary 22.92Mi ± 0% 22.94Mi ± 0% +0.07% (n=1) Compile/text 8.428Mi ± 0% 8.435Mi ± 0% +0.08% (n=1) Change-Id: I5f75fcceb177f05853996b75184a486528eafe96 Reviewed-on: https://go-review.googlesource.com/c/go/+/492017 Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
* cmd/compile: un-hide closure func if parent expr moved to staticinitThan McIntosh2023-05-051-0/+6
| | | | | | | | | | | | | | | | | | If the function referenced by a closure expression is incorporated into a static init, be sure to mark it as non-hidden, since otherwise it will be live but no longer reachable from the init func, hence it will be skipped during escape analysis, which can lead to miscompilations. Fixes #59680. Change-Id: Ib858aee296efcc0b7655d25c23ab8a6a8dbdc5f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/492135 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
* cmd/compile: rework marking of dead hidden closure functionsThan McIntosh2023-05-051-37/+58
| | | | | | | | | | | | | | | | | | | | [This is a roll-forward of CL 484859, this time including a fix for issue #59709. The call to do dead function marking was taking place in the wrong spot, causing it to run more than once if generics were instantiated.] This patch generalizes the code in the inliner that marks unreferenced hidden closure functions as dead. Rather than doing the marking on the fly (previous approach), this new approach does a single pass at the end of inlining, which catches more dead functions. Change-Id: I0e079ad755c21295477201acbd7e1a732a98fffd Reviewed-on: https://go-review.googlesource.com/c/go/+/492016 Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
* go/types, types2: better error message for bad assignmentRobert Griesemer2023-05-051-1/+1
| | | | | | | | | | | | | | | | If the LHS of an assignment is neither addressable nor a map expression (and not the blank identifier), explicitly say so for a better error message. For #3117. Change-Id: I4bffc35574fe390a0567e89182b23585eb5a90de Reviewed-on: https://go-review.googlesource.com/c/go/+/492875 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com>
* go/types, types2: exclude untyped nil arguments early in type inferenceRobert Griesemer2023-05-052-7/+7
| | | | | | | | | | | | | An untyped nil argument cannot be used to infer any type information. We don't need to include it in the untyped arguments. Change-Id: Ied44738ff1b135e65a3acfa19223cd3889b7fa7d Reviewed-on: https://go-review.googlesource.com/c/go/+/492695 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
* cmd/compile: work with new bisect commandRuss Cox2023-05-054-55/+56
| | | | | | | | | | | | | | | | | | | | CL 491875 introduces a new bisect command, which we plan to document for use by end users to debug semantic changes in the compiler and in GODEBUGs. This CL adapts the existing GOSSAHASH support, which bisect is a revision of, to support the specific syntax and output used by bisect as well. A followup CL will remove the old GOSSAHASH syntax and output once existing consumers of that interface have been updated. Change-Id: I99c4af54bb82c91c74bd8b8282ded968e6316f56 Reviewed-on: https://go-review.googlesource.com/c/go/+/491895 Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: David Chase <drchase@google.com>