Skip to content
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

Ban direct indexing #369

Merged
merged 12 commits into from
Apr 30, 2024
Merged

Ban direct indexing #369

merged 12 commits into from
Apr 30, 2024

Conversation

keithtensor
Copy link
Contributor

This PR resolves #278 by enabling CI to detect direct indexing and calls to unwrap.

@keithtensor keithtensor requested review from orriin and a team April 26, 2024 15:22
@sam0x17
Copy link
Contributor

sam0x17 commented Apr 26, 2024

note for reviewers: we are manually adding #[allow(clippy::indexing_slicing)] in a few places for now until we have a sparse matrix implementation that can replace these few places where this is still unavoidable. Luckily we can global find for #[allow(clippy::indexing_slicing)] when the time comes, just wanted to document that here

@keithtensor keithtensor marked this pull request as ready for review April 29, 2024 05:08
@sam0x17 sam0x17 removed their request for review April 29, 2024 13:36
Comment on lines +1 to +2
// Allowed since it's actually better to panic during chain setup when there is an error
#![allow(clippy::unwrap_used)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, nice to allow this in tests, benchmarks, and some node stuff like this

Comment on lines -128 to +144
T::Currency::reserve(&who, id.deposit - old_deposit)?;
T::Currency::hold(
&HoldReason::RegistryIdentity.into(),
&who,
id.deposit - old_deposit,
)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to do the currency -> fungible migration here? Seems unrelated to direct indexing and I think you need a migration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should have gone into the 1.0 branch, but I forgot to commit it and now i'm rolling into this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gregzaitsev is this what you were referring to a while back ? I remember we had some conversation about it. #353

Copy link
Contributor

@sam0x17 sam0x17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 awesome

Comment on lines 266 to +276
assert_eq!(x.len(), y.len());
let n = x.len();
let mut result: Vec<I32F32> = vec![I32F32::from_num(0); n];
for i in 0..n {
if y[i] != 0 {
result[i] = x[i] / y[i];
}
}
result
x.iter()
.zip(y)
.map(|(x_i, y_i)| {
if *y_i != 0 {
x_i / y_i
} else {
I32F32::from_num(0)
}
})
.collect()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@sam0x17 sam0x17 merged commit 35dc836 into development Apr 30, 2024
7 checks passed
@sam0x17 sam0x17 deleted the ban-direct-indexing branch April 30, 2024 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lints to prevent panicking + direct indexing
4 participants