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

Deep view unsupported for &[u8] #1070

Closed
gancherj opened this issue Apr 12, 2024 · 3 comments
Closed

Deep view unsupported for &[u8] #1070

gancherj opened this issue Apr 12, 2024 · 3 comments

Comments

@gancherj
Copy link

gancherj commented Apr 12, 2024

This works:

spec fn test(xs : &[u8]) -> Seq<u8> { 
    xs.view()
}

but this doesn't:

spec fn test(xs : &[u8]) -> Seq<u8> { 
    xs.deep_view()
}

as it returns the error

  ^^^^^^^^^ method cannot be called on `&'a [u8]` due to unsatisfied trait bounds
  
   = note: the following trait bounds were not satisfied:
           `[u8]: std::marker::Sized`
           which is required by `&[u8]: vstd::view::DeepView`
           `[u8]: vstd::view::DeepView`
           which is required by `&[u8]: vstd::view::DeepView`

Is this simply a matter of adding the function to SliceAdditionalSpecFns?

@jaybosamiya
Copy link
Contributor

jaybosamiya commented Apr 22, 2024

Adding this to source/vstd/view.rs works:

modified   source/vstd/view.rs
@@ -1,4 +1,6 @@
 #[allow(unused_imports)]
+use crate::prelude::*;
+#[allow(unused_imports)]
 use builtin::*;
 #[allow(unused_imports)]
 use builtin_macros::*;
@@ -40,6 +42,16 @@ impl<A: DeepView> DeepView for &A {
     }
 }
 
+impl<T: DeepView> DeepView for [T] {
+    type V = Seq<T::V>;
+
+    #[verifier::inline]
+    open spec fn deep_view(&self) -> Self::V {
+        let v = self.view();
+        Seq::new(v.len(), |i: int| v[i].deep_view())
+    }
+}
+
 #[cfg(feature = "alloc")]
 impl<A: View> View for alloc::boxed::Box<A> {
     type V = A::V;

To make a PR, this probably needs some tests, but otherwise yeah, this code is sufficient to get deep_view on slices

@Chris-Hawblitzel
Copy link
Collaborator

@jaybosamiya Thanks! I turned this into pull request #1078 .

@Chris-Hawblitzel
Copy link
Collaborator

Implemented by #1078

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

No branches or pull requests

3 participants