TVM-Solidity-Compiler
TVM-Solidity-Compiler copied to clipboard
Consider adding unit type to ton-solidity
Suppose we want to store a set of some entries: for example, a set of already presented hashes for reply-protection.
The conventional solidity-way is to make a map like mapping(uint256 => bool) hashUsed
and set hashUsed[h] = true
whenever hash h
is presented. It is quite straight-forward because in Solidity there is no way to check whether a specific key is presented in the map -- they all are presented and initialized with default value.
However, in Ton-Solidity we have .exists()
method, so it doesn't make sense to store a boolean value in the map -- we can just store nothing! Thus, using unit type (which unique value serializes to empty builder) in mapping(uint256 => Unit)
efficiently allows us to use maps as sets. You can even add a new type set(...)
, internally represented as mapping with Unit
value type. After all, it could allow to write more structured code.
Actually it could be implemented as empty structure struct Unit{}
, but compiler tells that defining empty structures is disallowed.
You can use mapping(uint256 => TvmSlice)