Skip to content

Commit

Permalink
feat(gnovm)!: remove bigint type (#3641)
Browse files Browse the repository at this point in the history
This PR removes the `bigint` type. It is a new feature deviating from
the go programming language, and it is largely untested and possibly
dangerous to have as we approach mainnet, as it is only used publicly in
a few test files.
  • Loading branch information
thehowl authored Feb 18, 2025
1 parent de78e5b commit 0a3df04
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 70 deletions.
3 changes: 1 addition & 2 deletions gnovm/pkg/gnolang/gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func TestBuiltinIdentifiersShadowing(t *testing.T) {
"println",
"recover",
"nil",
"bigint",
"bool",
"byte",
"float32",
Expand Down Expand Up @@ -247,7 +246,7 @@ func main() {
},
{
`package test
func main() {
const f = float64(1.0)
println(int64(f))
Expand Down
8 changes: 4 additions & 4 deletions gnovm/pkg/gnolang/gonative.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,9 @@ func gno2GoType(t Type) reflect.Type {
return reflect.TypeOf(float32(0))
case Float64Type:
return reflect.TypeOf(float64(0))
case BigintType, UntypedBigintType:
case UntypedBigintType:
panic("not yet implemented")
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:
panic("not yet implemented")
default:
panic("should not happen")
Expand Down Expand Up @@ -887,9 +887,9 @@ func gno2GoTypeMatches(t Type, rt reflect.Type) (result bool) {
return rt.Kind() == reflect.Float32
case Float64Type:
return rt.Kind() == reflect.Float64
case BigintType, UntypedBigintType:
case UntypedBigintType:
panic("not yet implemented")
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:
panic("not yet implemented")
default:
panic("should not happen")
Expand Down
30 changes: 15 additions & 15 deletions gnovm/pkg/gnolang/op_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,11 @@ func addAssign(alloc *Allocator, lv, rv *TypedValue) {
case Float64Type:
// NOTE: gno doesn't fuse *+.
lv.SetFloat64(softfloat.Fadd64(lv.GetFloat64(), rv.GetFloat64()))
case BigintType, UntypedBigintType:
case UntypedBigintType:
lb := lv.GetBigInt()
lb = big.NewInt(0).Add(lb, rv.GetBigInt())
lv.V = BigintValue{V: lb}
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:
lb := lv.GetBigDec()
rb := rv.GetBigDec()
sum := apd.New(0, 0)
Expand Down Expand Up @@ -775,11 +775,11 @@ func subAssign(lv, rv *TypedValue) {
case Float64Type:
// NOTE: gno doesn't fuse *+.
lv.SetFloat64(softfloat.Fsub64(lv.GetFloat64(), rv.GetFloat64()))
case BigintType, UntypedBigintType:
case UntypedBigintType:
lb := lv.GetBigInt()
lb = big.NewInt(0).Sub(lb, rv.GetBigInt())
lv.V = BigintValue{V: lb}
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:
lb := lv.GetBigDec()
rb := rv.GetBigDec()
diff := apd.New(0, 0)
Expand Down Expand Up @@ -831,11 +831,11 @@ func mulAssign(lv, rv *TypedValue) {
case Float64Type:
// NOTE: gno doesn't fuse *+.
lv.SetFloat64(softfloat.Fmul64(lv.GetFloat64(), rv.GetFloat64()))
case BigintType, UntypedBigintType:
case UntypedBigintType:
lb := lv.GetBigInt()
lb = big.NewInt(0).Mul(lb, rv.GetBigInt())
lv.V = BigintValue{V: lb}
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:
lb := lv.GetBigDec()
rb := rv.GetBigDec()
prod := apd.New(0, 0)
Expand Down Expand Up @@ -929,14 +929,14 @@ func quoAssign(lv, rv *TypedValue) *Exception {
if ok {
lv.SetFloat64(softfloat.Fdiv64(lv.GetFloat64(), rv.GetFloat64()))
}
case BigintType, UntypedBigintType:
case UntypedBigintType:
if rv.GetBigInt().Sign() == 0 {
return expt
}
lb := lv.GetBigInt()
lb = big.NewInt(0).Quo(lb, rv.GetBigInt())
lv.V = BigintValue{V: lb}
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:
if rv.GetBigDec().Cmp(apd.New(0, 0)) == 0 {
return expt
}
Expand Down Expand Up @@ -1022,7 +1022,7 @@ func remAssign(lv, rv *TypedValue) *Exception {
return expt
}
lv.SetUint64(lv.GetUint64() % rv.GetUint64())
case BigintType, UntypedBigintType:
case UntypedBigintType:
if rv.GetBigInt().Sign() == 0 {
return expt
}
Expand Down Expand Up @@ -1067,7 +1067,7 @@ func bandAssign(lv, rv *TypedValue) {
lv.SetUint32(lv.GetUint32() & rv.GetUint32())
case Uint64Type:
lv.SetUint64(lv.GetUint64() & rv.GetUint64())
case BigintType, UntypedBigintType:
case UntypedBigintType:
lb := lv.GetBigInt()
lb = big.NewInt(0).And(lb, rv.GetBigInt())
lv.V = BigintValue{V: lb}
Expand Down Expand Up @@ -1106,7 +1106,7 @@ func bandnAssign(lv, rv *TypedValue) {
lv.SetUint32(lv.GetUint32() &^ rv.GetUint32())
case Uint64Type:
lv.SetUint64(lv.GetUint64() &^ rv.GetUint64())
case BigintType, UntypedBigintType:
case UntypedBigintType:
lb := lv.GetBigInt()
lb = big.NewInt(0).AndNot(lb, rv.GetBigInt())
lv.V = BigintValue{V: lb}
Expand Down Expand Up @@ -1145,7 +1145,7 @@ func borAssign(lv, rv *TypedValue) {
lv.SetUint32(lv.GetUint32() | rv.GetUint32())
case Uint64Type:
lv.SetUint64(lv.GetUint64() | rv.GetUint64())
case BigintType, UntypedBigintType:
case UntypedBigintType:
lb := lv.GetBigInt()
lb = big.NewInt(0).Or(lb, rv.GetBigInt())
lv.V = BigintValue{V: lb}
Expand Down Expand Up @@ -1184,7 +1184,7 @@ func xorAssign(lv, rv *TypedValue) {
lv.SetUint32(lv.GetUint32() ^ rv.GetUint32())
case Uint64Type:
lv.SetUint64(lv.GetUint64() ^ rv.GetUint64())
case BigintType, UntypedBigintType:
case UntypedBigintType:
lb := lv.GetBigInt()
lb = big.NewInt(0).Xor(lb, rv.GetBigInt())
lv.V = BigintValue{V: lb}
Expand Down Expand Up @@ -1308,7 +1308,7 @@ func shlAssign(m *Machine, lv, rv *TypedValue) {
})

lv.SetUint64(lv.GetUint64() << rv.GetUint())
case BigintType, UntypedBigintType:
case UntypedBigintType:
lb := lv.GetBigInt()
lb = big.NewInt(0).Lsh(lb, uint(rv.GetUint()))
lv.V = BigintValue{V: lb}
Expand Down Expand Up @@ -1432,7 +1432,7 @@ func shrAssign(m *Machine, lv, rv *TypedValue) {
})

lv.SetUint64(lv.GetUint64() >> rv.GetUint())
case BigintType, UntypedBigintType:
case UntypedBigintType:
lb := lv.GetBigInt()
lb = big.NewInt(0).Rsh(lb, uint(rv.GetUint()))
lv.V = BigintValue{V: lb}
Expand Down
8 changes: 4 additions & 4 deletions gnovm/pkg/gnolang/op_inc_dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ func (m *Machine) doOpInc() {
lv.SetFloat32(softfloat.Fadd32(lv.GetFloat32(), softfloat.Fintto32(1)))
case Float64Type:
lv.SetFloat64(softfloat.Fadd64(lv.GetFloat64(), softfloat.Fintto64(1)))
case BigintType, UntypedBigintType:
case UntypedBigintType:
lb := lv.GetBigInt()
lb = big.NewInt(0).Add(lb, big.NewInt(1))
lv.V = BigintValue{V: lb}
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:
lb := lv.GetBigDec()
sum := apd.New(0, 0)
cond, err := apd.BaseContext.WithPrecision(0).Add(sum, lb, apd.New(1, 0))
Expand Down Expand Up @@ -128,11 +128,11 @@ func (m *Machine) doOpDec() {
lv.SetFloat32(softfloat.Fsub32(lv.GetFloat32(), softfloat.Fintto32(1)))
case Float64Type:
lv.SetFloat64(softfloat.Fsub64(lv.GetFloat64(), softfloat.Fintto64(1)))
case BigintType, UntypedBigintType:
case UntypedBigintType:
lb := lv.GetBigInt()
lb = big.NewInt(0).Sub(lb, big.NewInt(1))
lv.V = BigintValue{V: lb}
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:
lb := lv.GetBigDec()
sum := apd.New(0, 0)
cond, err := apd.BaseContext.WithPrecision(0).Sub(sum, lb, apd.New(1, 0))
Expand Down
6 changes: 3 additions & 3 deletions gnovm/pkg/gnolang/op_unary.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func (m *Machine) doOpUneg() {
xv.SetFloat32(softfloat.Fneg32(xv.GetFloat32()))
case Float64Type:
xv.SetFloat64(softfloat.Fneg64(xv.GetFloat64()))
case UntypedBigintType, BigintType:
case UntypedBigintType:
bv := xv.V.(BigintValue)
xv.V = BigintValue{V: new(big.Int).Neg(bv.V)}
case UntypedBigdecType, BigdecType:
case UntypedBigdecType:
bv := xv.V.(BigdecValue)
xv.V = BigdecValue{V: apd.New(0, 0).Neg(bv.V)}
case nil:
Expand Down Expand Up @@ -112,7 +112,7 @@ func (m *Machine) doOpUxor() {
xv.SetUint32(^xv.GetUint32())
case Uint64Type:
xv.SetUint64(^xv.GetUint64())
case UntypedBigintType, BigintType:
case UntypedBigintType:
// XXX can it even be implemented?
panic("not yet implemented")
default:
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ func InitStoreCaches(store Store) {
StringType, UntypedStringType,
IntType, Int8Type, Int16Type, Int32Type, Int64Type, UntypedRuneType,
UintType, Uint8Type, Uint16Type, Uint32Type, Uint64Type,
BigintType, UntypedBigintType,
UntypedBigintType,
gTypeType,
gPackageType,
blockType{},
Expand Down
38 changes: 9 additions & 29 deletions gnovm/pkg/gnolang/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ const (
Float32Type
Float64Type
UntypedBigintType
BigintType
UntypedBigdecType
BigdecType
// UintptrType
)

Expand Down Expand Up @@ -153,20 +151,16 @@ func (pt PrimitiveType) Specificity() int {
return 0
case Float64Type:
return 0
case BigintType:
return 1
case BigdecType:
return 2
case UntypedBigdecType:
return 3
return 1
case UntypedStringType:
return 4
return 2
case UntypedBigintType:
return 4
return 2
case UntypedRuneType:
return 5
return 3
case UntypedBoolType:
return 6
return 4
default:
panic(fmt.Sprintf("unexpected primitive type %v", pt))
}
Expand Down Expand Up @@ -204,9 +198,9 @@ func (pt PrimitiveType) Kind() Kind {
return Float32Kind
case Float64Type:
return Float64Kind
case BigintType, UntypedBigintType:
case UntypedBigintType:
return BigintKind
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:
return BigdecKind
default:
panic(fmt.Sprintf("unexpected primitive type %v", pt))
Expand Down Expand Up @@ -256,12 +250,8 @@ func (pt PrimitiveType) TypeID() TypeID {
return typeid("float64")
case UntypedBigintType:
return typeid("<untyped> bigint")
case BigintType:
return typeid("bigint")
case UntypedBigdecType:
return typeid("<untyped> bigdec")
case BigdecType:
return typeid("bigdec")
default:
panic(fmt.Sprintf("unexpected primitive type %v", pt))
}
Expand Down Expand Up @@ -309,12 +299,8 @@ func (pt PrimitiveType) String() string {
return string("float64")
case UntypedBigintType:
return string("<untyped> bigint")
case BigintType:
return string("bigint")
case UntypedBigdecType:
return string("<untyped> bigdec")
case BigdecType:
return string("bigdec")
default:
panic(fmt.Sprintf("unexpected primitive type %d", pt))
}
Expand Down Expand Up @@ -2206,9 +2192,9 @@ func KindOf(t Type) Kind {
return Float32Kind
case Float64Type:
return Float64Kind
case BigintType, UntypedBigintType:
case UntypedBigintType:
return BigintKind
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:
return BigdecKind
default:
panic(fmt.Sprintf("unexpected primitive type %s", t.String()))
Expand Down Expand Up @@ -2401,12 +2387,6 @@ func fillEmbeddedName(ft *FieldType) {
ft.Name = Name("float32")
case Float64Type:
ft.Name = Name("float64")
case BigintType:
ft.Name = Name("bigint")
case BigdecType:
ft.Name = Name("bigdec")
default:
panic("should not happen")
}
case *NativeType:
panic("native type cannot be embedded")
Expand Down
1 change: 0 additions & 1 deletion gnovm/pkg/gnolang/uverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ func makeUverseNode() {
def("._", undefined) // special, path is zero.
def("iota", undefined) // special
def("nil", undefined)
def("bigint", asValue(BigintType))
def("bool", asValue(BoolType))
def("byte", asValue(Uint8Type))
def("float32", asValue(Float32Type))
Expand Down
2 changes: 0 additions & 2 deletions gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -1130,8 +1130,6 @@ func (tv *TypedValue) PrimitiveBytes() (data []byte) {
binary.LittleEndian.PutUint64(
data, u64)
return data
case BigintType:
return tv.V.(BigintValue).V.Bytes()
default:
panic(fmt.Sprintf(
"unexpected primitive value type: %s",
Expand Down
4 changes: 2 additions & 2 deletions gnovm/pkg/gnolang/values_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ func (tv *TypedValue) ProtectedSprint(seen *seenValues, considerDeclaredType boo
return fmt.Sprintf("%v", math.Float32frombits(tv.GetFloat32()))
case Float64Type:
return fmt.Sprintf("%v", math.Float64frombits(tv.GetFloat64()))
case UntypedBigintType, BigintType:
case UntypedBigintType:
return tv.V.(BigintValue).V.String()
case UntypedBigdecType, BigdecType:
case UntypedBigdecType:
return tv.V.(BigdecValue).V.String()
default:
panic("should not happen")
Expand Down
11 changes: 4 additions & 7 deletions gnovm/tests/files/zpersist_valids.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type myStruct struct {

var (
// Native types
abigint bigint = 16
abool bool = true
abyte byte = 0x16
afloat32 float32 = 16.16
Expand Down Expand Up @@ -52,7 +51,6 @@ func main() {
}

func mutateVars(stringModifier string) {
abigint *= 2
abool = !abool
abyte *= 2
afloat32 *= 2
Expand Down Expand Up @@ -82,7 +80,6 @@ func mutateVars(stringModifier string) {
func printVars(phase string) {
println(phase,
// variables
abigint,
abool,
abyte,
afloat32,
Expand All @@ -108,7 +105,7 @@ func printVars(phase string) {
}

// Output:
// preinit 16 true 22 16.16 16.16 16 16 16 16 16 97 hello slice[("A" string)] A (struct{(16 int),("A" string)} gno.land/r/demo/tests_test.myStruct) 16 16 16 16 16 struct{(16 float32)} A
// postinit 32 false 44 32.32 32.32 32 32 32 32 32 66 helloB slice[("A" string),("B" string)] A (struct{(32 int),("B" string)} gno.land/r/demo/tests_test.myStruct) 32 32 32 32 32 struct{("B" string)} B
// premain 32 false 44 32.32 32.32 32 32 32 32 32 66 helloB slice[("A" string),("B" string)] A (struct{(32 int),("B" string)} gno.land/r/demo/tests_test.myStruct) 32 32 32 32 32 struct{("B" string)} B
// postmain 64 true 88 64.64 64.64 64 64 64 64 64 67 helloBC slice[("A" string),("B" string),("C" string)] A (struct{(64 int),("C" string)} gno.land/r/demo/tests_test.myStruct) 64 64 64 64 64 struct{("C" string)} C
// preinit true 22 16.16 16.16 16 16 16 16 16 97 hello slice[("A" string)] A (struct{(16 int),("A" string)} gno.land/r/demo/tests_test.myStruct) 16 16 16 16 16 struct{(16 float32)} A
// postinit false 44 32.32 32.32 32 32 32 32 32 66 helloB slice[("A" string),("B" string)] A (struct{(32 int),("B" string)} gno.land/r/demo/tests_test.myStruct) 32 32 32 32 32 struct{("B" string)} B
// premain false 44 32.32 32.32 32 32 32 32 32 66 helloB slice[("A" string),("B" string)] A (struct{(32 int),("B" string)} gno.land/r/demo/tests_test.myStruct) 32 32 32 32 32 struct{("B" string)} B
// postmain true 88 64.64 64.64 64 64 64 64 64 67 helloBC slice[("A" string),("B" string),("C" string)] A (struct{(64 int),("C" string)} gno.land/r/demo/tests_test.myStruct) 64 64 64 64 64 struct{("C" string)} C

0 comments on commit 0a3df04

Please sign in to comment.