Skip to content

Commit

Permalink
lint: remove unncessary conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes committed Jan 23, 2025
1 parent 6544a85 commit 868fd26
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 35 deletions.
20 changes: 10 additions & 10 deletions gnovm/pkg/gnolang/gonative.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -1082,15 +1082,15 @@ 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
}
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))
Expand All @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions gnovm/pkg/gnolang/op_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()))

Check warning on line 1260 in gnovm/pkg/gnolang/op_binary.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/op_binary.go#L1260

Added line #L1260 was not covered by tests

return r.Cmp(big.NewInt(0).SetUint64(math.MaxUint)) != 1
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gnovm/pkg/gnolang/uverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 17 additions & 18 deletions gnovm/pkg/gnolang/values_conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 868fd26

Please sign in to comment.