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
Recv
External choice: receive from partner with offered continuations
Mu
Recursive type: μt.T binds variable t in body T
Var(String)
Type variable: reference to enclosing μ-binder
Implementations§
Source§impl LocalTypeR
impl LocalTypeR
Sourcepub fn send(
partner: impl Into<String>,
label: Label,
cont: LocalTypeR,
) -> LocalTypeR
pub fn send( partner: impl Into<String>, label: Label, cont: LocalTypeR, ) -> LocalTypeR
Create a simple send with one label
Sourcepub fn send_choice(
partner: impl Into<String>,
branches: Vec<(Label, Option<ValType>, LocalTypeR)>,
) -> LocalTypeR
pub fn send_choice( partner: impl Into<String>, branches: Vec<(Label, Option<ValType>, LocalTypeR)>, ) -> LocalTypeR
Create a send with multiple branches
Sourcepub fn recv(
partner: impl Into<String>,
label: Label,
cont: LocalTypeR,
) -> LocalTypeR
pub fn recv( partner: impl Into<String>, label: Label, cont: LocalTypeR, ) -> LocalTypeR
Create a simple recv with one label
Sourcepub fn recv_choice(
partner: impl Into<String>,
branches: Vec<(Label, Option<ValType>, LocalTypeR)>,
) -> LocalTypeR
pub fn recv_choice( partner: impl Into<String>, branches: Vec<(Label, Option<ValType>, LocalTypeR)>, ) -> LocalTypeR
Create a recv with multiple branches
Sourcepub fn mu(var: impl Into<String>, body: LocalTypeR) -> LocalTypeR
pub fn mu(var: impl Into<String>, body: LocalTypeR) -> LocalTypeR
Create a recursive type
Sourcepub fn var(name: impl Into<String>) -> LocalTypeR
pub fn var(name: impl Into<String>) -> LocalTypeR
Create a type variable
Sourcepub fn free_vars(&self) -> Vec<String>
pub fn free_vars(&self) -> Vec<String>
Extract free type variables from a local type.
Corresponds to Lean’s LocalTypeR.freeVars.
Sourcepub fn substitute(&self, var_name: &str, replacement: &LocalTypeR) -> LocalTypeR
pub fn substitute(&self, var_name: &str, replacement: &LocalTypeR) -> LocalTypeR
Substitute a local type for a variable.
Corresponds to Lean’s LocalTypeR.substitute.
Sourcepub fn unfold(&self) -> LocalTypeR
pub fn unfold(&self) -> LocalTypeR
Unfold one level of recursion: μt.T ↦ T[μt.T/t]
Corresponds to Lean’s LocalTypeR.unfold.
Sourcepub fn mu_height(&self) -> usize
pub fn mu_height(&self) -> usize
Count nested recursion binders at the current head position.
Corresponds to Lean’s LocalTypeR.muHeight.
Sourcepub fn full_unfold(&self) -> LocalTypeR
pub fn full_unfold(&self) -> LocalTypeR
Fully unfold leading recursion until a non-Mu head is exposed.
Corresponds to Lean’s LocalTypeR.fullUnfold.
Sourcepub fn dual(&self) -> LocalTypeR
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.
Sourcepub fn all_vars_bound(&self) -> bool
pub fn all_vars_bound(&self) -> bool
Check if all recursion variables are bound.
Corresponds to Lean’s LocalTypeR.allVarsBound.
Sourcepub fn all_choices_non_empty(&self) -> bool
pub fn all_choices_non_empty(&self) -> bool
Check if each choice has at least one branch.
Corresponds to Lean’s LocalTypeR.allChoicesNonEmpty.
Sourcepub fn unique_branch_labels(&self) -> bool
pub fn unique_branch_labels(&self) -> bool
Check if all send/recv nodes have unique branch label names.
Sourcepub fn well_formed(&self) -> bool
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:
- All recursion variables are bound
- Each choice has at least one branch
- All recursion is guarded (no immediate recursion without communication)
Sourcepub fn reaches_communication(&self) -> bool
pub fn reaches_communication(&self) -> bool
Check whether full unfolding exposes a communication head.
Corresponds to Lean’s LocalTypeR.reachesCommunication.
Sourcepub fn regular_practical_fragment(&self) -> bool
pub fn regular_practical_fragment(&self) -> bool
Mechanically characterized practical fragment that needs no manual ReachesComm.
Corresponds to Lean’s LocalTypeR.regularPracticalFragment.
Sourcepub fn depth(&self) -> usize
pub fn depth(&self) -> usize
Count the depth of a local type (for termination proofs).
Corresponds to Lean’s LocalTypeR.depth.
Sourcepub fn is_guarded(&self) -> bool
pub fn is_guarded(&self) -> bool
Check if a local type is guarded (no immediate recursion).
Corresponds to Lean’s LocalTypeR.isGuarded.
Sourcepub fn is_var_guarded(&self, var: &str) -> bool
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.
Sourcepub fn head_labels(&self) -> Vec<String>
pub fn head_labels(&self) -> Vec<String>
Extract labels from the outermost visible choice node.
For recursive terms (Mu), this inspects the wrapped body.
Sourcepub fn all_labels(&self) -> Vec<String>
pub fn all_labels(&self) -> Vec<String>
Extract all labels that appear anywhere in the local type.
Sourcepub fn partners(&self) -> Vec<String>
pub fn partners(&self) -> Vec<String>
Extract all partners from a local type.
Corresponds to Lean’s LocalTypeR.partners.
Sourcepub fn mentions_partner(&self, role: &str) -> bool
pub fn mentions_partner(&self, role: &str) -> bool
Check if a local type mentions a specific partner.
Trait Implementations§
Source§impl Clone for LocalTypeR
impl Clone for LocalTypeR
Source§fn clone(&self) -> LocalTypeR
fn clone(&self) -> LocalTypeR
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Contentable for LocalTypeR
impl Contentable for LocalTypeR
Source§fn to_bytes(&self) -> Result<Vec<u8>, ContentableError>
fn to_bytes(&self) -> Result<Vec<u8>, ContentableError>
Source§fn to_template_bytes(&self) -> Result<Vec<u8>, ContentableError>
fn to_template_bytes(&self) -> Result<Vec<u8>, ContentableError>
Source§fn from_bytes(bytes: &[u8]) -> Result<LocalTypeR, ContentableError>
fn from_bytes(bytes: &[u8]) -> Result<LocalTypeR, ContentableError>
Source§fn from_bytes_verified<H>(
bytes: &[u8],
expected: &ContentId<H>,
) -> Result<Self, ContentableError>where
H: Hasher,
fn from_bytes_verified<H>(
bytes: &[u8],
expected: &ContentId<H>,
) -> Result<Self, ContentableError>where
H: Hasher,
Source§fn content_id<H>(&self) -> Result<ContentId<H>, ContentableError>where
H: Hasher,
fn content_id<H>(&self) -> Result<ContentId<H>, ContentableError>where
H: Hasher,
Source§fn content_id_default(&self) -> Result<ContentId, ContentableError>
fn content_id_default(&self) -> Result<ContentId, ContentableError>
Source§fn content_id_blake3(&self) -> Result<ContentId, ContentableError>
fn content_id_blake3(&self) -> Result<ContentId, ContentableError>
Source§fn template_id<H>(&self) -> Result<ContentId<H>, ContentableError>where
H: Hasher,
fn template_id<H>(&self) -> Result<ContentId<H>, ContentableError>where
H: Hasher,
Source§fn template_id_default(&self) -> Result<ContentId, ContentableError>
fn template_id_default(&self) -> Result<ContentId, ContentableError>
Source§fn template_id_blake3(&self) -> Result<ContentId, ContentableError>
fn template_id_blake3(&self) -> Result<ContentId, ContentableError>
Source§impl Debug for LocalTypeR
impl Debug for LocalTypeR
Source§impl<'de> Deserialize<'de> for LocalTypeR
impl<'de> Deserialize<'de> for LocalTypeR
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<LocalTypeR, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<LocalTypeR, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Hash for LocalTypeR
impl Hash for LocalTypeR
Source§impl PartialEq for LocalTypeR
impl PartialEq for LocalTypeR
Source§impl Serialize for LocalTypeR
impl Serialize for LocalTypeR
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for LocalTypeR
impl StructuralPartialEq for LocalTypeR
Auto Trait Implementations§
impl Freeze for LocalTypeR
impl RefUnwindSafe for LocalTypeR
impl Send for LocalTypeR
impl Sync for LocalTypeR
impl Unpin for LocalTypeR
impl UnsafeUnpin for LocalTypeR
impl UnwindSafe for LocalTypeR
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.