diff options
author | Keith Randall <khr@golang.org> | 2024-03-28 08:47:52 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2024-03-28 22:06:51 +0000 |
commit | 8f618c1f5329bd81912f8f776cb8bf028c750687 (patch) | |
tree | 279faa182298dd8f516dbb56106117168ba0967b /src/cmd/compile/internal/types2/initorder.go | |
parent | 3f90ba7f1f0ecb230105ad1068ffdc3c2f9a8a97 (diff) | |
download | go-8f618c1f5329bd81912f8f776cb8bf028c750687.tar.gz go-8f618c1f5329bd81912f8f776cb8bf028c750687.zip |
cmd/compile: put constants before variables in initialization order
Fixes #66575
Change-Id: I03f4d4577b88ad0a92b260b2efd0cb9fe5082b2f
Reviewed-on: https://go-review.googlesource.com/c/go/+/575075
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/initorder.go')
-rw-r--r-- | src/cmd/compile/internal/types2/initorder.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types2/initorder.go b/src/cmd/compile/internal/types2/initorder.go index 0d28495542..86cb9036c4 100644 --- a/src/cmd/compile/internal/types2/initorder.go +++ b/src/cmd/compile/internal/types2/initorder.go @@ -309,6 +309,14 @@ func (a nodeQueue) Swap(i, j int) { func (a nodeQueue) Less(i, j int) bool { x, y := a[i], a[j] + + // Prioritize all constants before non-constants. See go.dev/issue/66575/. + _, xConst := x.obj.(*Const) + _, yConst := y.obj.(*Const) + if xConst != yConst { + return xConst + } + // nodes are prioritized by number of incoming dependencies (1st key) // and source order (2nd key) return x.ndeps < y.ndeps || x.ndeps == y.ndeps && x.obj.order() < y.obj.order() |