Commit ecead89b authored by Rob Pike's avatar Rob Pike

go/types: remove the renaming import of go/constant

For niceness, when go/exact was moved from x/tools, it
was renamed go/constant.

For simplicity, when go/types was moved from x/tools, its
imports of (now) go/constant were done with a rename:

    import exact "go/constant"

This kept the code just as it was before and avoided the issue
of what to call the internal constant called, um, constant.

But not all was hidden, as the text of some fields of structs and
the like leaked the old name, so things like "exact.Value" appeared
in type definitions and function signatures in the documentation.
This is unacceptable.

Fix the documentation issue by fixing the code. Rename the constant
constant constant_, and remove the renaming import.

This should go into 1.5. It's mostly a mechanical change, is
internal to the package, and fixes the documentation. It contains
no semantic changes except to fix a benchmark that was broken
in the original transition.

Fixes #11949.

Change-Id: Ieb94b6558535b504180b1378f19e8f5a96f92d3c
Reviewed-on: https://go-review.googlesource.com/13051Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 2bd52370
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"go/ast" "go/ast"
exact "go/constant" // Renamed to reduce diffs from x/tools. TODO: remove "go/constant"
"go/token" "go/token"
) )
...@@ -218,7 +218,7 @@ func (info *Info) ObjectOf(id *ast.Ident) Object { ...@@ -218,7 +218,7 @@ func (info *Info) ObjectOf(id *ast.Ident) Object {
type TypeAndValue struct { type TypeAndValue struct {
mode operandMode mode operandMode
Type Type Type Type
Value exact.Value // == constant.Value Value constant.Value
} }
// TODO(gri) Consider eliminating the IsVoid predicate. Instead, report // TODO(gri) Consider eliminating the IsVoid predicate. Instead, report
...@@ -246,7 +246,7 @@ func (tv TypeAndValue) IsBuiltin() bool { ...@@ -246,7 +246,7 @@ func (tv TypeAndValue) IsBuiltin() bool {
// nil Value. // nil Value.
func (tv TypeAndValue) IsValue() bool { func (tv TypeAndValue) IsValue() bool {
switch tv.mode { switch tv.mode {
case constant, variable, mapindex, value, commaok: case constant_, variable, mapindex, value, commaok:
return true return true
} }
return false return false
......
...@@ -23,7 +23,7 @@ func (check *Checker) assignment(x *operand, T Type) bool { ...@@ -23,7 +23,7 @@ func (check *Checker) assignment(x *operand, T Type) bool {
switch x.mode { switch x.mode {
case invalid: case invalid:
return true // error reported before return true // error reported before
case constant, variable, mapindex, value, commaok: case constant_, variable, mapindex, value, commaok:
// ok // ok
default: default:
unreachable() unreachable()
...@@ -74,7 +74,7 @@ func (check *Checker) initConst(lhs *Const, x *operand) { ...@@ -74,7 +74,7 @@ func (check *Checker) initConst(lhs *Const, x *operand) {
} }
// rhs must be a constant // rhs must be a constant
if x.mode != constant { if x.mode != constant_ {
check.errorf(x.pos(), "%s is not constant", x) check.errorf(x.pos(), "%s is not constant", x)
if lhs.typ == nil { if lhs.typ == nil {
lhs.typ = Typ[Invalid] lhs.typ = Typ[Invalid]
......
...@@ -8,7 +8,7 @@ package types ...@@ -8,7 +8,7 @@ package types
import ( import (
"go/ast" "go/ast"
exact "go/constant" // Renamed to reduce diffs from x/tools. TODO: remove "go/constant"
"go/token" "go/token"
) )
...@@ -138,13 +138,13 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b ...@@ -138,13 +138,13 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
// len(x) // len(x)
mode := invalid mode := invalid
var typ Type var typ Type
var val exact.Value var val constant.Value
switch typ = implicitArrayDeref(x.typ.Underlying()); t := typ.(type) { switch typ = implicitArrayDeref(x.typ.Underlying()); t := typ.(type) {
case *Basic: case *Basic:
if isString(t) && id == _Len { if isString(t) && id == _Len {
if x.mode == constant { if x.mode == constant_ {
mode = constant mode = constant_
val = exact.MakeInt64(int64(len(exact.StringVal(x.val)))) val = constant.MakeInt64(int64(len(constant.StringVal(x.val))))
} else { } else {
mode = value mode = value
} }
...@@ -157,8 +157,8 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b ...@@ -157,8 +157,8 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
// the expression s does not contain channel receives or // the expression s does not contain channel receives or
// function calls; in this case s is not evaluated." // function calls; in this case s is not evaluated."
if !check.hasCallOrRecv { if !check.hasCallOrRecv {
mode = constant mode = constant_
val = exact.MakeInt64(t.len) val = constant.MakeInt64(t.len)
} }
case *Slice, *Chan: case *Slice, *Chan:
...@@ -178,7 +178,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b ...@@ -178,7 +178,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
x.mode = mode x.mode = mode
x.typ = Typ[Int] x.typ = Typ[Int]
x.val = val x.val = val
if check.Types != nil && mode != constant { if check.Types != nil && mode != constant_ {
check.recordBuiltinType(call.Fun, makeSig(x.typ, typ)) check.recordBuiltinType(call.Fun, makeSig(x.typ, typ))
} }
...@@ -228,8 +228,8 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b ...@@ -228,8 +228,8 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
return return
} }
if x.mode == constant && y.mode == constant { if x.mode == constant_ && y.mode == constant_ {
x.val = exact.BinaryOp(x.val, token.ADD, exact.MakeImag(y.val)) x.val = constant.BinaryOp(x.val, token.ADD, constant.MakeImag(y.val))
} else { } else {
x.mode = value x.mode = value
} }
...@@ -242,7 +242,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b ...@@ -242,7 +242,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
case Float64: case Float64:
complexT = Typ[Complex128] complexT = Typ[Complex128]
case UntypedInt, UntypedRune, UntypedFloat: case UntypedInt, UntypedRune, UntypedFloat:
if x.mode == constant { if x.mode == constant_ {
realT = defaultType(realT).(*Basic) realT = defaultType(realT).(*Basic)
complexT = Typ[UntypedComplex] complexT = Typ[UntypedComplex]
} else { } else {
...@@ -257,11 +257,11 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b ...@@ -257,11 +257,11 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
} }
x.typ = complexT x.typ = complexT
if check.Types != nil && x.mode != constant { if check.Types != nil && x.mode != constant_ {
check.recordBuiltinType(call.Fun, makeSig(complexT, realT, realT)) check.recordBuiltinType(call.Fun, makeSig(complexT, realT, realT))
} }
if x.mode != constant { if x.mode != constant_ {
// The arguments have now their final types, which at run- // The arguments have now their final types, which at run-
// time will be materialized. Update the expression trees. // time will be materialized. Update the expression trees.
// If the current types are untyped, the materialized type // If the current types are untyped, the materialized type
...@@ -339,11 +339,11 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b ...@@ -339,11 +339,11 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
check.invalidArg(x.pos(), "%s must be a complex number", x) check.invalidArg(x.pos(), "%s must be a complex number", x)
return return
} }
if x.mode == constant { if x.mode == constant_ {
if id == _Real { if id == _Real {
x.val = exact.Real(x.val) x.val = constant.Real(x.val)
} else { } else {
x.val = exact.Imag(x.val) x.val = constant.Imag(x.val)
} }
} else { } else {
x.mode = value x.mode = value
...@@ -360,7 +360,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b ...@@ -360,7 +360,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
unreachable() unreachable()
} }
if check.Types != nil && x.mode != constant { if check.Types != nil && x.mode != constant_ {
check.recordBuiltinType(call.Fun, makeSig(Typ[k], x.typ)) check.recordBuiltinType(call.Fun, makeSig(Typ[k], x.typ))
} }
x.typ = Typ[k] x.typ = Typ[k]
...@@ -471,8 +471,8 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b ...@@ -471,8 +471,8 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
return return
} }
x.mode = constant x.mode = constant_
x.val = exact.MakeInt64(check.conf.alignof(x.typ)) x.val = constant.MakeInt64(check.conf.alignof(x.typ))
x.typ = Typ[Uintptr] x.typ = Typ[Uintptr]
// result is constant - no need to record signature // result is constant - no need to record signature
...@@ -516,8 +516,8 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b ...@@ -516,8 +516,8 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
check.recordSelection(selx, FieldVal, base, obj, index, false) check.recordSelection(selx, FieldVal, base, obj, index, false)
offs := check.conf.offsetof(base, index) offs := check.conf.offsetof(base, index)
x.mode = constant x.mode = constant_
x.val = exact.MakeInt64(offs) x.val = constant.MakeInt64(offs)
x.typ = Typ[Uintptr] x.typ = Typ[Uintptr]
// result is constant - no need to record signature // result is constant - no need to record signature
...@@ -528,8 +528,8 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b ...@@ -528,8 +528,8 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
return return
} }
x.mode = constant x.mode = constant_
x.val = exact.MakeInt64(check.conf.sizeof(x.typ)) x.val = constant.MakeInt64(check.conf.sizeof(x.typ))
x.typ = Typ[Uintptr] x.typ = Typ[Uintptr]
// result is constant - no need to record signature // result is constant - no need to record signature
...@@ -537,15 +537,15 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b ...@@ -537,15 +537,15 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
// assert(pred) causes a typechecker error if pred is false. // assert(pred) causes a typechecker error if pred is false.
// The result of assert is the value of pred if there is no error. // The result of assert is the value of pred if there is no error.
// Note: assert is only available in self-test mode. // Note: assert is only available in self-test mode.
if x.mode != constant || !isBoolean(x.typ) { if x.mode != constant_ || !isBoolean(x.typ) {
check.invalidArg(x.pos(), "%s is not a boolean constant", x) check.invalidArg(x.pos(), "%s is not a boolean constant", x)
return return
} }
if x.val.Kind() != exact.Bool { if x.val.Kind() != constant.Bool {
check.errorf(x.pos(), "internal error: value of %s should be a boolean constant", x) check.errorf(x.pos(), "internal error: value of %s should be a boolean constant", x)
return return
} }
if !exact.BoolVal(x.val) { if !constant.BoolVal(x.val) {
check.errorf(call.Pos(), "%s failed", call) check.errorf(call.Pos(), "%s failed", call)
// compile-time assertion failure - safe to continue // compile-time assertion failure - safe to continue
} }
......
...@@ -46,7 +46,7 @@ func (check *Checker) call(x *operand, e *ast.CallExpr) exprKind { ...@@ -46,7 +46,7 @@ func (check *Checker) call(x *operand, e *ast.CallExpr) exprKind {
} }
x.expr = e x.expr = e
// a non-constant result implies a function call // a non-constant result implies a function call
if x.mode != invalid && x.mode != constant { if x.mode != invalid && x.mode != constant_ {
check.hasCallOrRecv = true check.hasCallOrRecv = true
} }
return predeclaredFuncs[id].kind return predeclaredFuncs[id].kind
...@@ -302,7 +302,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) { ...@@ -302,7 +302,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) {
switch exp := exp.(type) { switch exp := exp.(type) {
case *Const: case *Const:
assert(exp.Val() != nil) assert(exp.Val() != nil)
x.mode = constant x.mode = constant_
x.typ = exp.typ x.typ = exp.typ
x.val = exp.val x.val = exp.val
case *TypeName: case *TypeName:
......
...@@ -8,7 +8,7 @@ package types ...@@ -8,7 +8,7 @@ package types
import ( import (
"go/ast" "go/ast"
exact "go/constant" // Renamed to reduce diffs from x/tools. TODO: remove "go/constant"
"go/token" "go/token"
) )
...@@ -36,7 +36,7 @@ type exprInfo struct { ...@@ -36,7 +36,7 @@ type exprInfo struct {
isLhs bool // expression is lhs operand of a shift with delayed type-check isLhs bool // expression is lhs operand of a shift with delayed type-check
mode operandMode mode operandMode
typ *Basic typ *Basic
val exact.Value // constant value; or nil (if not a constant) val constant.Value // constant value; or nil (if not a constant)
} }
// funcInfo stores the information required for type-checking a function. // funcInfo stores the information required for type-checking a function.
...@@ -51,7 +51,7 @@ type funcInfo struct { ...@@ -51,7 +51,7 @@ type funcInfo struct {
type context struct { type context struct {
decl *declInfo // package-level declaration whose init expression/function body is checked decl *declInfo // package-level declaration whose init expression/function body is checked
scope *Scope // top-most scope for lookups scope *Scope // top-most scope for lookups
iota exact.Value // value of iota in a constant declaration; nil otherwise iota constant.Value // value of iota in a constant declaration; nil otherwise
sig *Signature // function signature if inside a function; nil otherwise sig *Signature // function signature if inside a function; nil otherwise
hasLabel bool // set if a function makes use of labels (only ~1% of functions); unused outside functions hasLabel bool // set if a function makes use of labels (only ~1% of functions); unused outside functions
hasCallOrRecv bool // set if an expression contains a function call or channel receive operation hasCallOrRecv bool // set if an expression contains a function call or channel receive operation
...@@ -126,7 +126,7 @@ func (check *Checker) assocMethod(tname string, meth *Func) { ...@@ -126,7 +126,7 @@ func (check *Checker) assocMethod(tname string, meth *Func) {
m[tname] = append(m[tname], meth) m[tname] = append(m[tname], meth)
} }
func (check *Checker) rememberUntyped(e ast.Expr, lhs bool, mode operandMode, typ *Basic, val exact.Value) { func (check *Checker) rememberUntyped(e ast.Expr, lhs bool, mode operandMode, typ *Basic, val constant.Value) {
m := check.untyped m := check.untyped
if m == nil { if m == nil {
m = make(map[ast.Expr]exprInfo) m = make(map[ast.Expr]exprInfo)
...@@ -257,14 +257,14 @@ func (check *Checker) recordUntyped() { ...@@ -257,14 +257,14 @@ func (check *Checker) recordUntyped() {
} }
} }
func (check *Checker) recordTypeAndValue(x ast.Expr, mode operandMode, typ Type, val exact.Value) { func (check *Checker) recordTypeAndValue(x ast.Expr, mode operandMode, typ Type, val constant.Value) {
assert(x != nil) assert(x != nil)
assert(typ != nil) assert(typ != nil)
if mode == invalid { if mode == invalid {
return // omit return // omit
} }
assert(typ != nil) assert(typ != nil)
if mode == constant { if mode == constant_ {
assert(val != nil) assert(val != nil)
assert(typ == Typ[Invalid] || isConstType(typ)) assert(typ == Typ[Invalid] || isConstType(typ))
} }
......
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
package types package types
import exact "go/constant" // Renamed to reduce diffs from x/tools. TODO: remove import "go/constant"
// Conversion type-checks the conversion T(x). // Conversion type-checks the conversion T(x).
// The result is in x. // The result is in x.
func (check *Checker) conversion(x *operand, T Type) { func (check *Checker) conversion(x *operand, T Type) {
constArg := x.mode == constant constArg := x.mode == constant_
var ok bool var ok bool
switch { switch {
...@@ -22,13 +22,13 @@ func (check *Checker) conversion(x *operand, T Type) { ...@@ -22,13 +22,13 @@ func (check *Checker) conversion(x *operand, T Type) {
ok = true ok = true
case isInteger(x.typ) && isString(t): case isInteger(x.typ) && isString(t):
codepoint := int64(-1) codepoint := int64(-1)
if i, ok := exact.Int64Val(x.val); ok { if i, ok := constant.Int64Val(x.val); ok {
codepoint = i codepoint = i
} }
// If codepoint < 0 the absolute value is too large (or unknown) for // If codepoint < 0 the absolute value is too large (or unknown) for
// conversion. This is the same as converting any other out-of-range // conversion. This is the same as converting any other out-of-range
// value - let string(codepoint) do the work. // value - let string(codepoint) do the work.
x.val = exact.MakeString(string(codepoint)) x.val = constant.MakeString(string(codepoint))
ok = true ok = true
} }
case x.convertibleTo(check.conf, T): case x.convertibleTo(check.conf, T):
......
...@@ -6,7 +6,7 @@ package types ...@@ -6,7 +6,7 @@ package types
import ( import (
"go/ast" "go/ast"
exact "go/constant" // Renamed to reduce diffs from x/tools. TODO: remove "go/constant"
"go/token" "go/token"
) )
...@@ -105,7 +105,7 @@ func (check *Checker) constDecl(obj *Const, typ, init ast.Expr) { ...@@ -105,7 +105,7 @@ func (check *Checker) constDecl(obj *Const, typ, init ast.Expr) {
defer func() { check.iota = nil }() defer func() { check.iota = nil }()
// provide valid constant value under all circumstances // provide valid constant value under all circumstances
obj.val = exact.MakeUnknown() obj.val = constant.MakeUnknown()
// determine type, if any // determine type, if any
if typ != nil { if typ != nil {
...@@ -335,7 +335,7 @@ func (check *Checker) declStmt(decl ast.Decl) { ...@@ -335,7 +335,7 @@ func (check *Checker) declStmt(decl ast.Decl) {
// declare all constants // declare all constants
lhs := make([]*Const, len(s.Names)) lhs := make([]*Const, len(s.Names))
for i, name := range s.Names { for i, name := range s.Names {
obj := NewConst(name.Pos(), pkg, name.Name, nil, exact.MakeInt64(int64(iota))) obj := NewConst(name.Pos(), pkg, name.Name, nil, constant.MakeInt64(int64(iota)))
lhs[i] = obj lhs[i] = obj
var init ast.Expr var init ast.Expr
......
This diff is collapsed.
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"go/ast" "go/ast"
exact "go/constant" // Renamed to reduce diffs from x/tools. TODO: remove "go/constant"
"go/token" "go/token"
) )
...@@ -143,15 +143,15 @@ func (obj *PkgName) Imported() *Package { return obj.imported } ...@@ -143,15 +143,15 @@ func (obj *PkgName) Imported() *Package { return obj.imported }
// A Const represents a declared constant. // A Const represents a declared constant.
type Const struct { type Const struct {
object object
val exact.Value val constant.Value
visited bool // for initialization cycle detection visited bool // for initialization cycle detection
} }
func NewConst(pos token.Pos, pkg *Package, name string, typ Type, val exact.Value) *Const { func NewConst(pos token.Pos, pkg *Package, name string, typ Type, val constant.Value) *Const {
return &Const{object{nil, pos, pkg, name, typ, 0, token.NoPos}, val, false} return &Const{object{nil, pos, pkg, name, typ, 0, token.NoPos}, val, false}
} }
func (obj *Const) Val() exact.Value { return obj.val } func (obj *Const) Val() constant.Value { return obj.val }
// A TypeName represents a declared type. // A TypeName represents a declared type.
type TypeName struct { type TypeName struct {
......
...@@ -9,7 +9,7 @@ package types ...@@ -9,7 +9,7 @@ package types
import ( import (
"bytes" "bytes"
"go/ast" "go/ast"
exact "go/constant" // Renamed to reduce diffs from x/tools. TODO: remove "go/constant"
"go/token" "go/token"
) )
...@@ -21,7 +21,7 @@ const ( ...@@ -21,7 +21,7 @@ const (
novalue // operand represents no value (result of a function call w/o result) novalue // operand represents no value (result of a function call w/o result)
builtin // operand is a built-in function builtin // operand is a built-in function
typexpr // operand is a type typexpr // operand is a type
constant // operand is a constant; the operand's typ is a Basic type constant_ // operand is a constant; the operand's typ is a Basic type
variable // operand is an addressable variable variable // operand is an addressable variable
mapindex // operand is a map index expression (acts like a variable on lhs, commaok on rhs of an assignment) mapindex // operand is a map index expression (acts like a variable on lhs, commaok on rhs of an assignment)
value // operand is a computed value value // operand is a computed value
...@@ -33,7 +33,7 @@ var operandModeString = [...]string{ ...@@ -33,7 +33,7 @@ var operandModeString = [...]string{
novalue: "no value", novalue: "no value",
builtin: "built-in", builtin: "built-in",
typexpr: "type", typexpr: "type",
constant: "constant", constant_: "constant",
variable: "variable", variable: "variable",
mapindex: "map index expression", mapindex: "map index expression",
value: "value", value: "value",
...@@ -50,7 +50,7 @@ type operand struct { ...@@ -50,7 +50,7 @@ type operand struct {
mode operandMode mode operandMode
expr ast.Expr expr ast.Expr
typ Type typ Type
val exact.Value val constant.Value
id builtinId id builtinId
} }
...@@ -105,7 +105,7 @@ func operandString(x *operand, qf Qualifier) string { ...@@ -105,7 +105,7 @@ func operandString(x *operand, qf Qualifier) string {
expr = predeclaredFuncs[x.id].name expr = predeclaredFuncs[x.id].name
case typexpr: case typexpr:
expr = TypeString(x.typ, qf) expr = TypeString(x.typ, qf)
case constant: case constant_:
expr = x.val.String() expr = x.val.String()
} }
} }
...@@ -135,7 +135,7 @@ func operandString(x *operand, qf Qualifier) string { ...@@ -135,7 +135,7 @@ func operandString(x *operand, qf Qualifier) string {
buf.WriteString(operandModeString[x.mode]) buf.WriteString(operandModeString[x.mode])
// <val> // <val>
if x.mode == constant { if x.mode == constant_ {
if s := x.val.String(); s != expr { if s := x.val.String(); s != expr {
buf.WriteByte(' ') buf.WriteByte(' ')
buf.WriteString(s) buf.WriteString(s)
...@@ -166,7 +166,7 @@ func (x *operand) String() string { ...@@ -166,7 +166,7 @@ func (x *operand) String() string {
// setConst sets x to the untyped constant for literal lit. // setConst sets x to the untyped constant for literal lit.
func (x *operand) setConst(tok token.Token, lit string) { func (x *operand) setConst(tok token.Token, lit string) {
val := exact.MakeFromLiteral(lit, tok, 0) val := constant.MakeFromLiteral(lit, tok, 0)
if val == nil { if val == nil {
// TODO(gri) Should we make it an unknown constant instead? // TODO(gri) Should we make it an unknown constant instead?
x.mode = invalid x.mode = invalid
...@@ -187,7 +187,7 @@ func (x *operand) setConst(tok token.Token, lit string) { ...@@ -187,7 +187,7 @@ func (x *operand) setConst(tok token.Token, lit string) {
kind = UntypedString kind = UntypedString
} }
x.mode = constant x.mode = constant_
x.typ = Typ[kind] x.typ = Typ[kind]
x.val = val x.val = val
} }
...@@ -260,7 +260,7 @@ func (x *operand) assignableTo(conf *Config, T Type) bool { ...@@ -260,7 +260,7 @@ func (x *operand) assignableTo(conf *Config, T Type) bool {
if isUntyped(Vu) { if isUntyped(Vu) {
switch t := Tu.(type) { switch t := Tu.(type) {
case *Basic: case *Basic:
if x.mode == constant { if x.mode == constant_ {
return representableConst(x.val, conf, t.kind, nil) return representableConst(x.val, conf, t.kind, nil)
} }
// The result of a comparison is an untyped boolean, // The result of a comparison is an untyped boolean,
...@@ -283,5 +283,5 @@ func (x *operand) assignableTo(conf *Config, T Type) bool { ...@@ -283,5 +283,5 @@ func (x *operand) assignableTo(conf *Config, T Type) bool {
func (x *operand) isInteger() bool { func (x *operand) isInteger() bool {
return x.mode == invalid || return x.mode == invalid ||
isInteger(x.typ) || isInteger(x.typ) ||
isUntyped(x.typ) && x.mode == constant && representableConst(x.val, nil, UntypedInt, nil) // no *Config required for UntypedInt isUntyped(x.typ) && x.mode == constant_ && representableConst(x.val, nil, UntypedInt, nil) // no *Config required for UntypedInt
} }
...@@ -7,7 +7,7 @@ package types ...@@ -7,7 +7,7 @@ package types
import ( import (
"fmt" "fmt"
"go/ast" "go/ast"
exact "go/constant" // Renamed to reduce diffs from x/tools. TODO: remove "go/constant"
"go/token" "go/token"
pathLib "path" pathLib "path"
"strconv" "strconv"
...@@ -256,7 +256,7 @@ func (check *Checker) collectObjects() { ...@@ -256,7 +256,7 @@ func (check *Checker) collectObjects() {
// declare all constants // declare all constants
for i, name := range s.Names { for i, name := range s.Names {
obj := NewConst(name.Pos(), pkg, name.Name, nil, exact.MakeInt64(int64(iota))) obj := NewConst(name.Pos(), pkg, name.Name, nil, constant.MakeInt64(int64(iota)))
var init ast.Expr var init ast.Expr
if i < len(last.Values) { if i < len(last.Values) {
......
...@@ -47,7 +47,7 @@ func TestBenchmark(t *testing.T) { ...@@ -47,7 +47,7 @@ func TestBenchmark(t *testing.T) {
// We're not using testing's benchmarking mechanism directly // We're not using testing's benchmarking mechanism directly
// because we want custom output. // because we want custom output.
for _, p := range []string{"types", "exact", "gcimporter"} { for _, p := range []string{"types", "constant", filepath.Join("internal", "gcimporter")} {
path := filepath.Join("..", p) path := filepath.Join("..", p)
runbench(t, path, false) runbench(t, path, false)
runbench(t, path, true) runbench(t, path, true)
......
...@@ -9,7 +9,7 @@ package types ...@@ -9,7 +9,7 @@ package types
import ( import (
"fmt" "fmt"
"go/ast" "go/ast"
exact "go/constant" // Renamed to reduce diffs from x/tools. TODO: remove "go/constant"
"go/token" "go/token"
) )
...@@ -402,9 +402,9 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) { ...@@ -402,9 +402,9 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
} else { } else {
// spec: "A missing switch expression is // spec: "A missing switch expression is
// equivalent to the boolean value true." // equivalent to the boolean value true."
x.mode = constant x.mode = constant_
x.typ = Typ[Bool] x.typ = Typ[Bool]
x.val = exact.MakeBool(true) x.val = constant.MakeBool(true)
x.expr = &ast.Ident{NamePos: s.Body.Lbrace, Name: "true"} x.expr = &ast.Ident{NamePos: s.Body.Lbrace, Name: "true"}
} }
......
...@@ -8,7 +8,7 @@ package types ...@@ -8,7 +8,7 @@ package types
import ( import (
"go/ast" "go/ast"
exact "go/constant" // Renamed to reduce diffs from x/tools. TODO: remove "go/constant"
"go/token" "go/token"
"sort" "sort"
"strconv" "strconv"
...@@ -65,7 +65,7 @@ func (check *Checker) ident(x *operand, e *ast.Ident, def *Named, path []*TypeNa ...@@ -65,7 +65,7 @@ func (check *Checker) ident(x *operand, e *ast.Ident, def *Named, path []*TypeNa
x.val = obj.val x.val = obj.val
} }
assert(x.val != nil) assert(x.val != nil)
x.mode = constant x.mode = constant_
case *TypeName: case *TypeName:
x.mode = typexpr x.mode = typexpr
...@@ -367,7 +367,7 @@ func (check *Checker) typOrNil(e ast.Expr) Type { ...@@ -367,7 +367,7 @@ func (check *Checker) typOrNil(e ast.Expr) Type {
func (check *Checker) arrayLength(e ast.Expr) int64 { func (check *Checker) arrayLength(e ast.Expr) int64 {
var x operand var x operand
check.expr(&x, e) check.expr(&x, e)
if x.mode != constant { if x.mode != constant_ {
if x.mode != invalid { if x.mode != invalid {
check.errorf(x.pos(), "array length %s must be constant", &x) check.errorf(x.pos(), "array length %s must be constant", &x)
} }
...@@ -377,7 +377,7 @@ func (check *Checker) arrayLength(e ast.Expr) int64 { ...@@ -377,7 +377,7 @@ func (check *Checker) arrayLength(e ast.Expr) int64 {
check.errorf(x.pos(), "array length %s must be integer", &x) check.errorf(x.pos(), "array length %s must be integer", &x)
return 0 return 0
} }
n, ok := exact.Int64Val(x.val) n, ok := constant.Int64Val(x.val)
if !ok || n < 0 { if !ok || n < 0 {
check.errorf(x.pos(), "invalid array length %s", &x) check.errorf(x.pos(), "invalid array length %s", &x)
return 0 return 0
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
package types package types
import ( import (
exact "go/constant" // Renamed to reduce diffs from x/tools. TODO: remove "go/constant"
"go/token" "go/token"
"strings" "strings"
) )
...@@ -76,11 +76,11 @@ func defPredeclaredTypes() { ...@@ -76,11 +76,11 @@ func defPredeclaredTypes() {
var predeclaredConsts = [...]struct { var predeclaredConsts = [...]struct {
name string name string
kind BasicKind kind BasicKind
val exact.Value val constant.Value
}{ }{
{"true", UntypedBool, exact.MakeBool(true)}, {"true", UntypedBool, constant.MakeBool(true)},
{"false", UntypedBool, exact.MakeBool(false)}, {"false", UntypedBool, constant.MakeBool(false)},
{"iota", UntypedInt, exact.MakeInt64(0)}, {"iota", UntypedInt, constant.MakeInt64(0)},
} }
func defPredeclaredConsts() { func defPredeclaredConsts() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment