Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.

Test monomorphized AST - #240

Open
cyberbono3 wants to merge 3 commits into
zksecurity:mainfrom
cyberbono3:test-mast
Open

Test monomorphized AST#240
cyberbono3 wants to merge 3 commits into
zksecurity:mainfrom
cyberbono3:test-mast

Conversation

@cyberbono3

Copy link
Copy Markdown

Closes #200

@katat

katat commented Dec 4, 2024

Copy link
Copy Markdown
Contributor

hmm, I think the issue is to add tests to compare the AST during monomorphization phase (MAST). It is useful to review the effects on the generated MAST nodes if there are changes to the logic in MAST pipeline.

There is some tool like https://github.com/mitsuhiko/insta?tab=readme-ov-file to do the job. But I think we should be able to structure the snapshot tests small enough, so the generated AST string can be compared in a manageable way.

@cyberbono3

Copy link
Copy Markdown
Author

@katat Thanks for clarification. test_simple_mast yields some ambiguity in MAST snapshots. Every new snapshot generates new functions description: "functions":[["std/bits/nth_bit", "functions":[["std/builtins/log"
You can reproduce it by cargo insta test --review

@katat

katat commented Dec 10, 2024

Copy link
Copy Markdown
Contributor

Ah, it is because the resulted MAST can have the same set of the functions but in different order. The whole MAST contains all the stdlib and builtin functions.

For this kind of test, we should only snapshot the functions in concern, such as the generic examples test_generic_*. The snapshot test for MAST is to check if the monomorphization done properly for the generic features.

I think you can create a new test set, similar to the negative_tests.rs, for snapshot tests for MAST generation. For the generic feature examples to test snapshot, you can copy the code from the examples folder. Ideally, each snapshot test one generic feature that is already covered in the examples folder.

@cyberbono3

cyberbono3 commented Dec 13, 2024

Copy link
Copy Markdown
Author

For this kind of test, we should only snapshot the functions in concern, such as the generic examples test_generic_*. The snapshot test for MAST is to check if the monomorphization done properly for the generic features.
For the generic feature examples to test snapshot, you can copy the code from the examples folder

The snapshot test cases from examples folder (arithmetic.no, array.no etc) will produce an ambiguity as I mentioned above.

There are test_generic_ test cases presented n src/negative_tests.rs and in src/tests/examples.rs.
I assume, you would like to make snapshot tests for MAST generation for test cases test_generic_ listed in src/tests/examples.rs Right?

@katat

katat commented Dec 16, 2024

Copy link
Copy Markdown
Contributor

There are test_generic_ test cases presented n src/negative_tests.rs and in src/tests/examples.rs.
I assume, you would like to make snapshot tests for MAST generation for test cases test_generic_ listed in src/tests/examples.rs Right?

Yes, it should only cover the generic functions that involve MAST generation.

The snapshot test cases from examples folder (arithmetic.no, array.no etc) will produce an ambiguity as I mentioned above.

Not sure If I understood this. The discrepancy is due to the order of the MAST functions. That doesn't mean there is a discrepancy from the MAST. When it comes to comparison, I would suggest checking the monomorphized functions / instantiated function in a narrowed context, that would be easier to find the root causes if there are any discrepancies.

For example, it would be easier to isolate the snapshot test per generic feature, such as generic array:

fn clone(const LEN: Field, val: Field) -> [Field; LEN] {
    let mut arr = [0; LEN];
    for idx in 0..LEN {
        arr[idx] = val;
    }
    return arr;
}

In other words, in the snapshot test, it should check if the MAST of instantiated function from this generic function is as expected.

}

#[test]
fn test_generic_builtin_bits() {

@cyberbono3 cyberbono3 Dec 21, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This test fails here At a first glance use std::btts yields this error.

failures:
---- tests::snapshots::mast::test_generic_builtin_bits stdout ----
[src/mast/mod.rs:590:13] module = Absolute(
    UserRepo {
        user: "std",
        repo: "bits",
    },
)
[src/mast/mod.rs:591:13] &fn_name.value = "to_bits"
thread 'tests::snapshots::mast::test_generic_builtin_bits' panicked at src/mast/mod.rs:596:18:
function not found
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@cyberbono3

Copy link
Copy Markdown
Author

Basically, I have performed snapshot testing for all fields of Mast(pub TypeChecker). for generic code snippets.

@cyberbono3

Copy link
Copy Markdown
Author

@katat could you take a look , please?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test monomorphized AST

2 participants