Vyper: VIP: Temporarily remove type units

Created on 10 Mar 2020  路  2Comments  路  Source: vyperlang/vyper

Simple Summary

The current implementation of type units feels inconsistent and confusing. I would like to remove them from the language in their current form.

Motivation

While working on type checking I keep running into issues with units. All of this is made much more difficult because there is very minimal documentation on the subject.

  1. uint256 is considered "unitless", so assignments such as uint256(wei) = uint256 are permitted. It took me a while to realize this was the case, I assumed uint256 was equivalent to uint256(None) and so should not be compatible with uint256(wei).
  2. Addition and subtraction between values with different units is disallowed, but multiplication and division is allowed and produces new compound unit types. This is completely undocumented and does not feel intuitive to me.
  3. wei_value and uint256(wei), despite both being uint256 with unit wei, are incompatible.
  4. Same for timestamp, timedelta, and uint256(sec). Per the documentation, timestamp additionally cannot be added or subtracted with another timestamp. I was unable to check with this firsthand, as attempting to assign to timestamp or timedelta gives me a TypeMistmatch. These feel broken.

While I'm not inherently opposed to the idea of units, the current implementation feels more confusing than beneficial. I propose we remove units altogether while refactoring. We can revisit the concept once refactoring is complete and documentation is up-to-date, and hopefully come up with another approach that's cleaner and more consistent.

Backwards Compatibility

It's a breaking change.

Copyright

Copyright and related rights waived via CC0

Discussion

Most helpful comment

image

All 2 comments

Meeting notes: discuss with the community, tentatively accepted for now

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ben-kaufman picture ben-kaufman  路  4Comments

domrany64 picture domrany64  路  3Comments

pipermerriam picture pipermerriam  路  3Comments

jacqueswww picture jacqueswww  路  3Comments

jacqueswww picture jacqueswww  路  4Comments