Skip to main content

LocalTypeR

Enum LocalTypeR 

Source
pub enum LocalTypeR {
    End,
    Send {
        partner: String,
        branches: Vec<(Label, Option<ValType>, LocalTypeR)>,
    },
    Recv {
        partner: String,
        branches: Vec<(Label, Option<ValType>, LocalTypeR)>,
    },
    Mu {
        var: String,
        body: Box<LocalTypeR>,
    },
    Var(String),
}
Expand description

Core local type matching Lean’s LocalTypeR.

This is the minimal type used for validation and correspondence proofs. For code generation, see the extended LocalType in the DSL crate.

§Examples

use telltale_types::{LocalTypeR, Label};

// Simple send: !B{msg.end}
let lt = LocalTypeR::send("B", Label::new("msg"), LocalTypeR::End);
assert!(lt.well_formed());

// Recursive type: μt. !B{msg.t}
let rec = LocalTypeR::mu(
    "t",
    LocalTypeR::send("B", Label::new("msg"), LocalTypeR::var("t")),
);
assert!(rec.well_formed());

Variants§

§

End

Protocol termination

§

Send

Internal choice: send to partner with choice of continuations

Fields

§partner: String
§

Recv

External choice: receive from partner with offered continuations

Fields

§partner: String
§

Mu

Recursive type: μt.T binds variable t in body T

Fields

§

Var(String)

Type variable: reference to enclosing μ-binder

Implementations§

Source§

impl LocalTypeR

Source

pub fn send(partner: impl Into<String>, label: Label, cont: LocalTypeR) -> Self

Create a simple send with one label

Source

pub fn send_choice( partner: impl Into<String>, branches: Vec<(Label, Option<ValType>, LocalTypeR)>, ) -> Self

Create a send with multiple branches

Source

pub fn recv(partner: impl Into<String>, label: Label, cont: LocalTypeR) -> Self

Create a simple recv with one label

Source

pub fn recv_choice( partner: impl Into<String>, branches: Vec<(Label, Option<ValType>, LocalTypeR)>, ) -> Self

Create a recv with multiple branches

Source

pub fn mu(var: impl Into<String>, body: LocalTypeR) -> Self

Create a recursive type

Source

pub fn var(name: impl Into<String>) -> Self

Create a type variable

Source

pub fn free_vars(&self) -> Vec<String>

Extract free type variables from a local type.

Corresponds to Lean’s LocalTypeR.freeVars.

Source

pub fn substitute(&self, var_name: &str, replacement: &LocalTypeR) -> LocalTypeR

Substitute a local type for a variable.

Corresponds to Lean’s LocalTypeR.substitute.

Source

pub fn unfold(&self) -> LocalTypeR

Unfold one level of recursion: μt.T ↦ T[μt.T/t]

Corresponds to Lean’s LocalTypeR.unfold.

Source

pub fn mu_height(&self) -> usize

Count nested recursion binders at the current head position.

Corresponds to Lean’s LocalTypeR.muHeight.

Source

pub fn full_unfold(&self) -> LocalTypeR

Fully unfold leading recursion until a non-Mu head is exposed.

Corresponds to Lean’s LocalTypeR.fullUnfold.

Source

pub fn dual(&self) -> LocalTypeR

Compute the dual of a local type (swap send/recv).

The dual of role A’s view is role B’s view when A and B are the only participants. Corresponds to Lean’s LocalTypeR.dual.

Source

pub fn all_vars_bound(&self) -> bool

Check if all recursion variables are bound.

Corresponds to Lean’s LocalTypeR.allVarsBound.

Source

pub fn all_choices_non_empty(&self) -> bool

Check if each choice has at least one branch.

Corresponds to Lean’s LocalTypeR.allChoicesNonEmpty.

Source

pub fn unique_branch_labels(&self) -> bool

Check if all send/recv nodes have unique branch label names.

Source

pub fn well_formed(&self) -> bool

Well-formedness predicate for local types.

