aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile
AgeCommit message (Collapse)Author
2025-10-28cmd/compile: extend ppc64 MADDLD to match const ADDconst & MULLDconstJorropo
Fixes #76084 I was focused on restoring the old behavior and fixing the failing test/codegen/arithmetic.go:MergeMuls2 test. It is probable this same bug hides elsewhere in this file. Change-Id: I17f2ee6b97a1e33b8132648d9d750749d006f7e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/715560 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Paul Murphy <paumurph@redhat.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jayanth Krishnamurthy <jayanth.krishnamurthy@ibm.com>
2025-10-28cmd/compile: name change isDirect -> isDirectAndComparableKeith Randall
Now that it also restricts to comparable types. Followon to CL 713840. Change-Id: Idd975c3fd16fb51f55360f2fa0b89ab0bf1d00ed Reviewed-on: https://go-review.googlesource.com/c/go/+/715700 Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Mateusz Poliwczak <mpoliwczak34@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-28cmd/compile: don't optimize away a panicing interface comparisonKeith Randall
We can't do direct pointer comparisons if the type is not a comparable type. Fixes #76008 Change-Id: I1687acff21832d2c2e8f3b875e7b5ec125702ef3 Reviewed-on: https://go-review.googlesource.com/c/go/+/713840 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com>
2025-10-28cmd/compile: extend loong MOV*idx rules to match ADDshiftLLVJorropo
Fixes #76085 I was focused on restoring the old behavior and fixing the failing test/codegen/floats.go:index* tests. It is probable this same bug hides elsewhere in this file. Change-Id: Ibb2cb2be5c7bbeb5eafa9705d998a67380f2b04c Reviewed-on: https://go-review.googlesource.com/c/go/+/715580 Reviewed-by: abner chenc <chenguoqi@loongson.cn> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-10-28go/types, types2: pull up package-level object sort to a separate phaseMark Freeman
This step allows future additional phases to reuse the sorted object list. Preparation for upcoming CLs. Change-Id: I22eaffd5bbe39c7cc101c6d860011dc3cb98ce37 Reviewed-on: https://go-review.googlesource.com/c/go/+/715480 Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Mark Freeman <markfreeman@google.com>
2025-10-28go/types, types2: reduce locks held at once in resolveUnderlyingMark Freeman
There is no need to hold locks for the entire chain of Named types in resolveUnderlying. This change moves the locking / unlocking right to where t.underlying is set. This change consolidates logic into resolveUnderlying where possible and makes minor stylistic / documentation adjustments. Change-Id: Ic5ec5a7e9a0da8bc34954bf456e4e23a28df296d Reviewed-on: https://go-review.googlesource.com/c/go/+/714403 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-28cmd/compile: rewrite proved multiplies by 0 or 1 into CondSelectJorropo
Updates #76056 Change-Id: I64fe631ab381c74f902f877392530d7cc91860ab Reviewed-on: https://go-review.googlesource.com/c/go/+/715044 Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-28cmd/compile: move branchelim supported arches to ConfigJorropo
Change-Id: I8d10399ba71e5fa97ead06a717fc972c806c0856 Reviewed-on: https://go-review.googlesource.com/c/go/+/715042 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-10-27crypto/subtle,cmd/compile: add intrinsics for ConstantTimeSelect and *EqJorropo
Targeting crypto/subtle rather than crypto/internal/fips140/subtle after discussion with Filippo. goos: linux goarch: amd64 pkg: crypto/subtle cpu: AMD Ryzen 5 3600 6-Core Processor │ /tmp/old.logs │ /tmp/new.logs │ │ sec/op │ sec/op vs base │ ConstantTimeSelect-12 0.5246n ± 1% 0.5217n ± 2% ~ (p=0.118 n=10) ConstantTimeByteEq-12 1.0415n ± 1% 0.5202n ± 2% -50.05% (p=0.000 n=10) ConstantTimeEq-12 0.7813n ± 2% 0.7819n ± 0% ~ (p=0.897 n=10) ConstantTimeLessOrEq-12 1.0415n ± 3% 0.7813n ± 1% -24.98% (p=0.000 n=10) geomean 0.8166n 0.6381n -21.86% The last three will become 1 lat-cycle (0.25ns) faster once #76066 is fixed. The Select being that fast with the old code is really impressive. I am pretty sure this happens because my CPU has BMI1&2 support and a fusing unit able to translate non BMI code into BMI code. This benchmark doesn't capture the CACHE gains from the shorter assembly. It currently compiles as: v17 = TESTQ <flags> v31 v31 // v != 0 v20 = CMOVQNE <int> v32 v33 v17 (y[int]) It is possible to remove the `TESTQ` by compiletime fusing it with the compare in a pattern like this: subtle.ConstantTimeSelect(subtle.ConstantTimeLessOrEq(left, right), right, left) Saving 2 latency-cycles (1 with #76066 fixed). Updates #76056 Change-Id: I61a1df99e97a1506f75dae13db529f43846d8f1e Reviewed-on: https://go-review.googlesource.com/c/go/+/715045 Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@google.com>
2025-10-27cmd/compile: add generic rules to remove bool → int → bool roundtripsJorropo
Change-Id: I8b0a3b64c89fe167d304f901a5d38470f35400ab Reviewed-on: https://go-review.googlesource.com/c/go/+/715200 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2025-10-27cmd/compile: do not Zext bools to 64bits in amd64 CMOV generation rulesJorropo
Change-Id: I77b714ed767e50d13183f4307f65e47ca7577f9f Reviewed-on: https://go-review.googlesource.com/c/go/+/715380 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-27cmd/compile: introduce bytesizeToConst to cleanup switches in proveJorropo
Change-Id: I32b45d9632a8131911cb9bd6eff075eb8312ccfd Reviewed-on: https://go-review.googlesource.com/c/go/+/715043 Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org>
2025-10-27cmd/compile: add position info to sccp debug messagesJorropo
Change-Id: Ic568dd3b2e3ebebb1b6aaa41ee78a12d4e8d3f06 Reviewed-on: https://go-review.googlesource.com/c/go/+/714221 Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Jorropo <jorropo.pgm@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>
2025-10-27cmd/compile: teach prove about unsigned rounding-up divideJorropo
Change-Id: Ia7b5242c723f83ba85d12e4ca64a19fbbd126016 Reviewed-on: https://go-review.googlesource.com/c/go/+/714622 Auto-Submit: Jorropo <jorropo.pgm@gmail.com> 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: Michael Knyszek <mknyszek@google.com>
2025-10-27cmd/compile: change !l.nonzero() into l.maybezero()Jorropo
if l.maybezero() is easier to read than if !l.nonzero() Change-Id: I1183b0c0dc51fa1eed26dfc7a5a996783806a991 Reviewed-on: https://go-review.googlesource.com/c/go/+/714621 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-10-27cmd/compile: optimize Add64carry with unused carries into plain Add64Jorropo
Change-Id: I8a63f567cfc574bb066ad6269eec6929760cb9c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/656338 Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com>
2025-10-27cmd/compile: remove 68857 ModU flowLimit workaround in proveJorropo
We can know this is correct because all the testcases added by CL 605156 are still passing. Partial revert of CL 605156 (everything but the testcases). Change-Id: I5d8daadb4cb35a9de29daaabc22baee642511fe0 Reviewed-on: https://go-review.googlesource.com/c/go/+/714941 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-27cmd/compile: remove 68857 min & max flowLimit workaround in proveJorropo
We can know this is correct because all the testcases added by CL 656157 are still passing. Partial revert of CL 656157 (everything but the testcases). Change-Id: I24931fa1affba7e9e92233b3de74ebade3d48a09 Reviewed-on: https://go-review.googlesource.com/c/go/+/714921 Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-27cmd/compile: use topo-sort in prove to correctly learn facts while walking onceJorropo
Fixes #68857 Change-Id: Ideb359cc6f1550afb4c79f02d25a00d0ae5e5c50 Reviewed-on: https://go-review.googlesource.com/c/go/+/714920 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
2025-10-27cmd/go: use tagged switchIan Alexander
Minor modernization to use a tagged switch statement in lieu of if-else chain. Change-Id: I132d279d421b4a609403f85f9f1ddfc2605a5399 Reviewed-on: https://go-review.googlesource.com/c/go/+/715341 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2025-10-27cmd/go: increase stmt threshold on amd64Ian Alexander
This change slightly increases the stmt threshold on the amd64 platform. Change-Id: I87e39753b52d6d72f2cd77f1cb8015b1e550921a Reviewed-on: https://go-review.googlesource.com/c/go/+/715340 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-27go/types, types2: clarify docs for resolveUnderlyingMark Freeman
The resolveUnderlying method only detects cycles among type names, where no type literal or predeclared type can be found (which would yield an underlying type). Change-Id: I203f3856eaf63a8a9d317c22521755390f9c1023 Reviewed-on: https://go-review.googlesource.com/c/go/+/714402 Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-27go/types, types2: wrap Named.fromRHS into Named.rhsMark Freeman
In debug mode, the Named.rhs method asserts that Named is in a state with Named.fromRHS populated. This caught a missing call to Named.unpack in validtype, which has been added. Change-Id: Id3f95f78f03d98a6efe87af6ac24f2ac2e285f96 Reviewed-on: https://go-review.googlesource.com/c/go/+/714242 Auto-Submit: Mark Freeman <markfreeman@google.com> Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-27go/types, types2: verify stateMask transitions in debug modeMark Freeman
Recently, we've changed the representation of Named type state from an integer to a bit mask, which is a bit more complicated. To make sure we uphold state invariants, we are adding a verification step on each state transition. This uncovered a few places where we do not uphold the transition invariants; those are patched in this CL. Change-Id: I76569e4326b2d362d7a1f078641029ffb3dca531 Reviewed-on: https://go-review.googlesource.com/c/go/+/714241 Auto-Submit: Mark Freeman <markfreeman@google.com> Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-26cmd/compile: use MOV(D|F) with const for Const(64|32)F on riscv64Meng Zhuo
The original Const64F using: AUIPC + LD + FMVDX to load float64 const, we can use AUIPC + FLD instead, same as Const32F. Change-Id: I8ca0a0e90d820a26e69b74cd25df3cc662132bf7 Reviewed-on: https://go-review.googlesource.com/c/go/+/703215 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Joel Sing <joel@sing.id.au> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-10-26cmd/compile: allow unaligned load/store on WasmCherry Mui
Wasm supports unaligned load/store instructions. Use them. This speeds up map hashing slightly (among others): goos: js goarch: wasm pkg: runtime │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ Hash5 14.06n ± 2% 13.83n ± 5% ~ (p=0.186 n=10) Hash16 17.52n ± 1% 17.04n ± 1% -2.71% (p=0.000 n=10) Hash64 28.68n ± 1% 26.61n ± 1% -7.18% (p=0.000 n=10) Hash1024 271.4n ± 0% 243.6n ± 1% -10.21% (p=0.000 n=10) Hash65536 16.66µ ± 0% 15.74µ ± 1% -5.49% (p=0.000 n=10) HashStringSpeed 29.23n ± 1% 28.70n ± 1% -1.83% (p=0.000 n=10) HashBytesSpeed 46.11n ± 4% 45.17n ± 5% -2.04% (p=0.008 n=10) HashInt32Speed 20.39n ± 1% 20.24n ± 5% ~ (p=0.239 n=10) HashInt64Speed 20.81n ± 7% 20.58n ± 7% ~ (p=0.238 n=10) HashStringArraySpeed 76.65n ± 2% 73.72n ± 1% -3.83% (p=0.000 n=10) FastrandHashiter 87.65n ± 1% 87.58n ± 1% ~ (p=0.725 n=10) geomean 67.03n 64.75n -3.40% Change-Id: I7fd1817c74323f628f310393b0330a0a51ffa3a7 Reviewed-on: https://go-review.googlesource.com/c/go/+/714720 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-24[dev.simd] cmd/compile, simd: add rewrite to convert logical expression ↵David Chase
trees into TERNLOG instructions includes tests of both rewrite application and rewrite correctness Change-Id: I7983ccf87a8408af95bb6c447cb22f01beda9f61 Reviewed-on: https://go-review.googlesource.com/c/go/+/710697 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Junyang Shao <shaojunyang@google.com>
2025-10-24[dev.simd] cmd/compile, simd: add SHA featuresJunyang Shao
This CL also fixed some bugs left in CL 712181. Change-Id: I9cb6cd9fbaef307f352809bf21b8fec3eb62721a Reviewed-on: https://go-review.googlesource.com/c/go/+/712361 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-23go/types, types2: rename Named.resolve to unpackMark Freeman
Named.resolve normalizes a named type's representation so that type operations have a uniform surface to work with, regardless of how the type was created. This often gives the type a heavier footprint, such as when filling in a lazy-loaded type from UIR, or expanding the RHS of an instantiated type. For that reason, it seems more appropriate to call this "unpacking" the type, as it hints to this heavier form. The term "resolving" is used in many contexts, and generally suggests that we are trying to figure out what a name means. Change-Id: Ia733fd68656380b2be4f7433b7b971b7c1422783 Reviewed-on: https://go-review.googlesource.com/c/go/+/713285 Auto-Submit: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com>
2025-10-23go/types, types2: rename loaded namedState to lazyLoadedMark Freeman
This is a minor renaming to help differentiate the two kinds of loading that can happen for named types (eager and lazy). Use of the term "loaded" suggests that it might also apply to types which are eagerly-loaded, which is not the case. This change uses "lazyLoaded" instead to mark this difference. Change-Id: Iee170024246d9adf3eed978bde2b0500f6d490b7 Reviewed-on: https://go-review.googlesource.com/c/go/+/713282 Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-23go/types, types2: rename complete namedState to hasMethodsMark Freeman
The complete namedState tracks whether an instantiated named type has expanded all of its methods. In the past, this was the terminal state of a linear lifecycle, and so a term like "complete" made sense. Now that we've expanded the lifecycle of named types to a tree structure, the complete namedState is no longer a terminal state, and so the term "complete" is now a bit confusing. This change a) makes the expansion aspect of the complete namedState more explicit and b) removes a misleading suggestion of terminality by changing the name from complete to hasMethods. To take a similar naming convention with the underlying namedState, which signals presence of Named.underlying, we rename the underlying namedState to hasUnder. Change-Id: I29fee26efea3de88c7c1240f2dc53df218acf8b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/713280 Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-23go/types, types2: set t.underlying exactly once in resolveUnderlyingMark Freeman
While the locking in Named.resolveUnderlying is mostly fine, we do not perform an atomic read before the write to underlying. If resolveUnderlying returns and another thread was waiting on the lock, it can perform a second (in this case identical) write to t.underlying. A reader thread on n.underlying can thus observe either of those writes, tripping the race detector. Michael was kind enough to provide a diagram: T1 T2 1. t.stateHas(underlying) // false 2. t.stateHas(underlying) // false 3. t.mu.Lock() // acquired 4. t.mu.Lock() // blocked 5. t.underlying = u 6. t.setState(underlying) 7. t.mu.Unlock() 8. t.underlying = u // overwritten 9. t.setState(underlying) 10. t.mu.Unlock() Adding a second check before setting t.underlying prevents the write on line 8. Change-Id: Ia43a6d3ba751caef436b9926c6ece2a71dfb9d38 Reviewed-on: https://go-review.googlesource.com/c/go/+/714300 Auto-Submit: Mark Freeman <markfreeman@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-22[dev.simd] cmd/compile, simd: add definitions for VPTERNLOG[DQ]David Chase
This includes an non-public intrinsic for testing, and a test. Optimizations using this instruction will follow in another CL. Change-Id: I7f7a93212249a16a30bd1379c717f8a7f9915daf Reviewed-on: https://go-review.googlesource.com/c/go/+/708995 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Junyang Shao <shaojunyang@google.com>
2025-10-22go/types, types2: simplify locking in Named.resolveUnderlyingRobert Griesemer
Avoid calling Named.resolveUnderlying in the first place (there is only one caller) if Named.underlying exists already. In Named.resolveUnderlying remove initial atomic check because of the check in Named.Underlying. Also, remove a 2nd atomic check after acquiring the lock as it likely won't help much. Change-Id: Ife87218fa2549d0903a10218f4dd7a70f85d6c7c Reviewed-on: https://go-review.googlesource.com/c/go/+/713521 Auto-Submit: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Mark Freeman <markfreeman@google.com>
2025-10-22go/types, types2: in resolveUnderlying, only compute path when neededRobert Griesemer
When following a RHS chain, the (TypeName) Object path is only needed when there is a cycle (i.e., an error), in which case we can be slow. Rather than always compute the path, only compute it in the error case. In the same vain, allocate the seen map lazily, only when needed. This code could use a test (it doesn't seem to be encountered by our test suite), but I haven't found a case to provoke the error yet. Change-Id: Iff6313394442a251adc56580f746928ec13450fd Reviewed-on: https://go-review.googlesource.com/c/go/+/712321 Auto-Submit: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
2025-10-22go/types, types2: rename Named.under to Named.resolveUnderlyingRobert Griesemer
Named.resolveUnderlying is now just a helper function for Underlying and only called from there. The name makes is clearer what this function does; it also doesn't need to return a result anymore. While at it, slightly simplify the function body. Change-Id: I167c4be89b1bfcc69f6b528ddb6ed4c90481194a Reviewed-on: https://go-review.googlesource.com/c/go/+/712521 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
2025-10-21go/types, types2: only report version errors if new(expr) is ok otherwiseRobert Griesemer
If new(expr) is used before Go 1.26, don't report version errors if there are other problems with the expression. While at it, implement multiple missing type checks for new(expr) and add corresponding test cases that were missed in CL 704935 (tests for no value expressions, generic types, untyped nil). Reorganize/rename builtins0.go tests for new to match existing test case patterns again. Fixes #75986. For #45624. Change-Id: I39e5516d3f8d191cc390a4d8b9911c312bbb177c Reviewed-on: https://go-review.googlesource.com/c/go/+/713241 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com>
2025-10-21go/types, types2: guard Named.underlying with Named.muMark Freeman
It appears that CL 695977 introduced a data race on Named.underlying. This fixes that race by specifying a new namedState called underlying, which, perhaps unsurprisingly, signals that Named.underlying is populated. Unfortunately, the underlying namedState is independent of the complete namedState (unsurprising since methods and the underlying type are not related). Hence, they cannot be ordered and thus do not fit the current integer-based state representation. To account for combinations of states, we introduce a bit set representation for namedState instead. The namedState field is also renamed to stateMask to reflect this new representation. Methods that operate on the stateMask are adjusted and exposition is added throughout. Fixes #75963 Change-Id: Icfa188ea2fa7916804c06f80668e99176bf4e978 Reviewed-on: https://go-review.googlesource.com/c/go/+/712720 Auto-Submit: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com>
2025-10-21cmd/compile/internal/ssa: fix typo in commentJes Cok
Change-Id: Ic48a756b71a62be1c6c4cfe781c02b89010e2338 GitHub-Last-Rev: 8c0d89b475c204af66d528799713276c57da16f8 GitHub-Pull-Request: golang/go#75985 Reviewed-on: https://go-review.googlesource.com/c/go/+/713041 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Keith Randall <khr@golang.org> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-21all: eliminate unnecessary type conversionsJes Cok
Found by github.com/mdempsky/unconvert Change-Id: I88ce10390a49ba768a4deaa0df9057c93c1164de GitHub-Last-Rev: 3b0f7e8f74f58340637f33287c238765856b2483 GitHub-Pull-Request: golang/go#75974 Reviewed-on: https://go-review.googlesource.com/c/go/+/712940 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com>
2025-10-21cmd/compile: leave the horses aloneJorropo
I don't know why we were eliminating horses, this not cool. Change-Id: I0d4b5a1b2f584e071de0a85ef88f9baf9183e12e Reviewed-on: https://go-review.googlesource.com/c/go/+/712820 Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Jorropo <jorropo.pgm@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>
2025-10-17go/types, types2: remove references to under function in commentsRobert Griesemer
Follow-up on CL 712400 which removed the under function. Change-Id: I253c8adbbaa058150f26e311e37b4c1644b6554d Reviewed-on: https://go-review.googlesource.com/c/go/+/712520 Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Robert Griesemer <gri@google.com>
2025-10-17all: correct name for commentsJes Cok
Change-Id: I390c380349e99ad421264b673ad7734eddb639d3 GitHub-Last-Rev: 32e849a6420574b0d878b9a449a8c044fd6ebdd1 GitHub-Pull-Request: golang/go#75905 Reviewed-on: https://go-review.googlesource.com/c/go/+/711941 Reviewed-by: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-10-16go/types, types2: remove under(Type) in favor of Type.Underlying()Mark Freeman
As of CL 695977, under(Type) simply delegates to Type.Underlying(). This is just a cleanup. Change-Id: I48d5fddc38560dfe485184faa6a5ff713bea74a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/712400 Commit-Queue: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-16go/types, types2: change and enforce lifecycle of Named.fromRHS and ↵Mark Freeman
Named.underlying fields A type definition or alias declaration consists of a type name (LHS) which is bound to a type expression (RHS) by the declaration. This CL consistently uses the fromRHS fields of Named and Alias types to represent that RHS type expression, and sets Named.underlying and Alias.actual only once those types have been computed. Currently, Named types use Named.underlying for some of this functionality, which makes the code difficult to understand. Operations which used Named.underlying now use Named.fromRHS. For example, in: type A = B type B = int A.fromRHS is B (Alias) and B.fromRHS is int (Basic). Meanwhile, in: type A B type B int A.underlying is B (Named) and B.underlying is int (Basic) initially. Note that despite A.underlying pointing to B, B is not the underlying type of A (it is int). At some point during type checking, A walks through the chain A.underlying -> B.underlying -> int and sets A.underlying to int. While this approach works, it introduces some problems: 1. Whether A.underlying refers to the underlying type (int) or not (B) depends on when the field is accessed. 2. There is no convenient mechanism to check if the underlying type of B has been deduced. One can check if B.underlying is a named type, but since B.underlying is already B's underlying type (int), it's still ambiguous. Operations derived from Named.underlying share similar problems. For example, Named.expandUnderlying() (which substitutes type arguments) returns an instantiated named type whose Named.underlying also may or may not refer to its underlying type. With this change, Named.underlying is nil as long as it is unknown, and non-nil and not a named type once it is known. Additional assertions are added to enforce that: 1. Named.underlying is not set until Named has been resolved. 2. Named is not resolved until Named.fromRHS is populated, unless it is given explicit permission. This permission is briefly given while type-checking declarations of named types to account for cycles of alias types represented as TypeNames. It is also given to named types created through NewNamed for backward compatibility. This permission is revoked when SetUnderlying is called. Accessors of Named.underlying are responsible for first resolving the named type, unless they are in a context where they know the type to already be resolved. This change also exposed a bug in validType wherein the underlying type for struct types containing invalid types did not have their underlying type set to invalid (see #75194). This bug was exploited by a test in x/tools, which has been disabled for Go 1.26 (via CL 700395). Other minor adjustments are made for instantiated and loaded types. Instantiated types have no RHS as they are not declared, and loaded types set their RHS to the underlying from export data directly. Minor simplifications are also made throughout. Fixes #75194 Change-Id: I72644d7329c996eb1e67514063fe51c3ae06c38d Reviewed-on: https://go-review.googlesource.com/c/go/+/695977 Auto-Submit: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com>
2025-10-16go/types, types2: remove superfluous unalias call (minor cleanup)Robert Griesemer
Change-Id: Ifc0d6e999777513498f070c5bc2fb4640d38c671 Reviewed-on: https://go-review.googlesource.com/c/go/+/712460 Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Mark Freeman <markfreeman@google.com>
2025-10-15cmd/compile: fix an error in commentsmohanson
Remove the redundant only. Change-Id: I9cf2d84ae080a567ad45a2d0ef002c7c89395479 Reviewed-on: https://go-review.googlesource.com/c/go/+/711960 Auto-Submit: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Bypass: Robert Griesemer <gri@google.com>
2025-10-15go/types, types2: fix misleading internal commentRobert Griesemer
See also the discussion in #75885. Change-Id: Ieb964ea6ee51600c0c08ecba0af50a1deb209a4d Reviewed-on: https://go-review.googlesource.com/c/go/+/712141 Reviewed-by: Mark Freeman <markfreeman@google.com> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Bypass: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
2025-10-15cmd/compile: replace angle brackets with squareWill Faught
Caused Markdown rendering error on https://go.dev/src/cmd/compile/README in macOS (15.6.1) Safari (18.6). Change-Id: Id71436d9a7bc7e461e522500d66df5dda7cd9f7f GitHub-Last-Rev: 4e4447e163ac65e6c394807ec4874bc5ca26bb32 GitHub-Pull-Request: golang/go#75549 Reviewed-on: https://go-review.googlesource.com/c/go/+/704716 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@google.com>
2025-10-15cmd/compile: remove rematerializable values from live set across callsAlexander Musman
Remove rematerializable values in the live set across call operations, preventing dead constant rematerialization. When computing live values across function calls, rematerializable values were being kept in the live set unnecessarily. This caused the shuffling to rematerialize dead constants. This change leads to code size reduction on arm64 linux: Executable Old .text New .text Change ------------------------------------------------------- asm 1969236 1964356 -0.25% cgo 1739588 1734884 -0.27% compile 8950788 8932500 -0.20% cover 1877268 1872916 -0.23% link 2572660 2565076 -0.29% preprofile 866772 863828 -0.34% vet 2888628 2881028 -0.26% There seems also some compile time effect: orig.results uexp.results sec/op sec/op vs base BleveIndexBatch100-4 7.414 ± 2% 7.352 ± 1% ~ (p=0.218 n=10) ESBuildThreeJS-4 777.3m ± 1% 778.1m ± 1% ~ (p=0.529 n=10) ESBuildRomeTS-4 197.3m ± 1% 199.0m ± 1% ~ (p=0.143 n=10) EtcdPut-4 64.92m ± 2% 64.95m ± 2% ~ (p=0.912 n=10) EtcdSTM-4 323.9m ± 1% 323.0m ± 1% ~ (p=0.393 n=10) GoBuildKubelet-4 160.1 ± 0% 159.4 ± 0% -0.42% (p=0.001 n=10) GoBuildKubeletLink-4 12.40 ± 1% 12.27 ± 1% ~ (p=0.529 n=10) GoBuildIstioctl-4 125.8 ± 0% 125.2 ± 0% -0.42% (p=0.000 n=10) GoBuildIstioctlLink-4 8.679 ± 0% 8.686 ± 1% ~ (p=0.912 n=10) GoBuildFrontend-4 49.18 ± 0% 48.73 ± 0% -0.92% (p=0.000 n=10) GoBuildFrontendLink-4 2.300 ± 1% 2.292 ± 1% -0.35% (p=0.043 n=10) GopherLuaKNucleotide-4 37.77 ± 6% 38.07 ± 2% ~ (p=0.218 n=10) MarkdownRenderXHTML-4 274.3m ± 0% 275.2m ± 0% +0.34% (p=0.003 n=10) Tile38QueryLoad-4 650.7µ ± 0% 650.2µ ± 0% ~ (p=0.971 n=10) geomean 2.130 2.127 -0.15% Change-Id: I7a766195ee17bfd9e47d7a940864619f553416ff Reviewed-on: https://go-review.googlesource.com/c/go/+/707415 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: 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>