1
0
mirror of https://github.com/golang/go synced 2024-11-11 19:41:36 -07:00

[dev.regabi] cmd/compile: tighten typecheckdef to *ir.Name

We only actually care about ir.Names in typecheckdef, so don't bother
calling it on anything else. Allows us to get rid of some more
superfluous .Name() calls and .(*ir.Name) assertions.

Passes toolstash -cmp.

Change-Id: I78c7cb680178991ea185958b47a36f101d4d5ef7
Reviewed-on: https://go-review.googlesource.com/c/go/+/281004
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Matthew Dempsky 2021-01-02 03:15:14 -08:00
parent b1747756e3
commit 57c426c9a5

View File

@ -474,12 +474,9 @@ func indexlit(n ir.Node) ir.Node {
// typecheck1 should ONLY be called from typecheck.
func typecheck1(n ir.Node, top int) ir.Node {
switch n.Op() {
case ir.OLITERAL, ir.ONAME, ir.OTYPE:
if n.Sym() != nil {
if n, ok := n.(*ir.Name); ok {
typecheckdef(n)
}
}
switch n.Op() {
default:
@ -1735,7 +1732,7 @@ func typecheckdeftype(n *ir.Name) {
types.ResumeCheckSize()
}
func typecheckdef(n ir.Node) {
func typecheckdef(n *ir.Name) {
if base.EnableTrace && base.Flag.LowerT {
defer tracePrint("typecheckdef", n)(nil)
}
@ -1755,7 +1752,7 @@ func typecheckdef(n ir.Node) {
}
lno := ir.SetPos(n)
typecheckdefstack = append(typecheckdefstack, n.(*ir.Name))
typecheckdefstack = append(typecheckdefstack, n)
if n.Walkdef() == 2 {
base.FlushErrors()
fmt.Printf("typecheckdef loop:")
@ -1774,18 +1771,18 @@ func typecheckdef(n ir.Node) {
base.Fatalf("typecheckdef %v", n.Op())
case ir.OLITERAL:
if n.Name().Ntype != nil {
n.Name().Ntype = typecheckNtype(n.Name().Ntype)
n.SetType(n.Name().Ntype.Type())
n.Name().Ntype = nil
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.Name().Defn
n.Name().Defn = nil
e := n.Defn
n.Defn = nil
if e == nil {
ir.Dump("typecheckdef nil defn", n)
base.ErrorfAt(n.Pos(), "xxx")
@ -1828,7 +1825,6 @@ func typecheckdef(n ir.Node) {
}
case ir.ONAME:
n := n.(*ir.Name)
if n.Ntype != nil {
n.Ntype = typecheckNtype(n.Ntype)
n.SetType(n.Ntype.Type())
@ -1865,7 +1861,6 @@ func typecheckdef(n ir.Node) {
n.Defn = Stmt(n.Defn) // fills in n.Type
case ir.OTYPE:
n := n.(*ir.Name)
if n.Alias() {
// Type alias declaration: Simply use the rhs type - no need
// to create a new type.