Corresponds to Lean’s LocalTypeR.wellFormed. A local type is well-formed if:

  1. All recursion variables are bound
  2. Each choice has at least one branch
  3. All recursion is guarded (no immediate recursion without communication)
Source

pub fn reaches_communication(&self) -> bool

Check whether full unfolding exposes a communication head.

Corresponds to Lean’s LocalTypeR.reachesCommunication.

Source

pub fn regular_practical_fragment(&self) -> bool

Mechanically characterized practical fragment that needs no manual ReachesComm.

Corresponds to Lean’s LocalTypeR.regularPracticalFragment.

Source

pub fn depth(&self) -> usize

Count the depth of a local type (for termination proofs).

Corresponds to Lean’s LocalTypeR.depth.

Source

pub fn is_guarded(&self) -> bool

Check if a local type is guarded (no immediate recursion).

Corresponds to Lean’s LocalTypeR.isGuarded.

Source

pub fn is_var_guarded(&self, var: &str) -> bool

Check if a specific recursion variable is guarded in this local type.

A variable v is guarded if it does not appear “bare” (i.e., every occurrence is under a send or recv). Corresponds to Lean’s LocalTypeR.isGuarded v.

Source

pub fn head_labels(&self) -> Vec<String>

Extract labels from the outermost visible choice node.

For recursive terms (Mu), this inspects the wrapped body.

Source

pub fn all_labels(&self) -> Vec<String>

Extract all labels that appear anywhere in the local type.

Source

pub fn partners(&self) -> Vec<String>

Extract all partners from a local type.

Corresponds to Lean’s LocalTypeR.partners.

Source

pub fn mentions_partner(&self, role: &str) -> bool

Check if a local type mentions a specific partner.

Source

pub fn is_send(&self) -> bool

Check if this is an internal choice (send)

Source

pub fn is_recv(&self) -> bool

Check if this is an external choice (recv)

Source

pub fn is_end(&self) -> bool

Check if this is a terminated type

Trait Implementations§

Source§

impl Clone for LocalTypeR

Source§

fn clone(&self) -> LocalTypeR

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Contentable for LocalTypeR

Source§

fn to_bytes(&self) -> Result<Vec<u8>, ContentableError>

Serialize to canonical byte representation (JSON format). Read more
Source§

fn to_template_bytes(&self) -> Result<Vec<u8>, ContentableError>

Serialize to template bytes, allowing open terms with explicit free-variable interfaces when supported by the implementation. Read more
Source§

fn from_bytes(bytes: &[u8]) -> Result<Self, ContentableError>

Deserialize from JSON bytes. Read more
Source§

fn content_id<H: Hasher>(&self) -> Result<ContentId<H>, ContentableError>

Compute content ID using the specified hasher (from JSON bytes). Read more
Source§

fn content_id_default( &self, ) -> Result<ContentId<DefaultContentHasher>, ContentableError>

Compute content ID using the central default content hasher (from JSON bytes). Read more
Source§

fn content_id_blake3(&self) -> Result<ContentId<Blake3Hasher>, ContentableError>

Compute content ID using explicit BLAKE3 (from JSON bytes). Read more
Source§

fn template_id<H: Hasher>(&self) -> Result<ContentId<H>, ContentableError>

Compute a template ID using the specified hasher (from template bytes). Read more
Source§

fn template_id_default( &self, ) -> Result<ContentId<DefaultContentHasher>, ContentableError>

Compute a template ID using the central default content hasher. Read more
Source§

fn template_id_blake3( &self, ) -> Result<ContentId<Blake3Hasher>, ContentableError>

Compute a template ID using explicit BLAKE3. Read more
Source§

impl Debug for LocalTypeR

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for LocalTypeR

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&LocalTypeR> for LocalTypeRDB

Source§

fn from(t: &LocalTypeR) -> Self

Converts to this type from the input type.
Source§

impl Hash for LocalTypeR

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for LocalTypeR

Source§

fn eq(&self, other: &LocalTypeR) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for LocalTypeR

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for LocalTypeR

Source§

impl StructuralPartialEq for LocalTypeR

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
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<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,