Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial primitive types #4

Closed
adlerjohn opened this issue Feb 2, 2021 · 3 comments
Closed

Initial primitive types #4

adlerjohn opened this issue Feb 2, 2021 · 3 comments
Assignees
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged

Comments

@adlerjohn
Copy link
Contributor

adlerjohn commented Feb 2, 2021

We'd like to support the following primitive types:

  1. Unsigned integers of variable width: u8, u16, u32, u64. Note that the FuelVM only has unsigned integer support for now, as signed integers are of dubious value in the context of smart contracts. Also note that the FuelVM is big-endian.
  2. bool: Standard Boolean.
  3. byte: A single byte. While we could use u8 like Rust, having a distinct type that forbids certain operations (e.g. arithmetic) without explicit casting increases type safety.
  4. bytes32: A 32-byte hash digest.
  5. address: A (for now) 32-byte address. This should be a parameter, since we may opt for shorter addresses in the future.

Additionally:

  1. Arrays and slices (like Rust's).
  2. Tuples (like Rust's).
  3. Sum types (like Rust's).

We expect blockchain applications to make heavy use of byte manipulation, and so we should promote these types to primitive types rather than having users go through a standard library for them.

@sezna
Copy link
Contributor

sezna commented Feb 4, 2021

Is there a reason we don't want to support signed integers? Lack of use on the blockchain?

@adlerjohn
Copy link
Contributor Author

adlerjohn commented Feb 4, 2021

In a blockchain context there's basically zero reason to use negative numbers. You can always express stuff with unsigned ints, e.g. this fairly complex DeFi contract only using unsigned ints: https://github.com/balancer-labs/balancer-core/blob/f4ed5d65362a8d6cec21662fb6eae233b0babc1f/contracts/BMath.sol. The only place I can imagine signed ints being used is in slices, but there are better ways to do that rust-lang/rfcs#2249 (comment).

@sezna
Copy link
Contributor

sezna commented May 8, 2021

These types have all been implemented with the exception of the address type, which is tracked in a separate issue. I'm going to close this one.

@sezna sezna closed this as completed May 8, 2021
@adlerjohn adlerjohn added the compiler General compiler. Should eventually become more specific as the issue is triaged label May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

No branches or pull requests

2 participants