creusot-rs / creusot

Creusot helps you prove your code is correct in an automated fashion.
GNU Lesser General Public License v2.1
1.11k stars 51 forks source link

Properly support open type invariants #843

Open voidc opened 1 year ago

voidc commented 1 year ago

The #[open_inv] attribute can be applied to functions, function arguments, and fields to declare them as having an open type invariant. Concretely:

In its current state, the feature is only meant to be used as an escape hatch for cases where would otherwise run into problems with translation cycles (e.g. the map tests). A proper implementation should have additional checks ensuring that it is used correctly. The issue becomes especially relevant with #842 which enables the following unsound uses:

fn magic1<T>(#[open_inv] x: T) -> T { x }

struct Foo<T> { #[open_inv] f: T }
fn magic2<T>(x: Foo<T>) -> T { x.f }

trait Bar { #[open_inv] fn f() -> Self; }
fn magic3<T: Bar>() -> T { T::f() }
voidc commented 1 year ago

One solution might be to only allow the attribute on fully concrete types.

jhjourdan commented 1 year ago

Why would it change anything?