-
Notifications
You must be signed in to change notification settings - Fork 369
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
refactor: make limbs generic to accept limb size #365
Conversation
diff curves Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
derive/src/lib.rs
Outdated
let name = &ast.ident; | ||
|
||
let methods = quote! { | ||
impl<T, const N: usize, const M: usize> Borrow<#name<T, N, M>> for [T] { |
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.
I wonder if there's some way to get all the generics from the ast
, similar to the name
parameter.
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.
Generic can be obtained from the derive macro token stream:
https://docs.rs/syn/latest/syn/struct.DeriveInput.html
@0xkanekiken I think your implementation could be changed a bit to support reading generic constants. There are ways to read the generics and add a new one (like T). Would be happy to chat about it more.
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.
Please see the commit diff. I've modified the AlignedBorrow
macro to support constant generics.
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
} | ||
}) | ||
.expect("Expected at least one type generic"); | ||
|
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.
Could you also add a panic!
that would occur if a non-const generic is used other than T? that would be really good for our user experience which might not be clear right now.
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.
Please see #368. Infact, I have modified the code to trigger a panic if the first generic is not a type, and for any subsequent generics, if they are not consts.
Closing in favor of this approach: #417 |
This PR tries to make the Limbs to be generic in the number of limbs size so that it could support points from different curves. At the moment the
LIMB_SIZE
is hardcoded to32
.sp1/core/src/operations/field/field_den.rs
Lines 21 to 29 in 809f5c4
Major changes:
2 * NUM_LIMBS - 2
, which in the above example, can be set to2 * N - 2
whereN
is the const generic passed to the struct. Unfortunately, passing a generic to a constant operation is not supported in stable Rust, and requires the use of the nightly version. To circumvent this, introduced an additional const parameter for the number of witnesses. Need to figure out the best way to handle this.AlignedBorrowWithGenerics
, to address the above issue. This implementation is not the cleanest and I am looking ways to modifyAlignedBorrow
to support use cases where the first generic is a type, and the rest are constants. At the very least, it should be capable of handling cases where the first generic is the type, and all subsequent generics are constants using one proc macro.