-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add support for generic integer type conversions to Expression::Constant #333
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! This is awesome for clean up any indirect type conversion 🔥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After approve and double check and left some comments :P
impl_from_unsigned!(u8, u16, u32, u64, usize); | ||
|
||
// Implement From trait for u128 separately since it requires explicit reduction | ||
impl<F: SmallField, E: ExtensionField<BaseField = F>> From<u128> for Expression<E> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this From<u128>
really necessary? It is a lossy conversion therefore error-prone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing conversion from usize
prior to this PR was already slightly lossy in this sense because the value has to be renormalized if between p_goldilocks
and 2^64 - 1
. The way I interpret the syntax (and the way it's implemented here) is "integer primitive types represent actual integers, and any conversion to a BaseField constant is by the 'reduce mod p' map", which seems natural.
Great move! |
Current implementation only provides
From<usize>
, which requires explicit type conversions in various locations. This PR provides support for type conversions for arbitrary primitive integer types, specifically:u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize
In reference to this comment.