From 902dc09c6115b7a9530a0e03562d83b71dbaa671 Mon Sep 17 00:00:00 2001 From: raviqqe Date: Thu, 15 Feb 2024 13:12:31 +0000 Subject: [PATCH] deploy: 026e2be39962aeb32124d2334c5319af05311c88 --- src/melior_macro/dialect/generation.rs.html | 2 +- .../generation/operation_builder.rs.html | 2 +- .../dialect/operation/builder.rs.html | 26 ++++++++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/melior_macro/dialect/generation.rs.html b/src/melior_macro/dialect/generation.rs.html index d6c4605cb4..5d8f6dbe61 100644 --- a/src/melior_macro/dialect/generation.rs.html +++ b/src/melior_macro/dialect/generation.rs.html @@ -105,7 +105,7 @@ .map(generate_attribute_accessors) .collect::<Result<Vec<_>, _>>()?; - let builder = OperationBuilder::new(operation); + let builder = OperationBuilder::new(operation)?; let builder_tokens = generate_operation_builder(&builder)?; let builder_fn = builder.create_op_builder_fn()?; let default_constructor = builder.create_default_constructor()?; diff --git a/src/melior_macro/dialect/generation/operation_builder.rs.html b/src/melior_macro/dialect/generation/operation_builder.rs.html index 49adbd8676..9a2029fe9e 100644 --- a/src/melior_macro/dialect/generation/operation_builder.rs.html +++ b/src/melior_macro/dialect/generation/operation_builder.rs.html @@ -90,7 +90,7 @@ let new = builder.create_new_fn(phantom_arguments.as_slice())?; let build = builder.create_build_fn()?; - let builder_identifier = builder.builder_identifier()?; + let builder_identifier = builder.identifier(); let doc = format!("Builder for {}", builder.operation().summary()?); let iter_arguments = builder.type_state().parameters(); diff --git a/src/melior_macro/dialect/operation/builder.rs.html b/src/melior_macro/dialect/operation/builder.rs.html index 13410bc993..7476612d86 100644 --- a/src/melior_macro/dialect/operation/builder.rs.html +++ b/src/melior_macro/dialect/operation/builder.rs.html @@ -188,6 +188,7 @@ 187 188 189 +190
mod type_state_item;
 mod type_state_list;
 
@@ -202,21 +203,27 @@
 
 pub struct OperationBuilder<'o> {
     operation: &'o Operation<'o>,
+    identifier: Ident,
     type_state: TypeStateList,
 }
 
 impl<'o> OperationBuilder<'o> {
-    pub fn new(operation: &'o Operation<'o>) -> Self {
-        Self {
+    pub fn new(operation: &'o Operation<'o>) -> Result<Self, Error> {
+        Ok(Self {
             operation,
+            identifier: format_ident!("{}Builder", operation.class_name()?),
             type_state: Self::create_type_state(operation),
-        }
+        })
     }
 
     pub fn operation(&self) -> &Operation {
         self.operation
     }
 
+    pub fn identifier(&self) -> &Ident {
+        &self.identifier
+    }
+
     pub fn type_state(&self) -> &TypeStateList {
         &self.type_state
     }
@@ -227,8 +234,7 @@
         phantoms: &'a [TokenStream],
     ) -> impl Iterator<Item = Result<TokenStream, Error>> + 'a {
         self.operation.fields().map(move |field| {
-            // TODO Initialize a builder identifier out of this closure.
-            let builder_ident = self.builder_identifier()?;
+            let builder_ident = self.identifier();
             let name = sanitize_snake_case_name(field.name())?;
             let parameter_type = field.parameter_type();
             let argument = quote! { #name: #parameter_type };
@@ -275,7 +281,7 @@
     }
 
     pub fn create_build_fn(&self) -> Result<TokenStream, Error> {
-        let builder_ident = self.builder_identifier()?;
+        let builder_ident = self.identifier();
         let arguments = self.type_state.arguments_all_set(true);
         let class_name = format_ident!("{}", &self.operation.class_name()?);
         let error = format!("should be a valid {class_name}");
@@ -294,7 +300,7 @@
     }
 
     pub fn create_new_fn(&self, phantoms: &[TokenStream]) -> Result<TokenStream, Error> {
-        let builder_ident = self.builder_identifier()?;
+        let builder_ident = self.identifier();
         let name = &self.operation.full_name()?;
         let arguments = self.type_state.arguments_all_set(false);
 
@@ -312,7 +318,7 @@
     }
 
     pub fn create_op_builder_fn(&self) -> Result<TokenStream, Error> {
-        let builder_ident = self.builder_identifier()?;
+        let builder_ident = self.identifier();
         let arguments = self.type_state.arguments_all_set(false);
 
         Ok(quote! {
@@ -372,9 +378,5 @@
                 .collect(),
         )
     }
-
-    pub fn builder_identifier(&self) -> Result<Ident, Error> {
-        Ok(format_ident!("{}Builder", self.operation.class_name()?))
-    }
 }
 
\ No newline at end of file