mirror of
https://github.com/golang/go
synced 2024-11-06 10:36:13 -07:00
cmd/compile/internal/typecheck: cleanup code
Removing a lot of functions/variables/constants which are un-unsed anymore in Unified IR frontend. Change-Id: Iccf73754196bf4fa40fe701a6468f4c8a1a0c655 Reviewed-on: https://go-review.googlesource.com/c/go/+/506477 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
4550055149
commit
5c2b43a761
@ -319,35 +319,6 @@ func tostr(v constant.Value) constant.Value {
|
||||
return v
|
||||
}
|
||||
|
||||
var tokenForOp = [...]token.Token{
|
||||
ir.OPLUS: token.ADD,
|
||||
ir.ONEG: token.SUB,
|
||||
ir.ONOT: token.NOT,
|
||||
ir.OBITNOT: token.XOR,
|
||||
|
||||
ir.OADD: token.ADD,
|
||||
ir.OSUB: token.SUB,
|
||||
ir.OMUL: token.MUL,
|
||||
ir.ODIV: token.QUO,
|
||||
ir.OMOD: token.REM,
|
||||
ir.OOR: token.OR,
|
||||
ir.OXOR: token.XOR,
|
||||
ir.OAND: token.AND,
|
||||
ir.OANDNOT: token.AND_NOT,
|
||||
ir.OOROR: token.LOR,
|
||||
ir.OANDAND: token.LAND,
|
||||
|
||||
ir.OEQ: token.EQL,
|
||||
ir.ONE: token.NEQ,
|
||||
ir.OLT: token.LSS,
|
||||
ir.OLE: token.LEQ,
|
||||
ir.OGT: token.GTR,
|
||||
ir.OGE: token.GEQ,
|
||||
|
||||
ir.OLSH: token.SHL,
|
||||
ir.ORSH: token.SHR,
|
||||
}
|
||||
|
||||
func makeFloat64(f float64) constant.Value {
|
||||
if math.IsInf(f, 0) {
|
||||
base.Fatalf("infinity is not a valid constant")
|
||||
|
@ -163,27 +163,6 @@ func checkdupfields(what string, fss ...[]*types.Field) {
|
||||
}
|
||||
}
|
||||
|
||||
// structs, functions, and methods.
|
||||
// they don't belong here, but where do they belong?
|
||||
func checkembeddedtype(t *types.Type) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if t.Sym() == nil && t.IsPtr() {
|
||||
t = t.Elem()
|
||||
if t.IsInterface() {
|
||||
base.Errorf("embedded type cannot be a pointer to interface")
|
||||
}
|
||||
}
|
||||
|
||||
if t.IsPtr() || t.IsUnsafePtr() {
|
||||
base.Errorf("embedded type cannot be a pointer")
|
||||
} else if t.Kind() == types.TFORW && !t.ForwardType().Embedlineno.IsKnown() {
|
||||
t.ForwardType().Embedlineno = base.Pos
|
||||
}
|
||||
}
|
||||
|
||||
var funcStack []funcStackEnt // stack of previous values of ir.CurFunc/DeclContext
|
||||
|
||||
type funcStackEnt struct {
|
||||
|
@ -5,28 +5,12 @@
|
||||
package typecheck
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
|
||||
"cmd/compile/internal/base"
|
||||
"cmd/compile/internal/ir"
|
||||
"cmd/compile/internal/types"
|
||||
"cmd/internal/src"
|
||||
)
|
||||
|
||||
// importalias declares symbol s as an imported type alias with type t.
|
||||
// ipkg is the package being imported.
|
||||
func importalias(pos src.XPos, s *types.Sym, t *types.Type) *ir.Name {
|
||||
return importobj(pos, s, ir.OTYPE, ir.PEXTERN, t)
|
||||
}
|
||||
|
||||
// importconst declares symbol s as an imported constant with type t and value val.
|
||||
// ipkg is the package being imported.
|
||||
func importconst(pos src.XPos, s *types.Sym, t *types.Type, val constant.Value) *ir.Name {
|
||||
n := importobj(pos, s, ir.OLITERAL, ir.PEXTERN, t)
|
||||
n.SetVal(val)
|
||||
return n
|
||||
}
|
||||
|
||||
// importfunc declares symbol s as an imported function with type t.
|
||||
// ipkg is the package being imported.
|
||||
func importfunc(pos src.XPos, s *types.Sym, t *types.Type) *ir.Name {
|
||||
@ -58,15 +42,6 @@ func importsym(pos src.XPos, s *types.Sym, op ir.Op, ctxt ir.Class) *ir.Name {
|
||||
return n
|
||||
}
|
||||
|
||||
// importtype returns the named type declared by symbol s.
|
||||
// If no such type has been declared yet, a forward declaration is returned.
|
||||
// ipkg is the package being imported.
|
||||
func importtype(pos src.XPos, s *types.Sym) *ir.Name {
|
||||
n := importsym(pos, s, ir.OTYPE, ir.PEXTERN)
|
||||
n.SetType(types.NewNamed(n))
|
||||
return n
|
||||
}
|
||||
|
||||
// importvar declares symbol s as an imported variable with type t.
|
||||
// ipkg is the package being imported.
|
||||
func importvar(pos src.XPos, s *types.Sym, t *types.Type) *ir.Name {
|
||||
|
@ -146,26 +146,6 @@ func MethodValueType(n *ir.SelectorExpr) *types.Type {
|
||||
return t
|
||||
}
|
||||
|
||||
// Get the function's package. For ordinary functions it's on the ->sym, but for imported methods
|
||||
// the ->sym can be re-used in the local package, so peel it off the receiver's type.
|
||||
func fnpkg(fn *ir.Name) *types.Pkg {
|
||||
if ir.IsMethod(fn) {
|
||||
// method
|
||||
rcvr := fn.Type().Recv().Type
|
||||
|
||||
if rcvr.IsPtr() {
|
||||
rcvr = rcvr.Elem()
|
||||
}
|
||||
if rcvr.Sym() == nil {
|
||||
base.Fatalf("receiver with no sym: [%v] %L (%v)", fn.Sym(), fn, rcvr)
|
||||
}
|
||||
return rcvr.Sym().Pkg
|
||||
}
|
||||
|
||||
// non-method
|
||||
return fn.Sym().Pkg
|
||||
}
|
||||
|
||||
// tcClosure typechecks an OCLOSURE node. It also creates the named
|
||||
// function associated with the closure.
|
||||
// TODO: This creation of the named function should probably really be done in a
|
||||
|
@ -235,69 +235,11 @@
|
||||
package typecheck
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"cmd/compile/internal/base"
|
||||
"cmd/compile/internal/ir"
|
||||
"cmd/compile/internal/types"
|
||||
)
|
||||
|
||||
// predeclReserved is the number of type offsets reserved for types
|
||||
// implicitly declared in the universe block.
|
||||
const predeclReserved = 32
|
||||
|
||||
// An itag distinguishes the kind of type that was written into the
|
||||
// indexed export format.
|
||||
type itag uint64
|
||||
|
||||
const (
|
||||
// Types
|
||||
definedType itag = iota
|
||||
pointerType
|
||||
sliceType
|
||||
arrayType
|
||||
chanType
|
||||
mapType
|
||||
signatureType
|
||||
structType
|
||||
interfaceType
|
||||
typeParamType
|
||||
instanceType // Instantiation of a generic type
|
||||
unionType
|
||||
)
|
||||
|
||||
const (
|
||||
debug = false
|
||||
magic = 0x6742937dc293105
|
||||
)
|
||||
|
||||
// exportPath returns the path for pkg as it appears in the iexport
|
||||
// file format. For historical reasons (before cmd/compile required
|
||||
// the -p flag), the local package is represented as the empty string,
|
||||
// instead of its actual path.
|
||||
func exportPath(pkg *types.Pkg) string {
|
||||
if pkg == types.LocalPkg {
|
||||
return ""
|
||||
}
|
||||
return pkg.Path
|
||||
}
|
||||
|
||||
const blankMarker = "$"
|
||||
|
||||
// TparamExportName creates a unique name for type param in a method or a generic
|
||||
// type, using the specified unique prefix and the index of the type param. The index
|
||||
// is only used if the type param is blank, in which case the blank is replace by
|
||||
// "$<index>". A unique name is needed for later substitution in the compiler and
|
||||
// export/import that keeps blank type params associated with the correct constraint.
|
||||
func TparamExportName(prefix string, name string, index int) string {
|
||||
if name == "_" {
|
||||
name = blankMarker + strconv.Itoa(index)
|
||||
}
|
||||
return prefix + "." + name
|
||||
}
|
||||
|
||||
// TparamName returns the real name of a type parameter, after stripping its
|
||||
// qualifying prefix and reverting blank-name encoding. See TparamExportName
|
||||
// for details.
|
||||
@ -314,83 +256,5 @@ func TparamName(exportName string) string {
|
||||
return name
|
||||
}
|
||||
|
||||
func constTypeOf(typ *types.Type) constant.Kind {
|
||||
switch typ {
|
||||
case types.UntypedInt, types.UntypedRune:
|
||||
return constant.Int
|
||||
case types.UntypedFloat:
|
||||
return constant.Float
|
||||
case types.UntypedComplex:
|
||||
return constant.Complex
|
||||
}
|
||||
|
||||
switch typ.Kind() {
|
||||
case types.TBOOL:
|
||||
return constant.Bool
|
||||
case types.TSTRING:
|
||||
return constant.String
|
||||
case types.TINT, types.TINT8, types.TINT16, types.TINT32, types.TINT64,
|
||||
types.TUINT, types.TUINT8, types.TUINT16, types.TUINT32, types.TUINT64, types.TUINTPTR:
|
||||
return constant.Int
|
||||
case types.TFLOAT32, types.TFLOAT64:
|
||||
return constant.Float
|
||||
case types.TCOMPLEX64, types.TCOMPLEX128:
|
||||
return constant.Complex
|
||||
}
|
||||
|
||||
base.Fatalf("unexpected constant type: %v", typ)
|
||||
return 0
|
||||
}
|
||||
|
||||
func intSize(typ *types.Type) (signed bool, maxBytes uint) {
|
||||
if typ.IsUntyped() {
|
||||
return true, ir.ConstPrec / 8
|
||||
}
|
||||
|
||||
switch typ.Kind() {
|
||||
case types.TFLOAT32, types.TCOMPLEX64:
|
||||
return true, 3
|
||||
case types.TFLOAT64, types.TCOMPLEX128:
|
||||
return true, 7
|
||||
}
|
||||
|
||||
signed = typ.IsSigned()
|
||||
maxBytes = uint(typ.Size())
|
||||
|
||||
// The go/types API doesn't expose sizes to importers, so they
|
||||
// don't know how big these types are.
|
||||
switch typ.Kind() {
|
||||
case types.TINT, types.TUINT, types.TUINTPTR:
|
||||
maxBytes = 8
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func isNonEmptyAssign(n ir.Node) bool {
|
||||
switch n.Op() {
|
||||
case ir.OAS:
|
||||
if n.(*ir.AssignStmt).Y != nil {
|
||||
return true
|
||||
}
|
||||
case ir.OAS2, ir.OAS2DOTTYPE, ir.OAS2FUNC, ir.OAS2MAPR, ir.OAS2RECV:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
func isNamedTypeSwitch(x ir.Node) bool {
|
||||
guard, ok := x.(*ir.TypeSwitchGuard)
|
||||
return ok && guard.Tag != nil
|
||||
}
|
||||
|
||||
func simplifyForExport(n ir.Node) ir.Node {
|
||||
switch n.Op() {
|
||||
case ir.OPAREN:
|
||||
n := n.(*ir.ParenExpr)
|
||||
return simplifyForExport(n.X)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// The name used for dictionary parameters or local variables.
|
||||
const LocalDictName = ".dict"
|
||||
|
@ -877,7 +877,3 @@ var slist []symlink
|
||||
type symlink struct {
|
||||
field *types.Field
|
||||
}
|
||||
|
||||
func assert(p bool) {
|
||||
base.Assert(p)
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
|
||||
var (
|
||||
okfor [ir.OEND][]bool
|
||||
iscmp [ir.OEND]bool
|
||||
)
|
||||
|
||||
var (
|
||||
@ -207,22 +206,3 @@ func InitUniverse() {
|
||||
okfor[ir.OCAP] = okforcap[:]
|
||||
okfor[ir.OLEN] = okforlen[:]
|
||||
}
|
||||
|
||||
// DeclareUniverse makes the universe block visible within the current package.
|
||||
func DeclareUniverse() {
|
||||
// Operationally, this is similar to a dot import of builtinpkg, except
|
||||
// that we silently skip symbols that are already declared in the
|
||||
// package block rather than emitting a redeclared symbol error.
|
||||
|
||||
for _, s := range types.BuiltinPkg.Syms {
|
||||
if s.Def == nil {
|
||||
continue
|
||||
}
|
||||
s1 := Lookup(s.Name)
|
||||
if s1.Def != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
s1.Def = s.Def
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user