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

Loop with side effect at the end of a function gives inconsistent type #1231

Open
maximebuyse opened this issue Jan 14, 2025 · 3 comments · May be fixed by #1232
Open

Loop with side effect at the end of a function gives inconsistent type #1231

maximebuyse opened this issue Jan 14, 2025 · 3 comments · May be fixed by #1232
Assignees

Comments

@maximebuyse
Copy link
Contributor

fn range() {
    let mut count = 0u8;
    for i in 0u8..10u8 {
        hax_lib::loop_invariant!(|i: u8| i <= 10);
        count = i;
    }
}

fn f() {
    range()
}

Open this code snippet in the playground

The produced F* for this:

let range (_: Prims.unit) : u8 =
  let count:u8 = 0uy in
  Rust_primitives.Hax.Folds.fold_range 0uy
    10uy
    (fun count i ->
        let count:u8 = count in
        let i:u8 = i in
        i <=. 10uy <: bool)
    count
    (fun count i ->
        let count:u8 = count in
        let i:u8 = i in
        let count:u8 = i in
        count)

let f (_: Prims.unit) : Prims.unit =
  range ()

The function range is typed as returning u8 but it should return unit.

@karthikbhargavan
Copy link
Contributor

karthikbhargavan commented Jan 14, 2025 via email

@maximebuyse
Copy link
Contributor Author

Is this solved by adding a () unit after the loop?

Yes, this works as a workaround, and the idea for the fix is to insert it. The problem is to do it only when necessary to avoid polluting the generated code.

@franziskuskiefer
Copy link
Member

franziskuskiefer commented Jan 15, 2025

Here's another reproducer.
Never mind, it was using an outdated hax revision.

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.

3 participants