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) -> Self
pub fn send(partner: impl Into<String>, label: Label, cont: LocalTypeR) -> Self
Create a simple send with one label
Sourcepub fn send_choice(
partner: impl Into<String>,
branches: Vec<(Label, Option<ValType>, LocalTypeR)>,
) -> Self
pub fn send_choice( partner: impl Into<String>, branches: Vec<(Label, Option<ValType>, LocalTypeR)>, ) -> Self
Create a send with multiple branches
Sourcepub fn recv(partner: impl Into<String>, label: Label, cont: LocalTypeR) -> Self
pub fn recv(partner: impl Into<String>, label: Label, cont: LocalTypeR) -> Self
Create a simple recv with one label
Sourcepub fn recv_choice(
partner: impl Into<String>,
branches: Vec<(Label, Option<ValType>, LocalTypeR)>,
) -> Self
pub fn recv_choice( partner: impl Into<String>, branches: Vec<(Label, Option<ValType>, LocalTypeR)>, ) -> Self
Create a recv with multiple branches
Sourcepub fn mu(var: impl Into<String>, body: LocalTypeR) -> Self
pub fn mu(var: impl Into<String>, body: LocalTypeR) -> Self
Create a recursive type
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 more