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

Feat: Implement Pod trait on Uint types #292

Merged
merged 10 commits into from Aug 5, 2023
Merged

Feat: Implement Pod trait on Uint types #292

merged 10 commits into from Aug 5, 2023

Conversation

0xKitsune
Copy link
Contributor

@0xKitsune 0xKitsune commented Aug 3, 2023

Motivation

This PR implements the Pod trait on Uint types where the size is a multiple of 64, up to 1024. This allows Uint types within this range to be used in instances where a Pod trait bound exists.

Solution

This implementation uses a simple macro to implement the Pod trait on the following Uint sizes listed below.

macro_rules! impl_pod {
    ($(($bits:expr, $limbs:expr)),+ $(,)?) => {
        $(
            unsafe impl Pod for Uint<{$bits}, $limbs> {}
        )+
    };
}


impl_pod! {
    (64, 1),
    (128, 2),
    (192, 3),
    (256, 4),
    (320, 5),
    (384, 6),
    (448, 7),
    (512, 8),
    (576, 9),
    (640, 10),
    (704, 11),
    (768, 12),
    (832, 13),
    (896, 14),
    (960, 15),
    (1024, 16),
}

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog

README.md Outdated Show resolved Hide resolved
src/support/bytemuck.rs Outdated Show resolved Hide resolved
src/support/bytemuck.rs Outdated Show resolved Hide resolved
src/support/bytemuck.rs Outdated Show resolved Hide resolved
src/support/bytemuck.rs Outdated Show resolved Hide resolved
};
}

impl_pod! {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to replace this with a generic_const_expr usage when cfg(feature = "nightly") ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide more insight on what this might look like? I can take a look into updating the implementation to use generic_const_expr when nightly is enabled.

Would you want this updated before merging the current changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just following up on this, let me know what you think. I'm happy to take a look into it if this would be blocking to get the PR merged.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't consider this a blocker

@codecov
Copy link

codecov bot commented Aug 3, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01% 🎉

Comparison is base (d92ca5a) 82.66% compared to head (d4abbcc) 82.67%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #292      +/-   ##
==========================================
+ Coverage   82.66%   82.67%   +0.01%     
==========================================
  Files          52       53       +1     
  Lines        5648     5681      +33     
==========================================
+ Hits         4669     4697      +28     
- Misses        979      984       +5     
Files Changed Coverage Δ
src/lib.rs 81.05% <ø> (ø)
src/support/bytemuck.rs 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

// 64, and using `Uint` sizes not divisible by 64 would violate Pod's
// guarantees potentially leading to undefined behavior.
macro_rules! impl_pod {
($(($bits:expr, $limbs:expr)),+ $(,)?) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: these are really literal, as non-literal expr are invalid in this context. no change needed

@recmo recmo merged commit 1b14a40 into recmo:main Aug 5, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants