[dev.regabi] cmd/compile: introduce cmd/compile/internal/base [generated]

Move Flag, Debug, Ctxt, Exit, and error messages to
new package cmd/compile/internal/base.

These are the core functionality that everything in gc uses
and which otherwise prevent splitting any other code
out of gc into different packages.

A minor milestone: the compiler source code
no longer contains the string "yy".

[git-generate]
cd src/cmd/compile/internal/gc
rf '
        mv atExit AtExit
        mv Ctxt atExitFuncs AtExit Exit base.go

        mv lineno Pos
        mv linestr FmtPos
        mv flusherrors FlushErrors
        mv yyerror Errorf
        mv yyerrorl ErrorfAt
        mv yyerrorv ErrorfVers
        mv noder.yyerrorpos noder.errorAt
        mv Warnl WarnfAt
        mv errorexit ErrorExit

        mv base.go debug.go flag.go print.go cmd/compile/internal/base
'

: # update comments
sed -i '' 's/yyerrorl/ErrorfAt/g; s/yyerror/Errorf/g' *.go

: # bootstrap.go is not built by default so invisible to rf
sed -i '' 's/Fatalf/base.Fatalf/' bootstrap.go
goimports -w bootstrap.go

: # update cmd/dist to add internal/base
cd ../../../dist
sed -i '' '/internal.amd64/a\
	"cmd/compile/internal/base",
' buildtool.go
gofmt -w buildtool.go

Change-Id: I59903c7084222d6eaee38823fd222159ba24a31a
Reviewed-on: https://go-review.googlesource.com/c/go/+/272250
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Russ Cox 2020-11-19 20:49:23 -05:00
parent eb3086e5a8
commit 26b66fd60b
67 changed files with 1626 additions and 1542 deletions

View file

