Skip to main content

GlobalType

Enum GlobalType 

Source
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 termination
  • Comm { sender, receiver, branches }: Communication with labeled branches
  • Mu { var, body }: Recursive type μt.G
  • Var(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

Fields

§sender: String
§receiver: String
§branches: Vec<(Label, GlobalType)>
§

Mu

Recursive type: μt.G binds variable t in body G

Fields

§

Var(String)

Type variable: reference to enclosing μ-binder

Implementations§

Source§

impl GlobalType

Source

pub fn send( sender: impl Into<String>, receiver: impl Into<String>, label: Label, cont: GlobalType, ) -> Self

Create a simple send without choice

Source

pub fn comm( sender: impl Into<String>, receiver: impl Into<String>, branches: Vec<(Label, GlobalType)>, ) -> Self

Create a communication with multiple branches

Source

pub fn mu(var: impl Into<String>, body: GlobalType) -> Self

Create a recursive type

Source

pub fn var(name: impl Into<String>) -> Self

Create a type variable

Source

pub fn roles(&self) -> Vec<String>

Extract all role names from this global type.

Corresponds to Lean’s GlobalType.roles.

Source

pub fn free_vars(&self) -> Vec<String>

Extract free type variables from this global type.

Corresponds to Lean’s GlobalType.freeVars.

Source

pub fn substitute(&self, var_name: &str, replacement: &GlobalType) -> GlobalType

Substitute a global type for a variable.

Corresponds to Lean’s GlobalType.substitute.

Source

pub fn unfold(&self) -> GlobalType

Unfold one level of recursion: μt.G ↦ G[μt.G/t]

Corresponds to Lean’s GlobalType.unfold.

Source

pub fn all_vars_bound(&self) -> bool

Check if all recursion variables are bound.

Corresponds to Lean’s GlobalType.allVarsBound.

Source

pub fn all_comms_non_empty(&self) -> bool

Check if each communication has at least one branch.

Corresponds to Lean’s GlobalType.allCommsNonEmpty.

Source

pub fn unique_branch_labels(&self) -> bool

Check if all communication nodes have unique branch label names.

Source

pub fn no_self_comm(&self) -> bool

Check if sender and receiver are different in each communication.

Corresponds to Lean’s GlobalType.noSelfComm.

Source

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:

  1. All recursion variables are bound
  2. Each communication has at least one branch
  3. Sender ≠ receiver in each communication
  4. All recursion is guarded (no immediate recursion without communication)
Source

pub fn mentions_role(&self, role: &str) -> bool

Check if a role participates in the global type.

Corresponds to Lean’s GlobalType.mentionsRole.

Source

pub fn depth(&self) -> usize

Count the depth of a global type (for termination proofs).

Corresponds to Lean’s GlobalType.depth.

Source

pub fn is_guarded(&self) -> bool

Check if a global type is guarded (no immediate recursion without communication).

Corresponds to Lean’s GlobalType.isGuarded.

Source

pub fn consume( &self, sender: &str, receiver: &str, label: &str, ) -> Option<GlobalType>

Consume a communication from a global type.

Corresponds to Lean’s GlobalType.consume. G \ p →ℓ q represents the global type after the communication p →ℓ q has been performed.

Trait Implementations§

Source§

impl Clone for GlobalType

Source§

fn clone(&self) -> GlobalType

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Contentable for GlobalType

Source§

fn to_bytes(&self) -> Result<Vec<u8>, ContentableError>

Serialize to canonical byte representation (JSON format). Read more
Source§

fn to_template_bytes(&self) -> Result<Vec<u8>, ContentableError>

Serialize to template bytes, allowing open terms with explicit free-variable interfaces when supported by the implementation. Read more
Source§

fn from_bytes(bytes: &[u8]) -> Result<Self, ContentableError>

Deserialize from JSON bytes. Read more
Source§

fn content_id<H: Hasher>(&self) -> Result<ContentId<H>, ContentableError>

Compute content ID using the specified hasher (from JSON bytes). Read more
Source§

fn content_id_default( &self, ) -> Result<ContentId<DefaultContentHasher>, ContentableError>

Compute content ID using the central default content hasher (from JSON bytes). Read more
Source§

fn content_id_blake3(&self) -> Result<ContentId<Blake3Hasher>, ContentableError>

Compute content ID using explicit BLAKE3 (from JSON bytes). Read more
Source§

fn template_id<H: Hasher>(&self) -> Result<ContentId<H>, ContentableError>

Compute a template ID using the specified hasher (from template bytes). Read more
Source§

fn template_id_default( &self, ) -> Result<ContentId<DefaultContentHasher>, ContentableError>

Compute a template ID using the central default content hasher. Read more
Source§

fn template_id_blake3( &self, ) -> Result<ContentId<Blake3Hasher>, ContentableError>

Compute a template ID using explicit BLAKE3. Read more
Source§

impl Debug for GlobalType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for GlobalType

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&GlobalType> for GlobalTypeDB

Source§

fn from(g: &GlobalType) -> Self

Converts to this type from the input type.
Source§

impl Hash for GlobalType

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for GlobalType

Source§

fn eq(&self, other: &GlobalType) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for GlobalType

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for GlobalType

Source§

impl StructuralPartialEq for GlobalType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,