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,
) -> GlobalType
pub fn send( sender: impl Into<String>, receiver: impl Into<String>, label: Label, cont: GlobalType, ) -> GlobalType
Create a simple send without choice
Sourcepub fn comm(
sender: impl Into<String>,
receiver: impl Into<String>,
branches: Vec<(Label, GlobalType)>,
) -> GlobalType
pub fn comm( sender: impl Into<String>, receiver: impl Into<String>, branches: Vec<(Label, GlobalType)>, ) -> GlobalType
Create a communication with multiple branches
Sourcepub fn mu(var: impl Into<String>, body: GlobalType) -> GlobalType
pub fn mu(var: impl Into<String>, body: GlobalType) -> GlobalType
Create a recursive type
Sourcepub fn var(name: impl Into<String>) -> GlobalType
pub fn var(name: impl Into<String>) -> GlobalType
Create a type variable
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 moreSource§impl Contentable for GlobalType
impl Contentable for GlobalType
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<GlobalType, ContentableError>
fn from_bytes(bytes: &[u8]) -> Result<GlobalType, 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 GlobalType
impl Debug for GlobalType
Source§impl<'de> Deserialize<'de> for GlobalType
impl<'de> Deserialize<'de> for GlobalType
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<GlobalType, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<GlobalType, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Hash for GlobalType
impl Hash for GlobalType
Source§impl PartialEq for GlobalType
impl PartialEq for GlobalType
Source§impl Serialize for GlobalType
impl Serialize for GlobalType
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 GlobalType
impl StructuralPartialEq for GlobalType
Auto Trait Implementations§
impl Freeze for GlobalType
impl RefUnwindSafe for GlobalType
impl Send for GlobalType
impl Sync for GlobalType
impl Unpin for GlobalType
impl UnsafeUnpin for GlobalType
impl UnwindSafe for GlobalType
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.