[dev.unified] cmd/compile/internal/reflectdata: remove hasRType's `required` param

Unified IR now always provides RTTI needed by the backend, no need to
allow exceptions anymore. 🥳

Change-Id: Ie1ba42c81f92cc43e1b01b3289de10e261ccef57
Reviewed-on: https://go-review.googlesource.com/c/go/+/415576
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Matthew Dempsky 2022-06-30 18:48:02 -07:00
parent 64cd6faa13
commit 7a8ba83b72
1 changed files with 23 additions and 17 deletions

View File

@ -11,13 +11,21 @@ import (
"cmd/internal/src" "cmd/internal/src"
) )
func hasRType(n, rtype ir.Node, fieldName string, required bool) bool { func hasRType(n, rtype ir.Node, fieldName string) bool {
if rtype != nil { if rtype != nil {
return true return true
} }
if base.Debug.Unified != 0 && required {
base.FatalfAt(n.Pos(), "missing %s: %+v", fieldName, n) // We make an exception for `init`, because we still depend on
// pkginit for sorting package initialization statements, and it
// gets confused by implicit conversions. Also, because
// package-scope statements can never be generic, so they'll never
// require dictionary lookups.
if base.Debug.Unified != 0 && ir.CurFunc.Nname.Sym().Name != "init" {
ir.Dump("CurFunc", ir.CurFunc)
base.FatalfAt(n.Pos(), "missing %s in %v: %+v", fieldName, ir.CurFunc, n)
} }
return false return false
} }
@ -71,7 +79,7 @@ func concreteRType(pos src.XPos, typ *types.Type) ir.Node {
// representing the result slice type's element type. // representing the result slice type's element type.
func AppendElemRType(pos src.XPos, n *ir.CallExpr) ir.Node { func AppendElemRType(pos src.XPos, n *ir.CallExpr) ir.Node {
assertOp(n, ir.OAPPEND) assertOp(n, ir.OAPPEND)
if hasRType(n, n.RType, "RType", true) { if hasRType(n, n.RType, "RType") {
return n.RType return n.RType
} }
return sliceElemRType(pos, n.Type()) return sliceElemRType(pos, n.Type())
@ -84,7 +92,7 @@ func AppendElemRType(pos src.XPos, n *ir.CallExpr) ir.Node {
func CompareRType(pos src.XPos, n *ir.BinaryExpr) ir.Node { func CompareRType(pos src.XPos, n *ir.BinaryExpr) ir.Node {
assertOp2(n, ir.OEQ, ir.ONE) assertOp2(n, ir.OEQ, ir.ONE)
base.AssertfAt(n.X.Type().IsInterface() != n.Y.Type().IsInterface(), n.Pos(), "expect mixed interface and non-interface, have %L and %L", n.X, n.Y) base.AssertfAt(n.X.Type().IsInterface() != n.Y.Type().IsInterface(), n.Pos(), "expect mixed interface and non-interface, have %L and %L", n.X, n.Y)
if hasRType(n, n.RType, "RType", true) { if hasRType(n, n.RType, "RType") {
return n.RType return n.RType
} }
typ := n.X.Type() typ := n.X.Type()
@ -105,8 +113,7 @@ func ConvIfaceTypeWord(pos src.XPos, n *ir.ConvExpr) ir.Node {
assertOp(n, ir.OCONVIFACE) assertOp(n, ir.OCONVIFACE)
src, dst := n.X.Type(), n.Type() src, dst := n.X.Type(), n.Type()
base.AssertfAt(dst.IsInterface(), n.Pos(), "want interface type, have %L", n) base.AssertfAt(dst.IsInterface(), n.Pos(), "want interface type, have %L", n)
// TODO(mdempsky): Need to handle implicit interface conversions. if hasRType(n, n.TypeWord, "TypeWord") {
if hasRType(n, n.TypeWord, "TypeWord", false) {
return n.TypeWord return n.TypeWord
} }
if dst.IsEmptyInterface() { if dst.IsEmptyInterface() {
@ -124,8 +131,7 @@ func ConvIfaceTypeWord(pos src.XPos, n *ir.ConvExpr) ir.Node {
// the convertee value to the heap. // the convertee value to the heap.
func ConvIfaceSrcRType(pos src.XPos, n *ir.ConvExpr) ir.Node { func ConvIfaceSrcRType(pos src.XPos, n *ir.ConvExpr) ir.Node {
assertOp2(n, ir.OCONVIFACE, ir.OCONVIDATA) assertOp2(n, ir.OCONVIFACE, ir.OCONVIDATA)
// TODO(mdempsky): Need to handle implicit interface conversions. if hasRType(n, n.SrcRType, "SrcRType") {
if hasRType(n, n.SrcRType, "SrcRType", false) {
return n.SrcRType return n.SrcRType
} }
return concreteRType(pos, n.X.Type()) return concreteRType(pos, n.X.Type())
@ -136,7 +142,7 @@ func ConvIfaceSrcRType(pos src.XPos, n *ir.ConvExpr) ir.Node {
// destination slice type's element type. // destination slice type's element type.
func CopyElemRType(pos src.XPos, n *ir.BinaryExpr) ir.Node { func CopyElemRType(pos src.XPos, n *ir.BinaryExpr) ir.Node {
assertOp(n, ir.OCOPY) assertOp(n, ir.OCOPY)
if hasRType(n, n.RType, "RType", true) { if hasRType(n, n.RType, "RType") {
return n.RType return n.RType
} }
return sliceElemRType(pos, n.X.Type()) return sliceElemRType(pos, n.X.Type())
@ -147,7 +153,7 @@ func CopyElemRType(pos src.XPos, n *ir.BinaryExpr) ir.Node {
// map type. // map type.
func DeleteMapRType(pos src.XPos, n *ir.CallExpr) ir.Node { func DeleteMapRType(pos src.XPos, n *ir.CallExpr) ir.Node {
assertOp(n, ir.ODELETE) assertOp(n, ir.ODELETE)
if hasRType(n, n.RType, "RType", true) { if hasRType(n, n.RType, "RType") {
return n.RType return n.RType
} }
return mapRType(pos, n.Args[0].Type()) return mapRType(pos, n.Args[0].Type())
@ -158,7 +164,7 @@ func DeleteMapRType(pos src.XPos, n *ir.CallExpr) ir.Node {
// map type. // map type.
func IndexMapRType(pos src.XPos, n *ir.IndexExpr) ir.Node { func IndexMapRType(pos src.XPos, n *ir.IndexExpr) ir.Node {
assertOp(n, ir.OINDEXMAP) assertOp(n, ir.OINDEXMAP)
if hasRType(n, n.RType, "RType", true) { if hasRType(n, n.RType, "RType") {
return n.RType return n.RType
} }
return mapRType(pos, n.X.Type()) return mapRType(pos, n.X.Type())
@ -169,7 +175,7 @@ func IndexMapRType(pos src.XPos, n *ir.IndexExpr) ir.Node {
// value representing that channel type. // value representing that channel type.
func MakeChanRType(pos src.XPos, n *ir.MakeExpr) ir.Node { func MakeChanRType(pos src.XPos, n *ir.MakeExpr) ir.Node {
assertOp(n, ir.OMAKECHAN) assertOp(n, ir.OMAKECHAN)
if hasRType(n, n.RType, "RType", true) { if hasRType(n, n.RType, "RType") {
return n.RType return n.RType
} }
return chanRType(pos, n.Type()) return chanRType(pos, n.Type())
@ -180,7 +186,7 @@ func MakeChanRType(pos src.XPos, n *ir.MakeExpr) ir.Node {
// representing that map type. // representing that map type.
func MakeMapRType(pos src.XPos, n *ir.MakeExpr) ir.Node { func MakeMapRType(pos src.XPos, n *ir.MakeExpr) ir.Node {
assertOp(n, ir.OMAKEMAP) assertOp(n, ir.OMAKEMAP)
if hasRType(n, n.RType, "RType", true) { if hasRType(n, n.RType, "RType") {
return n.RType return n.RType
} }
return mapRType(pos, n.Type()) return mapRType(pos, n.Type())
@ -191,7 +197,7 @@ func MakeMapRType(pos src.XPos, n *ir.MakeExpr) ir.Node {
// value representing that slice type's element type. // value representing that slice type's element type.
func MakeSliceElemRType(pos src.XPos, n *ir.MakeExpr) ir.Node { func MakeSliceElemRType(pos src.XPos, n *ir.MakeExpr) ir.Node {
assertOp2(n, ir.OMAKESLICE, ir.OMAKESLICECOPY) assertOp2(n, ir.OMAKESLICE, ir.OMAKESLICECOPY)
if hasRType(n, n.RType, "RType", true) { if hasRType(n, n.RType, "RType") {
return n.RType return n.RType
} }
return sliceElemRType(pos, n.Type()) return sliceElemRType(pos, n.Type())
@ -202,7 +208,7 @@ func MakeSliceElemRType(pos src.XPos, n *ir.MakeExpr) ir.Node {
// representing that map type. // representing that map type.
func RangeMapRType(pos src.XPos, n *ir.RangeStmt) ir.Node { func RangeMapRType(pos src.XPos, n *ir.RangeStmt) ir.Node {
assertOp(n, ir.ORANGE) assertOp(n, ir.ORANGE)
if hasRType(n, n.RType, "RType", true) { if hasRType(n, n.RType, "RType") {
return n.RType return n.RType
} }
return mapRType(pos, n.X.Type()) return mapRType(pos, n.X.Type())
@ -213,7 +219,7 @@ func RangeMapRType(pos src.XPos, n *ir.RangeStmt) ir.Node {
// representing the result slice type's element type. // representing the result slice type's element type.
func UnsafeSliceElemRType(pos src.XPos, n *ir.BinaryExpr) ir.Node { func UnsafeSliceElemRType(pos src.XPos, n *ir.BinaryExpr) ir.Node {
assertOp(n, ir.OUNSAFESLICE) assertOp(n, ir.OUNSAFESLICE)
if hasRType(n, n.RType, "RType", true) { if hasRType(n, n.RType, "RType") {
return n.RType return n.RType
} }
return sliceElemRType(pos, n.Type()) return sliceElemRType(pos, n.Type())