From 593daf785f5afc8106dd0b17fcad84c9627e5fae Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Thu, 22 Feb 2024 14:12:06 +0000 Subject: [PATCH] cmd/compiler/internal/ssagen: refactor code to sort stack vars Minor refactoring of the code that sorts stack variables to move from sort.Stable to sort.SliceStable. No change in semantics; this is intended to lay the groundwork for a future change. Change-Id: I9eb920e3b3029a734fbe0e0e88c0d57ea3452599 Reviewed-on: https://go-review.googlesource.com/c/go/+/566176 LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui --- src/cmd/compile/internal/ssagen/pgen.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/cmd/compile/internal/ssagen/pgen.go b/src/cmd/compile/internal/ssagen/pgen.go index e7a0699641..c3d9ec3091 100644 --- a/src/cmd/compile/internal/ssagen/pgen.go +++ b/src/cmd/compile/internal/ssagen/pgen.go @@ -84,13 +84,6 @@ func cmpstackvarlt(a, b *ir.Name) bool { return a.Sym().Name < b.Sym().Name } -// byStackVar implements sort.Interface for []*Node using cmpstackvarlt. -type byStackVar []*ir.Name - -func (s byStackVar) Len() int { return len(s) } -func (s byStackVar) Less(i, j int) bool { return cmpstackvarlt(s[i], s[j]) } -func (s byStackVar) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - // needAlloc reports whether n is within the current frame, for which we need to // allocate space. In particular, it excludes arguments and results, which are in // the callers frame. @@ -158,10 +151,12 @@ func (s *ssafn) AllocFrame(f *ssa.Func) { } } - // Use sort.Stable instead of sort.Sort so stack layout (and thus + // Use sort.SliceStable instead of sort.Slice so stack layout (and thus // compiler output) is less sensitive to frontend changes that // introduce or remove unused variables. - sort.Stable(byStackVar(fn.Dcl)) + sort.SliceStable(fn.Dcl, func(i, j int) bool { + return cmpstackvarlt(fn.Dcl[i], fn.Dcl[j]) + }) // Reassign stack offsets of the locals that are used. lastHasPtr := false -- 2.48.1