@ -5,6 +5,7 @@
package gc
import (
"cmd/compile/internal/base"
"cmd/compile/internal/syntax"
"cmd/compile/internal/types"
"cmd/internal/src"
@ -101,7 +102,7 @@ func typecheckclosure(clo *Node, top int) {
if !n.Name.Captured() {
n.Name.SetCaptured(true)
if n.Name.Decldepth == 0 {
Fatalf("typecheckclosure: var %S does not have decldepth assigned", n)
base.Fatalf("typecheckclosure: var %S does not have decldepth assigned", n)
}
// Ignore assignments to the variable in straightline code
@ -171,8 +172,8 @@ var capturevarscomplete bool
// We use value capturing for values <= 128 bytes that are never reassigned
// after capturing (effectively constant).
func capturevars(dcl *Node) {
lno := lineno
lineno = dcl.Pos
lno := base.Pos
base.Pos = dcl.Pos
fn := dcl.Func
cvars := fn.ClosureVars.Slice()
out := cvars[:0]
@ -203,7 +204,7 @@ func capturevars(dcl *Node) {
outer = nod(OADDR, outer, nil)
}
if Flag.LowerM > 1 {
if base.Flag.LowerM > 1 {
var name *types.Sym
if v.Name.Curfn != nil && v.Name.Curfn.Func.Nname != nil {
name = v.Name.Curfn.Func.Nname.Sym
@ -212,7 +213,7 @@ func capturevars(dcl *Node) {
if v.Name.Byval() {
how = "value"
}
Warnl(v.Pos, "%v capturing by %s: %v (addr=%v assign=%v width=%d)", name, how, v.Sym, outermost.Name.Addrtaken(), outermost.Name.Assigned(), int32(v.Type.Width))
base.WarnfAt(v.Pos, "%v capturing by %s: %v (addr=%v assign=%v width=%d)", name, how, v.Sym, outermost.Name.Addrtaken(), outermost.Name.Assigned(), int32(v.Type.Width))
}
outer = typecheck(outer, ctxExpr)
@ -220,14 +221,14 @@ func capturevars(dcl *Node) {
}
fn.ClosureVars.Set(out)
lineno = lno
base.Pos = lno
}
// transformclosure is called in a separate phase after escape analysis.
// It transform closure bodies to properly reference captured variables.
func transformclosure(dcl *Node) {
lno := lineno
lineno = dcl.Pos
lno := base.Pos
base.Pos = dcl.Pos
fn := dcl.Func
if fn.ClosureCalled {
@ -325,7 +326,7 @@ func transformclosure(dcl *Node) {
}
}
lineno = lno
base.Pos = lno
}
// hasemptycvars reports whether closure clo has an
@ -337,15 +338,15 @@ func hasemptycvars(clo *Node) bool {
// closuredebugruntimecheck applies boilerplate checks for debug flags
// and compiling runtime
func closuredebugruntimecheck(clo *Node) {
if Debug.Closure > 0 {
if base.Debug.Closure > 0 {
if clo.Esc == EscHeap {
Warnl(clo.Pos, "heap closure, captured vars = %v", clo.Func.ClosureVars)
base.WarnfAt(clo.Pos, "heap closure, captured vars = %v", clo.Func.ClosureVars)
} else {
Warnl(clo.Pos, "stack closure, captured vars = %v", clo.Func.ClosureVars)
base.WarnfAt(clo.Pos, "stack closure, captured vars = %v", clo.Func.ClosureVars)
}
}
if Flag.CompilingRuntime && clo.Esc == EscHeap {
yyerrorl(clo.Pos, "heap-allocated closure, not allowed in runtime")
if base.Flag.CompilingRuntime && clo.Esc == EscHeap {
base.ErrorfAt(clo.Pos, "heap-allocated closure, not allowed in runtime")
}
}
@ -386,8 +387,8 @@ func walkclosure(clo *Node, init *Nodes) *Node {
// If no closure vars, don't bother wrapping.
if hasemptycvars(clo) {
if Debug.Closure > 0 {
Warnl(clo.Pos, "closure converted to global")
if base.Debug.Closure > 0 {
base.WarnfAt(clo.Pos, "closure converted to global")
}
return fn.Nname
}
@ -423,7 +424,7 @@ func typecheckpartialcall(dot *Node, sym *types.Sym) {
break
default:
Fatalf("invalid typecheckpartialcall")
base.Fatalf("invalid typecheckpartialcall")
}
// Create top-level function.
@ -448,13 +449,13 @@ func makepartialcall(dot *Node, t0 *types.Type, meth *types.Sym) *Node {
sym.SetUniq(true)
savecurfn := Curfn
saveLineNo := lineno
saveLineNo := base.Pos
Curfn = nil
// Set line number equal to the line number where the method is declared.
var m *types.Field
if lookdot0(meth, rcvrtype, &m, false) == 1 && m.Pos.IsKnown() {
lineno = m.Pos
base.Pos = m.Pos
}
// Note: !m.Pos.IsKnown() happens for method expressions where
// the method is implicitly declared. The Error method of the
@ -512,7 +513,7 @@ func makepartialcall(dot *Node, t0 *types.Type, meth *types.Sym) *Node {
sym.Def = asTypesNode(dcl)
xtop = append(xtop, dcl)
Curfn = savecurfn
lineno = saveLineNo
base.Pos = saveLineNo
return dcl
}
@ -579,14 +580,14 @@ func walkpartialcall(n *Node, init *Nodes) *Node {
// referenced by method value n.
func callpartMethod(n *Node) *types.Field {
if n.Op != OCALLPART {
Fatalf("expected OCALLPART, got %v", n)
base.Fatalf("expected OCALLPART, got %v", n)
}
// TODO(mdempsky): Optimize this. If necessary,
// makepartialcall could save m for us somewhere.
var m *types.Field
if lookdot0(n.Right.Sym, n.Left.Type, &m, false) != 1 {
Fatalf("failed to find field for OCALLPART")
base.Fatalf("failed to find field for OCALLPART")
}
return m