Support multiple trait implementations for the same outer type #496
Replies: 4 comments 3 replies
-
Unfortunately, this is a currently known limitation, and the fix requires a partial redesign of some of the encoding (with fairly far-reaching implications). We have candidate designs, but it will take some time before we get around to it. I'm going to consider this a "feature request" at this stage, and turn it into a discussion. |
Beta Was this translation helpful? Give feedback.
-
This came up recently when I brought up the possibility of using the same AIR type to represent both slices and arrays. utaal pointed out that, because of this existing limitation, it wouldn't be possible to do this while also allowing us to implement traits on them. I think there are workarounds there, but we have to be careful about it. The limitation also makes it hard to support |
Beta Was this translation helpful? Give feedback.
-
What are the candidate designs, by the way? Right now the only idea I see is to do it similar to coq encoding of type classes: make AIR objects for trait implementations, and pass them as arguments to generic functions, rather than just passing arguments representing the types. |
Beta Was this translation helpful? Give feedback.
-
This is now supported: use vstd::prelude::*;
verus! {
trait Foo {
spec fn foo(&self) -> bool;
}
impl Foo for Option<u8> {
spec fn foo(&self) -> bool { true }
}
impl Foo for Option<u64> {
spec fn foo(&self) -> bool { false }
}
fn main() {
let a: Option<u8> = None;
let b: Option<u64> = None;
assert(a.foo());
assert(!b.foo());
}
} |
Beta Was this translation helpful? Give feedback.
-
@utaal's note: originally reported as a bug by @jaybosamiya:
Previous discussion on traits here: #73
Consider:
We get (at least on latest
main_new
c81e6dc, I haven't tested on other branches):My guess is that it is keying based on the
Option
rather than on the specific typesOption<u8>
andOption<u64>
?Beta Was this translation helpful? Give feedback.
All reactions