pub trait Type:
Printable
+ Verify
+ Downcast
+ Sync
+ Send
+ Debug {
// Required methods
fn hash_type(&self) -> TypeValueHash;
fn eq_type(&self, other: &dyn Type) -> bool;
fn get_type_id(&self) -> TypeId;
fn get_type_id_static() -> TypeId
where Self: Sized;
fn verify_interfaces(&self, ctx: &Context) -> Result<()>;
// Provided methods
fn get_self_ptr(&self, ctx: &Context) -> Ptr<TypeObj> { ... }
fn register_instance(t: Self, ctx: &mut Context) -> TypePtr<Self>
where Self: Sized { ... }
fn get_instance(t: Self, ctx: &Context) -> Option<TypePtr<Self>>
where Self: Sized { ... }
fn register_type_in_dialect(
ctx: &mut Context,
parser: ParserFn<(), TypePtr<Self>>,
)
where Self: Sized { ... }
}Expand description
Basic functionality that every type in the IR must implement. Type objects (instances of a Type) are (mostly) immutable once created, and are uniqued globally. Uniquing is based on the type name (i.e., the rust type being defined) and its contents.
So, for example, if we have
#[def_type("test.intty")]
#[derive(Debug, PartialEq, Eq, Hash)]
struct IntType {
width: u64
}the uniquing will include
Types can have mutable contents that can be modified after the type is created. This enables creation of recursive types. In such a case, it is up to the type definition to ensure that
- It manually implements Hash, ignoring these mutable fields.
- A proper distinguisher content (such as a string), that is part of the hash, is used so that uniquing still works.
Required Methods§
Sourcefn hash_type(&self) -> TypeValueHash
fn hash_type(&self) -> TypeValueHash
Compute and get the hash for this instance of Self. Hash collisions can be a possibility.
Sourcefn get_type_id(&self) -> TypeId
fn get_type_id(&self) -> TypeId
Get a Type’s static name. This is not per instantiation of the type. It is mostly useful for printing and parsing the type. Uniquing does not use this, but instead uses std::any::TypeId.
Sourcefn get_type_id_static() -> TypeIdwhere
Self: Sized,
fn get_type_id_static() -> TypeIdwhere
Self: Sized,
Same as get_type_id, but without the self reference.
Sourcefn verify_interfaces(&self, ctx: &Context) -> Result<()>
fn verify_interfaces(&self, ctx: &Context) -> Result<()>
Verify all interfaces implemented by this Type.
Provided Methods§
Sourcefn get_self_ptr(&self, ctx: &Context) -> Ptr<TypeObj>
fn get_self_ptr(&self, ctx: &Context) -> Ptr<TypeObj>
Get a copyable pointer to this type.
Sourcefn register_instance(t: Self, ctx: &mut Context) -> TypePtr<Self>where
Self: Sized,
fn register_instance(t: Self, ctx: &mut Context) -> TypePtr<Self>where
Self: Sized,
Register an instance of a type in the provided Context Returns a pointer to self. If the type was already registered, a pointer to the existing object is returned.
Implementations§
Source§impl dyn Type
impl dyn Type
Sourcepub fn is<__T: Type>(&self) -> bool
pub fn is<__T: Type>(&self) -> bool
Returns true if the trait object wraps an object of type __T.
Sourcepub fn downcast<__T: Type>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>
pub fn downcast<__T: Type>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>
Returns a boxed object from a boxed trait object if the underlying object is of type
__T. Returns the original boxed trait if it isn’t.
Sourcepub fn downcast_rc<__T: Type>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>
pub fn downcast_rc<__T: Type>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>
Returns an Rc-ed object from an Rc-ed trait object if the underlying object is of
type __T. Returns the original Rc-ed trait if it isn’t.
Sourcepub fn downcast_ref<__T: Type>(&self) -> Option<&__T>
pub fn downcast_ref<__T: Type>(&self) -> Option<&__T>
Returns a reference to the object within the trait object if it is of type __T, or
None if it isn’t.
Sourcepub fn downcast_mut<__T: Type>(&mut self) -> Option<&mut __T>
pub fn downcast_mut<__T: Type>(&mut self) -> Option<&mut __T>
Returns a mutable reference to the object within the trait object if it is of type
__T, or None if it isn’t.