cmd/compile: remove unused code from typecheckdef

typecheckdef used to be used to handle references to package-level
declarations that hadn't yet been typechecked yet. It's no longer
needed, as the current IR frontends construct package-level
declarations with proper types upfront.

Exception: this code is still used for compiler-generated function
declarations, so that code needs to be kept. Eventually that code can
be moved elsewhere, but for now this CL makes it obvious that the rest
of the code paths really are unused.

Updates #51691.

Change-Id: I5322edb686aaf5dc4627288f3d9ba910a017b41d
Reviewed-on: https://go-review.googlesource.com/c/go/+/393256
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Matthew Dempsky 2022-03-15 23:07:41 -07:00
parent d661bdeabf
commit 81d3c25c6c
1 changed files with 8 additions and 152 deletions

View File

@ -1686,41 +1686,6 @@ func stringtoruneslit(n *ir.ConvExpr) ir.Node {
return Expr(nn)
}
func typecheckdeftype(n *ir.Name) {
if base.EnableTrace && base.Flag.LowerT {
defer tracePrint("typecheckdeftype", n)(nil)
}
t := types.NewNamed(n)
if n.Curfn != nil {
t.SetVargen()
}
if n.Pragma()&ir.NotInHeap != 0 {
t.SetNotInHeap(true)
}
n.SetType(t)
n.SetTypecheck(1)
n.SetWalkdef(1)
types.DeferCheckSize()
errorsBefore := base.Errors()
n.Ntype = typecheckNtype(n.Ntype)
if underlying := n.Ntype.Type(); underlying != nil {
t.SetUnderlying(underlying)
} else {
n.SetDiag(true)
n.SetType(nil)
}
if t.Kind() == types.TFORW && base.Errors() > errorsBefore {
// Something went wrong during type-checking,
// but it was reported. Silence future errors.
t.SetBroke(true)
}
types.ResumeCheckSize()
}
func typecheckdef(n *ir.Name) {
if base.EnableTrace && base.Flag.LowerT {
defer tracePrint("typecheckdef", n)(nil)
@ -1741,15 +1706,7 @@ func typecheckdef(n *ir.Name) {
}
lno := ir.SetPos(n)
typecheckdefstack = append(typecheckdefstack, n)
if n.Walkdef() == 2 {
base.FlushErrors()
fmt.Printf("typecheckdef loop:")
for i := len(typecheckdefstack) - 1; i >= 0; i-- {
n := typecheckdefstack[i]
fmt.Printf(" %v", n.Sym())
}
fmt.Printf("\n")
base.Fatalf("typecheckdef loop")
}
@ -1759,127 +1716,26 @@ func typecheckdef(n *ir.Name) {
default:
base.Fatalf("typecheckdef %v", n.Op())
case ir.OLITERAL:
if n.Ntype != nil {
n.Ntype = typecheckNtype(n.Ntype)
n.SetType(n.Ntype.Type())
n.Ntype = nil
if n.Type() == nil {
n.SetDiag(true)
goto ret
}
}
e := n.Defn
n.Defn = nil
if e == nil {
ir.Dump("typecheckdef nil defn", n)
base.ErrorfAt(n.Pos(), "xxx")
}
e = Expr(e)
if e.Type() == nil {
goto ret
}
if !ir.IsConstNode(e) {
if !e.Diag() {
if e.Op() == ir.ONIL {
base.ErrorfAt(n.Pos(), "const initializer cannot be nil")
} else {
base.ErrorfAt(n.Pos(), "const initializer %v is not a constant", e)
}
e.SetDiag(true)
}
goto ret
}
t := n.Type()
if t != nil {
if !ir.OKForConst[t.Kind()] {
base.ErrorfAt(n.Pos(), "invalid constant type %v", t)
goto ret
}
if !e.Type().IsUntyped() && !types.Identical(t, e.Type()) {
base.ErrorfAt(n.Pos(), "cannot use %L as type %v in const initializer", e, t)
goto ret
}
e = convlit(e, t)
}
n.SetType(e.Type())
if n.Type() != nil {
n.SetVal(e.Val())
}
case ir.ONAME:
if n.BuiltinOp != 0 { // like OPRINTN
base.Assertf(n.Ntype == nil, "unexpected Ntype: %+v", n)
break
}
base.Assertf(n.Class == ir.PFUNC, "expected PFUNC: %+v", n)
if n.Ntype != nil {
n.Ntype = typecheckNtype(n.Ntype)
n.SetType(n.Ntype.Type())
if n.Type() == nil {
n.SetDiag(true)
goto ret
}
}
if n.Type() != nil {
break
}
if n.Defn == nil {
if n.BuiltinOp != 0 { // like OPRINTN
break
}
if base.Errors() > 0 {
// Can have undefined variables in x := foo
// that make x have an n.name.Defn == nil.
// If there are other errors anyway, don't
// bother adding to the noise.
break
}
base.Fatalf("var without type, init: %v", n.Sym())
}
if n.Defn.Op() == ir.ONAME {
n.Defn = Expr(n.Defn)
n.SetType(n.Defn.Type())
break
}
n.Defn = Stmt(n.Defn) // fills in n.Type
case ir.OTYPE:
if n.Alias() {
// Type alias declaration: Simply use the rhs type - no need
// to create a new type.
// If we have a syntax error, name.Ntype may be nil.
if n.Ntype != nil {
n.Ntype = typecheckNtype(n.Ntype)
n.SetType(n.Ntype.Type())
if n.Type() == nil {
n.SetDiag(true)
goto ret
}
}
break
}
// regular type declaration
typecheckdeftype(n)
base.Fatalf("missing type: %v", n)
}
ret:
if n.Op() != ir.OLITERAL && n.Type() != nil && n.Type().IsUntyped() {
base.Fatalf("got %v for %v", n.Type(), n)
}
last := len(typecheckdefstack) - 1
if typecheckdefstack[last] != n {
base.Fatalf("typecheckdefstack mismatch")
}
typecheckdefstack[last] = nil
typecheckdefstack = typecheckdefstack[:last]
base.Pos = lno
n.SetWalkdef(1)
}