From 868fd26cce20d60395e851082f741066be9b4c0b Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Thu, 23 Jan 2025 16:07:51 +0100 Subject: [PATCH] lint: remove unncessary conversions --- gnovm/pkg/gnolang/gonative.go | 20 +++++++------- gnovm/pkg/gnolang/op_binary.go | 8 +++--- gnovm/pkg/gnolang/uverse.go | 4 +-- gnovm/pkg/gnolang/values.go | 2 +- gnovm/pkg/gnolang/values_conversions.go | 35 ++++++++++++------------- 5 files changed, 34 insertions(+), 35 deletions(-) diff --git a/gnovm/pkg/gnolang/gonative.go b/gnovm/pkg/gnolang/gonative.go index b49b202d5fe..a777c1cef3e 100644 --- a/gnovm/pkg/gnolang/gonative.go +++ b/gnovm/pkg/gnolang/gonative.go @@ -493,7 +493,7 @@ func go2GnoValueUpdate(alloc *Allocator, rlm *Realm, lvl int, tv *TypedValue, rv et := st.Elt for i := 0; i < rvl; i++ { erv := rv.Index(i) - etv := &sv.GetBase(nil).List[int(svo)+i] // XXX: svo may overflow on 32 bits platform. + etv := &sv.GetBase(nil).List[svo+i] // XXX use Assign and Realm? if etv.T == nil && et.Kind() != InterfaceKind { etv.T = et @@ -506,7 +506,7 @@ func go2GnoValueUpdate(alloc *Allocator, rlm *Realm, lvl int, tv *TypedValue, rv } else { for i := 0; i < rvl; i++ { erv := rv.Index(i) - sv.GetBase(nil).Data[int(svo)+i] = uint8(erv.Uint()) // XXX: svo may overflow on 32 bits platform. + sv.GetBase(nil).Data[svo+i] = uint8(erv.Uint()) } } case PointerKind: @@ -780,7 +780,7 @@ func gno2GoType(t Type) reflect.Type { et := gno2GoType(ct.Elem()) return reflect.PointerTo(et) case *ArrayType: - ne := int(ct.Len) // XXX: may overflow on 32 bits platforms. + ne := ct.Len et := gno2GoType(ct.Elem()) return reflect.ArrayOf(ne, et) case *SliceType: @@ -1032,7 +1032,7 @@ func gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { case StringType, UntypedStringType: rv.SetString(tv.GetString()) case IntType: - rv.SetInt(int64(tv.GetInt())) + rv.SetInt(tv.GetInt()) case Int8Type: rv.SetInt(int64(tv.GetInt8())) case Int16Type: @@ -1042,7 +1042,7 @@ func gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { case Int64Type: rv.SetInt(tv.GetInt64()) case UintType: - rv.SetUint(uint64(tv.GetUint())) + rv.SetUint(tv.GetUint()) case Uint8Type: rv.SetUint(uint64(tv.GetUint8())) case Uint16Type: @@ -1082,7 +1082,7 @@ func gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { // General case. av := tv.V.(*ArrayValue) if av.Data == nil { - for i := 0; i < int(ct.Len); i++ { + for i := 0; i < ct.Len; i++ { etv := &av.List[i] if etv.IsUndefined() { continue @@ -1090,7 +1090,7 @@ func gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { gno2GoValue(etv, rv.Index(i)) } } else { - for i := 0; i < int(ct.Len); i++ { + for i := 0; i < ct.Len; i++ { val := av.Data[i] erv := rv.Index(i) erv.SetUint(uint64(val)) @@ -1108,9 +1108,9 @@ func gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { svl := sv.Length svc := sv.Maxcap if sv.GetBase(nil).Data == nil { - rv.Set(reflect.MakeSlice(st, int(svl), int(svc))) // XXX: svl and svc may overflow on 32 bits platforms. - for i := 0; i < int(svl); i++ { - etv := &(sv.GetBase(nil).List[int(svo)+i]) // XXX: svo may overflow on 32 bits platforms. + rv.Set(reflect.MakeSlice(st, svl, svc)) + for i := 0; i < svl; i++ { + etv := &(sv.GetBase(nil).List[svo+i]) if etv.IsUndefined() { continue } diff --git a/gnovm/pkg/gnolang/op_binary.go b/gnovm/pkg/gnolang/op_binary.go index a6a2b46bf22..42419ec5d54 100644 --- a/gnovm/pkg/gnolang/op_binary.go +++ b/gnovm/pkg/gnolang/op_binary.go @@ -1211,7 +1211,7 @@ func shlAssign(m *Machine, lv, rv *TypedValue) { switch baseOf(lv.T) { case IntType: checkOverflow(func() bool { - l := big.NewInt(int64(lv.GetInt())) + l := big.NewInt(lv.GetInt()) r := big.NewInt(0).Lsh(l, uint(rv.GetUint())) return r.Cmp(big.NewInt(math.MaxInt)) != 1 @@ -1256,7 +1256,7 @@ func shlAssign(m *Machine, lv, rv *TypedValue) { lv.SetInt64(lv.GetInt64() << rv.GetUint()) case UintType: checkOverflow(func() bool { - l := big.NewInt(0).SetUint64(uint64(lv.GetUint())) + l := big.NewInt(0).SetUint64(lv.GetUint()) r := big.NewInt(0).Lsh(l, uint(rv.GetUint())) return r.Cmp(big.NewInt(0).SetUint64(math.MaxUint)) != 1 @@ -1335,7 +1335,7 @@ func shrAssign(m *Machine, lv, rv *TypedValue) { switch baseOf(lv.T) { case IntType: checkOverflow(func() bool { - l := big.NewInt(int64(lv.GetInt())) + l := big.NewInt(lv.GetInt()) r := big.NewInt(0).Rsh(l, uint(rv.GetUint())) return r.Cmp(big.NewInt(math.MaxInt)) != 1 @@ -1380,7 +1380,7 @@ func shrAssign(m *Machine, lv, rv *TypedValue) { lv.SetInt64(lv.GetInt64() >> rv.GetUint()) case UintType: checkOverflow(func() bool { - l := big.NewInt(0).SetUint64(uint64(lv.GetUint())) + l := big.NewInt(0).SetUint64(lv.GetUint()) r := big.NewInt(0).Rsh(l, uint(rv.GetUint())) return r.Cmp(big.NewInt(0).SetUint64(math.MaxUint)) != 1 diff --git a/gnovm/pkg/gnolang/uverse.go b/gnovm/pkg/gnolang/uverse.go index 29864df1ef7..bfa4a6c65a7 100644 --- a/gnovm/pkg/gnolang/uverse.go +++ b/gnovm/pkg/gnolang/uverse.go @@ -986,7 +986,7 @@ func makeUverseNode() { func(m *Machine) { arg0 := m.LastBlock().GetParams1() xv := arg0 - xvl := int(xv.TV.GetLength()) + xvl := xv.TV.GetLength() ss := make([]string, xvl) for i := 0; i < xvl; i++ { ev := xv.TV.GetPointerAtIndexInt(m.Store, i).Deref() @@ -1007,7 +1007,7 @@ func makeUverseNode() { func(m *Machine) { arg0 := m.LastBlock().GetParams1() xv := arg0 - xvl := int(xv.TV.GetLength()) + xvl := xv.TV.GetLength() ss := make([]string, xvl) for i := 0; i < xvl; i++ { ev := xv.TV.GetPointerAtIndexInt(m.Store, i).Deref() diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 1d55aa2e2e1..ef537502bda 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -1116,7 +1116,7 @@ func (tv *TypedValue) PrimitiveBytes() (data []byte) { case UintType, Uint64Type: data = make([]byte, 8) binary.LittleEndian.PutUint64( - data, uint64(tv.GetUint())) + data, tv.GetUint()) return data case Float32Type: data = make([]byte, 4) diff --git a/gnovm/pkg/gnolang/values_conversions.go b/gnovm/pkg/gnolang/values_conversions.go index c1994fe6d55..f6e39bd1912 100644 --- a/gnovm/pkg/gnolang/values_conversions.go +++ b/gnovm/pkg/gnolang/values_conversions.go @@ -130,7 +130,7 @@ GNO_CASE: tv.T = t tv.SetInt32(x) case Int64Kind: - x := int64(tv.GetInt()) + x := tv.GetInt() tv.T = t tv.SetInt64(x) case UintKind: @@ -164,11 +164,11 @@ GNO_CASE: tv.T = t tv.SetUint64(x) case Float32Kind: - x := softfloat.Fintto32(int64(tv.GetInt())) + x := softfloat.Fintto32(tv.GetInt()) tv.T = t tv.SetFloat32(x) case Float64Kind: - x := softfloat.Fintto64(int64(tv.GetInt())) + x := softfloat.Fintto64(tv.GetInt()) tv.T = t tv.SetFloat64(x) case StringKind: @@ -401,7 +401,7 @@ GNO_CASE: case Int64Kind: switch k { case IntKind: - x := int64(tv.GetInt64()) + x := tv.GetInt64() tv.T = t tv.SetInt(x) case Int8Kind: @@ -502,7 +502,7 @@ GNO_CASE: tv.T = t tv.SetInt32(x) case Int64Kind: - validate(UintKind, Int64Kind, func() bool { return uint64(tv.GetUint()) <= math.MaxInt64 }) + validate(UintKind, Int64Kind, func() bool { return tv.GetUint() <= math.MaxInt64 }) x := int64(tv.GetUint()) tv.T = t @@ -530,15 +530,15 @@ GNO_CASE: tv.T = t tv.SetUint32(x) case Uint64Kind: - x := uint64(tv.GetUint()) + x := tv.GetUint() tv.T = t tv.SetUint64(x) case Float32Kind: - x := softfloat.Fuint64to32(uint64(tv.GetUint())) + x := softfloat.Fuint64to32(tv.GetUint()) tv.T = t tv.SetFloat32(x) case Float64Kind: - x := softfloat.Fuint64to64(uint64(tv.GetUint())) + x := softfloat.Fuint64to64(tv.GetUint()) tv.T = t tv.SetFloat64(x) case StringKind: @@ -800,7 +800,7 @@ GNO_CASE: case UintKind: validate(Uint64Kind, UintKind, func() bool { return tv.GetUint64() <= math.MaxUint }) - x := uint64(tv.GetUint64()) + x := tv.GetUint64() tv.T = t tv.SetUint64(x) case Uint8Kind: @@ -858,7 +858,7 @@ GNO_CASE: return truncInt64 >= math.MinInt && truncInt64 <= math.MaxInt }) - x := int64(softfloat.F32toint64(tv.GetFloat32())) + x := softfloat.F32toint64(tv.GetFloat32()) tv.T = t tv.SetInt(x) case Int8Kind: @@ -928,7 +928,7 @@ GNO_CASE: return truncUint64 >= 0 && truncUint64 <= math.MaxUint }) - x := uint64(softfloat.F32touint64(tv.GetFloat32())) + x := softfloat.F32touint64(tv.GetFloat32()) tv.T = t tv.SetUint(x) case Uint8Kind: @@ -1019,9 +1019,8 @@ GNO_CASE: }) xp, _ := softfloat.F64toint(tv.GetFloat64()) - x := int64(xp) tv.T = t - tv.SetInt(x) + tv.SetInt(xp) case Int8Kind: validate(Float64Kind, Int8Kind, func() bool { trunc := softfloat.Ftrunc64(tv.GetFloat64()) @@ -1090,7 +1089,7 @@ GNO_CASE: return truncUint64 >= 0 && truncUint64 <= math.MaxUint }) - x := uint64(softfloat.F64touint64(tv.GetFloat64())) + x := softfloat.F64touint64(tv.GetFloat64()) tv.T = t tv.SetUint(x) case Uint8Kind: @@ -1523,9 +1522,9 @@ func ConvertUntypedBigintTo(dst *TypedValue, bv BigintValue, t Type) { if sv < math.MinInt32 { panic("bigint underflows target kind") } - dst.SetInt(int64(sv)) + dst.SetInt(sv) } else if strconv.IntSize == 64 { - dst.SetInt(int64(sv)) + dst.SetInt(sv) } else { panic("unexpected IntSize") } @@ -1560,9 +1559,9 @@ func ConvertUntypedBigintTo(dst *TypedValue, bv BigintValue, t Type) { if math.MaxUint32 < uv { panic("bigint overflows target kind") } - dst.SetUint(uint64(uv)) + dst.SetUint(uv) } else if strconv.IntSize == 64 { - dst.SetUint(uint64(uv)) + dst.SetUint(uv) } else { panic("unexpected IntSize") }