pub enum GlobalType {
End,
Comm {
sender: String,
receiver: String,
branches: Vec<(Label, GlobalType)>,
},
Mu {
var: String,
body: Box<GlobalType>,
},
Var(String),
}Expand description
Global types describe protocols from the bird’s-eye view.
Corresponds to Lean’s GlobalType inductive type.
§Syntax
End: Protocol terminationComm { sender, receiver, branches }: Communication with labeled branchesMu { var, body }: Recursive type μt.GVar(t): Type variable reference
The Comm variant models p → q : {l₁(S₁).G₁, l₂(S₂).G₂, ...}
where the sender p chooses which branch to take.
§Examples
use telltale_types::{GlobalType, Label};
// Simple protocol: A -> B: hello. end
let g = GlobalType::send("A", "B", Label::new("hello"), GlobalType::End);
assert!(g.well_formed());
// Recursive protocol: μt. A -> B: msg. t
let rec = GlobalType::mu(
"t",
GlobalType::send("A", "B", Label::new("msg"), GlobalType::var("t")),
);
assert!(rec.well_formed());Variants§
End
Protocol termination
Comm
Communication: sender → receiver with choice of labeled continuations
Mu
Recursive type: μt.G binds variable t in body G
Var(String)
Type variable: reference to enclosing μ-binder
Implementations§
Source§impl GlobalType
impl GlobalType
Sourcepub fn send(
sender: impl Into<String>,
receiver: impl Into<String>,
label: Label,
cont: GlobalType,
) -> Self
pub fn send( sender: impl Into<String>, receiver: impl Into<String>, label: Label, cont: GlobalType, ) -> Self
Create a simple send without choice
Sourcepub fn comm(
sender: impl Into<String>,
receiver: impl Into<String>,
branches: Vec<(Label, GlobalType)>,
) -> Self
pub fn comm( sender: impl Into<String>, receiver: impl Into<String>, branches: Vec<(Label, GlobalType)>, ) -> Self
Create a communication with multiple branches
Sourcepub fn mu(var: impl Into<String>, body: GlobalType) -> Self
pub fn mu(var: impl Into<String>, body: GlobalType) -> Self
Create a recursive type
Sourcepub fn roles(&self) -> Vec<String>
pub fn roles(&self) -> Vec<String>
Extract all role names from this global type.
Corresponds to Lean’s GlobalType.roles.
Sourcepub fn free_vars(&self) -> Vec<String>
pub fn free_vars(&self) -> Vec<String>
Extract free type variables from this global type.
Corresponds to Lean’s GlobalType.freeVars.
Sourcepub fn substitute(&self, var_name: &str, replacement: &GlobalType) -> GlobalType
pub fn substitute(&self, var_name: &str, replacement: &GlobalType) -> GlobalType
Substitute a global type for a variable.
Corresponds to Lean’s GlobalType.substitute.
Sourcepub fn unfold(&self) -> GlobalType
pub fn unfold(&self) -> GlobalType
Unfold one level of recursion: μt.G ↦ G[μt.G/t]
Corresponds to Lean’s GlobalType.unfold.
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 GlobalType.allVarsBound.
Sourcepub fn all_comms_non_empty(&self) -> bool
pub fn all_comms_non_empty(&self) -> bool
Check if each communication has at least one branch.
Corresponds to Lean’s GlobalType.allCommsNonEmpty.
Sourcepub fn unique_branch_labels(&self) -> bool
pub fn unique_branch_labels(&self) -> bool
Check if all communication nodes have unique branch label names.
Sourcepub fn no_self_comm(&self) -> bool
pub fn no_self_comm(&self) -> bool
Check if sender and receiver are different in each communication.
Corresponds to Lean’s GlobalType.noSelfComm.
Sourcepub fn well_formed(&self) -> bool
pub fn well_formed(&self) -> bool
Well-formedness predicate for global types.
Corresponds to Lean’s GlobalType.wellFormed.
A global type is well-formed if:
- All recursion variables are bound
- Each communication has at least one branch
- Sender ≠ receiver in each communication
- All recursion is guarded (no immediate recursion without communication)
Sourcepub fn mentions_role(&self, role: &str) -> bool
pub fn mentions_role(&self, role: &str) -> bool
Check if a role participates in the global type.
Corresponds to Lean’s GlobalType.mentionsRole.
Sourcepub fn depth(&self) -> usize
pub fn depth(&self) -> usize
Count the depth of a global type (for termination proofs).
Corresponds to Lean’s GlobalType.depth.
Sourcepub fn is_guarded(&self) -> bool
pub fn is_guarded(&self) -> bool
Check if a global type is guarded (no immediate recursion without communication).
Corresponds to Lean’s GlobalType.isGuarded.
Trait Implementations§
Source§impl Clone for GlobalType
impl Clone for GlobalType
Source§fn clone(&self) -> GlobalType
fn clone(&self) -> GlobalType
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more