Struct spacetimedb_sats::typespace::Typespace
source · pub struct Typespace {
pub types: Vec<AlgebraicType>,
}
Expand description
A Typespace
represents the typing context in SATS.
That is, this is the Δ
or Γ
you’ll see in type theory litterature.
We use (sort of) deBrujin indices
to represent our type variables.
Notably however, these are given for the entire module
and there are no universal quantifiers (i.e., Δ, α ⊢ τ | Δ ⊢ ∀ α. τ
)
nor are there type lambdas (i.e., Λτ. v
).
See System F, the second-order lambda calculus, for more on ∀
and Λ
.
There are however recursive types in SATs,
e.g., &0 = { Cons({ v: U8, t: &0 }), Nil }
represents a basic cons list
where &0
is the type reference at index 0
.
Fields§
§types: Vec<AlgebraicType>
The types in our typing context that can be referred to with AlgebraicTypeRef
s.
Implementations§
source§impl Typespace
impl Typespace
pub const EMPTY: &'static Typespace = _
sourcepub const fn new(types: Vec<AlgebraicType>) -> Self
pub const fn new(types: Vec<AlgebraicType>) -> Self
Returns a context (Typespace
) with the given types
.
sourcepub fn get(&self, r: AlgebraicTypeRef) -> Option<&AlgebraicType>
pub fn get(&self, r: AlgebraicTypeRef) -> Option<&AlgebraicType>
Returns the AlgebraicType
referred to by r
within this context.
sourcepub fn get_mut(&mut self, r: AlgebraicTypeRef) -> Option<&mut AlgebraicType>
pub fn get_mut(&mut self, r: AlgebraicTypeRef) -> Option<&mut AlgebraicType>
Returns a mutable reference to the AlgebraicType
referred to by r
within this context.
sourcepub fn add(&mut self, ty: AlgebraicType) -> AlgebraicTypeRef
pub fn add(&mut self, ty: AlgebraicType) -> AlgebraicTypeRef
Inserts an AlgebraicType
into the typespace
and returns an AlgebraicTypeRef
that refers to the inserted AlgebraicType
.
This allows for self referential, recursive or other complex types to be declared in the typespace.
You can also use this to later change the meaning of the returned AlgebraicTypeRef
when you cannot provide the full definition of the type yet.
Panics if the number of type references exceeds an u32
.
sourcepub const fn with_type<'a, T: ?Sized>(
&'a self,
ty: &'a T
) -> WithTypespace<'a, T>
pub const fn with_type<'a, T: ?Sized>( &'a self, ty: &'a T ) -> WithTypespace<'a, T>
Returns ty
combined with the context self
.
sourcepub fn inline_typerefs_in_type(
&mut self,
ty: &mut AlgebraicType
) -> Result<(), TypeRefError>
pub fn inline_typerefs_in_type( &mut self, ty: &mut AlgebraicType ) -> Result<(), TypeRefError>
Inlines all type references in ty
recursively using the current typeset.
sourcepub fn inline_all_typerefs(&mut self) -> Result<(), TypeRefError>
pub fn inline_all_typerefs(&mut self) -> Result<(), TypeRefError>
Inlines all type references in the typespace recursively.
Errors out if any type reference is invalid or self-referential.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Typespace
impl<'de> Deserialize<'de> for Typespace
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
deserializer
.source§impl Index<AlgebraicTypeRef> for Typespace
impl Index<AlgebraicTypeRef> for Typespace
§type Output = AlgebraicType
type Output = AlgebraicType
source§impl IndexMut<AlgebraicTypeRef> for Typespace
impl IndexMut<AlgebraicTypeRef> for Typespace
Auto Trait Implementations§
impl Freeze for Typespace
impl RefUnwindSafe for Typespace
impl Send for Typespace
impl Sync for Typespace
impl Unpin for Typespace
impl UnwindSafe for Typespace
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> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> Satn for T
impl<T> Satn for T
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
f
.source§fn fmt_psql(&self, f: &mut Formatter<'_>) -> Result
fn fmt_psql(&self, f: &mut Formatter<'_>) -> Result
f
.source§fn to_satn(&self) -> String
fn to_satn(&self) -> String
String
.source§fn to_satn_pretty(&self) -> String
fn to_satn_pretty(&self) -> String
String
.