-
Notifications
You must be signed in to change notification settings - Fork 490
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: add Nullable deref_or
method
#4037
Conversation
80a7370
to
e2ed93c
Compare
Hi @orizi @yuvalsw would it be possible to have a review on this? Also, what's a good rule to follow when inlining functions? My rule of thumb depended on an arbitrary number of lines / complexity of the function (which is why most one-liner I just noticed that tests failed but I'm not sure how to interpret that - it seems that it modifies the CASM code generation, which doesn't match the expected data anymore |
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.
Generally, don't add inline for single line no side effect extern function calls, as these will be auto inlined mostly.
Regarding Onable - it is an internal trait, don't add things into it. Instead we may add One and Zero traits matching the corresponding rust ones.
Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @enitrat)
corelib/src/integer.cairo
line 1463 at r2 (raw file):
} impl Felt252IntoFelt252 of Into<felt252, felt252> {
I believe there already is a T into T impl, this would cause duplicated impl.
Does that mean a function like fn try_into(self: felt252) -> Option<u16> {
u16_try_from_felt252(self)
} will be inlined automatically?
Not sure I understood that - do I need to remove something related to Oneable in my PR? |
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.
Reviewed 1 of 3 files at r1, 1 of 2 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @enitrat)
corelib/src/nullable.cairo
line 21 at r3 (raw file):
fn deref_or<impl TDrop: Drop<T>>(self: Nullable<T>, default: T) -> T; fn new(value: T) -> Nullable<T>; }
While you are here, please remove and use #[generate_trait] on the impl. Thanks!
Code quote:
trait NullableTrait<T> {
fn deref(self: Nullable<T>) -> T;
fn deref_or<impl TDrop: Drop<T>>(self: Nullable<T>, default: T) -> T;
fn new(value: T) -> Nullable<T>;
}
corelib/src/nullable.cairo
line 31 at r3 (raw file):
} fn deref_or<impl TDrop: Drop<T>>(self: Nullable<T>, default: T) -> T {
Suggestion:
+Drop<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.
it is - and yes - probably revert all you have done there.
as you added another impl Onable for felt - which we don't want, and added inlines, which are not relevant.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @enitrat)
8e8a0d1
to
b015f38
Compare
I wasn't able to find the implementation of |
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.
It didn't exist - and Onable
is an internal trait - i'd rather not have any additional impls for it if we encourage usage of a One
and Zero
traits instead.
Reviewable status: 0 of 3 files reviewed, 3 unresolved discussions (waiting on @enitrat and @yuvalsw)
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.
Reviewed 3 of 3 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @enitrat)
edit: Just noticed this sentence
What exactly do you mean by "Internal" trait? Should it not be used externally? And if I think there's a misunderstanding here - are you talking about Lines 91 to 101 in 8977d3b
I think the cairo/corelib/src/zeroable.cairo Lines 12 to 24 in 8977d3b
|
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.
Oneable
is an internal trait defined in math - it was added only for the implementation of inv_mod
for secp.
We want to have other traits similar to rust for One
and Zero
- which would not be internal.
therefore i don't want to add addtional impls for traits i do not want to extend.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @enitrat)
Ok, then I can continue the work started #3891 in another PR |
deref_or
method
b015f38
to
56f4a30
Compare
Required changes have been applied. This PR now only implements the |
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.
Reviewed 1 of 3 files at r4, 2 of 2 files at r5, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @enitrat)
deref_or
method toNullable
Closes #3854
This change is