aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder
AgeCommit message (Collapse)Author
2024-01-17cmd/compile: call types2.Unalias to be ready for GODEBUG=gotypesalias=1Robert Griesemer
types2.Unalias is not needed if we know we have a core or underlying type. Also, types of declared functions (signatures) cannot be aliases (this includes tuples). Fixes #65125. Change-Id: I1faa26b66f6c646719e830dd661136fae86f3775 Reviewed-on: https://go-review.googlesource.com/c/go/+/556036 Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2024-01-10cmd/compile: use hashed symbol name for go.shape types if too longThan McIntosh
Shape-based stenciling in the Go compiler's generic instantiation phase looks up shape types using the underlying type of a given target type. This has a beneficial effect in most cases (e.g. we can use the same shape type for two different named types whose underlying type is "int"), but causes some problems when the underlying type is a very large structure. The link string for the underlying type of a large imported struct can be extremely long, since the link string essentially enumerates the full package path for every field type; this can produce a "go.shape.struct { ... " symbol name that is absurdly long. This patch switches the compiler to use a hash of the underlying type link string instead of the string itself, which should continue to provide commoning but keep symbol name lengths reasonable for shape types based on large imported structs. Fixes #65030. Change-Id: I87d602626c43172beb99c186b8ef72327b8227a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/554975 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Than McIntosh <thanm@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-12-19cmd/compile: remove interfacecycles debug flagRobert Griesemer
Per the discussion on the issue, since no problems related to this appeared since Go 1.20, remove the ability to disable the check for anonymous interface cycles permanently. Adjust various tests accordingly. For #56103. Change-Id: Ica2b28752dca08934bbbc163a9b062ae1eb2a834 Reviewed-on: https://go-review.googlesource.com/c/go/+/550896 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: Matthew Dempsky <mdempsky@google.com>
2023-12-01cmd/compile: fix typecheck range over rune literalCuong Manh Le
With range over int, the rune literal in range expression will be left as untyped rune, but idealType is not handling this case, causing ICE. Fixing this by setting the concrete type for untyped rune expresison. Fixes #64471 Change-Id: I07a151c54ea1d9e1b92e4d96cdfb6e73dca13862 Reviewed-on: https://go-review.googlesource.com/c/go/+/546296 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-20cmd/compile: interleave devirtualization and inliningMatthew Dempsky
This CL interleaves devirtualization and inlining, so that devirtualized calls can be inlined. Fixes #52193. Change-Id: I681e7c55bdb90ebf6df315d334e7a58f05110d9c Reviewed-on: https://go-review.googlesource.com/c/go/+/528321 Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Bypass: Matthew Dempsky <mdempsky@google.com>
2023-11-17cmd/compile: use internal/buildcfg for checking newinliner enableCuong Manh Le
internal/goexperiment reports what GOEXPERIMENT the compiler itself was compiled with, not what experiment to use for the object code that the compiler is compiling. Fixes #64189 Change-Id: I892d78611f8c76376032fd7459e755380afafac6 Reviewed-on: https://go-review.googlesource.com/c/go/+/542995 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-15cmd/compile: check for iteration after range func loop exitDavid Chase
When this happens, panic. This is a revised version of a check that used #next, where this one instead uses a per-loop #exit flag, and catches more problematic iterators. Updates #56413. Updates #61405. Change-Id: I6574f754e475bb67b9236b4f6c25979089f9b629 Reviewed-on: https://go-review.googlesource.com/c/go/+/540263 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-11-13cmd/compile: support lookup of functions from export dataMichael Pratt
As of CL 539699, PGO-based devirtualization supports devirtualization of function values in addition to interface method calls. As with CL 497175, we need to explicitly look up functions from export data that may not be imported already. Symbol naming is ambiguous (`foo.Bar.func1` could be a closure or a method), so we simply attempt to do both types of lookup. That said, closures are defined in export data only as OCLOSURE nodes in the enclosing function, which this CL does not yet attempt to expand. For #61577. Change-Id: Ic7205b046218a4dfb8c4162ece3620ed1c3cb40a Reviewed-on: https://go-review.googlesource.com/c/go/+/540258 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-11-13cmd/compile: remove redundant function pkgNameOfaimuz
Replace calls to pkgNameOf with calls to types2.Info.PkgNameOf. Delete function pkgNameOf and file decl.go which are not needed anymore. For #62037 Change-Id: Ib8a0411cc9eb9fdd42ee6e73c23deed2daaf73d5 GitHub-Last-Rev: 3c8928fb5144f92ad9447e806e8d9b9ebf71003f GitHub-Pull-Request: golang/go#64075 Reviewed-on: https://go-review.googlesource.com/c/go/+/541738 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Robert Griesemer <gri@google.com> Run-TryBot: qiulaidongfeng <2645477756@qq.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
2023-11-10cmd/compile: update types2.Info.FileVersions API to match go/typesRobert Griesemer
This CL changes the FileVersions map to map to version strings rather than Version structs, for use with the new go/versions package. Adjust the cmd/dist bootstrap package list to include go/version. Adjust the compiler's noder to work with the new API. For #62605. For #63974. Change-Id: I191a7015ba3fb61c646e9f9d3c3dbafc9653ccb5 Reviewed-on: https://go-review.googlesource.com/c/go/+/541296 Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-10-19cmd/compile: report mismatched version set by //go:buildCuong Manh Le
Fixes #63489 Change-Id: I5e02dc5165ada7f5c292d56203dc670e96eaf2c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/534755 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-10-13cmd/compile: lookup indirect callees from export data for devirtualizationMichael Pratt
Today, the PGO IR graph only contains entries for ir.Func loaded into the package. This can include functions from transitive dependencies, but only if they happen to be referenced by something in the current package. If they are not referenced, noder never bothers to load them. This leads to a deficiency in PGO devirtualization: some callee methods are available in transitive dependencies but do not devirtualize because they happen to not get loaded from export data. Resolve this by adding an explicit lookup from export data of callees mentioned in the profile. I have chosen to do this during loading of the profile for simplicity: the PGO IR graph always contains all of the functions we might need. That said, it isn't strictly necessary. PGO devirtualization could do the lookup lazily if it decides it actually needs a method. This saves work at the expense of a bit more complexity, but I've chosen the simpler approach for now as I measured the cost of this as significantly less than the rest of PGO loading. For #61577. Change-Id: Ieafb2a549510587027270ee6b4c3aefd149a901f Reviewed-on: https://go-review.googlesource.com/c/go/+/497175 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-10-11cmd/compile: use absolute file name in isCgo checkIan Lance Taylor
For #23672 Fixes #63211 Fixes CVE-2023-39323 Change-Id: I4586a69e1b2560036afec29d53e53cf25e6c7352 Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/2032884 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Roland Shoemaker <bracewell@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/534158 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-10-09cmd/compile: fix typecheck range over negative integerCuong Manh Le
Before range over integer, types2 leaves constant expression in RHS of non-constant shift untyped, so idealType do the validation to ensure that constant value must be an int >= 0. With range over int, the range expression can also be left untyped, and can be an negative integer, causing the validation false. Fixing this by relaxing the validation in idealType, and moving the check to Unified IR reader. Fixes #63378 Change-Id: I43042536c09afd98d52c5981adff5dbc5e7d882a Reviewed-on: https://go-review.googlesource.com/c/go/+/532835 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org>
2023-10-08cmd/compile: fix ICE with parenthesized builtin callsCuong Manh Le
CL 419456 starts using lookupObj to find types2.Object associated with builtin functions. However, the new code does not un-parenthesized the callee expression, causing an ICE because of nil obj returned. Un-parenthesizing the callee expression fixes the problem. Fixes #63436 Change-Id: Iebb4fbc08575e7d0b1dbd026c98e8f949ca16460 Reviewed-on: https://go-review.googlesource.com/c/go/+/533476 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2023-10-05cmd/compile/internal/ir: tweak a couple namesMatthew Dempsky
CallExpr.X -> CallExpr.Fun This consistent with go/ast and cmd/compile/internal/syntax. OPRINTN -> OPRINTLN This op represents the "println" builtin; might as well spell it the same way. Change-Id: Iead1b007776658c717879cf0997b3c48028428f4 Reviewed-on: https://go-review.googlesource.com/c/go/+/532795 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com>
2023-09-20cmd/compile: implement range over funcRuss Cox
Add compiler support for range over functions. See the large comment at the top of cmd/compile/internal/rangefunc/rewrite.go for details. This is only reachable if GOEXPERIMENT=range is set, because otherwise type checking will fail. For proposal #61405 (but behind a GOEXPERIMENT). For #61717. Change-Id: I05717f94e63089c503acc49b28b47edeb4e011b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/510541 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Russ Cox <rsc@golang.org>
2023-09-20cmd/compile: implement range over integerRuss Cox
Add compiler implementation of range over integers. This is only reachable if GOEXPERIMENT=range is set, because otherwise type checking will fail. For proposal #61405 (but behind a GOEXPERIMENT). For #61717. Change-Id: I4e35a73c5df1ac57f61ffb54033a433967e5be51 Reviewed-on: https://go-review.googlesource.com/c/go/+/510538 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Russ Cox <rsc@golang.org>
2023-09-14cmd/compile/internal/noder: drop unused *types.Pkg resultsMatthew Dempsky
Several methods return a (*types.Pkg, *types.Sym) pair instead of just a *types.Sym, because we used to need to preserve the *types.Pkg for certain types so that we could write out export data for go/types to use (which exposes these through its APIs). But now that we write export data from the types2 representation directly, there's no need for the rest of the compiler to be concerned about that. Change-Id: I6ac81a6db71b8e0795ff2f33399b839871564eb7 Reviewed-on: https://go-review.googlesource.com/c/go/+/528416 Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-14cmd/compile/internal/ir: add Func.DeclareParamsMatthew Dempsky
There's several copies of this function. We only need one. While here, normalize so that we always declare parameters, and always use the names ~pNN for params and ~rNN for results. Change-Id: I49e90d3fd1820f3c07936227ed5cfefd75d49a1c Reviewed-on: https://go-review.googlesource.com/c/go/+/528415 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com>
2023-09-12cmd/compile/internal/ir: add NewZeroMatthew Dempsky
This constructs a zero value of any type, which helps address some corner case scenarios. It should also eventually handle the predeclared "zero" value, at least as currently implemented in go.dev/cl/520336. For #61372. Change-Id: I3a86a94fd8fa388c9c6bf281da8aa532b3da00fc Reviewed-on: https://go-review.googlesource.com/c/go/+/527696 Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-12cmd/compile: stop changing Field.Sym for parametersMatthew Dempsky
Field.Sym now always contains the original symbol as it appeared in Go source, so we don't need OrigSym anymore. Instead, when the mangled name is desired, Field.Nname.Sym() can be used instead, which is always non-nil if Nname is non-nil. Change-Id: I96cd61db6458d4a2e07ec5810239236e3dfba747 Reviewed-on: https://go-review.googlesource.com/c/go/+/527516 Auto-Submit: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com>
2023-09-11cmd/compile/internal/noder: handle unsafe.Sizeof, etc in unified IRMatthew Dempsky
Previously, the unified frontend implemented unsafe.Sizeof, etc that involved derived types by constructing a normal OSIZEOF, etc expression, including fully instantiating their argument. (When unsafe.Sizeof is applied to a non-generic type, types2 handles constant folding it.) This worked, but involves unnecessary work, since all we really need to track is the argument type (and the field selections, for unsafe.Offsetof). Further, the argument expression could generate temporary variables, which would then go unused after typecheck replaced the OSIZEOF expression with an OLITERAL. This results in compiler failures after CL 523315, which made later passes stricter about expecting the frontend to not construct unused temporaries. Fixes #62515. Change-Id: I37baed048fd2e35648c59243f66c97c24413aa94 Reviewed-on: https://go-review.googlesource.com/c/go/+/527097 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com>
2023-09-11cmd/compile/internal/ir: add Type param to NewBasicLitMatthew Dempsky
This CL adds an explicit Type parameter to NewBasicLit so that callers can directly construct typed OLITERAL nodes. Change-Id: I0ab50ac3d7ddb7adcc903633a62ac496921165e9 Reviewed-on: https://go-review.googlesource.com/c/go/+/527096 Auto-Submit: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2023-09-08cmd/compile: write "properties" to export data for inlinable funcsThan McIntosh
Augment the ir.Inline container to include an entry for function properties (currently serialized as a string), and if GOEXPERIMENT=newinliner is set, compute and store function properties for all inline candidates processed by the inliner. The idea here is that if the function properties are going to drive inlining decisions, we'd like to have the same info from non-local / imported functions as for local / in-package functions, hence we need to include the properties in the export data. Hand testing on the compiler itself and with k8s kubelet shows that this increases the size of export data overall by about 2-3 percent, so a pretty modest increase. Updates #61502. Change-Id: I9d1c311aa8418d02ffea3629c3dd9d8076886d15 Reviewed-on: https://go-review.googlesource.com/c/go/+/511562 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-09-08cmd/compile: cleanup uses of ir.Orig and ir.SepCopyMatthew Dempsky
Mostly automated refactoring with gofmt: gofmt -r 'ir.Orig(n) -> n' gofmt -r 'ir.SepCopy(n) -> ir.Copy(n)' Followed by some manual cleanups. Change-Id: Ib35abeba9e60b70ba463e161fb39358fb058a83e Reviewed-on: https://go-review.googlesource.com/c/go/+/526398 Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-08cmd/compile/internal/noder: stop preserving original const stringsMatthew Dempsky
One of the more tedious quirks of the original frontend (i.e., typecheck) to preserve was that it preserved the original representation of constants into the backend. To fit into the unified IR model, I ended up implementing a fairly heavyweight workaround: simply record the original constant's string expression in the export data, so that diagnostics could still report it back, and match the old test expectations. But now that there's just a single frontend to support, it's easy enough to just update the test expectations and drop this support for "raw" constant expressions. Change-Id: I1d859c5109d679879d937a2b213e777fbddf4f2f Reviewed-on: https://go-review.googlesource.com/c/go/+/526376 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2023-08-29cmd/compile/internal/ir: drop Inl.BodyMatthew Dempsky
We don't actually depend on Inl.Body anywhere, except it implicitly serves to indicate whether Inl.Dcl has been populated. So replace it with a boolean so we don't need to keep a useless copy of every inlinable function body in memory. While here, also add some Fatalfs to make sure there are no unused local variables. The unified frontend now omits unreachable code during export data writing, so there shouldn't be unused local variables. Also, since unified IR uses the same code/data to construct the original function as inlined and/or imported functions, the Dcl list should always be the same, which addresses the real root issue (i.e., that export/import could skew the Dcl lists). Change-Id: I6e3435f3a0352f6efbae787344006efac1891e84 Reviewed-on: https://go-review.googlesource.com/c/go/+/523315 Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-08-29cmd/compile: eliminate fallback code for missing -p flagMatthew Dempsky
cmd/compile has required the -p flag since go.dev/cl/391014. It's safe to eliminate the fallback code that tried to cope without. Change-Id: I9a62ff829e34a6fa5bfe6ae6a836610cc3f0cd33 Reviewed-on: https://go-review.googlesource.com/c/go/+/523337 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-26cmd/compile: un-hide closure func in init functionCuong Manh Le
Same as CL 492135, but for init function. Fixes #62277 Change-Id: If5ff9bc2ce2a73193b1f7ee5f7f14045d1354f56 Reviewed-on: https://go-review.googlesource.com/c/go/+/522956 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2023-08-25cmd/compile/internal/noder: avoid ir.Node temps in FixValueMatthew Dempsky
Instead of constructing an untyped basic literal IR node, having typecheck convert it and return a new one, only to extract the constant.Value; just have typecheck export the underlying value conversion function, so we can call it directly. Change-Id: Ie98f5362b3926a728d80262b0274a0b4fd023eaf Reviewed-on: https://go-review.googlesource.com/c/go/+/522878 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com>
2023-08-25cmd/compile: remove ErrorfVers and base.Flag.Lang hackMatthew Dempsky
ErrorfVers used to be used by typecheck to report when new language functionality was used, but the -lang flag (from go.mod) was set to an older version. However, all of the callers have been since removed, now that this is handled by types2. And for the same reason, we can stop changing base.Flag.Lang. This was previously a workaround so that the unified frontend could generate arbitrary IR without upsetting typecheck, at a time when typecheck was itself a real frontend. Now it's just a glorified desugaring pass. Change-Id: I1c0316dbfe2e08ba089acd50fdfe20b17176be25 Reviewed-on: https://go-review.googlesource.com/c/go/+/522877 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@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-24cmd/compile: create "init" function during nodingMatthew Dempsky
This CL arranges for package-scope initialization statements to be constructed directly into their eventual "init" function, so we can eliminate the roundabout solution of using InitTodoFunc. While here, somewhat simplify and generalize the logic for outlining map initialization statements. Change-Id: I8aff042e6b266f7024de436424ec6711b8b69129 Reviewed-on: https://go-review.googlesource.com/c/go/+/522318 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-24cmd/compile/internal/syntax: add Unparen and UnpackListExpr helpersMatthew Dempsky
We've added Unparen to go/ast, so add syntax.Unparen to be consistent (and because it's similarly useful). Also, types2 and noder both have similar functions for unpacking ListExprs, so might as well add a common implementation in package syntax too. Finally, addressing the TODO: UnpackListExpr is small enough to be inlined (when default optimizations are enabled), and for typical uses of UnpackListExpr (e.g., "range UnpackListExpr(x)") the single-element slice result is stack allocated in the caller. This CL adds a test using testing.AllocsPerRun to ensure this remains so in the future. Change-Id: I96a5591d202193ed5bf1ce6f290919107e3dc01b Reviewed-on: https://go-review.googlesource.com/c/go/+/522336 Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com>
2023-08-24cmd/compile/internal: fix receiver names are differentcui fliter
Change-Id: I78a7d34a6e2558ecff0274170bffaa51e038d0bc Reviewed-on: https://go-review.googlesource.com/c/go/+/522415 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> Auto-Submit: Keith Randall <khr@golang.org>
2023-08-23cmd/compile/internal/noder: elide statically known "if" statementsMatthew Dempsky
In go.dev/cl/517775, I moved the frontend's deadcode elimination pass into unified IR. But I also made a small enhancement: a branch like "if x || true" is now detected as always taken, so the else branch can be eliminated. However, the inliner also has an optimization for delaying the introduction of the result temporary variables when there's a single return statement (added in go.dev/cl/266199). Consequently, the inliner turns "if x || true { return true }; return true" into: if x || true { ~R0 := true goto .i0 } .i0: // code that uses ~R0 In turn, this confuses phi insertion, because it doesn't recognize that the "if" statement is always taken, and so ~R0 will always be initialized. With this CL, after inlining we instead produce: _ = x || true ~R0 := true goto .i0 .i0: Fixes #62211. Change-Id: Ic8a12c9eb85833ee4e5d114f60e6c47817fce538 Reviewed-on: https://go-review.googlesource.com/c/go/+/522096 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2023-08-22cmd/compile/internal/types: simplify iterating all parametersMatthew Dempsky
The types.RecvsParamsResults, etc. helpers existed to make it "easier" to iterate over all parameters, or recvs+params, or params+results; but they end up still being quite clumsy to use due to the design goal of not allocating temporary slices. Now that recvs+params+results are stored in a single consecutive slice anyway, we can just return different subslices and simplify the loops. Change-Id: I84791b80dc099dfbfbbe6eddbc006135528c23b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/521375 Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2023-08-22cmd/compile: redo IsRuntimePkg/IsReflectPkg predicateAustin Clements
Currently, the types package has IsRuntimePkg and IsReflectPkg predicates for testing if a Pkg is the runtime or reflect packages. IsRuntimePkg returns "true" for any "CompilingRuntime" package, which includes all of the packages imported by the runtime. This isn't inherently wrong, except that all but one use of it is of the form "is this Sym a specific runtime.X symbol?" for which we clearly only want the package "runtime" itself. IsRuntimePkg was introduced (as isRuntime) in CL 37538 as part of separating the real runtime package from the compiler built-in fake runtime package. As of that CL, the "runtime" package couldn't import any other packages, so this was adequate at the time. We could fix this by just changing the implementation of IsRuntimePkg, but the meaning of this API is clearly somewhat ambiguous. Instead, we replace it with a new RuntimeSymName function that returns the name of a symbol if it's in package "runtime", or "" if not. This is what every call site (except one) actually wants, which lets us simplify the callers, and also more clearly addresses the ambiguity between package "runtime" and the general concept of a runtime package. IsReflectPkg doesn't have the same issue of ambiguity, but it parallels IsRuntimePkg and is used in the same way, so we replace it with a new ReflectSymName for consistency. Change-Id: If3a81d7d11732a9ab2cac9488d17508415cfb597 Reviewed-on: https://go-review.googlesource.com/c/go/+/521696 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-22cmd/compile/internal/types: overhaul and simplify APIMatthew Dempsky
This CL removes a lot of the redundant methods for accessing struct fields and signature parameters. In particular, users never have to write ".Slice()" or ".FieldSlice()" anymore; the exported APIs just do what you want. Further internal refactorings to follow. Change-Id: I45212f6772fe16aad39d0e68b82d71b0796e5639 Reviewed-on: https://go-review.googlesource.com/c/go/+/521295 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com>
2023-08-20cmd/compile/internal/typecheck: add selector helpersMatthew Dempsky
This CL refactors common patterns for constructing field and method selector expressions. Notably, XDotField and XDotMethod are now the only two functions where a SelecterExpr with OXDOT is constructed. Change-Id: I4c087225d8b295c4a6a92281ffcbcabafe2dc94d Reviewed-on: https://go-review.googlesource.com/c/go/+/520979 Auto-Submit: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-20cmd/compile/internal/typecheck: add NewMethodExpr helperMatthew Dempsky
This CL refactors the common pattern for constructing OMETHEXPR nodes, which is the most common use of ir.TypeNode currently. Change-Id: I446a21af97ab5a4bc2f04bbd581c1ede8a5ede60 Reviewed-on: https://go-review.googlesource.com/c/go/+/520978 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2023-08-18cmd/compile: construct more IR nodes as typedMatthew Dempsky
As of this CL, all OLITERAL, OLINKSYMOFFSET, ONIL, and OTYPE nodes are constructed as typed and typechecked. Change-Id: I39b2ad772a9b0419c701890a505a0949f9ea456e Reviewed-on: https://go-review.googlesource.com/c/go/+/520795 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2023-08-18cmd/compile/internal/ir: remove NtypeMatthew Dempsky
This type used to provide extra type safety around which syntactic nodes could also represent types, but now the only remaining use is ir.TypeNode, and it always ends up as an ir.Node anyway. So we might as well use Node instead. Change-Id: Ia0842864794365b0e155dc5af154c673ffa2967b Reviewed-on: https://go-review.googlesource.com/c/go/+/520609 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com>
2023-08-18cmd/compile: remove some uses of ir.CurFuncMatthew Dempsky
This CL updates several frontend passes to stop relying on ir.CurFunc (at least directly). Change-Id: I3c3529e81e27fb05d54a828f081f7c7efc31af67 Reviewed-on: https://go-review.googlesource.com/c/go/+/520606 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com>
2023-08-17cmd/compile/internal/typecheck: normalize go/defer statements earlierMatthew Dempsky
Normalizing go/defer statements to always use functions with zero parameters and zero results was added to escape analysis, because that was the earliest point at which all three frontends converged. Now that we only have the unified frontend, we can do it during typecheck, which is where we perform all other desugaring and normalization rewrites. Change-Id: Iebf7679b117fd78b1dffee2974bbf85ebc923b23 Reviewed-on: https://go-review.googlesource.com/c/go/+/520260 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-17cmd/compile/internal/noder: remove inlined closure naming hackMatthew Dempsky
I previously used a clumsy hack to copy Closgen back and forth while inlining, to handle when an inlined function contains closures, which need to each be uniquely numbered. The real solution was to name the closures using r.inlCaller, rather than r.curfn. This CL adds a helper method to do exactly this. Change-Id: I510553b5d7a8f6581ea1d21604e834fd6338cb06 Reviewed-on: https://go-review.googlesource.com/c/go/+/520339 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2023-08-17cmd/compile: cleanup Func constructionMatthew Dempsky
This CL moves more common Func-setup logic into ir.NewFunc. In particular, it now handles constructing the Name and wiring them together, setting the Typecheck bit, and setting Sym.Func. Relatedly, this CL also extends typecheck.DeclFunc to append the function to typecheck.Target.Funcs, so that callers no longer need to do this. Change-Id: Ifa0aded8df0517188eb295d0dccc107af85f1e8a Reviewed-on: https://go-review.googlesource.com/c/go/+/520338 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com>
2023-08-17cmd/compile: always construct typechecked closuresMatthew Dempsky
This CL extends ir.NewClosureFunc to take the signature type argument, and to handle naming the closure and adding it to typecheck.Target. It also removes the code for typechecking OCLOSURE and ODCLFUNC nodes, by having them always constructed as typechecked. ODCLFUNC node construction will be further simplified in the followup CL. Change-Id: Iabde4557d33051ee470a3bc4fd49599490024cba Reviewed-on: https://go-review.googlesource.com/c/go/+/520337 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2023-08-17cmd/compile/internal/ir: add typ parameter to NewNameAtMatthew Dempsky
Start making progress towards constructing IR with proper types. Change-Id: Iad32c1cf60f30ceb8e07c31c8871b115570ac3bd Reviewed-on: https://go-review.googlesource.com/c/go/+/520263 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2023-08-16cmd/compile: use types2.Sizes instead of compiler own implementationCuong Manh Le
With #61035 fixed, types2.Sizes matches the compiler behavior, so use its Sizes implementation instead of rolling our own copy. Updates #61035 Change-Id: I7b9efd27a01f729a04c79cd6b4ee5f417fe6e664 Reviewed-on: https://go-review.googlesource.com/c/go/+/506716 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: 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> Reviewed-by: Robert Griesemer <gri@google.com>