From 3431d9113c7e01a0ddb458a075ca571d3873e061 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Tue, 28 Mar 2017 13:52:14 -0700 Subject: [PATCH] cmd/compile: add global autogeneratedPos We use an "autogenerated" position in several places. Rather than recreate it each time, make one early on and reuse it. This removes the creation of new positions during the backend, which was not concurrency-safe. Updates #15756 Change-Id: Ic116b2e60f0e99de1a2ea87fe763831b50b645f8 Reviewed-on: https://go-review.googlesource.com/38915 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/alg.go | 4 ++-- src/cmd/compile/internal/gc/go.go | 2 ++ src/cmd/compile/internal/gc/init.go | 4 +--- src/cmd/compile/internal/gc/main.go | 2 ++ src/cmd/compile/internal/gc/subr.go | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cmd/compile/internal/gc/alg.go b/src/cmd/compile/internal/gc/alg.go index a63ae091fe..945f0f93f5 100644 --- a/src/cmd/compile/internal/gc/alg.go +++ b/src/cmd/compile/internal/gc/alg.go @@ -186,7 +186,7 @@ func genhash(sym *Sym, t *Type) { fmt.Printf("genhash %v %v\n", sym, t) } - lineno = makePos(nil, 1, 0) // less confusing than end of input + lineno = autogeneratedPos // less confusing than end of input dclcontext = PEXTERN markdcl() @@ -364,7 +364,7 @@ func geneq(sym *Sym, t *Type) { fmt.Printf("geneq %v %v\n", sym, t) } - lineno = makePos(nil, 1, 0) // less confusing than end of input + lineno = autogeneratedPos // less confusing than end of input dclcontext = PEXTERN markdcl() diff --git a/src/cmd/compile/internal/gc/go.go b/src/cmd/compile/internal/gc/go.go index 5d5f5a231c..f4ef28376c 100644 --- a/src/cmd/compile/internal/gc/go.go +++ b/src/cmd/compile/internal/gc/go.go @@ -286,6 +286,8 @@ var nodfp *Node var disable_checknil int +var autogeneratedPos src.XPos + // interface to back end type Arch struct { diff --git a/src/cmd/compile/internal/gc/init.go b/src/cmd/compile/internal/gc/init.go index 8355a735a9..0ebbffd83a 100644 --- a/src/cmd/compile/internal/gc/init.go +++ b/src/cmd/compile/internal/gc/init.go @@ -4,8 +4,6 @@ package gc -import "cmd/internal/src" - // a function named init is a special case. // it is called by the initialization before // main is run. to make it unique within a @@ -77,7 +75,7 @@ func anyinit(n []*Node) bool { } func fninit(n []*Node) { - lineno = makePos(src.NewFileBase("", ""), 1, 0) + lineno = autogeneratedPos nf := initfix(n) if !anyinit(nf) { return diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 413ff0e879..a676597911 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -351,6 +351,8 @@ func Main(archInit func(*Arch)) { dclcontext = PEXTERN nerrors = 0 + autogeneratedPos = makePos(src.NewFileBase("", ""), 1, 0) + timings.Start("fe", "loadsys") loadsys() diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go index df18606009..f6690e0f1b 100644 --- a/src/cmd/compile/internal/gc/subr.go +++ b/src/cmd/compile/internal/gc/subr.go @@ -1717,7 +1717,7 @@ func genwrapper(rcvr *Type, method *Field, newnam *Sym, iface int) { fmt.Printf("genwrapper rcvrtype=%v method=%v newnam=%v\n", rcvr, method, newnam) } - lineno = makePos(src.NewFileBase("", ""), 1, 0) + lineno = autogeneratedPos dclcontext = PEXTERN markdcl()