-
Notifications
You must be signed in to change notification settings - Fork 160
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 [breaking changes]: Extensible VirtualMachineError and removed PartialEq trait #783
feat [breaking changes]: Extensible VirtualMachineError and removed PartialEq trait #783
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.
- use assert_matches
- fix variable names
- try to make your assert in one single line when possible
- improve the
Other
error variant by use ofthiserror
features
81ff3ba
to
148140e
Compare
1afc853
to
a6e35f9
Compare
Is there any chance to require the new error to be |
a6e35f9
to
edbd652
Compare
It is not something you want to do. It would prevent users to use any error types that do not implement The reason why you want
Because the In conclusion, there is not really a way around it. If we want an escape variant for users' custom errors, it has to contain an |
See also this comment: #776 (comment) |
Sad, but we'll live. |
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.
Overall this looks good. There are a few minor comments and we need to update the change log before it can be merged, specially with regards to interface changes.
I'm a bit sad about the added verbosity, but I can't think of any way to avoid it so 🤷
src/vm/vm_core.rs
Outdated
); | ||
assert_eq!(error.unwrap_err().to_string(), "Inconsistent auto-deduction for builtin ec_op, expected 2739017437753868763038285897969098325279422804143820990343394856167768859289, got Some(Int(2778063437308421278851140253538604815869848682781135193774472480292420096757))"); | ||
//assert_eq!(error.unwrap_err().to_string(), "Inconsistent auto-deduction for builtin ec_op, expected 2739017437753868763038285897969098325279422804143820990343394856167768859289, got Some(Int(2778063437308421278851140253538604815869848682781135193774472480292420096757))"); |
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.
Why are we no longer checking this? Also, why leave the commented test?
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.
This part has not been addressed.
edbd652
to
2d6f092
Compare
2d6f092
to
bef7716
Compare
Review changes applied @Oppen :) Sorry for the delay |
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.
Looks Good!
@Oppen You can resolve the open conversations and merge? |
@tdelabro on it, sorry for the delay. |
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.
Hi @hurrikaanig @tdelabro. There are a few more things that need changing. They are tiny and should be quick and easy to fix. I talked with Timothée and he said it's OK if @Juan-M-V updates the PR with those changes to get them applied sooner. I think we can get this merged today 🎉
run_hint!(vm, ids_data, hint_code::FIND_ELEMENT), | ||
Err(HintError::Internal(VirtualMachineError::ExpectedInteger( | ||
relocatable | ||
_relocatable |
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.
Shouldn't this also check we have the same relocatable value?
run_hint!(vm, ids_data, hint_code::SEARCH_SORTED_LOWER), | ||
Err(HintError::ValueOutOfRange(Felt::zero())) | ||
Err(HintError::ValueOutOfRange(x)) if x == Felt::zero() |
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.
Err(HintError::ValueOutOfRange(x)) if x == Felt::zero() | |
Err(HintError::ValueOutOfRange(x)) if x.is_zero() |
run_hint!(vm, ids_data, HINT_CODE), | ||
Err(HintError::Internal(VirtualMachineError::ValueNotPositive( | ||
int | ||
_int |
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.
This should compare with the actual value, no?
src/types/relocatable.rs
Outdated
} | ||
|
||
#[test] | ||
fn add_bigint_to_relocatable() { | ||
let addr = MaybeRelocatable::RelocatableValue(relocatable!(7, 65)); | ||
let added_addr = addr.add_int(&Felt::new(2)); | ||
assert_eq!(Ok(MaybeRelocatable::from((7, 67))), added_addr); | ||
let _added_addr = addr.add_int(&Felt::new(2)); |
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.
This value is used, isn't it? Let's remove the underscore.
src/types/relocatable.rs
Outdated
// assert_eq!( | ||
// error.unwrap_err().to_string(), | ||
// "Offset 18446744073709551616 exceeds maximum offset value" | ||
// ); |
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.
This doesn't look like it should be commented.
src/types/relocatable.rs
Outdated
Ok::<MaybeRelocatable, VirtualMachineError>(MaybeRelocatable::RelocatableValue( | ||
relocatable!(7, 17) | ||
)), | ||
_added_addr |
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.
Ditto.
src/types/relocatable.rs
Outdated
Ok::<MaybeRelocatable, VirtualMachineError>(MaybeRelocatable::RelocatableValue( | ||
relocatable!(7, 14) | ||
)), | ||
_added_addr |
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.
Ditto.
src/types/relocatable.rs
Outdated
let _sub_addr = addr_a.sub(addr_b); | ||
assert_matches!( | ||
Ok::<MaybeRelocatable, VirtualMachineError>(MaybeRelocatable::from(Felt::new(2))), | ||
_sub_addr |
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.
Ditto.
src/types/relocatable.rs
Outdated
let _sub_addr = addr_a.sub(addr_b); | ||
assert_matches!( | ||
Ok::<MaybeRelocatable, VirtualMachineError>(MaybeRelocatable::from(Felt::new(10))), | ||
_sub_addr |
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.
Ditto.
src/vm/vm_memory/memory.rs
Outdated
mem.get(&MaybeRelocatable::from((1, 0))), | ||
_val_clone | ||
)); | ||
assert_matches!(mem.get(&MaybeRelocatable::from((1, 0))), _val_clone); |
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'm not sure I understand this particular test. I don't see a definition of _val_clone
, and if it's just a new name for the returned value wouldn't this always match?
Codecov Report
@@ Coverage Diff @@
## main #783 +/- ##
==========================================
- Coverage 97.81% 97.13% -0.69%
==========================================
Files 69 69
Lines 29380 28827 -553
==========================================
- Hits 28739 28001 -738
- Misses 641 826 +185
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
src/math_utils.rs
Outdated
} | ||
|
||
#[test] | ||
fn calculate_isqrt_c() { | ||
let n = biguint_str!( | ||
"3618502788666131213697322783095070105623107215331596699973092056135872020481" | ||
); | ||
assert_eq!(isqrt(&n.pow(2_u32)), Ok(n)); | ||
assert_matches!(isqrt(&n.pow(2_u32)), Ok(_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.
Let's compare the value 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.
Resolved: bce4570
src/math_utils.rs
Outdated
} | ||
|
||
#[test] | ||
fn calculate_isqrt_zero() { | ||
let n = BigUint::zero(); | ||
assert_eq!(isqrt(&n), Ok(BigUint::zero())); | ||
assert_matches!(isqrt(&n), Ok(_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.
Same 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.
Resolved: bce4570
src/types/relocatable.rs
Outdated
let _added_addr = addr.add_int(&Felt::new(2i32)); | ||
assert_matches!( | ||
Ok::<MaybeRelocatable, VirtualMachineError>(MaybeRelocatable::Int(Felt::new(9i32))), | ||
_added_addr |
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.
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.
Resolved 0247165
src/types/relocatable.rs
Outdated
let added_addr = addr.add_usize(2); | ||
assert_eq!(MaybeRelocatable::Int(Felt::new(9_i32)), added_addr); | ||
let _added_addr = addr.add_usize(2); | ||
assert_eq!(MaybeRelocatable::Int(Felt::new(9_i32)), _added_addr); |
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.
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.
Resolved: 0247165
@@ -934,7 +934,7 @@ mod tests { | |||
]; | |||
let builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true); | |||
|
|||
let _error = builtin.deduce_memory_cell(&Relocatable::from((3, 6)), &memory); | |||
let _expected_error = builtin.deduce_memory_cell(&Relocatable::from((3, 6)), &memory); | |||
/*assert_eq!( |
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.
This shouldn't be commented out I think. And _expected_error
should be used.
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.
Resolved: 220c537
src/math_utils.rs
Outdated
} | ||
|
||
#[test] | ||
fn calculate_isqrt_b() { | ||
let n = biguint_str!("4573659632505831259480"); | ||
assert_eq!(isqrt(&n.pow(2_u32)), Ok(n)); | ||
assert_matches!(isqrt(&n.pow(2_u32)), Ok(_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.
Compare 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.
Resolved: c0d94ba
Extensible VirtualMachineError and removed PartialEq trait
Description
Linked to this issue #751 I added VirtualMachineError::Other(anyhow::Error) to allow to returing custom errors when using cairo-rs
Also I removed PartialEq trait from VirtualMachineError enum as I found it was a bad practice through my research with @tdelabro help
See: https://users.rust-lang.org/t/help-understanding-io-error-and-lack-of-partialeq/13212
std::io::Error does not implement PartialEq (https://doc.rust-lang.org/std/io/struct.Error.html)
I have replaced assert_eq!() in tests with assert!(matches!()) (https://stackoverflow.com/questions/57234140/how-to-assert-io-errors-in-rust)
Checklist