From 57c426c9a57736d84f6ddd88d7a3306e63f66945 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sat, 2 Jan 2021 03:15:14 -0800 Subject: [PATCH] [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 Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- .../compile/internal/typecheck/typecheck.go | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go index d0922e8508..812b94de0d 100644 --- a/src/cmd/compile/internal/typecheck/typecheck.go +++ b/src/cmd/compile/internal/typecheck/typecheck.go @@ -474,11 +474,8 @@ 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 { - typecheckdef(n) - } + if n, ok := n.(*ir.Name); ok { + typecheckdef(n) } switch n.Op() { @@ -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.