diff options
| author | Russ Cox <rsc@golang.org> | 2023-05-08 20:23:40 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2023-05-09 16:07:01 +0000 |
| commit | ffc4cc05f596a38c19f0d7e1ee91f17527ac3b37 (patch) | |
| tree | 24bfbb9373aeca964bd188fc758fbad17334da23 /src/cmd/compile/internal/base/hashdebug.go | |
| parent | 81a31f5dd542f9a4d656067c9ed3298fcfb6cfea (diff) | |
| download | go-ffc4cc05f596a38c19f0d7e1ee91f17527ac3b37.tar.xz | |
cmd/compile: standardize on outer-to-inner for pos lists
The call sites that cared all reversed inner-to-outer to outer-to-inner already.
The ones that didn't care left it alone. No one explicitly wanted inner-to-outer.
Also change to a callback-based interface, so that call sites aren't required
to accumulate the results in a slice (the main reason for that before was to
reverse the slice!).
There were three places where these lists were printed:
1. -d=ssa/genssa/dump, explicitly reversing to outer-to-inner
2. node dumps like -W, leaving the default inner-to-outer
3. file positions for HashDebugs, explicitly reversing to outer-to-inner
It makes no sense that (1) and (2) would differ. The reason they do is that
the code for (2) was too lazy to bother to fix it to be the right way.
Consider this program:
package p
func f() {
g()
}
func g() {
println()
}
Both before and after this change, the ssa dump for f looks like:
# x.go:3
00000 (3) TEXT <unlinkable>.f(SB), ABIInternal
00001 (3) FUNCDATA $0, gclocals·g2BeySu+wFnoycgXfElmcg==(SB)
00002 (3) FUNCDATA $1, gclocals·g2BeySu+wFnoycgXfElmcg==(SB)
v4 00003 (-4) XCHGL AX, AX
# x.go:4
# x.go:8
v5 00004 (+8) PCDATA $1, $0
v5 00005 (+8) CALL runtime.printlock(SB)
v7 00006 (-8) CALL runtime.printnl(SB)
v9 00007 (-8) CALL runtime.printunlock(SB)
# x.go:5
b2 00008 (5) RET
00009 (?) END
Note # x.go:4 (f) then # x.go:8 (g, called from f) between v4 and v5.
The -W node dumps used the opposite order:
before walk f
. AS2 Def tc(1) # x.go:4:3
. INLMARK # +x.go:4:3
. PRINTN tc(1) # x.go:8:9,x.go:4:3
. LABEL p..i0 # x.go:4:3
Now they match the ssa dump order, and they use spaces as separators,
to avoid potential problems with commas in some editors.
before walk f
. AS2 Def tc(1) # x.go:4:3
. INLMARK # +x.go:4:3
. PRINTN tc(1) # x.go:4:3 x.go:8:9
. LABEL p..i0 # x.go:4:3
I'm unaware of any argument for the old order other than it was easier
to compute without allocation. The new code uses recursion to reverse
the order without allocation.
Now that the callers get the results outer-to-inner, most don't need
any slices at all.
This change is particularly important for HashDebug, which had been
using a locked temporary slice to walk the inline stack without allocation.
Now the temporary slice is gone.
Change-Id: I5cb6d76b2f950db67b248acc928e47a0460569f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/493735
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/base/hashdebug.go')
| -rw-r--r-- | src/cmd/compile/internal/base/hashdebug.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/cmd/compile/internal/base/hashdebug.go b/src/cmd/compile/internal/base/hashdebug.go index 0d0b3f3123..5492d9cda2 100644 --- a/src/cmd/compile/internal/base/hashdebug.go +++ b/src/cmd/compile/internal/base/hashdebug.go @@ -351,24 +351,24 @@ func (d *HashDebug) debugHashMatchPos(ctxt *obj.Link, pos src.XPos) bool { // bytesForPos renders a position, including inlining, into d.bytesTmp // and returns the byte array. d.mu must be locked. func (d *HashDebug) bytesForPos(ctxt *obj.Link, pos src.XPos) []byte { - d.posTmp = ctxt.AllPos(pos, d.posTmp) - // Reverse posTmp to put outermost first. b := &d.bytesTmp b.Reset() - start := len(d.posTmp) - 1 - if d.inlineSuffixOnly { - start = 0 - } - for i := start; i >= 0; i-- { - p := &d.posTmp[i] + format := func(p src.Pos) { f := p.Filename() if d.fileSuffixOnly { f = filepath.Base(f) } fmt.Fprintf(b, "%s:%d:%d", f, p.Line(), p.Col()) - if i != 0 { - b.WriteByte(';') - } + } + if d.inlineSuffixOnly { + format(ctxt.InnermostPos(pos)) + } else { + ctxt.AllPos(pos, func(p src.Pos) { + if b.Len() > 0 { + b.WriteByte(';') + } + format(p) + }) } return b.Bytes() } |
