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

Unsupported constant string in println #1504

Open
MathieuSoysal opened this issue Mar 3, 2024 · 1 comment
Open

Unsupported constant string in println #1504

MathieuSoysal opened this issue Mar 3, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@MathieuSoysal
Copy link

Current code:

use prusti_contracts::*;

const MAX_FIBONACCI: u32 = 2_971_215_073;

pub fn play_game(n: u32) {
    println!("{}", fizz_buzz_fibonacci(n));
}

#[trusted]
fn is_fibonacci_number(n: u32) -> bool {
    let (mut previous, mut current) = (0, 1);
    while current < n && n <= MAX_FIBONACCI {
        let next = previous + current;
        previous = current;
        current = next;
    }
    current == n
}

pub fn fizz_buzz_fibonacci(n: u32) -> String {
    if is_fibonacci_number(n) {
        "Fibonacci".to_string()
    } else {
        match (n % 3, n % 5) {
            (0, 0) => "FizzBuzz".to_string(),
            (0, _) => "Fizz".to_string(),
            (_, 0) => "Buzz".to_string(),
            (_, _) => n.to_string(),
        }
    }
}

But I obtain this error:

image

[Prusti: unsupported feature] unsupported constant type &'?11 [&'?12 str; Const { ty: usize, kind: Leaf(0x0000000000000002) }]

Someone know how to fix it ?

@fpoli
Copy link
Member

fpoli commented Mar 7, 2024

The error message is reporting that the string used in the println! is not supported. At the moment, there is not much that we do to veryify I/O or string properties. To work around the error you could mark play_game as #[trusted], meaning that it won't be verified.

If you still want to prove some properties about it you could, for example, add a parameter to counts how many times the play_game function has been executed. This makes it possible to prove properties in the code that calls play_game. However, it depends a lot on what you want to do.

#[trusted]
#[ensures(*counter == old(*counter) + 1)]
pub fn play_game(n: u32, counter: &mut usize) {
    println!("{}", fizz_buzz_fibonacci(n));
    counter += 1;
}

@fpoli fpoli added the enhancement New feature or request label Mar 7, 2024
@fpoli fpoli changed the title Printl: unsuported feature Unsupported constant string in println Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants