diff options
Diffstat (limited to 'src/cmd/compile/internal')
| -rw-r--r-- | src/cmd/compile/internal/base/hashdebug.go | 22 | ||||
| -rw-r--r-- | src/cmd/compile/internal/ir/fmt.go | 10 | ||||
| -rw-r--r-- | src/cmd/compile/internal/logopt/log_opts.go | 13 | ||||
| -rw-r--r-- | src/cmd/compile/internal/ssagen/ssa.go | 10 |
4 files changed, 26 insertions, 29 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() } diff --git a/src/cmd/compile/internal/ir/fmt.go b/src/cmd/compile/internal/ir/fmt.go index dcb8988b66..a9cf716dff 100644 --- a/src/cmd/compile/internal/ir/fmt.go +++ b/src/cmd/compile/internal/ir/fmt.go @@ -1085,15 +1085,15 @@ func dumpNodeHeader(w io.Writer, n Node) { case src.PosIsStmt: fmt.Fprint(w, "+") } - for i, pos := range base.Ctxt.AllPos(n.Pos(), nil) { - if i > 0 { - fmt.Fprint(w, ",") - } + sep := "" + base.Ctxt.AllPos(n.Pos(), func(pos src.Pos) { + fmt.Fprint(w, sep) + sep = " " // TODO(mdempsky): Print line pragma details too. file := filepath.Base(pos.Filename()) // Note: this output will be parsed by ssa/html.go:(*HTMLWriter).WriteAST. Keep in sync. fmt.Fprintf(w, "%s:%d:%d", file, pos.Line(), pos.Col()) - } + }) } } diff --git a/src/cmd/compile/internal/logopt/log_opts.go b/src/cmd/compile/internal/logopt/log_opts.go index f74be6a63c..b731e55938 100644 --- a/src/cmd/compile/internal/logopt/log_opts.go +++ b/src/cmd/compile/internal/logopt/log_opts.go @@ -532,12 +532,9 @@ func appendInlinedPos(posTmp, lastTmp []src.Pos, diagnostic *Diagnostic) { // parsePos expands a src.XPos into a slice of src.Pos, with the outermost first. // It returns the slice, and the outermost. func parsePos(ctxt *obj.Link, pos src.XPos, posTmp []src.Pos) ([]src.Pos, src.Pos) { - posTmp = ctxt.AllPos(pos, posTmp) - // Reverse posTmp to put outermost first. - l := len(posTmp) - for i := 0; i < l/2; i++ { - posTmp[i], posTmp[l-i-1] = posTmp[l-i-1], posTmp[i] - } - p0 := posTmp[0] - return posTmp, p0 + posTmp = posTmp[:0] + ctxt.AllPos(pos, func(p src.Pos) { + posTmp = append(posTmp, p) + }) + return posTmp, posTmp[0] } diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go index 37b5a26d5c..a037b7494d 100644 --- a/src/cmd/compile/internal/ssagen/ssa.go +++ b/src/cmd/compile/internal/ssagen/ssa.go @@ -7331,7 +7331,7 @@ func genssa(f *ssa.Func, pp *objw.Progs) { fi := f.DumpFileForPhase("genssa") if fi != nil { - // inliningDiffers if any filename changes or if any line number except the innermost (index 0) changes. + // inliningDiffers if any filename changes or if any line number except the innermost (last index) changes. inliningDiffers := func(a, b []src.Pos) bool { if len(a) != len(b) { return true @@ -7340,7 +7340,7 @@ func genssa(f *ssa.Func, pp *objw.Progs) { if a[i].Filename() != b[i].Filename() { return true } - if i > 0 && a[i].Line() != b[i].Line() { + if i != len(a)-1 && a[i].Line() != b[i].Line() { return true } } @@ -7352,10 +7352,10 @@ func genssa(f *ssa.Func, pp *objw.Progs) { for p := pp.Text; p != nil; p = p.Link { if p.Pos.IsKnown() { - allPos = p.AllPos(allPos) + allPos = allPos[:0] + p.Ctxt.AllPos(p.Pos, func(pos src.Pos) { allPos = append(allPos, pos) }) if inliningDiffers(allPos, allPosOld) { - for i := len(allPos) - 1; i >= 0; i-- { - pos := allPos[i] + for _, pos := range allPos { fmt.Fprintf(fi, "# %s:%d\n", pos.Filename(), pos.Line()) } allPos, allPosOld = allPosOld, allPos // swap, not copy, so that they do not share slice storage. |
