Open tac0turtle opened 9 months ago
Additionally, we can revert this (https://github.com/cosmos/cosmos-sdk/pull/17803, that hasn't been released and which would fit here. I'll edit your message above.
The proposal would be to introduce a new type: type IntMut Int
which can be converted from and to Int
with little to no overhead by doing (IntMut)(Int)
and vice-versa (Int)(IntMut)
, then the mutative API would be implemented on top of IntMut
, this would reduce the API surface of Int
which is already big and support the mutative API in a performant way.
Eg:
type IntMut Int
func (i IntMut) ToInt() Int { return (Int)(i) }
func (i IntMut) Quo/Add/Sub/Etc() { ... }
func (i Int) ToIntMutUnsafe() IntMut { return (IntMut)(i) }
func (i Int) ToIntMut() IntMut { return NewIntMutFromBigInt(i) } // this NewIntMutFromBigInt would copy the underlying Int.bigInt
FWIW comment from the bot: https://github.com/cosmos/cosmos-sdk/pull/18247#discussion_r1371130502
Summary
There has been a need for more mutable apis in math, they have been getting added to the current struct which could cause confusion for users.
Problem Definition
separate immutable from mutable in math
Proposed Feature
Create a new mutable struct for users to use when needed.
New api to add: