Skip to main content

RefinedTypeDecl

Struct RefinedTypeDecl 

Source
pub struct RefinedTypeDecl {
    pub name: String,
    pub carrier_type: String,
    pub carrier_field: String,
    pub predicate_param: String,
    pub invariant: Predicate,
    pub witness: Option<String>,
}
Expand description

A refinement-lifted user type — opaque record with a single carrier field, paired with a validating smart constructor. The presence of this decl in ProofIR.refined_types is the decision: “emit this as a subtype on Lean and a subset type on Dafny”. Backends never re-decide.

Fields§

§name: String

Source-level type name (e.g. "Natural"). NOT canonicalised — backends emit using the source name; canonical form is the map key.

§carrier_type: String

Carrier annotation from the record’s single field (typically "Int"). Drives the Lean Subtype underlying type and the Dafny subset type’s base.

§carrier_field: String

Carrier-field source name (e.g. "value"). Lean uses .val to project Subtype values regardless of source name; Dafny’s subset binds the source name in its predicate.

§predicate_param: String

Smart constructor’s input parameter name (e.g. "n") — the invariant predicate’s free variable.

§invariant: Predicate

Bool predicate that every value of the refined type must satisfy, in terms of predicate_param. Comes from the smart constructor’s match <pred> { true -> Ok(...); false -> Err(...) } subject.

§witness: Option<String>

Inhabitation witness: a literal value of carrier_type that the lowerer verified satisfies invariant. Resolved by first trying the smart constructor’s verify block (fromX(K) => Ok(...) for some literal K — verified by the user via aver verify), then evaluating the predicate against small candidates as a fallback.

Why the IR carries this even though only Dafny’s subset type strictly requires a non-emptiness witness: it’s a fact about the type (∃ v : carrier, invariant(v) holds), not a Dafny-specific syntactic obligation. Backends use it as they see fit:

  • Dafny: emits type X = v: int | P v witness <W>. Required for the subset type to be inhabited and elaborable.
  • Lean: currently unused — propositional Subtype may be empty, so { v : Int // P v } elaborates regardless. Step N+1 could emit a def sample_X : X := ⟨W, by decide⟩ for roundtrip / test convenience.
  • Future Z3 / Coq / etc.: same fact, rendered per target.

None when no satisfier was found. Backends that require a witness must either reject the type or fall back to a target- default (Dafny picks 0 and crosses fingers).

Trait Implementations§

Source§

impl Clone for RefinedTypeDecl

Source§

fn clone(&self) -> RefinedTypeDecl

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RefinedTypeDecl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V