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

We do not support closures that do a recursive call. #1299

Open
Lysxia opened this issue Dec 10, 2024 · 3 comments
Open

We do not support closures that do a recursive call. #1299

Lysxia opened this issue Dec 10, 2024 · 3 comments
Labels
bug Something isn't working enhancement New feature or request error-messages Improve error messages

Comments

@Lysxia
Copy link
Collaborator

Lysxia commented Dec 10, 2024

extern crate creusot_contracts;
use creusot_contracts::*;

#[variant(i)]
pub fn count_paths(i: usize) {
    (0..i).map(|j| count_paths(j));
}
thread 'rustc' panicked at creusot/src/backend/clone_map.rs:383:17:
assertion `left == right` failed
  left: 2
 right: 1

The mentioned line:

for scc in petgraph::algo::tarjan_scc(&graph).into_iter() {
if scc.iter().any(|node| node == &self_node) {
assert_eq!(scc.len(), 1);
bodies.remove(&scc[0]);
continue;
}

@jhjourdan
Copy link
Collaborator

Ok, the error message is not nice. But the problem here is that this is essentially mutually recursive functions (closure / function), which we do not support.

@jhjourdan jhjourdan changed the title Panic in clone_map.rs We do not support closures that do a recursive call. Dec 10, 2024
@jhjourdan jhjourdan added bug Something isn't working enhancement New feature or request error-messages Improve error messages labels Dec 10, 2024
@arnaudgolfouse
Copy link
Collaborator

arnaudgolfouse commented Dec 11, 2024

Ok, the error message is not nice. But the problem here is that this is essentially mutually recursive functions (closure / function), which we do not support.

But we do (in programs)? E.g.

pub fn count_paths(i: usize) {
    (0..i).map(|j| closure(j));
}

fn closure(j: usize) { count_paths(j) }

Works. The error is caused by the closure calling the enclosing function directly.

@jhjourdan
Copy link
Collaborator

Right. We do not support it in the case the mutual recursion is between a closure and the function which contains it. That's clearly a limitation we need to work on.

One issue is that Coma would not support (yet?) spec inference in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request error-messages Improve error messages
Projects
None yet
Development

No branches or pull requests

3 participants