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

Expression->String->Expression doesn't always work #215

Closed
genos opened this issue Jun 9, 2023 · 1 comment
Closed

Expression->String->Expression doesn't always work #215

genos opened this issue Jun 9, 2023 · 1 comment

Comments

@genos
Copy link
Contributor

genos commented Jun 9, 2023

In working on #210, I wanted to serialize a static collection of expressions to simplify for consistent benchmarking. Unfortunately, Expression::from_str(&expression.to_string()) doesn't reliably work.

For instance, this test:

proptest! {
    #[test]
    fn round_trip(e in arb_expr()) {
        let s = e.to_string();
        let p = Expression::from_str(&s);
        dbg!((&e, &s, &p));
        prop_assert!(p.is_ok());
        prop_assert_eq!(p.unwrap().into_simplified(), e.into_simplified());
    }
}

finds the following failure:

[quil-rs/src/expression.rs:1513] (&e, &s, &p) = (
    Infix(
        InfixExpression {
            left: Address(
                MemoryReference {
                    name: "A0",
                    index: 0,
                },
            ),
            operator: Caret,
            right: Address(
                MemoryReference {
                    name: "aa",
                    index: 0,
                },
            ),
        },
    ),
    "A0[0]^aa[0]",
    Err(
        Syntax(
            Leftover(
                LeftoverError {
                    line: 1,
                    column: 6,
                    snippet: "OPERATOR(^)",
                    parsed: Address(
                        MemoryReference {
                            name: "A0",
                            index: 0,
                        },
                    ),
                },
            ),
        ),
    ),
)
thread 'expression::tests::round_trip' panicked at 'Test failed: assertion failed: p.is_ok() at quil-rs/src/expression.rs:1514.
minimal failing input: e = Infix(
    InfixExpression {
        left: Address(
            MemoryReference {
                name: "A0",
                index: 0,
            },
        ),
        operator: Caret,
        right: Address(
            MemoryReference {
                name: "aa",
                index: 0,
            },
        ),
    },
)
        successes: 0
        local rejects: 0
        global rejects: 0
', quil-rs/src/expression.rs:1336:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Note that this test relies on changes made to arb_expr() and friends in #210.

This was referenced Jun 12, 2023
@genos
Copy link
Contributor Author

genos commented Jun 22, 2023

Closed in #210, using the parenthesized version to ensure consistency.

@genos genos closed this as completed Jun 22, 2023
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 a pull request may close this issue.

1 participant