Skip to content

Commit

Permalink
cmd/compile/internal/typecheck: remove DeclContext
Browse files Browse the repository at this point in the history
The last use of this was removed in go.dev/cl/518757.

Change-Id: I41ddc9601bfa7e553b83c4c5a055104b2044d5d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/520610
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
  • Loading branch information
mdempsky authored and gopherbot committed Aug 18, 2023
1 parent 09b0311 commit 4089b6a
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 33 deletions.
3 changes: 0 additions & 3 deletions src/cmd/compile/internal/gc/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"cmd/compile/internal/objw"
"cmd/compile/internal/ssagen"
"cmd/compile/internal/staticinit"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
"cmd/compile/internal/walk"
"cmd/internal/obj"
Expand Down Expand Up @@ -105,11 +104,9 @@ func prepareFunc(fn *ir.Func) {
// Calculate parameter offsets.
types.CalcSize(fn.Type())

typecheck.DeclContext = ir.PAUTO
ir.CurFunc = fn
walk.Walk(fn)
ir.CurFunc = nil // enforce no further uses of CurFunc
typecheck.DeclContext = ir.PEXTERN
}

// compileFunctions compiles all functions in compilequeue.
Expand Down
1 change: 0 additions & 1 deletion src/cmd/compile/internal/pkginit/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func MakeTask() {
if ni != 0 {
// Make an init._ function.
base.Pos = base.AutogeneratedPos
typecheck.DeclContext = ir.PEXTERN
name := noder.Renameinit()
fnInit := typecheck.DeclFunc(name, nil, nil, nil)

Expand Down
2 changes: 0 additions & 2 deletions src/cmd/compile/internal/reflectdata/alg.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func hashFunc(t *types.Type) *ir.Func {
}

base.Pos = base.AutogeneratedPos // less confusing than end of input
typecheck.DeclContext = ir.PEXTERN

// func sym(p *T, h uintptr) uintptr
args := []*ir.Field{
Expand Down Expand Up @@ -367,7 +366,6 @@ func eqFunc(t *types.Type) *ir.Func {
return sym.Def.(*ir.Name).Func
}
base.Pos = base.AutogeneratedPos // less confusing than end of input
typecheck.DeclContext = ir.PEXTERN

// func sym(p, q *T) bool
fn := typecheck.DeclFunc(sym, nil,
Expand Down
3 changes: 0 additions & 3 deletions src/cmd/compile/internal/ssagen/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,9 @@ func makeABIWrapper(f *ir.Func, wrapperABI obj.ABI) {

// Q: is this needed?
savepos := base.Pos
savedclcontext := typecheck.DeclContext
savedcurfn := ir.CurFunc

base.Pos = base.AutogeneratedPos
typecheck.DeclContext = ir.PEXTERN

// At the moment we don't support wrapping a method, we'd need machinery
// below to handle the receiver. Panic if we see this scenario.
Expand Down Expand Up @@ -329,7 +327,6 @@ func makeABIWrapper(f *ir.Func, wrapperABI obj.ABI) {

// Restore previous context.
base.Pos = savepos
typecheck.DeclContext = savedclcontext
ir.CurFunc = savedcurfn
}

Expand Down
29 changes: 5 additions & 24 deletions src/cmd/compile/internal/typecheck/dcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import (
"cmd/internal/src"
)

var DeclContext ir.Class = ir.PEXTERN // PEXTERN/PAUTO
var funcStack []*ir.Func // stack of previous values of ir.CurFunc

func DeclFunc(sym *types.Sym, recv *ir.Field, params, results []*ir.Field) *ir.Func {
fn := ir.NewFunc(base.Pos, base.Pos, sym, nil)
StartFuncBody(fn)

funcStack = append(funcStack, ir.CurFunc)
ir.CurFunc = fn

var recv1 *types.Field
if recv != nil {
Expand All @@ -38,25 +40,11 @@ func DeclFunc(sym *types.Sym, recv *ir.Field, params, results []*ir.Field) *ir.F
return fn
}

// declare the function proper
// and declare the arguments.
// called in extern-declaration context
// returns in auto-declaration context.
func StartFuncBody(fn *ir.Func) {
// change the declaration context from extern to auto
funcStack = append(funcStack, funcStackEnt{ir.CurFunc, DeclContext})
ir.CurFunc = fn
DeclContext = ir.PAUTO
}

// finish the body.
// called in auto-declaration context.
// returns in extern-declaration context.
func FinishFuncBody() {
// change the declaration context from auto to previous context
var e funcStackEnt
funcStack, e = funcStack[:len(funcStack)-1], funcStack[len(funcStack)-1]
ir.CurFunc, DeclContext = e.curfn, e.dclcontext
funcStack, ir.CurFunc = funcStack[:len(funcStack)-1], funcStack[len(funcStack)-1]
}

func CheckFuncStack() {
Expand All @@ -83,13 +71,6 @@ func checkdupfields(what string, fss ...[]*types.Field) {
}
}

var funcStack []funcStackEnt // stack of previous values of ir.CurFunc/DeclContext

type funcStackEnt struct {
curfn *ir.Func
dclcontext ir.Class
}

func declareParams(fn *ir.Func, ctxt ir.Class, l []*ir.Field) []*types.Field {
fields := make([]*types.Field, len(l))
for i, n := range l {
Expand Down

0 comments on commit 4089b6a

Please sign in to comment.