diff --git a/src/melior_macro/dialect/generation.rs.html b/src/melior_macro/dialect/generation.rs.html index a75ffb088f..1b45e1752d 100644 --- a/src/melior_macro/dialect/generation.rs.html +++ b/src/melior_macro/dialect/generation.rs.html @@ -158,7 +158,7 @@ let attribute_accessors = operation .attributes() .map(generate_attribute_accessors) - .collect::<Result<Vec<_>, _>>()?; + .collect::<Vec<_>>(); let builder = OperationBuilder::new(operation)?; let builder_tokens = generate_operation_builder(&builder)?; diff --git a/src/melior_macro/dialect/generation/attribute_accessor.rs.html b/src/melior_macro/dialect/generation/attribute_accessor.rs.html index 7181484cee..bd7063be89 100644 --- a/src/melior_macro/dialect/generation/attribute_accessor.rs.html +++ b/src/melior_macro/dialect/generation/attribute_accessor.rs.html @@ -76,31 +76,23 @@ 75 76 77 -78 -79 -80 -81 -
use crate::dialect::{
-    error::Error,
-    operation::{Attribute, OperationField},
-    utility::sanitize_snake_case_identifier,
-};
+
use crate::dialect::operation::{Attribute, OperationField};
 use proc_macro2::TokenStream;
 use quote::quote;
 
-pub fn generate_attribute_accessors(attribute: &Attribute) -> Result<TokenStream, Error> {
-    let getter = generate_getter(attribute)?;
-    let setter = generate_setter(attribute)?;
-    let remover = generate_remover(attribute)?;
+pub fn generate_attribute_accessors(attribute: &Attribute) -> TokenStream {
+    let getter = generate_getter(attribute);
+    let setter = generate_setter(attribute);
+    let remover = generate_remover(attribute);
 
-    Ok(quote! {
+    quote! {
         #getter
         #setter
         #remover
-    })
+    }
 }
 
-fn generate_getter(attribute: &Attribute) -> Result<TokenStream, Error> {
+fn generate_getter(attribute: &Attribute) -> TokenStream {
     let name = attribute.name();
 
     let identifier = attribute.singular_identifier();
@@ -112,15 +104,15 @@
         quote! { Ok(self.operation.attribute(#name)?.try_into()?) }
     };
 
-    Ok(quote! {
+    quote! {
         #[allow(clippy::needless_question_mark)]
         pub fn #identifier(&self) -> #return_type {
             #body
         }
-    })
+    }
 }
 
-fn generate_setter(attribute: &Attribute) -> Result<TokenStream, Error> {
+fn generate_setter(attribute: &Attribute) -> TokenStream {
     let name = attribute.name();
 
     let body = if attribute.is_unit() {
@@ -137,28 +129,28 @@
         }
     };
 
-    let ident = sanitize_snake_case_identifier(&format!("set_{}", attribute.name()))?;
+    let identifier = attribute.set_identifier();
     let r#type = attribute.parameter_type();
 
-    Ok(quote! {
-        pub fn #ident(&mut self, context: &'c ::melior::Context, value: #r#type) {
+    quote! {
+        pub fn #identifier(&mut self, context: &'c ::melior::Context, value: #r#type) {
             #body
         }
-    })
+    }
 }
 
-fn generate_remover(attribute: &Attribute) -> Result<Option<TokenStream>, Error> {
-    Ok(if attribute.is_unit() || attribute.is_optional() {
+fn generate_remover(attribute: &Attribute) -> Option<TokenStream> {
+    if attribute.is_unit() || attribute.is_optional() {
         let name = attribute.name();
-        let ident = sanitize_snake_case_identifier(&format!("remove_{}", attribute.name()))?;
+        let identifier = attribute.remove_identifier();
 
         Some(quote! {
-            pub fn #ident(&mut self, context: &'c ::melior::Context) -> Result<(), ::melior::Error> {
+            pub fn #identifier(&mut self, context: &'c ::melior::Context) -> Result<(), ::melior::Error> {
                 self.operation.remove_attribute(#name)
             }
         })
     } else {
         None
-    })
+    }
 }
 
\ No newline at end of file diff --git a/src/melior_macro/dialect/operation/attribute.rs.html b/src/melior_macro/dialect/operation/attribute.rs.html index 95ee4960f5..10592a2068 100644 --- a/src/melior_macro/dialect/operation/attribute.rs.html +++ b/src/melior_macro/dialect/operation/attribute.rs.html @@ -159,6 +159,18 @@ 158 159 160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172
use crate::dialect::{
     error::Error,
     operation::operation_field::OperationField,
@@ -223,6 +235,8 @@
     name: &'a str,
     singular_identifier: Ident,
     storage_type_string: String,
+    set_identifier: Ident,
+    remove_identifier: Ident,
     storage_type: Type,
     optional: bool,
     default: bool,
@@ -235,6 +249,8 @@
         Ok(Self {
             name,
             singular_identifier: sanitize_snake_case_identifier(name)?,
+            set_identifier: sanitize_snake_case_identifier(&format!("set_{name}"))?,
+            remove_identifier: sanitize_snake_case_identifier(&format!("remove_{name}"))?,
             storage_type: syn::parse_str(
                 ATTRIBUTE_TYPES
                     .get(storage_type_string.trim())
@@ -257,6 +273,14 @@
         })
     }
 
+    pub fn set_identifier(&self) -> &Ident {
+        &self.set_identifier
+    }
+
+    pub fn remove_identifier(&self) -> &Ident {
+        &self.remove_identifier
+    }
+
     pub fn is_optional(&self) -> bool {
         self.optional
     }