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
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, LocalTypeR)>,
) -> LocalTypeR
pub fn send_choice( partner: impl Into<String>, branches: Vec<(Label, 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, LocalTypeR)>,
) -> LocalTypeR
pub fn recv_choice( partner: impl Into<String>, branches: Vec<(Label, 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 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 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 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 labels(&self) -> Vec<String>
pub fn labels(&self) -> Vec<String>
Extract all labels from a local type.
Corresponds to Lean’s LocalTypeR.labels.
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