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

add crosscheck tests for filter function #388

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

csgui
Copy link
Collaborator

@csgui csgui commented Apr 22, 2024

No description provided.

Copy link

codecov bot commented Apr 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.93%. Comparing base (3cac25c) to head (acbc62f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #388      +/-   ##
==========================================
- Coverage   86.94%   86.93%   -0.02%     
==========================================
  Files          43       43              
  Lines       18232    18232              
  Branches    18232    18232              
==========================================
- Hits        15852    15850       -2     
- Misses       1044     1046       +2     
  Partials     1336     1336              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@csgui csgui requested a review from Acaccia April 22, 2024 18:46

match seq_data {
clarity::vm::types::SequenceData::Buffer(_) => {
let snippet = format!("(define-private (only-zero (byte (buff 1))) (is-eq byte 0x00)) (buff-to-int-be (filter only-zero {seq}))");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test doesn't allow us to check that the resulting buffer contains the right number of 0s. It should return a buffer instead of converting it to int.
I would also not use 0 in the predicate, because this is the default value of uninitialized memory in Wasm. So we don't know if the result is correct because it wrote the correct 0, or if it wrote nothing and we have the default 0 that was there in memory.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed the implementation to rely also on other values.

Comment on lines +313 to +315
&format!("(define-private (foo (el (list {max_len} {item_ty})))
(not (is-eq u0 (len el))))
(filter foo (list {seq}))"
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • Creating an empty list is not a frequent event, so I don't think this test is super reliable.
  • It doesn't check that the result of a filter operation leaves the correct number of element in the result list.
  • This is a crosscheck_compare_only, and we already had issues with this not doing what we expected. I suggest using a real crosscheck here.

let v: Vec<u32> = data.as_str().chars().filter_map(|a| a.to_digit(10)).collect();
let expected: String = v.into_iter().map(|i| i.to_string()).collect::<String>();
let snippet = format!("(define-private (is-int (char (string-ascii 1)))
(is-eq 0 (* 0 (unwrap! (string-to-int? char) false))))
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we replace all elements by a fixed 0, we are not sure the result of the filter would contain the correct elements.

crosscheck(
&snippet,
Ok(Some(Value::Sequence(SequenceData::String(
CharType::ASCII(ASCIIData {
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 understand this test: there is no distinction between ascii and utf8 string in the match clause, but the result is systematically ascii? What did I miss?

@Acaccia
Copy link
Collaborator

Acaccia commented May 14, 2024

I pushed the branch workaround to the repo. Feel free to merge it to yours, or refactor from it.

There are a few things to consider though:

  1. THIS IS A POC! It's incomplete and it's tailored to the specific example in the foo test in regression.rs.
  2. When I check for the function argument type, I only considered FixedFunction , we should consider the rest.
  3. We need to add in TypeMap in stacks-core a method to update an expression.
  4. The function does not apply to parents expressions: we need an adaptation of WasmGenerator::set_expr_type to make sure that the new type propagates bottom-up.

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.

None yet

2 participants