-
Notifications
You must be signed in to change notification settings - Fork 596
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: Default trait for Array/Dict #3048
Feat: Default trait for Array/Dict #3048
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.
Reviewable status: 0 of 35 files reviewed, 1 unresolved discussion (waiting on @wraitii)
corelib/src/lib.cairo
line 11 at r1 (raw file):
fn new<T, impl TDefault: Default<T>>() -> T { Default::default()
name is "too useful" - i have no issues with the fn itself - but i think we need a bit of a longer name at the very least.
(and the fact that Default::default()
would work seems to me to make it less necessary as well)
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 2 of 35 files at r1, all commit messages.
Reviewable status: 2 of 35 files reviewed, 1 unresolved discussion (waiting on @orizi)
corelib/src/lib.cairo
line 11 at r1 (raw file):
Previously, orizi wrote…
name is "too useful" - i have no issues with the fn itself - but i think we need a bit of a longer name at the very least.
(and the fact thatDefault::default()
would work seems to me to make it less necessary as well)
I don't like this function either. We can use Default::default()
e5de055
to
804a2dd
Compare
new
functionThere 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.
Reviewable status: 2 of 35 files reviewed, 1 unresolved discussion (waiting on @orizi and @spapinistarkware)
corelib/src/lib.cairo
line 11 at r1 (raw file):
Previously, spapinistarkware (Shahar Papini) wrote…
I don't like this function either. We can use
Default::default()
I've removed the function.
I think a shortened form could be useful (perhaps just default()
), but that would be mostly sidestepped if we had something like vec![]
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 5 of 21 files at r2, all commit messages.
Reviewable status: 7 of 35 files reviewed, 2 unresolved discussions (waiting on @orizi and @wraitii)
corelib/src/debug.cairo
line 24 at r2 (raw file):
fn print_felt252(message: felt252) { let mut arr = Default::default();
How does this actually work? With no type annotations, it can't know we want an array.
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.
Reviewable status: 7 of 35 files reviewed, 2 unresolved discussions (waiting on @orizi and @spapinistarkware)
corelib/src/debug.cairo
line 24 at r2 (raw file):
Previously, spapinistarkware (Shahar Papini) wrote…
How does this actually work? With no type annotations, it can't know we want an array.
I believe the type system deduces it from the print
statement. I'm honestly not entirely sure about the type-deduction system in Cairo though.
But this compiles and runs without problem.
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 12 of 35 files at r1, 18 of 21 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: 35 of 36 files reviewed, 2 unresolved discussions (waiting on @spapinistarkware and @wraitii)
corelib/src/traits.cairo
line 132 at r3 (raw file):
@Default::default() } }
Suggestion:
impl SnapshotDefault<T, impl TDefault: Default<T>, impl TDrop: Drop<T>> of Default<@T> {
#[inline(always)]
fn default() -> @T {
@Default::default()
}
}
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.
Reviewable status: 35 of 36 files reviewed, 2 unresolved discussions (waiting on @orizi and @spapinistarkware)
corelib/src/traits.cairo
line 132 at r3 (raw file):
@Default::default() } }
Done
045293b
to
3d7c914
Compare
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 35 files at r1, 8 of 8 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @spapinistarkware)
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.
Reviewable status:
complete! all files reviewed, all discussions resolved (waiting on @wraitii)
Looks like there are conflicts. If you resolve them, I'll merge |
3d7c914
to
f1894e5
Compare
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 16 of 16 files at r5, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @wraitii)
f1894e5
to
074010f
Compare
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 5 of 5 files at r6, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @wraitii)
wouldn't it be better to have both And I like being more explicit way more. similar to rust where there is Not to mention this would be a breaking change for anyone using |
Fixes #3046
This does two things:
Default
trait instead of adding a custom method to ArrayTrait/Felt252DictTraitUse that trait to create a simplenew
function that makes code leaner.If thenew
function isn't desired, I'll remove it, but I think it's overall a good readability improvement.NB: There is a
new
in BoxTrait that takes an argument. I haven't changed that.This change is