-
Notifications
You must be signed in to change notification settings - Fork 373
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
Reduce number of unwrap calls and make clippy warning for it opt-out per crate #6311
Conversation
d92f36b
to
575ed7c
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.
Wow, thank you so much for taking this on, love it! And even made the codegen shorter <3
So I think it's probably unrealistic to get rid of all of them, and probably also not necessary.
Yeah I also think that's more realistic than the aspiration on that ticket. However, in the limit we manage to handle it similar to unsafe code: opt-in where absolutely necessary but generally avoid it.
I.e. 100% agree with the strategy you described there.
Apart from the small questions/nits I had I think we should actually get this out of draft and land it almost as is - doing this in smaller steps reduces merge conflicts, makes it easier to review and gives it more churn sooner.
Thanks a lot!
Okay, great - I just have some changes from today that I want to commit first (mostly for tests and some low hanging fruits). And what about the last checkbox - what do I have to do to meet the conditions? |
90d2e78
to
3628dbc
Compare
Just one more thing: as this is work in progress - should we set again globally |
The lint warnings will make ci fail (so that if you check out it's always warning free), so leaving them is is not an option. Meaning we either have to opt-out crates that aren't ready or opt-in those that are. I'd prefer having crates to opt-out because new crates then have the new rules from the start, but it ofc means that we have to annotate a lot of them |
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.
getting there 🙃
Hmmm, makes sense but also has one disadvantage: we won't know then which ones will opt out because they are not refactored yet and which ones opt out for legit reasons.
What do you think?...there aren't that many crates that require it. |
ah yes that's what I meant with opting out 😄 . Using |
"opting out for legit reasons" should almost never happen on crate level anyways and if so we can comment on why :) |
There are quite a lot of tests/benches that are technically their own crates that need it. But I documented it anyway wherever I encountered it. |
Oooookay...hope now it arrived 😄 |
e33895d
to
e1824d4
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.
nice, thanks again!
Still need to get ci green though:
- unwraps where they are no longer allowed: https://github.com/rerun-io/rerun/actions/runs/9080837063/job/24958946682?pr=6311
pixi run lint-rerun
is unhappy:
https://github.com/rerun-io/rerun/actions/runs/9080837063/job/24958945687?pr=6311
let sh = Shell::new().expect("Shell::new() failed"); | ||
#[allow(clippy::unwrap_used)] // unwrap is okay 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.
something went sideways here or is cmd!
internally doing an unwrap?
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 have fixed hopefully all the linting errors.
something went sideways here or is cmd! internally doing an unwrap?
I'm not sure I understand, does it fail somewhere? I haven't seen anything in the logs.
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.
Btw, locally I get another error when running cargo test --quiet --all-targets
:
(I added some logs to bench_downcast_first
in rerun/crates/re_data_store/benches/arrow2.rs
):
bench_downcast_first: re_arrow2::array::fixed_size_list::FixedSizeListArray for kind: Struct
bench_downcast_first: cell:DataCell { inner: DataCellInner { name: "example.MyPoint", size_bytes: 0, values: StructArray[{x: 0, y: 0}] } }
thread 'main' panicked at crates/re_data_store/benches/arrow2.rs:298:30:
called `Option::unwrap()` on a `None` value
I don't know this code well but it seems some dynamic casting goes haywire.
The culprit seems to be this line:
ArrayKind::Struct => bench_downcast_first::<FixedSizeListArray>(&mut group, kind)
shouldn't it be?
ArrayKind::Struct => bench_downcast_first::<StructArray>(&mut group, kind)
...because judging from the logs above generate_cells
generates a StructArray
for MyPoint
.
impl Loggable for MyPoint
also uses Struct
/StructArray
and not FixedSizeListArray
.
I don't think this is caused by my changes though - and ideas?
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.
does it fail somewhere? I haven't seen anything in the logs.
I was just blind, didn't see the unwrap below. nvm.
Btw, locally I get another error
Hmm strange, also ci doesn't catch this either, it apparently doesn't run this benchmark. Repros for me cleanly on main
, so definitely not this changeset here. Cc: @teh-cmc
What
Resolves #3408: Remove all usages of unwrap() and forbid it's use (if applicable).
If applicable because even after the first batch of changes there are over 800(!) usages of unwrap() in the code - for various reasons, and often explicitly allowed. So I think it's probably unrealistic to get rid of all of them, and probably also not necessary.
The strategy:
unwrap()
.unwrap()
module by module.unwrap()
would be theoretically okay useexpect("error msg")
.allow-unwrap-in-tests
was anyway already set inclippy.toml
)clippy::unwrap_used
everywhere, unless explicitly allowed.Note: as this is my first PR, early feedback is greatly appreciated🙏
Also - rookie question - what (or where) are the guidelines for the last three items in the checklist? Are they needed for this PR, as this is just a cleanup?
Checklist
To run all checks from
main
, comment on the PR with@rerun-bot full-check
.