pub struct Context { /* private fields */ }
Expand description
Type inference context, or handle to a context.
Can be cheaply cloned with Context::shallow_clone
. These clones will
refer to the same underlying type inference context, and can be used as
handles to each other. The derived Context::clone
has the same effect.
There is currently no way to create an independent context with the same type inference variables (i.e. a deep clone). If you need this functionality, please file an issue.
Implementations§
Source§impl Context
impl Context
Sourcepub fn alloc_free(&self, name: String) -> BoundRef
pub fn alloc_free(&self, name: String) -> BoundRef
Allocate a new free type bound, and return a reference to it.
Sourcepub fn alloc_unit(&self) -> BoundRef
pub fn alloc_unit(&self) -> BoundRef
Allocate a new unit type bound, and return a reference to it.
Sourcepub fn alloc_complete(&self, data: Arc<Final>) -> BoundRef
pub fn alloc_complete(&self, data: Arc<Final>) -> BoundRef
Allocate a new unit type bound, and return a reference to it.
Sourcepub fn alloc_sum(&self, left: Type, right: Type) -> BoundRef
pub fn alloc_sum(&self, left: Type, right: Type) -> BoundRef
Allocate a new sum-type bound, and return a reference to it.
§Panics
Panics if either of the child types are from a different inference context.
Sourcepub fn alloc_product(&self, left: Type, right: Type) -> BoundRef
pub fn alloc_product(&self, left: Type, right: Type) -> BoundRef
Allocate a new product-type bound, and return a reference to it.
§Panics
Panics if either of the child types are from a different inference context.
Sourcepub fn shallow_clone(&self) -> Self
pub fn shallow_clone(&self) -> Self
Creates a new handle to the context.
This handle holds a reference to the underlying context and will keep it alive. The context will only be dropped once all handles, including the original context object, are dropped.
Sourcepub fn check_eq(&self, other: &Self) -> Result<(), Error>
pub fn check_eq(&self, other: &Self) -> Result<(), Error>
Checks whether two inference contexts are equal, and returns an error if not.
Sourcepub fn bind_product(
&self,
existing: &Type,
prod_l: &Type,
prod_r: &Type,
hint: &'static str,
) -> Result<(), Error>
pub fn bind_product( &self, existing: &Type, prod_l: &Type, prod_r: &Type, hint: &'static str, ) -> Result<(), Error>
Binds the type to a product bound formed by the two inner types. If this fails, attach the provided hint to the error.
Fails if the type has an existing incompatible bound.
§Panics
Panics if any of the three types passed in were allocated from a different context than this one.