-
Notifications
You must be signed in to change notification settings - Fork 265
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(sgx_types): add traits using derive #325
feat(sgx_types): add traits using derive #325
Conversation
thanks man! i have a |
Thanks a lot for giving some pointers and feedback! I will have a look at the branch and see if there is a way to get the proc macro to work without pulling in dependencies. If it does pull in a dependency, will it be OK to tie it to a feature that is not included by default, so that it will be up to the crate user to decide when they want the debug types etc? |
@dingelish I updated the existing macros to use derive for Debug and other implementations. This seems like the easiest way to go about this. The main concern with updating the existing macros is that the Also, I have not written macros before, so there might be other effects that I am missing here. Let me know if I should try a different angle or if there is something I can modify with this approach to make the implementation a little bit more sensible. The reason I replaced the existing copy functionality is because of a compiler warning that derive cannot be used on repr(packed) structs that does not derive Copy. rust-lang/rust#46043 should have more info |
@longtomjr I think we can refer to libc crate and use extra_traits feature to control derived debug, PartialEq, etc. For the repr(packed) structure, I think we can replace the original macro with the new |
Thanks for the feedback. I have some other urgent work that needs to be finalized. Will have a look at getting this done as soon as I get that done. |
0b082c5
to
2be8c35
Compare
@volcano0dr What is the reason for using custom copy and clone implementations rather than using derive? |
5424f5b
to
0ace603
Compare
Because in the early rust version, large arrays (count> 32) cannot automatically derive Clone, Debug, Default..traits. |
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 tried to submit code to your fork repo, but the permission was denied.
Can you add derive(Debug)
to enum types in sgx_types? thanks!
Should I update the code to use derive instead now?
Will do! |
For reference, These are the types that don't have rg -P "derive\((?!.*Debug)" -A 1
src/macros.rs
209: #[derive($($derive:meta),*)]
210- pub enum $name:ident {
--
216: #[derive($($derive),*)]
217- pub enum $name {
src/types.rs
1482:#[derive(Copy, Clone, Default)]
1483-pub struct sgx_align_key_128bit_t {
--
1489:#[derive(Copy, Clone, Default)]
1490-pub struct sgx_align_mac_128bit_t {
--
1496:#[derive(Copy, Clone, Default)]
1497-pub struct sgx_align_key_256bit_t {
--
1503:#[derive(Copy, Clone, Default)]
1504-pub struct sgx_align_mac_256bit_t {
--
1510:#[derive(Copy, Clone, Default)]
1511-pub struct sgx_align_ec256_dh_shared_t {
--
1517:#[derive(Copy, Clone, Default)]
1518-pub struct sgx_align_ec256_private_t {
|
@longtomjr You can implement Debug, Eq, PartialEq trait for sgx_align_xxx.
|
@volcano0dr I used derive for those types as well. If you would prefer I can add a macro that generates Sorry for the delay, had some time sensitive stuff I had to get sorted. |
I think it is inappropriate to use derive for these types. The |
@volcano0dr Make sense. |
Updated the derive to only be for debug, and added manual impl for Eq and PartialEq to the relevant types. |
I think it would be more appropriate not to include |
Make sense, updated it to use a manual impl. |
@longtomjr Can you squash all commits before I merge the changes? Thanks again for the contribution! |
feat(sgx_types): update macros to derive traits feat(sgx_types): add feature for extra traits feat(sgx_types): derive debug on enum types feat(sgx_types): add derives on align types feat(sgx_types): add manual impl for PartialEq, Eq feat(sgx_types): add manual debug impl for align*
715d3e7
to
c56a54b
Compare
@volcano0dr Anytime, thanks for all the help and guidance! Squashed the commits |
This standardises all the Rust SGX SDK repository references to: * git = "https://github.com/apache/incubator-teaclave-sgx-sdk.git" * rev = "b9d1bda" which is v1.1.3 plus "feat(sgx_types): add traits using derive #325": * apache/incubator-teaclave-sgx-sdk#325
I started implementing the Debug and PartialEq traits using derive. This is to facilitate creating strategies with proptest and to allow us to easily compare results after the test.
This is WIP, but I wanted to open it up for feedback and to get an idea on if this makes sense to add.