aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder
AgeCommit message (Collapse)Author
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>
2023-08-15cmd/compile: improve ir.StaticValue and extract ir.StaticCalleeNameMatthew Dempsky
This CL extends ir.StaticValue to also work on closure variables. Also, it extracts the code from escape analysis that's responsible for determining the static callee of a function. This will be useful when go/defer statement normalization is moved to typecheck. Change-Id: I69e1f7fb185658dc9fbfdc69d0f511c84df1d3ac Reviewed-on: https://go-review.googlesource.com/c/go/+/518959 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-11cmd/compile: simplify asmhdr and plugin exports handlingMatthew Dempsky
This CL removes a bunch of obsolete code, which made the overall possible data flow of the compiler much harder to understand. In particular, it: 1. Removes typecheck.Declare by inlining its only two remaining uses, and simplifying them down to just the couple of relevant assignments for each remaining caller. 2. Renames ir.Package.{Asms,Exports} to {AsmHdrDecls,PluginExports}, respectively, to better describe what they're used for. In particular, PluginExports now actually holds only the subset of Exports that used to be confusingly called "ptabs" in package reflectdata. 3. Renames reflectdata.WriteTabs to reflectdata.WritePluginTable, to make it clearer what it does. 4. Removes the consistency checks on len(Exports) and len(ptabs), since now it's plainly obvious that only the unified importer ever appends to PluginExports. Change-Id: Iedc9d0a4e7648de4e734f7e3e7df302580fed542 Reviewed-on: https://go-review.googlesource.com/c/go/+/518757 Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com>
2023-08-11cmd/compile: cleanup ir.PackageMatthew Dempsky
Decls used to contain initializer statement for package-level variables, but now it only contains ir.Funcs. So we might as well rename it to Funcs and tighten its type to []*ir.Func. Similarly, Externs always contains *ir.Names, so its type can be constrained too. Change-Id: I85b833e2f83d9d3559ab0ef8ab5d8324f4bc37b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/517855 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-11cmd/compile: move early deadcode into unified writerMatthew Dempsky
This CL moves the early deadcode elimination pass into the unified writer. This allows shrinking the export data, by simplifying expressions and removing unreachable statements. It also means we don't need to repeatedly apply deadcode elimination on inlined calls or instantiated generics. Change-Id: I19bdb04861e50815fccdab39790f4aaa076121fd Reviewed-on: https://go-review.googlesource.com/c/go/+/517775 Reviewed-by: Michael Knyszek <mknyszek@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> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-11cmd/compile: make use of types2.InitOrderMatthew Dempsky
types2 already computes the order that package-level variables need to be initialized in. Start using it. Change-Id: Idf2740f963b8146f7c927f57effdbf245f41d355 Reviewed-on: https://go-review.googlesource.com/c/go/+/517617 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-08-09cmd/compile: mark instantiated functions from package runtime as noraceCuong Manh Le
Fixes #60439 Change-Id: I09fcd2d3deb7f80ed012a769fdb6f53b09c0290b Reviewed-on: https://go-review.googlesource.com/c/go/+/502895 Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-08-08cmd/compile: use new for loop semantics for Go 1.22+ compilationsDavid Chase
This includes version-dependent support for GOEXPERIMENT and -d=loopvar, -d=loopvarhash, to allow testing/porting of old code. Includes tests of downgrade (1.22 -> 1.21) and upgrade (1.21 -> 1.22) based on //go:build lines (while running a 1.22 build/compiler). Change-Id: Idd3be61a2b46acec33c7e7edac0924158cc726b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/508819 Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-07-21cmd/compile: use "pw" as receiver name consistentlyCuong Manh Le
Change-Id: I912f1326fa442098065b62b7b0ef9048771e4701 Reviewed-on: https://go-review.googlesource.com/c/go/+/506476 Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-07-21cmd/compile/internal/noder: remove un-used funcs/varsCuong Manh Le
Change-Id: I755406e6c5b6a8cdaeeed8cd12d756e3847c8d4f Reviewed-on: https://go-review.googlesource.com/c/go/+/506475 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2023-06-23cmd/compile: scanning closures body when visiting wrapper functionCuong Manh Le
CL 410344 fixed missing method value wrapper, by visiting body of wrapper function after applying inlining pass. CL 492017 allow more inlining of functions that construct closures, which ends up making the wrapper function now inlineable, but can contain closure nodes that couldn't be inlined. These closures body may contain OMETHVALUE nodes that we never seen, thus we need to scan closures body for finding them. Fixes #60945 Change-Id: Ia1e31420bb172ff87d7321d2da2989ef23e6ebb6 Reviewed-on: https://go-review.googlesource.com/c/go/+/505255 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2023-05-24cmd/compile: report an error URL with error messagesRobert Griesemer
In the type checkers, add Config.ErrorURL (or Config._ErrorURL for go/types) to configure whether and how an error message should report a URL for errors that have an error code. In the compiler, configure types2 to report an error URL of the form " [go.dev/e/XXX]", where XXX stands for the error code, with the URL appended to the first line of an error. Rename the compiler flag -url to -errorurl. At the moment this flag is disabled by default. Example for a one-line error message: <pos>: undefined: f [go.dev/e/UndeclaredName] Example for a multi-line error message: <pos>: not enough arguments in call to min [go.dev/e/WrongArgCount] have () want (P, P) Change-Id: I26651ce2c92ad32fddd641f003db37fe12fdb1cd Reviewed-on: https://go-review.googlesource.com/c/go/+/497715 Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
2023-05-19cmd/compile: constant-fold loads from constant dictionaries and typesKeith Randall
Retrying the original CL with a small modification. The original CL did not handle the case of reading an itab out of a dictionary correctly. When we read an itab out of a dictionary, we must treat the type inside that itab as maybe being put in an interface. Original CL: 486895 Revert CL: 490156 Change-Id: Id2dc1699d184cd8c63dac83986a70b60b4e6cbd7 Reviewed-on: https://go-review.googlesource.com/c/go/+/491495 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-19cmd/compile: use more lenient type inference for untyped arguments for go1.21Robert Griesemer
This CL permanently enables the new behavior for -lang=go1.21 and newer, and keeps the existing behavior if -lang=go1.20 or older. To be submitted once #58671 is accepted. For #58671. Change-Id: I83a1d393f0ce7871be8f38ec35742d393946c55f Reviewed-on: https://go-review.googlesource.com/c/go/+/496035 Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
2023-05-18cmd/compile: enable more lenient type inference for untyped argumentsRobert Griesemer
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>
2023-05-16cmd/compile/internal/noder: suppress unionType consistency checkMatthew Dempsky
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>
2023-05-11cmd/compile: remove go:wasmimport restrictionJohan Brandhorst-Satzkorn
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>
2023-05-04go/types, types2: remove Config.EnableReverseTypeInference flagRobert Griesemer
Proposal #59338 has been accepted and we expect this feature to be available starting with Go 1.21. Remove the flag to explicitly enable it through the API and enable by default. For now keep an internal constant enableReverseTypeInference to guard and mark the respective code, so we can disable it for debugging purposes. For #59338. Change-Id: Ia1bf3032483ae603017a0f459417ec73837e2891 Reviewed-on: https://go-review.googlesource.com/c/go/+/491798 Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: 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>
2023-05-03cmd/compile: fix compilation of inferred type argumentsMatthew Dempsky
Previously, type arguments could only be inferred for generic functions in call expressions, whereas with the reverse type inference proposal they can now be inferred in assignment contexts too. As a consequence, we now need to check Info.Instances to find the inferred type for more cases now. Updates #59338. Fixes #59955. Change-Id: I9b6465395869459c2387d0424febe7337b28b90e Reviewed-on: https://go-review.googlesource.com/c/go/+/492455 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-05-03cmd/compile: enable reverse type inferenceRobert Griesemer
For #59338. Change-Id: I8141d421cdc60e47ee5794fc1ca81246bd8a8a25 Reviewed-on: https://go-review.googlesource.com/c/go/+/491475 Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-04-28Revert "cmd/compile: constant-fold loads from constant dictionaries and types"Chressie Himpel
This reverts CL 486895. Reason for revert: This breaks internal tests at Google, see b/280035614. Change-Id: I48772a44f5f6070a7f06b5704e9f9aa272b5f978 Reviewed-on: https://go-review.googlesource.com/c/go/+/490156 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Stapelberg <stapelberg@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Michael Stapelberg <stapelberg@google.com> Reviewed-by: David Chase <drchase@google.com>
2023-04-27cmd/compile: constant-fold loads from constant dictionaries and typesKeith Randall
Update #59591 Change-Id: Id250a7779c5b53776fff73f3e678fec54d92a8e3 Reviewed-on: https://go-review.googlesource.com/c/go/+/486895 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-04-12cmd/compile: fix reproducible build of aliased generic typesMatthew Dempsky
Due to a missing "&& !alias" check, the unified linker was treating type aliases the same as defined types for the purpose of exporting method bodies. The methods will get exported anyway alongside the aliased type, so this mistake is normally harmless. However, if multiple type aliases instantiated the same generic type but with different type arguments, this could result in the same (generic) method body being exported multiple times under different symbol names. Further, because bodies aren't expected to be exported multiple times, we were sorting them simply based on index. And consequently, the sort wasn't total and is sensitive to the map iteration order used while ranging over linker.bodies. The fix is simply to add the missing "&& !alias" check, so that we don't end up with duplicate bodies in the first place. Thanks rsc@ for providing a minimal repro case. Fixes #59571. Change-Id: Iaa55968cc7110b601e2f0f9b620901c2d55f7014 Reviewed-on: https://go-review.googlesource.com/c/go/+/484155 Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2023-03-30cmd/compile: allow go:wasmimport in syscallJohan Brandhorst-Satzkorn
The go:wasmimport compiler directive is used by the wasi port to access host APIs, some of need to implemented in the syscall package. Co-authored-by: Richard Musiol <neelance@gmail.com> Co-authored-by: Achille Roussel <achille.roussel@gmail.com> Co-authored-by: Julien Fabre <ju.pryz@gmail.com> Co-authored-by: Evan Phoenix <evan@phx.io> Change-Id: I3851e154c6989094effcd25bba5864faa133564e Reviewed-on: https://go-review.googlesource.com/c/go/+/479615 Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
2023-03-27cmd/compile: don't panic if unsafe.Sizeof/Offsetof is used with oversize typesRobert Griesemer
In the Sizes API, recognize an overflow (to a negative value) as a consequence of an oversize value, and specify as such in the API. Adjust the various size computations to take overflow into account. Recognize a negative size or offset as an error and report it rather than panicking. Use the same protocol for results provided by the default (StdSizes) and external Sizes implementations. Add a new error code TypeTooLarge for the new errors. Fixes #59190. Fixes #59207. Change-Id: I8c33a9e69932760275100112dde627289ac7695b Reviewed-on: https://go-review.googlesource.com/c/go/+/478919 Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
2023-03-22cmd/compile: re-compile instantiated generic methods in linkshared modeCuong Manh Le
For G[T] that was seen and compiled in imported package, it is not added to typecheck.Target.Decls, prevent wasting compile time re-creating DUPOKS symbols. However, the linker do not support a type symbol referencing a method symbol across DSO boundary. That causes unreachable sym error when building under -linkshared mode. To fix it, always re-compile generic methods in linkshared mode. Fixes #58966 Change-Id: I894b417cfe8234ae1fe809cc975889345df22cef Reviewed-on: https://go-review.googlesource.com/c/go/+/477375 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-03-10cmd/compile: pass type checker error codes in the compilerRobert Griesemer
Pass type checker error codes to base.ErrorfAt function calls in the compiler (but don't do anything yet with the code). Also, provide error codes to base.ErrorfAt calls in the compiler as needed. This opens the door towards reporting the error code and/or providing a link/reference to more detailed explanations (see internal/types/errors/codes.go). Change-Id: I0ff9368d8163499ffdac6adfe8331fdc4a19b4b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/475198 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-03-06cmd/compile: add flag to FOR/RANGE to preserve loop semantics across inlinesDavid Chase
This modifies the loopvar change to be tied to the package if it is specified that way, and preserves the change across inlining. Down the road, this will be triggered (and flow correctly) if the changed semantics are tied to Go version specified in go.mod (or rather, for the compiler, by the specified version for compilation). Includes tests. Change-Id: If54e8b6dd23273b86be5ba47838c90d38af9bd1a Reviewed-on: https://go-review.googlesource.com/c/go/+/463595 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-03-06cmd/compile: experimental loop iterator capture semantics changeDavid Chase
Adds: GOEXPERIMENT=loopvar (expected way of invoking) -d=loopvar={-1,0,1,2,11,12} (for per-package control and/or logging) -d=loopvarhash=... (for hash debugging) loopvar=11,12 are for testing, benchmarking, and debugging. If enabled,for loops of the form `for x,y := range thing`, if x and/or y are addressed or captured by a closure, are transformed by renaming x/y to a temporary and prepending an assignment to the body of the loop x := tmp_x. This changes the loop semantics by making each iteration's instance of x be distinct from the others (currently they are all aliased, and when this matters, it is almost always a bug). 3-range with captured iteration variables are also transformed, though it is a more complex transformation. "Optimized" to do a simpler transformation for 3-clause for where the increment is empty. (Prior optimization of address-taking under Return disabled, because it was incorrect; returns can have loops for children. Restored in a later CL.) Includes support for -d=loopvarhash=<binary string> intended for use with hash search and GOCOMPILEDEBUG=loopvarhash=<binary string> (use `gossahash -e loopvarhash command-that-fails`). Minor feature upgrades to hash-triggered features; clients can specify that file-position hashes use only the most-inline position, and/or that they use only the basenames of source files (not the full directory path). Most-inlined is the right choice for debugging loop-iteration change once the semantics are linked to the package across inlining; basename-only makes it tractable to write tests (which, otherwise, depend on the full pathname of the source file and thus vary). Updates #57969. Change-Id: I180a51a3f8d4173f6210c861f10de23de8a1b1db Reviewed-on: https://go-review.googlesource.com/c/go/+/411904 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-03-02all: implement wasmimport directiveEvan Phoenix
Go programs can now use the //go:wasmimport module_name function_name directive to import functions from the WebAssembly runtime. For now, the directive is restricted to the runtime and syscall/js packages. * Derived from CL 350737 * Original work modified to work with changes to the IR conversion code. * Modification of CL 350737 changes to fully exist in Unified IR path (emp) * Original work modified to work with changes to the ABI configuration code. * Fixes #38248 Co-authored-by: Vedant Roy <vroy101@gmail.com> Co-authored-by: Richard Musiol <mail@richard-musiol.de> Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Change-Id: I740719735d91c306ac718a435a78e1ee9686bc16 Reviewed-on: https://go-review.googlesource.com/c/go/+/463018 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
2023-03-01cmd/compile: relax overly strict assertionMatthew Dempsky
The assertion here was to make sure the newly constructed and typechecked expression selected the same receiver-qualified method, but in the case of anonymous receiver types we can actually end up with separate types.Field instances corresponding to each types.Type instance. In that case, the assertion spuriously failed. The fix here is to relax and assertion and just compare the method's name and type (including receiver type). Fixes #58563. Change-Id: I67d51ddb020e6ed52671473c93fc08f283a40886 Reviewed-on: https://go-review.googlesource.com/c/go/+/471676 Auto-Submit: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-28cmd/compile: preserve full inlined location for ir.Name localsDavid Chase
This was noticed while testing hash-search debugging of the loopvar experiment. The change is incomplete -- it only addresses local variables, not parameters. The code to log/search changes in loop variable semantics depends on this, so that will be the test. Change-Id: I0f84ab7696c6cab43486242cacaba6a0bfc45475 Reviewed-on: https://go-review.googlesource.com/c/go/+/464315 Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: David Chase <drchase@google.com>
2023-02-27cmd/compile/internal/noder: correct positions for synthetic closuresMatthew Dempsky
When inlining functions that contain function literals, we need to be careful about position information. The OCLOSURE node should use the inline-adjusted position, but the ODCLFUNC and its body should use the original positions. However, the same problem can arise with certain generic constructs, which require the compiler to synthesize function literals to insert dictionary arguments. go.dev/cl/425395 fixed the issue with user-written function literals in a somewhat kludgy way; this CL extends the same solution to synthetic function literals. This is all quite subtle and the solutions aren't terribly robust, so longer term it's probably desirable to revisit how we track inlining context for positions. But for now, this seems to be the least bad solution, esp. for backporting to 1.20. Updates #54625. Fixes #58513. Change-Id: Icc43a70dbb11a0e665cbc9e6a64ef274ad8253d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/468415 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com>
2023-01-27cmd/compile/internal/noder: remove unused noding codeMatthew Dempsky
This CL simplifies and removes some old noding code, which isn't necessary any more. Most notably, we no longer need separate posMaps for each noder, because noders are only used for parsing now. Before we started using types2, noders were also responsible for constructed (untyped) IR, so posMaps were necessary to translate syntax.Pos into src.XPos. Change-Id: Ic761abcd727f5ecefc71b611635a0f5b088c941f Reviewed-on: https://go-review.googlesource.com/c/go/+/463738 Auto-Submit: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2023-01-26cmd/compile/internal/types: remove unneeded functionalityMatthew Dempsky
This CL removes a handful of features that were only needed for the pre-unified frontends. In particular, Type.Pkg was a hack for iexport so that go/types.Var.Pkg could be precisely populated for struct fields and signature parameters by gcimporter, but it's no longer necessary with the unified export data format because we now write export data directly from types2-supplied type descriptors. Several other features (e.g., OrigType, implicit interfaces, type parameters on signatures) are no longer relevant to the unified frontend, because it only uses types1 to represent instantiated generic types. Updates #57410. Change-Id: I84fd1da5e0b65d2ab91d244a7bb593821ee916e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/458622 Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2023-01-26cmd/compile/internal/types: remove TTYPEPARAM and TUNION typesMatthew Dempsky
These were used by the nounified frontend for representing uninstantiated generic types; however, the unified frontend only needs types1 to represent instantiated types. Updates #57410. Change-Id: Iac417fbf2b86f4e08bd7fdd26ae8ed17395ce833 Reviewed-on: https://go-review.googlesource.com/c/go/+/458621 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-26cmd/compile: remove GOEXPERIMENT=nounified frontendMatthew Dempsky
This CL removes most of the code specific to the nounified frontend. To simplify review, it's a strict remove-only CL. Updates #57410. Change-Id: Ic3196570aa4286618c1d5e7fd0d0e6601a18195b Reviewed-on: https://go-review.googlesource.com/c/go/+/458620 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2023-01-26cmd/compile/internal/noder: stop creating TUNION typesMatthew Dempsky
In the types1 universe under the unified frontend, we never need to worry about type parameter constraints, so we only see pure interfaces. However, we might still see interfaces that contain union types, because of interfaces like "interface{ any | int }" (equivalent to just "any"). We can handle these without needing to actually represent type unions within types1 by simply mapping any union to "any". Updates #57410. Change-Id: I5e4efcf0339edbb01f4035c54fb6fb1f9ddc0c65 Reviewed-on: https://go-review.googlesource.com/c/go/+/458619 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2023-01-25cmd: remove GOEXPERIMENT=nounified knobMatthew Dempsky
This CL removes the GOEXPERIMENT=nounified knob, and any conditional statements that depend on that knob. Further CLs to remove unreachable code follow this one. Updates #57410. Change-Id: I39c147e1a83601c73f8316a001705778fee64a91 Reviewed-on: https://go-review.googlesource.com/c/go/+/458615 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-01-20all: fix typos in go file commentsMarcel Meyer
This is the second round to look for spelling mistakes. This time the manual sifting of the result list was made easier by filtering out capitalized and camelcase words. grep -r --include '*.go' -E '^// .*$' . | aspell list | grep -E -x '[A-Za-z]{1}[a-z]*' | sort | uniq This PR will be imported into Gerrit with the title and first comment (this text) used to generate the subject and body of the Gerrit change. Change-Id: Ie8a2092aaa7e1f051aa90f03dbaf2b9aaf5664a9 GitHub-Last-Rev: fc2bd6e0c51652f13a7588980f1408af8e6080f5 GitHub-Pull-Request: golang/go#57737 Reviewed-on: https://go-review.googlesource.com/c/go/+/461595 Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
2023-01-17cmd/dist: make toolchain build reproducibleRuss Cox
- Build cmd with CGO_ENABLED=0. Doing so removes the C compiler toolchain from the reproducibility perimeter and also results in cmd/go and cmd/pprof binaries that are statically linked, so that they will run on a wider variety of systems. In particular the Linux versions will run on Alpine and NixOS without needing a simulation of libc.so.6. The potential downside of disabling cgo is that cmd/go and cmd/pprof use the pure Go network resolver instead of the host resolver on Unix systems. This means they will not be able to use non-DNS resolver mechanisms that may be specified in /etc/resolv.conf, such as mDNS. Neither program seems likely to need non-DNS names like those, however. macOS and Windows systems still use the host resolver, which they access without cgo. - Build cmd with -trimpath when building a release. Doing so removes $GOPATH from the file name prefixes stored in the binary, so that the build directory does not leak into the final artifacts. - When CC and CXX are empty, do not pick values to hard-code into the source tree and binaries. Instead, emit code that makes the right decision at runtime. In addition to reproducibility, this makes cross-compiled toolchains work better. A macOS toolchain cross-compiled on Linux will now correctly look for clang, instead of looking for gcc because it was built on Linux. - Convert \ to / in file names stored in .a files. These are converted to / in the final binaries, but the hashes of the .a files affect the final build ID of the binaries. Without this change, builds of a Windows toolchain on Windows and non-Windows machines produce identical binaries except for the input hash part of the build ID. - Due to the conversion of \ to / in .a files, convert back when reading inline bodies on Windows to preserve output file names in error messages. Combined, these four changes (along with Go 1.20's removal of installed pkg/**.a files and conversion of macOS net away from cgo) make the output of make.bash fully reproducible, even when cross-compiling: a released macOS toolchain built on Linux or Windows will contain exactly the same bits as a released macOS toolchain built on macOS. The word "released" in the previous sentence is important. For the build IDs in the binaries to work out the same on both systems, a VERSION file must exist to provide a consistent compiler build ID (instead of using a content hash of the binary). For #24904. Fixes #57007. Change-Id: I665e1ef4ff207d6ff469452347dca5bfc81050e6 Reviewed-on: https://go-review.googlesource.com/c/go/+/454836 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>