LocalTypeR

Enum LocalTypeR 

Source
pub enum LocalTypeR {
    End,
    Send {
        partner: String,
        branches: Vec<(Label, LocalTypeR)>,
    },
    Recv {
        partner: String,
        branches: Vec<(Label, 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 rumpsteak_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
§branches: Vec<(Label, LocalTypeR)>
§

Recv

External choice: receive from partner with offered continuations

Fields

§partner: String
§branches: Vec<(Label, LocalTypeR)>
§

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, ) -> LocalTypeR

Create a simple send with one label

Source

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

Create a send with multiple branches

Source

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

Create a simple recv with one label

Source

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

Create a recv with multiple branches

Source

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

Create a recursive type

Source

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

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 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 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 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 labels(&self) -> Vec<String>

Extract all labels from a local type.

Corresponds to Lean’s LocalTypeR.labels.

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).
Source§

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

Deserialize from JSON bytes. Read more
Source§

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

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

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

Compute content ID using default SHA-256 hasher (from JSON bytes).
Source§

impl Debug for LocalTypeR

Source§

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

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

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

Source§

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

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

impl Hash for LocalTypeR

Source§

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

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 as Serializer>::Ok, <__S as Serializer>::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> 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> Same for T

Source§

type Output = T

Should always be Self
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,