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

Datatypes well-formedness checks may be overly conservative #1424

Open
y1ca1 opened this issue Jan 31, 2025 · 3 comments
Open

Datatypes well-formedness checks may be overly conservative #1424

y1ca1 opened this issue Jan 31, 2025 · 3 comments

Comments

@y1ca1
Copy link
Contributor

y1ca1 commented Jan 31, 2025

Issue 1: Verus might not be checking datatypes transitively:

Ok:

enum Foo {
    V1(u8),
    V2(Bar),
}

struct Bar(u8, Box<Foo>, u8);

Err:

enum Either<A, B> {
    Left(A),
    Right(B),
}
struct Foo(Either<u8, Bar>);

struct Bar(u8, Box<Foo>, u8);

Verus reports:

error: datatype must have at least one non-recursive variant
  --> /playground/src/main.rs:21:1
   |
21 | struct Bar(u8, Box<Foo>, u8);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Similarly, if Vec is wrapped Verus fails to see the well-formed datatype definition:
Ok:

struct Foo(Either<u8, Bar>);

struct Bar(u8, Vec<Foo>, u8);

Err:

struct VecWrapper<T>(Vec<T>);

struct Foo(Either<u8, Bar>);

struct Bar(u8, VecWrapper<Foo>, u8);

Issue 2: Verus might be overly conservative:

Consider a sensible use case of mutually recursive functions (modeling "lazy datatypes"):

ghost struct LazyFoo(u8, spec_fn() -> LazyBar);
ghost struct LazyBar(u8, spec_fn() -> LazyFoo);

spec fn lazy_foo() -> LazyFoo {
    LazyFoo(0, || lazy_bar())
}

spec fn lazy_bar() -> LazyBar {
    LazyBar(0, || lazy_foo())
}

Verus gives:

error: datatype must have at least one non-recursive variant
  --> /playground/src/main.rs:24:1
   |
24 | struct LazyBar(u8, spec_fn() -> LazyFoo);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Such pattern can perfectly occur in exec code (though not directly due to the lack of function pointers in Verus, but possible with custom traits).


Relevant comments from Travis a while back: From #1360: .

@y1ca1
Copy link
Contributor Author

y1ca1 commented Jan 31, 2025

Repro link.

@utaal utaal changed the title Verus checks on well-formed datatypes Datatypes well-formedness checks may be overly conservative Jan 31, 2025
@utaal
Copy link
Collaborator

utaal commented Jan 31, 2025

@y1ca1 is it correct that both issues are not soundness issues, in particular: in the first case we're only rejecting cases that we could be allowing?

@y1ca1
Copy link
Contributor Author

y1ca1 commented Jan 31, 2025

@y1ca1 is it correct that both issues are not soundness issues, in particular: in the first case we're only rejecting cases that we could be allowing?

Correct. It's more like completeness issues.

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

2 participants