-
Notifications
You must be signed in to change notification settings - Fork 550
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(corelib): Iterator::advance_by #7059
Conversation
2866d30
to
a779289
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 3 files at r1, all commit messages.
Reviewable status: 1 of 3 files reviewed, 1 unresolved discussion (waiting on @MagisterDallis)
a discussion (no related file):
@TomerStarkware for 2nd eye.
corelib/src/iter/traits/iterator.cairo
line 79 at r1 (raw file):
} }; res
Suggestion:
ref self: T, mut n: usize,
) -> Result<
(), NonZero<usize>,
> {
let mut res = Result::Ok(());
while let Option::Some(nz_n) = n.try_into() {
if Self::next(ref self).is_none() {
res = Result::Err(nz_n);
break;
}
n -= 1;
}
res
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 1 files at r2, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @MagisterDallis)
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 @MagisterDallis)
corelib/src/iter/traits/iterator.cairo
line 79 at r1 (raw file):
} }; res
error: Parameter of trait function Iterator::advance_by
can't be defined as mutable.
--> corelib/src/iter/traits/iterator.cairo:68:22
ref self: T, mut n: usize,
n: usize
and then let mut n = n
?
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 @MagisterDallis)
a discussion (no related file):
Previously, orizi wrote…
@TomerStarkware for 2nd eye.
@orizi I'm actually hitting a bigger issue which is that
error: Trait has no implementation in context: core::traits::Drop::<Iterator::Item>.
--> corelib/src/test/iter_test.cairo:5:21
assert_eq!(iter.advance_by(2), Result::Ok(()));
^^^^^^^^^^
A workaround would be to have something like:
pub trait IteratorEx<T, impl I: Iterator<T>, +Destruct<T>, +Drop<I::Item>> {
...
}
impl IteratorExImpl<T, impl I: Iterator<T>, +Destruct<T>, +Drop<I::Item>> of IteratorEx<T, I> {}
and expose IteratorEx
in the prelude, but perhaps there's better to do than that?
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 @MagisterDallis)
a discussion (no related file):
Previously, MagisterDallis wrote…
@orizi I'm actually hitting a bigger issue which is that
error: Trait has no implementation in context: core::traits::Drop::<Iterator::Item>. --> corelib/src/test/iter_test.cairo:5:21 assert_eq!(iter.advance_by(2), Result::Ok(())); ^^^^^^^^^^
A workaround would be to have something like:
pub trait IteratorEx<T, impl I: Iterator<T>, +Destruct<T>, +Drop<I::Item>> { ... } impl IteratorExImpl<T, impl I: Iterator<T>, +Destruct<T>, +Drop<I::Item>> of IteratorEx<T, I> {}
and expose
IteratorEx
in the prelude, but perhaps there's better to do than that?
are you fully rebased?
corelib/src/iter/traits/iterator.cairo
line 79 at r1 (raw file):
Previously, MagisterDallis wrote…
error: Parameter of trait function
Iterator::advance_by
can't be defined as mutable.
--> corelib/src/iter/traits/iterator.cairo:68:22
ref self: T, mut n: usize,
n: usize
and thenlet mut n = n
?
that would be good enough.
37c33c1
to
2b12465
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.
Reviewable status: 2 of 3 files reviewed, all discussions resolved (waiting on @orizi)
a discussion (no related file):
Previously, orizi wrote…
are you fully rebased?
On 6837d54
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: 2 of 3 files reviewed, all discussions resolved (waiting on @orizi)
corelib/src/iter/traits/iterator.cairo
line 79 at r1 (raw file):
Previously, orizi wrote…
that would be good enough.
Done.
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 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @TomerStarkware)
a discussion (no related file):
Previously, MagisterDallis wrote…
On 6837d54
in any case - IteratorEx in prelude won't happen.
we will just fix the underlying issue here.
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: all files reviewed, 2 unresolved discussions (waiting on @MagisterDallis and @TomerStarkware)
corelib/src/iter/traits/iterator.cairo
line 82 at r3 (raw file):
}; res }
Suggestion:
fn advance_by<+Destruct<T>, +Destruct<Self::Item>>(
ref self: T, n: usize,
) -> Result<
(), NonZero<usize>,
> {
let mut n = n;
let mut res = Result::Ok(());
while let Option::Some(nz_n) = n.try_into() {
if let Option::Some(_) = Self::next(ref self) {
n -= 1;
} else {
res = Result::Err(nz_n);
break;
}
};
res
}
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: all files reviewed, 2 unresolved discussions (waiting on @MagisterDallis and @TomerStarkware)
corelib/src/iter/traits/iterator.cairo
line 82 at r3 (raw file):
}; res }
(this allows using Destruct instead of Drop, does not solve the other issue)
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: all files reviewed, 2 unresolved discussions (waiting on @orizi and @TomerStarkware)
a discussion (no related file):
Previously, orizi wrote…
in any case - IteratorEx in prelude won't happen.
we will just fix the underlying issue here.
tracking in #7060
corelib/src/iter/traits/iterator.cairo
line 82 at r3 (raw file):
Previously, orizi wrote…
(this allows using Destruct instead of Drop, does not solve the other issue)
Done.
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 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @MagisterDallis and @TomerStarkware)
corelib/src/iter/traits/iterator.cairo
line 82 at r4 (raw file):
} }; res
It seems after the fix (#7067) there is still an issue with loops - but this would work instead (and would possibly be just a bit more efficient)
Suggestion:
if let Option::Some(nz_n) = n.try_into() {
if let Option::Some(_) = Self::next(ref self) {
Self:::advance_by(Self::advance_by(ref self, n - 1)
} else {
Result::Err(nz_n)
}
} else {
Result::Ok(())
}
0aeedd5
to
b1fedc2
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.
Reviewable status: 0 of 4 files reviewed, 2 unresolved discussions (waiting on @orizi and @TomerStarkware)
corelib/src/iter/traits/iterator.cairo
line 82 at r4 (raw file):
Previously, orizi wrote…
It seems after the fix (#7067) there is still an issue with loops - but this would work instead (and would possibly be just a bit more efficient)
Done.
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 4 of 4 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @MagisterDallis)
a discussion (no related file):
@TomerStarkware for 2nd eye.
corelib/src/iter/traits/iterator.cairo
line 74 at r5 (raw file):
(), NonZero<usize>, > { let mut n = n;
not required.
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: 3 of 4 files reviewed, 1 unresolved discussion (waiting on @orizi)
corelib/src/iter/traits/iterator.cairo
line 74 at r5 (raw file):
Previously, orizi wrote…
not required.
Done.
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 1 files at r6, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @MagisterDallis)
a discussion (no related file):
Previously, orizi wrote…
@TomerStarkware for 2nd eye.
ping
ec266b8
to
3b5479d
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 2 of 2 files at r7, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @MagisterDallis)
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 @MagisterDallis)
…7087) chore: orthographic correction in file if_else (#7088) prevents closure parameters from being declared as refrences (#7078) Refactored bounded_int_trim. (#7062) Added const for starknet types. (#6961) feat(corelib): Iterator::fold (#7084) feat(corelib): Iterator::advance_by (#7059) fix(corelib): Add the #[test] annotation to enumerate test (#7098) feat(corelib): storage vectors iterators (#6941) Extract ModuleHelper from const folding. (#7099) Added support for basic `Into`s in consts. (#7100) Removed taking value for `validate_literal`. (#7101) added closure params to semantic defs in lowering (#7085) Added support for `downcast` in constant context. (#7102) fix(corelib): Add the #[test] annotation to enumerate test (#7098)
feat(corelib): Iterator::enumerate (#7048) fix: Fix handling of --skip-first argument Update release_crates.sh (#7087) chore: orthographic correction in file if_else (#7088) prevents closure parameters from being declared as refrences (#7078) Refactored bounded_int_trim. (#7062) Added const for starknet types. (#6961) feat(corelib): Iterator::fold (#7084) feat(corelib): Iterator::advance_by (#7059) fix(corelib): Add the #[test] annotation to enumerate test (#7098) feat(corelib): storage vectors iterators (#6941) Extract ModuleHelper from const folding. (#7099) Added support for basic `Into`s in consts. (#7100) Removed taking value for `validate_literal`. (#7101) added closure params to semantic defs in lowering (#7085) Added support for `downcast` in constant context. (#7102) fix(corelib): Add the #[test] annotation to enumerate test (#7098)
feat(corelib): Iterator::enumerate (#7048) fix: Fix handling of --skip-first argument Update release_crates.sh (#7087) chore: orthographic correction in file if_else (#7088) prevents closure parameters from being declared as refrences (#7078) Refactored bounded_int_trim. (#7062) Added const for starknet types. (#6961) feat(corelib): Iterator::fold (#7084) feat(corelib): Iterator::advance_by (#7059) fix(corelib): Add the #[test] annotation to enumerate test (#7098) feat(corelib): storage vectors iterators (#6941) Extract ModuleHelper from const folding. (#7099) Added support for basic `Into`s in consts. (#7100) Removed taking value for `validate_literal`. (#7101) added closure params to semantic defs in lowering (#7085) Added support for `downcast` in constant context. (#7102) fix(corelib): Add the #[test] annotation to enumerate test (#7098)
Adds
advance_by
toIterator