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

Global frombytearray #795

Merged
merged 4 commits into from
Dec 27, 2024

Conversation

sebastianrof
Copy link
Contributor

No description provided.

@sebastianrof
Copy link
Contributor Author

@SethDusek i fixed the clippy and rustfmt errors in the workflow

Copy link
Collaborator

@SethDusek SethDusek left a 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

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()],
Copy link
Collaborator

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:

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

Copy link
Contributor Author

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);
Copy link
Collaborator

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

Copy link
Contributor Author

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();
Copy link
Collaborator

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)

Copy link
Contributor Author

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]
Copy link
Collaborator

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

Copy link
Contributor Author

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.

@@ -100,3 +100,14 @@ pub struct STypeParam {
upper_bound: Option<SType>,
lower_bound: Option<SType>,
}

impl STypeParam {
Copy link
Collaborator

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

Copy link
Contributor Author

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>();
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@coveralls
Copy link

coveralls commented Dec 19, 2024

Pull Request Test Coverage Report for Build 12515526296

Details

  • 33 of 49 (67.35%) changed or added relevant lines in 3 files are covered.
  • 18 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.1%) to 78.334%

Changes Missing Coverage Covered Lines Changed/Added Lines %
ergotree-ir/src/types/sglobal.rs 7 8 87.5%
ergotree-interpreter/src/eval/sglobal.rs 25 40 62.5%
Files with Coverage Reduction New Missed Lines %
ergo-p2p/src/peer_info.rs 1 68.42%
ergotree-ir/src/chain/token.rs 5 72.88%
ergotree-ir/src/serialization/types.rs 6 80.42%
ergo-p2p/src/peer_spec.rs 6 76.56%
Totals Coverage Status
Change from base Build 12422681236: -0.1%
Covered Lines: 11031
Relevant Lines: 14082

💛 - Coveralls

@sebastianrof
Copy link
Contributor Author

@SethDusek, I've made the requested changes. Could you please review again?

@sebastianrof
Copy link
Contributor Author

@SethDusek i fix the build without default features issue faced in the pipeline.

})?,
))
}
SType::SUnit => {
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, Removed it.

@sebastianrof
Copy link
Contributor Author

@SethDusek I removed the SUint additional type

Copy link
Collaborator

@SethDusek SethDusek left a 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?

@sebastianrof
Copy link
Contributor Author

Looks good, but can you please squash your last 4 commits into one?

Done.

@SethDusek SethDusek merged commit 5ce27fd into ergoplatform:develop Dec 27, 2024
10 of 12 checks passed
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.

3 participants