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

Test monomorphized AST #240

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

Conversation

cyberbono3
Copy link

Closes #200

@katat
Copy link
Collaborator

katat commented Dec 4, 2024

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

katat commented Dec 10, 2024

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
Copy link
Author

cyberbono3 commented Dec 13, 2024

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

katat commented Dec 16, 2024

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() {
Copy link
Author

@cyberbono3 cyberbono3 Dec 21, 2024

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
Author

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

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.

Test monomorphized AST
2 participants