From: Mark Freeman Date: Thu, 5 Feb 2026 21:16:22 +0000 (-0500) Subject: go/types, types2: mechanically swap x.mode() == invalid for !x.isValid() X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e2a34c7e9b04564ddad50bd7ec7b52fabde74192;p=gostls13.git go/types, types2: mechanically swap x.mode() == invalid for !x.isValid() Change-Id: I2e98178a42ad225aa3803dc4ccd26d50938f29b7 Reviewed-on: https://go-review.googlesource.com/c/go/+/742501 Reviewed-by: Robert Griesemer LUCI-TryBot-Result: Go LUCI Auto-Submit: Mark Freeman --- diff --git a/src/cmd/compile/internal/types2/assignments.go b/src/cmd/compile/internal/types2/assignments.go index bd188d51da..f4ad4938ac 100644 --- a/src/cmd/compile/internal/types2/assignments.go +++ b/src/cmd/compile/internal/types2/assignments.go @@ -116,7 +116,7 @@ func (check *Checker) assignment(x *operand, T Type, context string) { } func (check *Checker) initConst(lhs *Const, x *operand) { - if x.mode() == invalid || !isValid(x.typ()) || !isValid(lhs.typ) { + if !x.isValid() || !isValid(x.typ()) || !isValid(lhs.typ) { if lhs.typ == nil { lhs.typ = Typ[Invalid] } @@ -139,7 +139,7 @@ func (check *Checker) initConst(lhs *Const, x *operand) { } check.assignment(x, lhs.typ, "constant declaration") - if x.mode() == invalid { + if !x.isValid() { return } @@ -151,7 +151,7 @@ func (check *Checker) initConst(lhs *Const, x *operand) { // or Typ[Invalid] in case of an error. // If the initialization check fails, x.mode is set to invalid. func (check *Checker) initVar(lhs *Var, x *operand, context string) { - if x.mode() == invalid || !isValid(x.typ()) || !isValid(lhs.typ) { + if !x.isValid() || !isValid(x.typ()) || !isValid(lhs.typ) { if lhs.typ == nil { lhs.typ = Typ[Invalid] } @@ -216,7 +216,7 @@ func (check *Checker) lhsVar(lhs syntax.Expr) Type { check.usedVars[v] = v_used // restore v.used } - if x.mode() == invalid || !isValid(x.typ()) { + if !x.isValid() || !isValid(x.typ()) { return Typ[Invalid] } diff --git a/src/cmd/compile/internal/types2/builtins.go b/src/cmd/compile/internal/types2/builtins.go index c975767fc6..45b0f41a5e 100644 --- a/src/cmd/compile/internal/types2/builtins.go +++ b/src/cmd/compile/internal/types2/builtins.go @@ -53,7 +53,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( args = check.exprList(argList) nargs = len(args) for _, a := range args { - if a.mode() == invalid { + if !a.isValid() { return } } @@ -312,7 +312,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( // and check below } } - if x.mode() == invalid || y.mode() == invalid { + if !x.isValid() || !y.isValid() { return } @@ -438,7 +438,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( *x = *args[1] // key check.assignment(x, key, "argument to delete") - if x.mode() == invalid { + if !x.isValid() { return } @@ -466,7 +466,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( // result in an error (shift of complex value) check.convertUntyped(x, Typ[Complex128]) // x should be invalid now, but be conservative and check - if x.mode() == invalid { + if !x.isValid() { return } } @@ -585,7 +585,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( } for i, a := range args { - if a.mode() == invalid { + if !a.isValid() { return } @@ -597,7 +597,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( // The first argument is already in x and there's nothing left to do. if i > 0 { check.matchTypes(x, a) - if x.mode() == invalid { + if !x.isValid() { return } @@ -621,7 +621,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( x.mode_ = value // A value must not be untyped. check.assignment(x, &emptyInterface, "argument to built-in "+bin.name) - if x.mode() == invalid { + if !x.isValid() { return } } @@ -656,7 +656,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( if isUntyped(x.typ()) { // check for overflow and untyped nil check.assignment(x, nil, "argument to new") - if x.mode() == invalid { + if !x.isValid() { return } assert(isTyped(x.typ())) @@ -688,7 +688,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( } check.assignment(x, &emptyInterface, "argument to panic") - if x.mode() == invalid { + if !x.isValid() { return } @@ -705,7 +705,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( params = make([]Type, nargs) for i, a := range args { check.assignment(a, nil, "argument to built-in "+predeclaredFuncs[id].name) - if a.mode() == invalid { + if !a.isValid() { return } params[i] = a.typ() @@ -730,7 +730,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( check.verifyVersionf(call.Fun, go1_17, "unsafe.Add") check.assignment(x, Typ[UnsafePointer], "argument to unsafe.Add") - if x.mode() == invalid { + if !x.isValid() { return } @@ -748,7 +748,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( case _Alignof: // unsafe.Alignof(x T) uintptr check.assignment(x, nil, "argument to unsafe.Alignof") - if x.mode() == invalid { + if !x.isValid() { return } @@ -776,7 +776,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( } check.expr(nil, x, selx.X) - if x.mode() == invalid { + if !x.isValid() { return } @@ -836,7 +836,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( case _Sizeof: // unsafe.Sizeof(x T) uintptr check.assignment(x, nil, "argument to unsafe.Sizeof") - if x.mode() == invalid { + if !x.isValid() { return } @@ -901,7 +901,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( check.verifyVersionf(call.Fun, go1_20, "unsafe.String") check.assignment(x, NewPointer(universeByte), "argument to unsafe.String") - if x.mode() == invalid { + if !x.isValid() { return } @@ -921,7 +921,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( check.verifyVersionf(call.Fun, go1_20, "unsafe.StringData") check.assignment(x, Typ[String], "argument to unsafe.StringData") - if x.mode() == invalid { + if !x.isValid() { return } @@ -967,7 +967,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( check.dump("%v: %s", atPos(x1), x1) x1 = &t // use incoming x only for first argument } - if x.mode() == invalid { + if !x.isValid() { return } // trace is only available in test mode - no need to record signature @@ -976,7 +976,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( panic("unreachable") } - assert(x.mode() != invalid) + assert(x.isValid()) return true } diff --git a/src/cmd/compile/internal/types2/call.go b/src/cmd/compile/internal/types2/call.go index 467dc37609..21f929642a 100644 --- a/src/cmd/compile/internal/types2/call.go +++ b/src/cmd/compile/internal/types2/call.go @@ -194,7 +194,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind { case typexpr: // conversion check.nonGeneric(nil, x) - if x.mode() == invalid { + if !x.isValid() { return conversion } T := x.typ() @@ -209,7 +209,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind { check.errorf(call, WrongArgCount, "missing argument in conversion to %s", T) case 1: check.expr(nil, x, call.ArgList[0]) - if x.mode() != invalid { + if x.isValid() { if t, _ := T.Underlying().(*Interface); t != nil && !isTypeParam(T) { if !t.IsMethodSet() { check.errorf(call, MisplacedConstraintIface, "cannot use interface %s in conversion (contains specific type constraints or is comparable)", T) @@ -237,7 +237,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind { } x.expr = call // a non-constant result implies a function call - if x.mode() != invalid && x.mode() != constant_ { + if x.isValid() && x.mode() != constant_ { check.hasCallOrRecv = true } return predeclaredFuncs[id].kind @@ -417,7 +417,7 @@ func (check *Checker) genericExprList(elist []syntax.Expr) (resList []*operand, // x is not a function instantiation (it may still be a generic function). check.rawExpr(nil, &x, e, nil, true) check.exclude(&x, 1< 0 { check.matchTypes(x, a) - if x.mode() == invalid { + if !x.isValid() { return } @@ -624,7 +624,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b x.mode_ = value // A value must not be untyped. check.assignment(x, &emptyInterface, "argument to built-in "+bin.name) - if x.mode() == invalid { + if !x.isValid() { return } } @@ -659,7 +659,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b if isUntyped(x.typ()) { // check for overflow and untyped nil check.assignment(x, nil, "argument to new") - if x.mode() == invalid { + if !x.isValid() { return } assert(isTyped(x.typ())) @@ -691,7 +691,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b } check.assignment(x, &emptyInterface, "argument to panic") - if x.mode() == invalid { + if !x.isValid() { return } @@ -708,7 +708,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b params = make([]Type, nargs) for i, a := range args { check.assignment(a, nil, "argument to built-in "+predeclaredFuncs[id].name) - if a.mode() == invalid { + if !a.isValid() { return } params[i] = a.typ() @@ -733,7 +733,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b check.verifyVersionf(call.Fun, go1_17, "unsafe.Add") check.assignment(x, Typ[UnsafePointer], "argument to unsafe.Add") - if x.mode() == invalid { + if !x.isValid() { return } @@ -751,7 +751,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b case _Alignof: // unsafe.Alignof(x T) uintptr check.assignment(x, nil, "argument to unsafe.Alignof") - if x.mode() == invalid { + if !x.isValid() { return } @@ -779,7 +779,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b } check.expr(nil, x, selx.X) - if x.mode() == invalid { + if !x.isValid() { return } @@ -839,7 +839,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b case _Sizeof: // unsafe.Sizeof(x T) uintptr check.assignment(x, nil, "argument to unsafe.Sizeof") - if x.mode() == invalid { + if !x.isValid() { return } @@ -904,7 +904,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b check.verifyVersionf(call.Fun, go1_20, "unsafe.String") check.assignment(x, NewPointer(universeByte), "argument to unsafe.String") - if x.mode() == invalid { + if !x.isValid() { return } @@ -924,7 +924,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b check.verifyVersionf(call.Fun, go1_20, "unsafe.StringData") check.assignment(x, Typ[String], "argument to unsafe.StringData") - if x.mode() == invalid { + if !x.isValid() { return } @@ -970,7 +970,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b check.dump("%v: %s", x1.Pos(), x1) x1 = &t // use incoming x only for first argument } - if x.mode() == invalid { + if !x.isValid() { return } // trace is only available in test mode - no need to record signature @@ -979,7 +979,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b panic("unreachable") } - assert(x.mode() != invalid) + assert(x.isValid()) return true } diff --git a/src/go/types/call.go b/src/go/types/call.go index 0b8ef351db..744f246d24 100644 --- a/src/go/types/call.go +++ b/src/go/types/call.go @@ -196,7 +196,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind { case typexpr: // conversion check.nonGeneric(nil, x) - if x.mode() == invalid { + if !x.isValid() { return conversion } T := x.typ() @@ -211,7 +211,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind { check.errorf(inNode(call, call.Rparen), WrongArgCount, "missing argument in conversion to %s", T) case 1: check.expr(nil, x, call.Args[0]) - if x.mode() != invalid { + if x.isValid() { if hasDots(call) { check.errorf(call.Args[0], BadDotDotDotSyntax, "invalid use of ... in conversion to %s", T) break @@ -239,7 +239,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind { } x.expr = call // a non-constant result implies a function call - if x.mode() != invalid && x.mode() != constant_ { + if x.isValid() && x.mode() != constant_ { check.hasCallOrRecv = true } return predeclaredFuncs[id].kind @@ -419,7 +419,7 @@ func (check *Checker) genericExprList(elist []ast.Expr) (resList []*operand, tar // x is not a function instantiation (it may still be a generic function). check.rawExpr(nil, &x, e, nil, true) check.exclude(&x, 1<