-
Notifications
You must be signed in to change notification settings - Fork 49
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
Global frombytearray #795
Global frombytearray #795
Conversation
@SethDusek i fixed the clippy and rustfmt errors in the workflow |
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, thanks for the contribution. Please see my comments
ergotree-ir/src/types/sglobal.rs
Outdated
tpe: SFunc { | ||
t_dom: vec![SType::SGlobal, SType::SColl(SType::SByte.into())], | ||
t_range:SType::STypeVar(STypeVar::t()).into(), | ||
tpe_params: vec![STypeParam::param_t()], |
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 don't think this is the right way to do this. Since the output type of fromBigEndianBytes can't be inferred from input, the output type needs to be explicitly serialized/deserialized, so add it to explicit_type_args list, see:
sigma-rust/ergotree-ir/src/types/sbox.rs
Line 60 in f6048c1
explicit_type_args: vec![STypeVar::t()] |
Also, can you add roundtrip tests for MethodCalls using this new method? You can skip versioning for now as versioning semantics are still not final in sigmastate-interpreter
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.
Thanks for the review. I'll add explicit type args for proper type inference and include proptest roundtrip tests for MethodCall.
)); | ||
} | ||
let bytes_vec: Vec<u8> = bytes.iter().map(|&x| x as u8).collect(); | ||
let big_int = num_bigint::BigInt::from_bytes_be(num_bigint::Sign::Plus, &bytes_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.
This would make it impossible to deserialize negative bigints, I suggest using BigInt256::from_be_slice instead
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.
Using BigInt256::from_be_slice now to handle negative bigints correctly.
"To deserialize Int with fromBigEndianBytes, exactly four bytes should be provided".to_string(), | ||
)); | ||
} | ||
let bytes_vec: Vec<u8> = bytes.iter().map(|&x| x as u8).collect(); |
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.
Better to do this without heap allocating, rust doesn't have any great ways to collect into fixed-size arrays, so maybe a fold that accumulates bytes would be better: something like bytes.iter().map(|b| b as u8).fold(0i32, |acc, x| (acc << 8) || x as i32)
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.
Fixed to use fold for heap-free byte accumulation.
@@ -98,4 +196,98 @@ mod tests { | |||
expected_xor.as_slice() | |||
); | |||
} | |||
|
|||
#[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.
Can you add roundtrip tests (for example i64->big-endian byte array->back to i64 using this method) for arbitrary bytes/shorts/etc using proptest? See other proptest examples like in src/eval/downcast.rs
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.
Added proptest roundtrip tests following the pattern in downcast.rs.
ergotree-ir/src/types/stype_param.rs
Outdated
@@ -100,3 +100,14 @@ pub struct STypeParam { | |||
upper_bound: Option<SType>, | |||
lower_bound: Option<SType>, | |||
} | |||
|
|||
impl STypeParam { |
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.
Don't think this is needed, check comments in sglobal.rs
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.
you are right. i removed it.
) | ||
.unwrap() | ||
.into(); | ||
let ctx = force_any_val::<Context>(); |
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.
Consider using eval_out_wo_ctx instead for clarity
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.
Done.
Pull Request Test Coverage Report for Build 12515526296Details
💛 - Coveralls |
@SethDusek, I've made the requested changes. Could you please review again? |
@SethDusek i fix the |
})?, | ||
)) | ||
} | ||
SType::SUnit => { |
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.
The original implementation does not have a case for SUnit
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.
Yes, Removed it.
@SethDusek I removed the |
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, but can you please squash your last 4 commits into one?
f706a18
to
c1022e7
Compare
Done. |
No description provided.