Skip to content

Commit

Permalink
Introduce interfaces for Types (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaivaswatha authored Jun 25, 2024
1 parent ce1c83c commit 30ebc17
Show file tree
Hide file tree
Showing 5 changed files with 424 additions and 26 deletions.
24 changes: 24 additions & 0 deletions pliron-derive/src/derive_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ impl ToTokens for ImplType {
dialect: ::pliron::dialect::DialectName::new(#dialect),
}
}

fn verify_interfaces(&self, ctx: &::pliron::context::Context) -> ::pliron::result::Result<()> {
if let Some(interface_verifiers) =
::pliron::r#type::TYPE_INTERFACE_VERIFIERS_MAP.get(&Self::get_type_id_static())
{
for (_, verifier) in interface_verifiers {
verifier(self, ctx)?;
}
}
Ok(())
}
}
});
}
Expand Down Expand Up @@ -152,6 +163,19 @@ mod tests {
dialect: ::pliron::dialect::DialectName::new("testing"),
}
}
fn verify_interfaces(
&self,
ctx: &::pliron::context::Context,
) -> ::pliron::result::Result<()> {
if let Some(interface_verifiers) = ::pliron::r#type::TYPE_INTERFACE_VERIFIERS_MAP
.get(&Self::get_type_id_static())
{
for (_, verifier) in interface_verifiers {
verifier(self, ctx)?;
}
}
Ok(())
}
}
"##]]
.assert_eq(&got);
Expand Down
5 changes: 3 additions & 2 deletions src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! and [Interfaces](https://mlir.llvm.org/docs/Interfaces/).
//! Interfaces must all implement an associated function named `verify` with
//! the type [AttrInterfaceVerifier].
//! New attributes must be specified via [decl_attr_interface](pliron::decl_attr_interface)
//! New interfaces must be specified via [decl_attr_interface](pliron::decl_attr_interface)
//! for proper verification.
//!
//! [Attribute]s that implement an interface must do so using the
Expand All @@ -27,7 +27,8 @@
//! is [implemented](attr_impls)) with ease.
//!
//! [AttrObj]s can be downcasted to their concrete types using
/// [downcast_rs](https://docs.rs/downcast-rs/1.2.0/downcast_rs/index.html#example-without-generics).
//! [downcast_rs](https://docs.rs/downcast-rs/1.2.0/downcast_rs/index.html#example-without-generics).
use std::{
fmt::{Debug, Display},
hash::Hash,
Expand Down
19 changes: 3 additions & 16 deletions src/builtin/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ impl Printable for IntegerAttr {
}
}

impl Verify for IntegerAttr {
fn verify(&self, _ctx: &Context) -> Result<()> {
Ok(())
}
}
impl_verify_succ!(IntegerAttr);

impl IntegerAttr {
/// Create a new [IntegerAttr].
Expand Down Expand Up @@ -371,12 +367,7 @@ impl Printable for UnitAttr {
write!(f, "()")
}
}

impl Verify for UnitAttr {
fn verify(&self, _ctx: &Context) -> Result<()> {
Ok(())
}
}
impl_verify_succ!(UnitAttr);

impl Parsable for UnitAttr {
type Arg = ();
Expand Down Expand Up @@ -428,11 +419,7 @@ impl Parsable for TypeAttr {
}
}

impl Verify for TypeAttr {
fn verify(&self, _ctx: &Context) -> Result<()> {
Ok(())
}
}
impl_verify_succ!(TypeAttr);

impl Typed for TypeAttr {
fn get_type(&self, _ctx: &Context) -> Ptr<TypeObj> {
Expand Down
Loading

0 comments on commit 30ebc17

Please sign in to comment.