Type

Trait Type 

Source
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

  1. It manually implements Hash, ignoring these mutable fields.
  2. A proper distinguisher content (such as a string), that is part of the hash, is used so that uniquing still works.

Required Methods§

Source

fn hash_type(&self) -> TypeValueHash

Compute and get the hash for this instance of Self. Hash collisions can be a possibility.

Source

fn eq_type(&self, other: &dyn Type) -> bool

Is self equal to an other Type?

Source

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.

Source

fn get_type_id_static() -> TypeId
where Self: Sized,

Same as get_type_id, but without the self reference.

Source

fn verify_interfaces(&self, ctx: &Context) -> Result<()>

Verify all interfaces implemented by this Type.

Provided Methods§

Source

fn get_self_ptr(&self, ctx: &Context) -> Ptr<TypeObj>

Get a copyable pointer to this type.

Source

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.

Source

fn get_instance(t: Self, ctx: &Context) -> Option<TypePtr<Self>>
where Self: Sized,

If an instance of t already exists, get a Ptr to it. Consumes t either way.

Source

fn register_type_in_dialect( ctx: &mut Context, parser: ParserFn<(), TypePtr<Self>>, )
where Self: Sized,

Register this Type’s TypeId in the dialect it belongs to.

Implementations§

Source§

impl dyn Type

Source

pub fn is<__T: Type>(&self) -> bool

Returns true if the trait object wraps an object of type __T.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Typed for dyn Type

Source§

fn get_type(&self, ctx: &Context) -> Ptr<TypeObj>

Get the Type of the current entity.

Implementors§