]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.inline] cmd/internal/src: introduce NoPos and use it instead Pos{}
authorRobert Griesemer <gri@golang.org>
Thu, 8 Dec 2016 23:19:47 +0000 (15:19 -0800)
committerRobert Griesemer <gri@golang.org>
Fri, 9 Dec 2016 00:35:07 +0000 (00:35 +0000)
Using a variable instead of a composite literal makes
the code independent of implementation changes of Pos.

Per David Lazar's suggestion.

Change-Id: I336967ac12a027c51a728a58ac6207cb5119af4a
Reviewed-on: https://go-review.googlesource.com/34148
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/order.go
src/cmd/compile/internal/gc/racewalk.go
src/cmd/compile/internal/ssa/compile.go
src/cmd/compile/internal/ssa/config.go
src/cmd/compile/internal/ssa/deadstore.go
src/cmd/compile/internal/ssa/func_test.go
src/cmd/compile/internal/ssa/html.go
src/cmd/compile/internal/ssa/regalloc.go
src/cmd/compile/internal/ssa/sparsemap.go
src/cmd/compile/internal/ssa/stackalloc.go
src/cmd/internal/src/src.go

index 433a89d0d1b83ad8b22354625f0abf54706f7aaa..7edb1eaa9dd6de38241fadb443ffbb4090ade5a3 100644 (file)
@@ -511,7 +511,7 @@ func orderstmt(n *Node, order *Order) {
 
                n.Left = orderexpr(n.Left, order, nil)
                n.Left = ordersafeexpr(n.Left, order)
-               tmp1 := treecopy(n.Left, src.Pos{})
+               tmp1 := treecopy(n.Left, src.NoPos)
                if tmp1.Op == OINDEXMAP {
                        tmp1.Etype = 0 // now an rvalue not an lvalue
                }
index f4a02f355308256b1f51661ba2623959a13e9fea..088fa78e1da55c5590575ec911dc9498ef75a341 100644 (file)
@@ -496,7 +496,7 @@ func callinstr(np **Node, init *Nodes, wr int, skip int) bool {
                        *np = n
                }
 
-               n = treecopy(n, src.Pos{})
+               n = treecopy(n, src.NoPos)
                makeaddable(n)
                var f *Node
                if flag_msan {
index 6fe731d1a3c6ddaf44f25358b039ae0be345d8af..bbc994d384918ccbd867af4c9e1bb52584ddab6e 100644 (file)
@@ -129,7 +129,7 @@ func (f *Func) dumpFile(phaseName string) {
 
        fi, err := os.Create(fname)
        if err != nil {
-               f.Config.Warnl(src.Pos{}, "Unable to create after-phase dump file %s", fname)
+               f.Config.Warnl(src.NoPos, "Unable to create after-phase dump file %s", fname)
                return
        }
 
index 5704adfb614c6ed36b8714a80edd338350a1f7ec..577e0ff68154f16cdc59d230a155b51499afefcd 100644 (file)
@@ -270,7 +270,7 @@ func NewConfig(arch string, fe Frontend, ctxt *obj.Link, optimize bool) *Config
                c.hasGReg = true
                c.noDuffDevice = true
        default:
-               fe.Fatalf(src.Pos{}, "arch %s not implemented", arch)
+               fe.Fatalf(src.NoPos, "arch %s not implemented", arch)
        }
        c.ctxt = ctxt
        c.optimize = optimize
@@ -310,7 +310,7 @@ func NewConfig(arch string, fe Frontend, ctxt *obj.Link, optimize bool) *Config
        if ev != "" {
                v, err := strconv.ParseInt(ev, 10, 64)
                if err != nil {
-                       fe.Fatalf(src.Pos{}, "Environment variable GO_SSA_PHI_LOC_CUTOFF (value '%s') did not parse as a number", ev)
+                       fe.Fatalf(src.NoPos, "Environment variable GO_SSA_PHI_LOC_CUTOFF (value '%s') did not parse as a number", ev)
                }
                c.sparsePhiCutoff = uint64(v) // convert -1 to maxint, for never use sparse
        }
@@ -332,7 +332,7 @@ func (c *Config) Ctxt() *obj.Link         { return c.ctxt }
 func (c *Config) NewFunc() *Func {
        // TODO(khr): should this function take name, type, etc. as arguments?
        if c.curFunc != nil {
-               c.Fatalf(src.Pos{}, "NewFunc called without previous Free")
+               c.Fatalf(src.NoPos, "NewFunc called without previous Free")
        }
        f := &Func{Config: c, NamedValues: map[LocalSlot][]*Value{}}
        c.curFunc = f
@@ -355,7 +355,7 @@ func (c *Config) logDebugHashMatch(evname, name string) {
                        var ok error
                        file, ok = os.Create(tmpfile)
                        if ok != nil {
-                               c.Fatalf(src.Pos{}, "Could not open hash-testing logfile %s", tmpfile)
+                               c.Fatalf(src.NoPos, "Could not open hash-testing logfile %s", tmpfile)
                        }
                }
                c.logfiles[evname] = file
index 0a4862be94dfe5115fd9590b39c3755ae3f392e5..68bfb53c2f49c1d59546c8cbac19df24cbe74583 100644 (file)
@@ -113,7 +113,7 @@ func dse(f *Func) {
                                if sz > 0x7fffffff { // work around sparseMap's int32 value type
                                        sz = 0x7fffffff
                                }
-                               shadowed.set(v.Args[0].ID, int32(sz), src.Pos{})
+                               shadowed.set(v.Args[0].ID, int32(sz), src.NoPos)
                        }
                }
                // walk to previous store
index 81f1c33cde8136b4b36a07aab32a6d1463f34197..2609551f04a6d691264bc0e626f9a7494965b034 100644 (file)
@@ -155,7 +155,7 @@ func Fun(c *Config, entry string, blocs ...bloc) fun {
                blocks[bloc.name] = b
                for _, valu := range bloc.valus {
                        // args are filled in the second pass.
-                       values[valu.name] = b.NewValue0IA(src.Pos{}, valu.op, valu.t, valu.auxint, valu.aux)
+                       values[valu.name] = b.NewValue0IA(src.NoPos, valu.op, valu.t, valu.auxint, valu.aux)
                }
        }
        // Connect the blocks together and specify control values.
@@ -429,12 +429,12 @@ func TestConstCache(t *testing.T) {
                Bloc("entry",
                        Valu("mem", OpInitMem, TypeMem, 0, nil),
                        Exit("mem")))
-       v1 := f.f.ConstBool(src.Pos{}, TypeBool, false)
-       v2 := f.f.ConstBool(src.Pos{}, TypeBool, true)
+       v1 := f.f.ConstBool(src.NoPos, TypeBool, false)
+       v2 := f.f.ConstBool(src.NoPos, TypeBool, true)
        f.f.freeValue(v1)
        f.f.freeValue(v2)
-       v3 := f.f.ConstBool(src.Pos{}, TypeBool, false)
-       v4 := f.f.ConstBool(src.Pos{}, TypeBool, true)
+       v3 := f.f.ConstBool(src.NoPos, TypeBool, false)
+       v4 := f.f.ConstBool(src.NoPos, TypeBool, true)
        if v3.AuxInt != 0 {
                t.Errorf("expected %s to have auxint of 0\n", v3.LongString())
        }
index 355dc75e75f16088b8c3f2dadce461bf8660e985..b9a1f29aa487644695f322898673a5e1a92f27be 100644 (file)
@@ -21,7 +21,7 @@ type HTMLWriter struct {
 func NewHTMLWriter(path string, logger Logger, funcname string) *HTMLWriter {
        out, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
        if err != nil {
-               logger.Fatalf(src.Pos{}, "%v", err)
+               logger.Fatalf(src.NoPos, "%v", err)
        }
        html := HTMLWriter{File: out, Logger: logger}
        html.start(funcname)
@@ -329,13 +329,13 @@ func (w *HTMLWriter) WriteColumn(title string, html string) {
 
 func (w *HTMLWriter) Printf(msg string, v ...interface{}) {
        if _, err := fmt.Fprintf(w.File, msg, v...); err != nil {
-               w.Fatalf(src.Pos{}, "%v", err)
+               w.Fatalf(src.NoPos, "%v", err)
        }
 }
 
 func (w *HTMLWriter) WriteString(s string) {
        if _, err := w.File.WriteString(s); err != nil {
-               w.Fatalf(src.Pos{}, "%v", err)
+               w.Fatalf(src.NoPos, "%v", err)
        }
 }
 
index 42f6e0d254719b8bfca4937488c9102bea90257a..27b5624d6652c024c3ce0d78ad454bd1e11535f1 100644 (file)
@@ -555,7 +555,7 @@ func (s *regAllocState) init(f *Func) {
                case "s390x":
                        // nothing to do, R10 & R11 already reserved
                default:
-                       s.f.Config.fe.Fatalf(src.Pos{}, "arch %s not implemented", s.f.Config.arch)
+                       s.f.Config.fe.Fatalf(src.NoPos, "arch %s not implemented", s.f.Config.arch)
                }
        }
        if s.f.Config.nacl {
@@ -1912,13 +1912,13 @@ func (e *edgeState) setup(idx int, srcReg []endReg, dstReg []startReg, stacklive
 
        // Live registers can be sources.
        for _, x := range srcReg {
-               e.set(&e.s.registers[x.r], x.v.ID, x.c, false, src.Pos{}) // don't care the position of the source
+               e.set(&e.s.registers[x.r], x.v.ID, x.c, false, src.NoPos) // don't care the position of the source
        }
        // So can all of the spill locations.
        for _, spillID := range stacklive {
                v := e.s.orig[spillID]
                spill := e.s.values[v.ID].spill
-               e.set(e.s.f.getHome(spillID), v.ID, spill, false, src.Pos{}) // don't care the position of the source
+               e.set(e.s.f.getHome(spillID), v.ID, spill, false, src.NoPos) // don't care the position of the source
        }
 
        // Figure out all the destinations we need.
index d2a07e2534042452506f10f1a1f5caafeaa1742a..9fb0a7d83d0462185c7a4b66c582034b431ceb09 100644 (file)
@@ -66,7 +66,7 @@ func (s *sparseMap) setBit(k ID, v uint) {
                s.dense[i].val |= 1 << v
                return
        }
-       s.dense = append(s.dense, sparseEntry{k, 1 << v, src.Pos{}})
+       s.dense = append(s.dense, sparseEntry{k, 1 << v, src.NoPos})
        s.sparse[k] = int32(len(s.dense)) - 1
 }
 
index 599dc934f1f2c07f16c3a143760e53c352fe209d..f39d7f47e48dff35bd30cb8a34183ee6f6566e97 100644 (file)
@@ -40,7 +40,7 @@ func newStackAllocState(f *Func) *stackAllocState {
                return new(stackAllocState)
        }
        if s.f != nil {
-               f.Config.Fatalf(src.Pos{}, "newStackAllocState called without previous free")
+               f.Config.Fatalf(src.NoPos, "newStackAllocState called without previous free")
        }
        return s
 }
index 8691a9aa7493304da97dc2a75077f0acc772fcef..cfa13286d6c15a915d03ee6d5205bbc8cd6cb8f4 100644 (file)
@@ -18,6 +18,9 @@ type Pos struct {
        line int32
 }
 
+// NoPos is a valid unknown position.
+var NoPos Pos
+
 // MakePos creates a new Pos from a line index.
 // It requires intimate knowledge of the underlying
 // implementation and should be used with caution.