Skip to main content

RecursionContract

Enum RecursionContract 

Source
pub enum RecursionContract {
    Fuel {
        fuel_metric: FuelMetric,
    },
    LinearRecurrence2,
    Native {
        precondition: Vec<Predicate>,
        measure: Measure,
        preservation: PreservationProof,
        decrease: DecreaseProof,
        body: NativeIntCountdownBody,
    },
    WellFoundedToNat {
        param: String,
        floor_div: Option<FloorDivShrink>,
    },
}
Expand description

Recursion-shape decision. Each variant carries everything its emit needs AND the side-conditions the lowerer proved to choose it. The variants intentionally cannot be constructed without their side-conditions — backends cannot render Native without the lowerer having proved preservation + decrease.

Variants§

§

Fuel

Fuel-encoded fallback. No side-conditions to prove; works for any shape the classifier accepted as recursive.

Fields

§fuel_metric: FuelMetric

Symbolic measure feeding the wrapper (natAbs n + 1, |xs| + 1, etc.). Backends translate per target.

§

LinearRecurrence2

Affine second-order linear recurrence on Int, shape f(n) = a*f(n-1) + b*f(n-2) with literal 0/1 base cases and an n < 0 guard. Lowered to a private Nat pair-state worker (Lean / Dafny both emit native structural recursion on the Nat counter, no fuel). The lowerer doesn’t carry the shape coefficients yet — backends still pattern-match the fn body via lean::recurrence::detect_second_order_int_ linear_recurrence. Step N+1 could materialise them here.

§

Native

Native recursion with explicit precondition. Lowerer proved both preservation (rec args stay in domain) and decrease (measure strictly drops) before constructing this variant. Currently specialised to the IntCountdown-literal-zero shape (match p { 0 -> BASE; _ -> rec(p-1, ...) }); other native- recursion shapes (e.g. linear recurrence on a pair-state worker) will land as additional RecursionContract variants.

Fields

§precondition: Vec<Predicate>

Conjunction of precondition clauses, kept as a vector so backends can render one requires per clause (Dafny) or fold into a single && chain (Lean). Empty means “no caller-derived precondition” — the backend synthesises a fibTR-style default (param ≥ 0) at emit time.

§measure: Measure

Symbolic measure (e.g. natAbs(n)). Backends render per target language (Int.natAbs n on Lean, n with a requires n >= 0 clause on Dafny).

§preservation: PreservationProof

Side-condition tag: lowerer attests the recursive args preserve the precondition. Empty enum payload — its existence in the type is the proof, not its content.

§decrease: DecreaseProof

Same for the decreasing measure.

§body: NativeIntCountdownBody

Body decomposition for the IntCountdown-literal-zero shape: the literal int that selects the base arm, the base arm’s body, and the wildcard arm’s body. Carried so backends can render the if h : p = <lit> then base else rec(p-1, ...) switch without re-walking the source AST. The literal is always 0 today — the IntCountdownLiteralZero preservation marker attests it; carrying the value as data keeps the IR shape forward-compatible with future preservation proofs that admit other literals.

§

WellFoundedToNat

Well-founded native def on param.toNat — graduates a fn out of the fuel/partial encoding so it stays kernel-transparent (Lean: termination_by param.toNat + a decreasing_by the kernel re-checks; Dafny: decreases if param >= 0 then param else 0 with NO synthesized requires, so total callers stay wellformed). Two validated sources:

  • floor_div: Some(..) — every self-call shrinks param by a literal-divisor floor division (Result.withDefault(Int.div(p, k), d) with literal k >= 2, possibly through a unary wrapper fn), and the classifier verified the guard chain enclosing every self-call site implies p >= 1 — so p / k < p and the measure strictly drops. Never guessed: a fn whose guards don’t justify the shrink keeps its prior (partial/opaque) emission.
  • floor_div: None — guard-protected subtractive countdown (p - k, literal k >= 1, guards imply p >= 1), graduated out of fuel on demand by the floor-division window law family, whose proof templates need the fn’s defining equations and functional-induction principle.

Fields

§param: String

The decreasing Int parameter (source name).

§floor_div: Option<FloorDivShrink>

Some for the floor-division shrink; None for the guarded subtractive countdown.

Trait Implementations§

Source§

impl Clone for RecursionContract

Source§

fn clone(&self) -> RecursionContract

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 RecursionContract

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