]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/typecheck: cleanup code
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 27 Jun 2023 03:03:55 +0000 (10:03 +0700)
committerGopher Robot <gobot@golang.org>
Fri, 21 Jul 2023 02:40:02 +0000 (02:40 +0000)
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>

src/cmd/compile/internal/typecheck/const.go
src/cmd/compile/internal/typecheck/dcl.go
src/cmd/compile/internal/typecheck/export.go
src/cmd/compile/internal/typecheck/func.go
src/cmd/compile/internal/typecheck/iexport.go
src/cmd/compile/internal/typecheck/subr.go
src/cmd/compile/internal/typecheck/universe.go

index f4fb614e639a17bdd759d413e75f70d702f2acb0..f56d330e7fc693dd39f64946bea2e740934e6d0e 100644 (file)
@@ -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")
index 029c14f81924cf58d8435d313bbe108b7112a9a0..cd31c5fea4da04951dfab5cc09cb2d27eef370c3 100644 (file)
@@ -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 {
index af56ea8d986735411e0c35a35b96f5ae11074b43..40cf451d6a1e29d555f04e7f61240ef2012d7888 100644 (file)
@@ -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 {
index 1d1de5bf942c68ea0ea8249259fdb8e6b813a419..0bcb319291a0d5a7802037a76a0d1ebe79479ed7 100644 (file)
@@ -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
index df579b716660c1ea68f661c6a6bc0b59b4c8e6ba..83d35b365f29d561f0e6b78bda439933aeae6a4f 100644 (file)
 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"
index 2bb978a0fa60efe08363a64c279a752bceafceaa..011cb3c7cf7df8c81faac78c43c60add7c062d01 100644 (file)
@@ -877,7 +877,3 @@ var slist []symlink
 type symlink struct {
        field *types.Field
 }
-
-func assert(p bool) {
-       base.Assert(p)
-}
index e43bede4ce29ad68492fc321e0fdbdedbd7d9bcd..076c9da0b15a5e6c489af25b4f9bb928dd1aa1bc 100644 (file)
@@ -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
-       }
-}