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

Unspecialized extern specs #1304

Open
arnaudgolfouse opened this issue Dec 12, 2024 · 1 comment
Open

Unspecialized extern specs #1304

arnaudgolfouse opened this issue Dec 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@arnaudgolfouse
Copy link
Collaborator

In creusot_contracts, when implementing a trait that is specified with extern_spec!, the calls to the trait methods will ignore the spec of the implementation and fetch the spec of the trait instead.

Example

// in creusot_contracts

pub struct EmptyIt {}
impl ::std::iter::Iterator for EmptyIt {
    type Item = ();
    #[ensures(result == None)]
    fn next(&mut self) -> Option<()> { None }
}
impl creusot_contracts::std::iter::Iterator for EmptyIt { /* ... */ }
// in user code
let mut empty = EmptyIt {};
let x = empty.next();

Then in coma, next appears as:

let rec next'0 (self:borrowed ()) (return'  (ret:t_Option'0))= any
    [ return' (result:t_Option'0)-> {[%#siter1] match result with
        | C_None'0 -> completed'0 self
        | C_Some'0 v -> produces'0 self.current (Seq.singleton v) self.final
        end}
      (! return' {result}) ]

This is the spec of the trait, not the one we wrote on EmptyIt::next.
(Note that completed'0 and produces'0 are the correct ones, so it still works in this case)

@arnaudgolfouse
Copy link
Collaborator Author

This is mainly an issue for #[pure]/#[terminates] functions, where putting the annotation on the trait implementation does nothing.

@jhjourdan jhjourdan added the bug Something isn't working label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants