From 4be32d5297eaa8f5253f5dd0899a2a21131c0034 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 19 May 2025 11:30:43 -0300 Subject: [PATCH 01/78] Add a SymbolTableRef to Component so that it will be used as build argument Signed-off-by: Tomas Fabrizio Orsi --- hir/src/dialects/builtin/builders/world.rs | 2 +- hir/src/dialects/builtin/ops/component.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index 38408b6b7..3c6d92ae4 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -42,7 +42,7 @@ impl WorldBuilder { ver: Version, ) -> Result { let builder = PrimComponentBuilder::new(&mut self.builder, name.span()); - let component_ref = builder(ns, name, ver.clone())?; + let component_ref = builder(ns, name, ver.clone(), self.world)?; let is_new = self .world .borrow_mut() diff --git a/hir/src/dialects/builtin/ops/component.rs b/hir/src/dialects/builtin/ops/component.rs index 2f7d275d5..7c4b3f876 100644 --- a/hir/src/dialects/builtin/ops/component.rs +++ b/hir/src/dialects/builtin/ops/component.rs @@ -12,7 +12,7 @@ use crate::{ }, version::Version, Ident, OpPrinter, Operation, RegionKind, RegionKindInterface, Symbol, SymbolManager, - SymbolManagerMut, SymbolMap, SymbolName, SymbolRef, SymbolTable, SymbolUseList, + SymbolManagerMut, SymbolMap, SymbolName, SymbolRef, SymbolTable, SymbolTableRef, SymbolUseList, UnsafeIntrusiveEntityRef, Usable, Visibility, }; @@ -82,6 +82,8 @@ pub struct Component { #[attr] #[default] visibility: Visibility, + /// Reference to the parent symbol table where this operation will be inserted. + parent: SymbolTableRef, #[region] body: RegionRef, #[default] From 80f08054bdd227a9a6b1acd220b77156ef9d1bdd Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 19 May 2025 17:11:18 -0300 Subject: [PATCH 02/78] Add a quoted macro to the operation builder. Curren tly expands correctly but is only debug Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 12 ++++++++++++ hir/src/dialects/builtin/ops/component.rs | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 3f7928a1d..4ad133c7f 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -661,6 +661,7 @@ impl quote::ToTokens for OpCreateFn<'_> { let initialize_custom_fields = InitializeCustomFields(self.op); let with_symbols = WithSymbols(self.op); let with_attrs = WithAttrs(self.op); + let with_jamon = WithJamon(self.op); let with_operands = WithOperands(self.op); let with_results = WithResults(self.op); let with_regions = self.op.regions.iter().map(|_| { @@ -718,6 +719,7 @@ impl quote::ToTokens for OpCreateFn<'_> { )* #with_successors #with_results + #with_jamon // Finalize construction of this op, verifying it #build_op @@ -2752,3 +2754,13 @@ mod tests { } } } + +struct WithJamon<'a>(&'a OpDefinition); +impl quote::ToTokens for WithJamon<'_> { + fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { + // std::dbg!("Funcion to tokens de with jamon"); + tokens.extend(quote! { + std::dbg!("DBG quoteado de with_jamon"); + }) + } +} diff --git a/hir/src/dialects/builtin/ops/component.rs b/hir/src/dialects/builtin/ops/component.rs index 7c4b3f876..929354a65 100644 --- a/hir/src/dialects/builtin/ops/component.rs +++ b/hir/src/dialects/builtin/ops/component.rs @@ -83,7 +83,8 @@ pub struct Component { #[default] visibility: Visibility, /// Reference to the parent symbol table where this operation will be inserted. - parent: SymbolTableRef, + #[jamon] + crema: SymbolTableRef, #[region] body: RegionRef, #[default] From 6c3e62d3b5d92599bb467d52fd4ff77cfb5dd91c Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 19 May 2025 17:43:42 -0300 Subject: [PATCH 03/78] Add jamon field to OperationFieldAttrs. Now it gets parsed :partying_face: Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 4ad133c7f..263e4b00b 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -2014,7 +2014,7 @@ pub struct Operation { #[derive(Debug, FromField)] #[darling(forward_attrs( doc, cfg, allow, attr, operand, operands, region, successor, successors, result, results, - default, order, symbol + default, order, symbol, jamon ))] pub struct OperationField { /// The name of this field. @@ -2053,6 +2053,8 @@ pub struct OperationFieldAttrs { results: Flag, /// Was this a `#[region]` field? region: Flag, + /// Was this a `#[jamon]` field? + jamon: Flag, /// Was this a `#[successor]` field? successor: Flag, /// Was this a `#[successors]` field? @@ -2149,6 +2151,15 @@ impl OperationFieldAttrs { } result.region = Flag::from_meta(&attr.meta).unwrap(); } + "jamon" => { + if let Some(prev) = prev_decorator.replace("region") { + return Err(Error::custom(format!( + "#[region] conflicts with a previous #[{prev}] decorator" + )) + .with_span(&attr)); + } + result.jamon = Flag::from_meta(&attr.meta).unwrap(); + } "successor" => { if let Some(prev) = prev_decorator.replace("successor") { return Err(Error::custom(format!( From 93a609a598ee0fb770e743edc4a6019931e963e9 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 20 May 2025 10:53:47 -0300 Subject: [PATCH 04/78] WIP: Checkpoint Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/lib.rs | 5 +- hir-macros/src/operation.rs | 58 ++++++++++++++++++-- hir/src/dialects/builtin/builders/world.rs | 1 + hir/src/dialects/builtin/ops/component.rs | 4 +- hir/src/ir/operation/builder.rs | 6 ++ hir/src/lib.rs | 2 +- tests/integration/src/rust_masm_tests/mod.rs | 2 +- 7 files changed, 68 insertions(+), 10 deletions(-) diff --git a/hir-macros/src/lib.rs b/hir-macros/src/lib.rs index d41541360..c05857727 100644 --- a/hir-macros/src/lib.rs +++ b/hir-macros/src/lib.rs @@ -1,4 +1,4 @@ -#![deny(warnings)] +// #![deny(warnings)] extern crate proc_macro; @@ -66,6 +66,7 @@ pub fn operation( item: proc_macro::TokenStream, ) -> proc_macro::TokenStream { let attr = proc_macro2::TokenStream::from(attr); + // std::dbg!(&attr); let mut input = syn::parse_macro_input!(item as syn::ItemStruct); let span = input.span(); @@ -86,6 +87,8 @@ pub fn operation( let input = syn::parse_quote! { #input }; + // std::dbg!(&input); + // Sigue estando jamon match operation::derive_operation(input) { Ok(token_stream) => proc_macro::TokenStream::from(token_stream), diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 263e4b00b..fb42be04d 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -10,7 +10,12 @@ use syn::{parse_quote, spanned::Spanned, Ident, Token}; pub fn derive_operation(input: syn::DeriveInput) -> darling::Result { let op = OpDefinition::from_derive_input(&input)?; + // if op.name == + // std::dbg!(&input); + // Sigue teniendo jamon + // This method is implicitly implemented using `to_tokens`, and acts as a + // convenience method for consumers of the `ToTokens` trait. Ok(op.into_token_stream()) } @@ -51,6 +56,7 @@ pub struct OpDefinition { /// Keyed successor groups are handled a bit differently than "normal" successor groups in terms /// of the types expected by the op builder for this type. successors: Vec, + parent_jamon: Option, /// The symbolic references held by this op symbols: Vec, /// The struct definition @@ -63,6 +69,7 @@ pub struct OpDefinition { impl OpDefinition { /// Initialize an [OpDefinition] from the parsed [Operation] received as input fn from_operation(span: proc_macro2::Span, op: &mut Operation) -> darling::Result { + // std::dbg!(&op); let dialect = op.dialect.clone(); let name = op.ident.clone(); let opcode = op.name.clone().unwrap_or_else(|| { @@ -71,8 +78,10 @@ impl OpDefinition { format_ident!("{name}", span = name.span()) }); let traits = core::mem::take(&mut op.traits); + // std::dbg!(&traits); let implements = core::mem::take(&mut op.implements); + // std::dbg!("NUEVOS FIELDS"); let fields = core::mem::replace( &mut op.data, darling::ast::Data::Struct(darling::ast::Fields::new( @@ -82,6 +91,7 @@ impl OpDefinition { ) .take_struct() .unwrap(); + // std::dbg!(&fields); let mut named_fields = syn::punctuated::Punctuated::::new(); // Add the `op` field (which holds the underlying Operation) @@ -123,6 +133,7 @@ impl OpDefinition { operands: vec![], results: None, successors: vec![], + parent_jamon: None, symbols: vec![], op, op_builder_impl, @@ -141,7 +152,7 @@ impl OpDefinition { }; let mut create_params = vec![]; let (_, mut fields) = fields.split(); - + // std::dbg!(&fields); // Compute the absolute ordering of op parameters as follows: // // * By default, the ordering is implied by the order of field declarations in the struct @@ -190,6 +201,8 @@ impl OpDefinition { let field_ty = field.ty.clone(); let op_field_ty = field.attrs.pseudo_type(); + std::dbg!(&field); + std::dbg!(&op_field_ty); match op_field_ty.as_deref() { // Forwarded field None => { @@ -251,6 +264,22 @@ impl OpDefinition { }); self.operands.push(OpOperandGroup::Named(field_name, field_ty)); } + Some(OperationFieldType::Jamon) => { + create_params.push(OpCreateParam { + param_ty: OpCreateParamType::CustomField(field_name.clone(), field_ty), + r#default: field.attrs.default.is_present(), + }); + named_fields.push(syn::Field { + attrs: field.attrs.forwarded, + vis: field.vis, + mutability: syn::FieldMutability::None, + ident: Some(field_name), + colon_token: Some(syn::token::Colon(field_span)), + ty: field.ty, + }); + continue; + // panic!(); + } Some(OperationFieldType::Result) => { let result = OpResult { name: field_name.clone(), @@ -354,6 +383,7 @@ impl FromDeriveInput for OpDefinition { fn from_derive_input(input: &syn::DeriveInput) -> darling::Result { let span = input.span(); let mut operation = Operation::from_derive_input(input)?; + // std::dbg!(&operation); Self::from_operation(span, &mut operation) } } @@ -639,6 +669,7 @@ impl quote::ToTokens for BuildOp<'_> { #verify_result_constraints } + Ok(op) }) } @@ -1470,6 +1501,11 @@ pub struct OpResult { pub constraint: Constraint, } +#[derive(Debug, Clone)] +pub struct OpJamon { + pub name: Ident, +} + pub type OpResultGroup = EntityGroup; #[derive(Debug)] @@ -2291,6 +2327,8 @@ impl OperationFieldAttrs { self.symbol .as_ref() .map(|sym| sym.map_ref(|sym| OperationFieldType::Symbol(sym.clone()))) + } else if self.jamon.is_present() { + Some(SpannedValue::new(OperationFieldType::Jamon, self.jamon.span())) } else { None } @@ -2314,6 +2352,8 @@ pub enum OperationFieldType { Region, /// A named successor Successor, + /// Parent symbol table + Jamon, /// A named variadic successor group (zero or more successors) Successors(SuccessorsType), /// A symbol operand @@ -2332,6 +2372,7 @@ impl core::fmt::Display for OperationFieldType { Self::Attr(AttrKind::Default) => f.write_str("attr"), Self::Attr(AttrKind::Hidden) => f.write_str("attr(hidden)"), Self::Operand => f.write_str("operand"), + Self::Jamon => f.write_str("jamon"), Self::Operands => f.write_str("operands"), Self::Result => f.write_str("result"), Self::Results => f.write_str("results"), @@ -2769,9 +2810,16 @@ mod tests { struct WithJamon<'a>(&'a OpDefinition); impl quote::ToTokens for WithJamon<'_> { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { - // std::dbg!("Funcion to tokens de with jamon"); - tokens.extend(quote! { - std::dbg!("DBG quoteado de with_jamon"); - }) + match self.0.parent_jamon.as_ref() { + None => { + // std::dbg!("No hay definido un parent"); + } + Some(_) => { + // std::dbg!("Hay definido un parent"); + tokens.extend(quote! { + std::dbg!("DBG quoteado de with_jamon"); + }) + } + } } } diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index 3c6d92ae4..ef4ec5d9b 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -43,6 +43,7 @@ impl WorldBuilder { ) -> Result { let builder = PrimComponentBuilder::new(&mut self.builder, name.span()); let component_ref = builder(ns, name, ver.clone(), self.world)?; + // let component_ref = builder(ns, name, ver.clone())?; let is_new = self .world .borrow_mut() diff --git a/hir/src/dialects/builtin/ops/component.rs b/hir/src/dialects/builtin/ops/component.rs index 929354a65..a0793c421 100644 --- a/hir/src/dialects/builtin/ops/component.rs +++ b/hir/src/dialects/builtin/ops/component.rs @@ -83,14 +83,14 @@ pub struct Component { #[default] visibility: Visibility, /// Reference to the parent symbol table where this operation will be inserted. - #[jamon] - crema: SymbolTableRef, #[region] body: RegionRef, #[default] symbols: SymbolMap, #[default] uses: SymbolUseList, + #[jamon] + crema: SymbolTableRef, } impl OpPrinter for Component { diff --git a/hir/src/ir/operation/builder.rs b/hir/src/ir/operation/builder.rs index 251de660a..b7ff61227 100644 --- a/hir/src/ir/operation/builder.rs +++ b/hir/src/ir/operation/builder.rs @@ -101,6 +101,12 @@ where op.regions.push_back(region); } + pub fn add_to_symbol_table(&mut self) { + // pub fn add_to_symbol_table(&mut self, _sym_table: SymbolTableRef) { + // let sym_manager = sym_table.borrow_mut().symbol_manager_mut(); + todo!() + } + pub fn with_successor( &mut self, dest: BlockRef, diff --git a/hir/src/lib.rs b/hir/src/lib.rs index 51f0af058..d5bcac6d5 100644 --- a/hir/src/lib.rs +++ b/hir/src/lib.rs @@ -41,7 +41,7 @@ // Some of the above features require us to disable these warnings #![allow(incomplete_features)] #![allow(internal_features)] -#![deny(warnings)] +// #![deny(warnings)] extern crate alloc; diff --git a/tests/integration/src/rust_masm_tests/mod.rs b/tests/integration/src/rust_masm_tests/mod.rs index aa40cca4c..35a8c296e 100644 --- a/tests/integration/src/rust_masm_tests/mod.rs +++ b/tests/integration/src/rust_masm_tests/mod.rs @@ -28,7 +28,7 @@ where let exec = Executor::for_package(package, args.iter().copied(), session) .map_err(|err| TestCaseError::fail(err.to_string()))?; let output = exec.execute_into(&package.unwrap_program(), session); - std::dbg!(&output); + // std::dbg!(&output); prop_assert_eq!(rust_out.clone(), output, "VM output mismatch"); // TODO: Uncomment after https://github.com/0xMiden/compiler/issues/228 is fixed // let emul_out: T = (*execute_emulator(ir_program.clone(), args).first().unwrap()).into(); From 3b1e541006631ac78bfce935ea43351ad7440a5d Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 20 May 2025 11:33:12 -0300 Subject: [PATCH 05/78] Checkpoint 2: Code is generated when using the #[jamon] decorator Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 9 +++++---- hir/src/dialects/builtin/ops/component.rs | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index fb42be04d..2d903ee6d 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -269,16 +269,17 @@ impl OpDefinition { param_ty: OpCreateParamType::CustomField(field_name.clone(), field_ty), r#default: field.attrs.default.is_present(), }); + // TODO: Remove from fields, only used when building named_fields.push(syn::Field { attrs: field.attrs.forwarded, vis: field.vis, mutability: syn::FieldMutability::None, - ident: Some(field_name), + ident: Some(field_name.clone()), colon_token: Some(syn::token::Colon(field_span)), ty: field.ty, }); + self.parent_jamon = Some(OpJamon { name: field_name }); continue; - // panic!(); } Some(OperationFieldType::Result) => { let result = OpResult { @@ -2812,10 +2813,10 @@ impl quote::ToTokens for WithJamon<'_> { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { match self.0.parent_jamon.as_ref() { None => { - // std::dbg!("No hay definido un parent"); + std::dbg!("No hay definido un parent"); } Some(_) => { - // std::dbg!("Hay definido un parent"); + std::dbg!("Hay definido un parent"); tokens.extend(quote! { std::dbg!("DBG quoteado de with_jamon"); }) diff --git a/hir/src/dialects/builtin/ops/component.rs b/hir/src/dialects/builtin/ops/component.rs index a0793c421..71493e975 100644 --- a/hir/src/dialects/builtin/ops/component.rs +++ b/hir/src/dialects/builtin/ops/component.rs @@ -79,6 +79,8 @@ pub struct Component { name: Ident, #[attr] version: Version, + #[jamon] + crema: SymbolTableRef, #[attr] #[default] visibility: Visibility, @@ -89,8 +91,6 @@ pub struct Component { symbols: SymbolMap, #[default] uses: SymbolUseList, - #[jamon] - crema: SymbolTableRef, } impl OpPrinter for Component { From 15f4723f97ebb6fe2657e3d83afe2879965c1b70 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 20 May 2025 12:23:55 -0300 Subject: [PATCH 06/78] Checkpoint 3: The member variable name is expanded correctly Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 2d903ee6d..a51e683d8 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -278,7 +278,10 @@ impl OpDefinition { colon_token: Some(syn::token::Colon(field_span)), ty: field.ty, }); - self.parent_jamon = Some(OpJamon { name: field_name }); + self.parent_jamon = Some(OpJamon { + name: field_name, + span: field_span, + }); continue; } Some(OperationFieldType::Result) => { @@ -751,7 +754,9 @@ impl quote::ToTokens for OpCreateFn<'_> { )* #with_successors #with_results - #with_jamon + unsafe { + #with_jamon + } // Finalize construction of this op, verifying it #build_op @@ -1505,6 +1510,7 @@ pub struct OpResult { #[derive(Debug, Clone)] pub struct OpJamon { pub name: Ident, + pub span: proc_macro2::Span, } pub type OpResultGroup = EntityGroup; @@ -2815,9 +2821,11 @@ impl quote::ToTokens for WithJamon<'_> { None => { std::dbg!("No hay definido un parent"); } - Some(_) => { + Some(OpJamon { name, span }) => { std::dbg!("Hay definido un parent"); tokens.extend(quote! { + std::dbg!(#name); + // core::ptr::addr_of_mut!((*__ptr).#id).write(#id); std::dbg!("DBG quoteado de with_jamon"); }) } From 35116e07c39cf93df855300446d1a0b217d9edad Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 20 May 2025 14:41:26 -0300 Subject: [PATCH 07/78] Remove unsafe from macro as it is not currently needed Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index a51e683d8..6579593a9 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -280,9 +280,9 @@ impl OpDefinition { }); self.parent_jamon = Some(OpJamon { name: field_name, - span: field_span, + // span: field_span, }); - continue; + // continue; } Some(OperationFieldType::Result) => { let result = OpResult { @@ -754,9 +754,7 @@ impl quote::ToTokens for OpCreateFn<'_> { )* #with_successors #with_results - unsafe { - #with_jamon - } + #with_jamon // Finalize construction of this op, verifying it #build_op @@ -1510,7 +1508,7 @@ pub struct OpResult { #[derive(Debug, Clone)] pub struct OpJamon { pub name: Ident, - pub span: proc_macro2::Span, + // pub span: proc_macro2::Span, } pub type OpResultGroup = EntityGroup; @@ -2821,10 +2819,10 @@ impl quote::ToTokens for WithJamon<'_> { None => { std::dbg!("No hay definido un parent"); } - Some(OpJamon { name, span }) => { + Some(OpJamon { name }) => { std::dbg!("Hay definido un parent"); tokens.extend(quote! { - std::dbg!(#name); + #name.borrow().as_symbol_table_operation(); // core::ptr::addr_of_mut!((*__ptr).#id).write(#id); std::dbg!("DBG quoteado de with_jamon"); }) From 9e9f4d0f0a1fc710c9cc1df89f7ef15deb1a780d Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 20 May 2025 14:58:51 -0300 Subject: [PATCH 08/78] Save reference in macro Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 6579593a9..23f959970 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -600,7 +600,8 @@ impl quote::ToTokens for BuildOp<'_> { match self.0.results.as_ref() { None => { tokens.extend(quote! { - op_builder.build() + let op = op_builder.build(); + op }); } Some(group) => { From 613c9e114bf7548bf00bfb7d3da5890182942844 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 20 May 2025 15:08:00 -0300 Subject: [PATCH 09/78] Extend BuildOp to use with_jamon Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 23f959970..4db2279be 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -601,6 +601,22 @@ impl quote::ToTokens for BuildOp<'_> { None => { tokens.extend(quote! { let op = op_builder.build(); + }); + match self.0.parent_jamon.as_ref() { + None => { + std::dbg!("No hay definido un parent"); + } + Some(OpJamon { name }) => { + std::dbg!("Hay definido un parent"); + tokens.extend(quote! { + #name.borrow().symbol_manager(); + // core::ptr::addr_of_mut!((*__ptr).#id).write(#id); + std::dbg!("DBG quoteado de with_jamon"); + }) + } + }; + + tokens.extend(quote! { op }); } @@ -755,7 +771,7 @@ impl quote::ToTokens for OpCreateFn<'_> { )* #with_successors #with_results - #with_jamon + // #with_jamon // Finalize construction of this op, verifying it #build_op From 4404ad0f32644a0ace531a62065b762b07e41d65 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 20 May 2025 15:12:14 -0300 Subject: [PATCH 10/78] WARNING: This doesn't compile, this is the macro we need, but has borrow checker issues Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 4db2279be..a11aba45d 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -609,7 +609,7 @@ impl quote::ToTokens for BuildOp<'_> { Some(OpJamon { name }) => { std::dbg!("Hay definido un parent"); tokens.extend(quote! { - #name.borrow().symbol_manager(); + #name.borrow_mut().symbol_manager_mut().insert_new(op, crate::ProgramPoint::Invalid); // core::ptr::addr_of_mut!((*__ptr).#id).write(#id); std::dbg!("DBG quoteado de with_jamon"); }) From 2c4c5d2d39b72814817bdf7641af72ca1ba0dd21 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 20 May 2025 15:31:40 -0300 Subject: [PATCH 11/78] Basic macro structure seems to be in place, mutability is missing Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index a11aba45d..f54a52e56 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -609,10 +609,8 @@ impl quote::ToTokens for BuildOp<'_> { Some(OpJamon { name }) => { std::dbg!("Hay definido un parent"); tokens.extend(quote! { - #name.borrow_mut().symbol_manager_mut().insert_new(op, crate::ProgramPoint::Invalid); - // core::ptr::addr_of_mut!((*__ptr).#id).write(#id); - std::dbg!("DBG quoteado de with_jamon"); - }) + op.as_ref().map(|op| #name.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid)); + }); } }; From 740267868573456cfcb7af4af600cc3d25570cb6 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 20 May 2025 16:37:39 -0300 Subject: [PATCH 12/78] Checkpoint: Fideos trait in place. Better alternative? Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 34 +++++++++++++++++++++-- hir/src/dialects/builtin/ops/component.rs | 7 +++-- hir/src/ir/traits.rs | 3 ++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index f54a52e56..2764c5549 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -1,7 +1,7 @@ use std::rc::Rc; use darling::{ - util::{Flag, SpannedValue}, + util::{Flag, PathList, SpannedValue}, Error, FromDeriveInput, FromField, FromMeta, }; use inflector::Inflector; @@ -69,7 +69,6 @@ pub struct OpDefinition { impl OpDefinition { /// Initialize an [OpDefinition] from the parsed [Operation] received as input fn from_operation(span: proc_macro2::Span, op: &mut Operation) -> darling::Result { - // std::dbg!(&op); let dialect = op.dialect.clone(); let name = op.ident.clone(); let opcode = op.name.clone().unwrap_or_else(|| { @@ -146,6 +145,7 @@ impl OpDefinition { } fn hydrate(&mut self, fields: darling::ast::Fields) -> darling::Result<()> { + std::dbg!(&self.traits); let named_fields = match &mut self.op.fields { syn::Fields::Named(syn::FieldsNamed { ref mut named, .. }) => named, _ => unreachable!(), @@ -265,6 +265,8 @@ impl OpDefinition { self.operands.push(OpOperandGroup::Named(field_name, field_ty)); } Some(OperationFieldType::Jamon) => { + std::dbg!("MANTECA MANTECA"); + std::dbg!(&field_ty); create_params.push(OpCreateParam { param_ty: OpCreateParamType::CustomField(field_name.clone(), field_ty), r#default: field.attrs.default.is_present(), @@ -377,9 +379,35 @@ impl OpDefinition { } } } + if self.traits.iter().any(|tr| tr.get_ident().unwrap().to_string() == "Fideos") { + let parent_jamon_name = Ident::new("dinosaurio", proc_macro2::Span::call_site()); + + create_params.push(OpCreateParam { + param_ty: OpCreateParamType::CustomField( + parent_jamon_name.clone(), + make_type("SymbolTableRef"), + ), + r#default: false, + }); + self.parent_jamon = Some(OpJamon { + name: parent_jamon_name, + // span: field_span, + }); + } self.op_builder_impl.set_create_params(&self.op.generics, create_params); + // for tr in self.traits.iter() { + // std::dbg!("BARRIl"); + // std::dbg!(tr.get_ident().unwrap().to_string()); + // } + // // if *tr.get_ident().unwrap() == <&str as Into>::into("Fideos") { + // // std::dbg!("BANDERA"); + // // } else { + // // std::dbg!("TERMO"); + // // }; + // } + Ok(()) } } @@ -609,7 +637,7 @@ impl quote::ToTokens for BuildOp<'_> { Some(OpJamon { name }) => { std::dbg!("Hay definido un parent"); tokens.extend(quote! { - op.as_ref().map(|op| #name.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid)); + // op.as_ref().map(|op| #name.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid)); }); } }; diff --git a/hir/src/dialects/builtin/ops/component.rs b/hir/src/dialects/builtin/ops/component.rs index 71493e975..29abcb79b 100644 --- a/hir/src/dialects/builtin/ops/component.rs +++ b/hir/src/dialects/builtin/ops/component.rs @@ -7,7 +7,7 @@ use crate::{ derive::operation, dialects::builtin::BuiltinDialect, traits::{ - GraphRegionNoTerminator, HasOnlyGraphRegion, IsolatedFromAbove, NoRegionArguments, + Fideos, GraphRegionNoTerminator, HasOnlyGraphRegion, IsolatedFromAbove, NoRegionArguments, NoTerminator, SingleBlock, SingleRegion, }, version::Version, @@ -69,6 +69,7 @@ pub type ComponentRef = UnsafeIntrusiveEntityRef; HasOnlyGraphRegion, GraphRegionNoTerminator, IsolatedFromAbove, + Fideos, ), implements(RegionKindInterface, SymbolTable, Symbol, OpPrinter) )] @@ -79,8 +80,8 @@ pub struct Component { name: Ident, #[attr] version: Version, - #[jamon] - crema: SymbolTableRef, + // #[jamon] + // crema: SymbolTableRef, #[attr] #[default] visibility: Visibility, diff --git a/hir/src/ir/traits.rs b/hir/src/ir/traits.rs index d82c6603c..cc32ab391 100644 --- a/hir/src/ir/traits.rs +++ b/hir/src/ir/traits.rs @@ -40,6 +40,9 @@ pub trait Involution {} /// Marker trait for ops which are not permitted to access values defined above them pub trait IsolatedFromAbove {} +/// Marker trait for ops whose parent op needs to add them to their own symbol list. +pub trait Fideos {} + /// Marker trait for ops which have only regions of [`RegionKind::Graph`] pub trait HasOnlyGraphRegion {} From 557f75fbeaac721402e89a3446652df36a22bb78 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 20 May 2025 16:55:46 -0300 Subject: [PATCH 13/78] Create Custom field mandioca for pareny symbol table Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 2764c5549..9b427decd 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -383,7 +383,7 @@ impl OpDefinition { let parent_jamon_name = Ident::new("dinosaurio", proc_macro2::Span::call_site()); create_params.push(OpCreateParam { - param_ty: OpCreateParamType::CustomField( + param_ty: OpCreateParamType::Mandioca( parent_jamon_name.clone(), make_type("SymbolTableRef"), ), @@ -2464,6 +2464,7 @@ pub enum OpCreateParamType { #[allow(dead_code)] OperandGroup(Ident, syn::Type), CustomField(Ident, syn::Type), + Mandioca(Ident, syn::Type), Successor(Ident), SuccessorGroupNamed(Ident), SuccessorGroupKeyed(Ident, syn::Type), @@ -2477,6 +2478,7 @@ impl OpCreateParam { | OpCreateParamType::CustomField(name, _) | OpCreateParamType::Operand(Operand { name, .. }) | OpCreateParamType::OperandGroup(name, _) + | OpCreateParamType::Mandioca(name, _) | OpCreateParamType::SuccessorGroupNamed(name) | OpCreateParamType::SuccessorGroupKeyed(name, _) | OpCreateParamType::Symbol(Symbol { name, .. }) => vec![name.clone()], @@ -2502,6 +2504,7 @@ impl OpCreateParam { vec![ty.clone()] } OpCreateParamType::Operand(_) => vec![make_type("::midenc_hir::ValueRef")], + OpCreateParamType::Mandioca(_, ty) => vec![ty.clone()], OpCreateParamType::OperandGroup(group_name, _) | OpCreateParamType::SuccessorGroupNamed(group_name) | OpCreateParamType::SuccessorGroupKeyed(group_name, _) => { From a7315bd8e5f4eb17165d4ec24860878821995b63 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 20 May 2025 17:02:52 -0300 Subject: [PATCH 14/78] De-comment call to insert map Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 9b427decd..916518a77 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -633,11 +633,13 @@ impl quote::ToTokens for BuildOp<'_> { match self.0.parent_jamon.as_ref() { None => { std::dbg!("No hay definido un parent"); + std::dbg!("PODRIDO"); } Some(OpJamon { name }) => { + std::dbg!("ROQUEFORT"); std::dbg!("Hay definido un parent"); tokens.extend(quote! { - // op.as_ref().map(|op| #name.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid)); + op.as_ref().map(|op| #name.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid)); }); } }; From db07c413781ae39ab4bd7b4962e26eed6c64c1e0 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Wed, 21 May 2025 09:57:54 -0300 Subject: [PATCH 15/78] Checkpoint: It compiles but it's missing a casting implementation Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 11 ++++--- hir/src/dialects/builtin/builders/world.rs | 34 ++++++++++++---------- hir/src/dialects/builtin/ops/component.rs | 5 ++++ hir/src/dialects/builtin/ops/interface.rs | 9 ++++-- hir/src/dialects/builtin/ops/module.rs | 7 ++++- hir/src/dialects/builtin/ops/world.rs | 8 ++++- hir/src/ir/symbols/table.rs | 3 ++ 7 files changed, 53 insertions(+), 24 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 916518a77..ccd674859 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -382,11 +382,14 @@ impl OpDefinition { if self.traits.iter().any(|tr| tr.get_ident().unwrap().to_string() == "Fideos") { let parent_jamon_name = Ident::new("dinosaurio", proc_macro2::Span::call_site()); + let c = syn::Type::Reference(syn::TypeReference { + and_token: syn::token::And(proc_macro2::Span::call_site()), + lifetime: None, + mutability: Some(syn::token::Mut(proc_macro2::Span::call_site())), + elem: Box::new(make_type("SymbolTableRef")), + }); create_params.push(OpCreateParam { - param_ty: OpCreateParamType::Mandioca( - parent_jamon_name.clone(), - make_type("SymbolTableRef"), - ), + param_ty: OpCreateParamType::Mandioca(parent_jamon_name.clone(), c), r#default: false, }); self.parent_jamon = Some(OpJamon { diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index ef4ec5d9b..4fc077cea 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -42,23 +42,25 @@ impl WorldBuilder { ver: Version, ) -> Result { let builder = PrimComponentBuilder::new(&mut self.builder, name.span()); - let component_ref = builder(ns, name, ver.clone(), self.world)?; + let component_ref = + builder(ns, name, ver.clone(), &mut self.world.borrow_mut().as_symbol_table_ref())?; // let component_ref = builder(ns, name, ver.clone())?; - let is_new = self - .world - .borrow_mut() - .symbol_manager_mut() - .insert_new(component_ref, crate::ProgramPoint::Invalid); - assert!( - is_new, - "component {} already exists in world", - ComponentId { - namespace: ns.name, - name: name.name, - version: ver - } - ); - Ok(component_ref) + // let is_new = self + // .world + // .borrow_mut() + // .symbol_manager_mut() + // .insert_new(component_ref, crate::ProgramPoint::Invalid); + // assert!( + // is_new, + // "component {} already exists in world", + // ComponentId { + // namespace: ns.name, + // name: name.name, + // version: ver + // } + // ); + // Ok(component_ref) + todo!() } pub fn find_component(&self, id: &ComponentId) -> Option { diff --git a/hir/src/dialects/builtin/ops/component.rs b/hir/src/dialects/builtin/ops/component.rs index 29abcb79b..fd98f4698 100644 --- a/hir/src/dialects/builtin/ops/component.rs +++ b/hir/src/dialects/builtin/ops/component.rs @@ -196,6 +196,11 @@ impl SymbolTable for Component { &self.op } + #[inline(always)] + fn as_symbol_table_ref(&self) -> SymbolTableRef { + todo!() + } + #[inline(always)] fn as_symbol_table_operation_mut(&mut self) -> &mut Operation { &mut self.op diff --git a/hir/src/dialects/builtin/ops/interface.rs b/hir/src/dialects/builtin/ops/interface.rs index 856b18a99..d35ee6844 100644 --- a/hir/src/dialects/builtin/ops/interface.rs +++ b/hir/src/dialects/builtin/ops/interface.rs @@ -8,8 +8,8 @@ use crate::{ NoTerminator, SingleBlock, SingleRegion, }, Ident, Op, Operation, RegionKind, RegionKindInterface, Symbol, SymbolManager, SymbolManagerMut, - SymbolMap, SymbolName, SymbolRef, SymbolTable, SymbolUseList, UnsafeIntrusiveEntityRef, Usable, - Visibility, + SymbolMap, SymbolName, SymbolRef, SymbolTable, SymbolTableRef, SymbolUseList, + UnsafeIntrusiveEntityRef, Usable, Visibility, }; pub type InterfaceRef = UnsafeIntrusiveEntityRef; @@ -119,6 +119,11 @@ impl SymbolTable for Interface { &self.op } + #[inline(always)] + fn as_symbol_table_ref(&self) -> SymbolTableRef { + todo!() + } + #[inline(always)] fn as_symbol_table_operation_mut(&mut self) -> &mut Operation { &mut self.op diff --git a/hir/src/dialects/builtin/ops/module.rs b/hir/src/dialects/builtin/ops/module.rs index 5fb6100fc..b06899146 100644 --- a/hir/src/dialects/builtin/ops/module.rs +++ b/hir/src/dialects/builtin/ops/module.rs @@ -6,7 +6,7 @@ use crate::{ NoTerminator, SingleBlock, SingleRegion, }, Ident, OpPrinter, Operation, RegionKind, RegionKindInterface, Symbol, SymbolManager, - SymbolManagerMut, SymbolMap, SymbolName, SymbolRef, SymbolTable, SymbolUseList, + SymbolManagerMut, SymbolMap, SymbolName, SymbolRef, SymbolTable, SymbolTableRef, SymbolUseList, UnsafeIntrusiveEntityRef, Usable, Visibility, }; @@ -176,6 +176,11 @@ impl SymbolTable for Module { &self.op } + #[inline(always)] + fn as_symbol_table_ref(&self) -> SymbolTableRef { + todo!() + } + #[inline(always)] fn as_symbol_table_operation_mut(&mut self) -> &mut Operation { &mut self.op diff --git a/hir/src/dialects/builtin/ops/world.rs b/hir/src/dialects/builtin/ops/world.rs index 9a922b632..71397a4e6 100644 --- a/hir/src/dialects/builtin/ops/world.rs +++ b/hir/src/dialects/builtin/ops/world.rs @@ -6,7 +6,8 @@ use crate::{ NoTerminator, SingleBlock, SingleRegion, }, Operation, RegionKind, RegionKindInterface, SymbolManager, SymbolManagerMut, SymbolMap, - SymbolName, SymbolRef, SymbolTable, SymbolUseList, UnsafeIntrusiveEntityRef, Usable, + SymbolName, SymbolRef, SymbolTable, SymbolTableRef, SymbolUseList, UnsafeIntrusiveEntityRef, + Usable, }; pub type WorldRef = UnsafeIntrusiveEntityRef; @@ -68,6 +69,11 @@ impl SymbolTable for World { &self.op } + #[inline(always)] + fn as_symbol_table_ref(&self) -> SymbolTableRef { + todo!() + } + #[inline(always)] fn as_symbol_table_operation_mut(&mut self) -> &mut Operation { &mut self.op diff --git a/hir/src/ir/symbols/table.rs b/hir/src/ir/symbols/table.rs index 53caba022..fba3c5f9d 100644 --- a/hir/src/ir/symbols/table.rs +++ b/hir/src/ir/symbols/table.rs @@ -23,6 +23,9 @@ pub trait SymbolTable { /// Get a reference to the underlying [Operation] fn as_symbol_table_operation(&self) -> &Operation; + // /// Get a reference to the underlying [Operation] + fn as_symbol_table_ref(&self) -> SymbolTableRef; + /// Get a mutable reference to the underlying [Operation] fn as_symbol_table_operation_mut(&mut self) -> &mut Operation; From b7816a86c2875a693933e38fb530412b92eb567a Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Wed, 21 May 2025 12:12:42 -0300 Subject: [PATCH 16/78] Try doing an unsafe cast Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 2 ++ hir/src/dialects/builtin/builders/world.rs | 4 ++-- hir/src/dialects/builtin/ops/component.rs | 4 +++- hir/src/dialects/builtin/ops/interface.rs | 2 +- hir/src/dialects/builtin/ops/module.rs | 2 +- hir/src/dialects/builtin/ops/world.rs | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index ccd674859..65379d47a 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -379,6 +379,7 @@ impl OpDefinition { } } } + if self.traits.iter().any(|tr| tr.get_ident().unwrap().to_string() == "Fideos") { let parent_jamon_name = Ident::new("dinosaurio", proc_macro2::Span::call_site()); @@ -388,6 +389,7 @@ impl OpDefinition { mutability: Some(syn::token::Mut(proc_macro2::Span::call_site())), elem: Box::new(make_type("SymbolTableRef")), }); + // let c = make_type("SymbolManagerMut<'_>"); create_params.push(OpCreateParam { param_ty: OpCreateParamType::Mandioca(parent_jamon_name.clone(), c), r#default: false, diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index 4fc077cea..15a4248ff 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -44,6 +44,7 @@ impl WorldBuilder { let builder = PrimComponentBuilder::new(&mut self.builder, name.span()); let component_ref = builder(ns, name, ver.clone(), &mut self.world.borrow_mut().as_symbol_table_ref())?; + // let a = self.world.borrow_mut(); // let component_ref = builder(ns, name, ver.clone())?; // let is_new = self // .world @@ -59,8 +60,7 @@ impl WorldBuilder { // version: ver // } // ); - // Ok(component_ref) - todo!() + Ok(component_ref) } pub fn find_component(&self, id: &ComponentId) -> Option { diff --git a/hir/src/dialects/builtin/ops/component.rs b/hir/src/dialects/builtin/ops/component.rs index fd98f4698..36f450792 100644 --- a/hir/src/dialects/builtin/ops/component.rs +++ b/hir/src/dialects/builtin/ops/component.rs @@ -1,5 +1,7 @@ mod interface; +use core::borrow::BorrowMut; + pub use self::interface::{ ComponentExport, ComponentId, ComponentInterface, ModuleExport, ModuleInterface, }; @@ -198,7 +200,7 @@ impl SymbolTable for Component { #[inline(always)] fn as_symbol_table_ref(&self) -> SymbolTableRef { - todo!() + unsafe { SymbolTableRef::from_raw(self) } } #[inline(always)] diff --git a/hir/src/dialects/builtin/ops/interface.rs b/hir/src/dialects/builtin/ops/interface.rs index d35ee6844..14a486f5b 100644 --- a/hir/src/dialects/builtin/ops/interface.rs +++ b/hir/src/dialects/builtin/ops/interface.rs @@ -121,7 +121,7 @@ impl SymbolTable for Interface { #[inline(always)] fn as_symbol_table_ref(&self) -> SymbolTableRef { - todo!() + unsafe { SymbolTableRef::from_raw(self) } } #[inline(always)] diff --git a/hir/src/dialects/builtin/ops/module.rs b/hir/src/dialects/builtin/ops/module.rs index b06899146..8777dc677 100644 --- a/hir/src/dialects/builtin/ops/module.rs +++ b/hir/src/dialects/builtin/ops/module.rs @@ -178,7 +178,7 @@ impl SymbolTable for Module { #[inline(always)] fn as_symbol_table_ref(&self) -> SymbolTableRef { - todo!() + unsafe { SymbolTableRef::from_raw(self) } } #[inline(always)] diff --git a/hir/src/dialects/builtin/ops/world.rs b/hir/src/dialects/builtin/ops/world.rs index 71397a4e6..4dc93cf9e 100644 --- a/hir/src/dialects/builtin/ops/world.rs +++ b/hir/src/dialects/builtin/ops/world.rs @@ -71,7 +71,7 @@ impl SymbolTable for World { #[inline(always)] fn as_symbol_table_ref(&self) -> SymbolTableRef { - todo!() + unsafe { SymbolTableRef::from_raw(self) } } #[inline(always)] From bf2b41b7a77524e83eb44c34779dd8e75c4d51f4 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Wed, 21 May 2025 12:55:05 -0300 Subject: [PATCH 17/78] Comment out dbg! Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 65379d47a..4cd37781b 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -145,7 +145,7 @@ impl OpDefinition { } fn hydrate(&mut self, fields: darling::ast::Fields) -> darling::Result<()> { - std::dbg!(&self.traits); + // std::dbg!(&self.traits); let named_fields = match &mut self.op.fields { syn::Fields::Named(syn::FieldsNamed { ref mut named, .. }) => named, _ => unreachable!(), @@ -201,8 +201,8 @@ impl OpDefinition { let field_ty = field.ty.clone(); let op_field_ty = field.attrs.pseudo_type(); - std::dbg!(&field); - std::dbg!(&op_field_ty); + // std::dbg!(&field); + // std::dbg!(&op_field_ty); match op_field_ty.as_deref() { // Forwarded field None => { @@ -265,8 +265,8 @@ impl OpDefinition { self.operands.push(OpOperandGroup::Named(field_name, field_ty)); } Some(OperationFieldType::Jamon) => { - std::dbg!("MANTECA MANTECA"); - std::dbg!(&field_ty); + // std::dbg!("MANTECA MANTECA"); + // std::dbg!(&field_ty); create_params.push(OpCreateParam { param_ty: OpCreateParamType::CustomField(field_name.clone(), field_ty), r#default: field.attrs.default.is_present(), From 0e0dc1ee2f1419cd51a6687c6000f761c7f62250 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Wed, 21 May 2025 12:55:48 -0300 Subject: [PATCH 18/78] Add lifetime parameters to variable Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 4cd37781b..5b8b7b78a 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -383,11 +383,12 @@ impl OpDefinition { if self.traits.iter().any(|tr| tr.get_ident().unwrap().to_string() == "Fideos") { let parent_jamon_name = Ident::new("dinosaurio", proc_macro2::Span::call_site()); + let lifetime = syn::Lifetime::new("'a", proc_macro2::Span::call_site()); let c = syn::Type::Reference(syn::TypeReference { and_token: syn::token::And(proc_macro2::Span::call_site()), - lifetime: None, + lifetime: Some(lifetime), mutability: Some(syn::token::Mut(proc_macro2::Span::call_site())), - elem: Box::new(make_type("SymbolTableRef")), + elem: Box::new(make_type("SymbolManagerMut")), }); // let c = make_type("SymbolManagerMut<'_>"); create_params.push(OpCreateParam { From 80bd1704047a2c729071fc410ee41ff970ce1025 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Wed, 21 May 2025 15:44:20 -0300 Subject: [PATCH 19/78] Create a lifetime + remove call to get_symbol_manager_mut Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 21 ++++++++++++++++++--- hir/src/dialects/builtin/builders/world.rs | 3 ++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 5b8b7b78a..6db324ee9 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -93,6 +93,7 @@ impl OpDefinition { // std::dbg!(&fields); let mut named_fields = syn::punctuated::Punctuated::::new(); + // Add the `op` field (which holds the underlying Operation) named_fields.push(syn::Field { attrs: vec![], @@ -417,11 +418,12 @@ impl OpDefinition { Ok(()) } } + impl FromDeriveInput for OpDefinition { fn from_derive_input(input: &syn::DeriveInput) -> darling::Result { let span = input.span(); let mut operation = Operation::from_derive_input(input)?; - // std::dbg!(&operation); + Self::from_operation(span, &mut operation) } } @@ -645,7 +647,7 @@ impl quote::ToTokens for BuildOp<'_> { std::dbg!("ROQUEFORT"); std::dbg!("Hay definido un parent"); tokens.extend(quote! { - op.as_ref().map(|op| #name.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid)); + op.as_ref().map(|op| #name.insert_new(*op, crate::ProgramPoint::Invalid)); }); } }; @@ -735,7 +737,20 @@ impl quote::ToTokens for BuildOp<'_> { impl quote::ToTokens for OpCreateFn<'_> { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { let dialect = &self.op.dialect; - let (impl_generics, _, where_clause) = self.generics.split_for_impl(); + + // Create a new Lifetime + let lifetime: syn::Lifetime = syn::Lifetime::new("'a", proc_macro2::Span::call_site()); + let lifetime = syn::LifetimeParam::new(lifetime); + + // Create a LifetimeDef + // let lifetime_def = syn::LifetimeDef::new(lifetime); + + // self.generics.params.insert(0, syn::GenericParam::Lifetime(lifetime)); + //https://users.rust-lang.org/t/add-lifetime-to-procedural-macro/97988/4 + let mut generics = self.generics.clone(); + generics.params.insert(0, syn::GenericParam::Lifetime(lifetime)); + + let (impl_generics, _, where_clause) = generics.split_for_impl(); let param_names = self.op.op_builder_impl.create_params.iter().flat_map(OpCreateParam::bindings); let param_types = self diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index 15a4248ff..d50cd91eb 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -43,7 +43,8 @@ impl WorldBuilder { ) -> Result { let builder = PrimComponentBuilder::new(&mut self.builder, name.span()); let component_ref = - builder(ns, name, ver.clone(), &mut self.world.borrow_mut().as_symbol_table_ref())?; + builder(ns, name, ver.clone(), &mut self.world.borrow_mut().symbol_manager_mut())?; + // builder(ns, name, ver.clone(),)?; // let a = self.world.borrow_mut(); // let component_ref = builder(ns, name, ver.clone())?; // let is_new = self From fcb87a8218d857bb8e68beceeed5db70ac0945fe Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Wed, 21 May 2025 18:41:40 -0300 Subject: [PATCH 20/78] Revert "Create a lifetime + remove call to get_symbol_manager_mut" This reverts commit 80bd1704047a2c729071fc410ee41ff970ce1025. --- hir-macros/src/operation.rs | 21 +++------------------ hir/src/dialects/builtin/builders/world.rs | 3 +-- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 6db324ee9..5b8b7b78a 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -93,7 +93,6 @@ impl OpDefinition { // std::dbg!(&fields); let mut named_fields = syn::punctuated::Punctuated::::new(); - // Add the `op` field (which holds the underlying Operation) named_fields.push(syn::Field { attrs: vec![], @@ -418,12 +417,11 @@ impl OpDefinition { Ok(()) } } - impl FromDeriveInput for OpDefinition { fn from_derive_input(input: &syn::DeriveInput) -> darling::Result { let span = input.span(); let mut operation = Operation::from_derive_input(input)?; - + // std::dbg!(&operation); Self::from_operation(span, &mut operation) } } @@ -647,7 +645,7 @@ impl quote::ToTokens for BuildOp<'_> { std::dbg!("ROQUEFORT"); std::dbg!("Hay definido un parent"); tokens.extend(quote! { - op.as_ref().map(|op| #name.insert_new(*op, crate::ProgramPoint::Invalid)); + op.as_ref().map(|op| #name.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid)); }); } }; @@ -737,20 +735,7 @@ impl quote::ToTokens for BuildOp<'_> { impl quote::ToTokens for OpCreateFn<'_> { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { let dialect = &self.op.dialect; - - // Create a new Lifetime - let lifetime: syn::Lifetime = syn::Lifetime::new("'a", proc_macro2::Span::call_site()); - let lifetime = syn::LifetimeParam::new(lifetime); - - // Create a LifetimeDef - // let lifetime_def = syn::LifetimeDef::new(lifetime); - - // self.generics.params.insert(0, syn::GenericParam::Lifetime(lifetime)); - //https://users.rust-lang.org/t/add-lifetime-to-procedural-macro/97988/4 - let mut generics = self.generics.clone(); - generics.params.insert(0, syn::GenericParam::Lifetime(lifetime)); - - let (impl_generics, _, where_clause) = generics.split_for_impl(); + let (impl_generics, _, where_clause) = self.generics.split_for_impl(); let param_names = self.op.op_builder_impl.create_params.iter().flat_map(OpCreateParam::bindings); let param_types = self diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index d50cd91eb..15a4248ff 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -43,8 +43,7 @@ impl WorldBuilder { ) -> Result { let builder = PrimComponentBuilder::new(&mut self.builder, name.span()); let component_ref = - builder(ns, name, ver.clone(), &mut self.world.borrow_mut().symbol_manager_mut())?; - // builder(ns, name, ver.clone(),)?; + builder(ns, name, ver.clone(), &mut self.world.borrow_mut().as_symbol_table_ref())?; // let a = self.world.borrow_mut(); // let component_ref = builder(ns, name, ver.clone())?; // let is_new = self From a309e25ee274c6d567a372ea154faca712789263 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Wed, 21 May 2025 18:41:47 -0300 Subject: [PATCH 21/78] Revert "Add lifetime parameters to variable" This reverts commit 0e0dc1ee2f1419cd51a6687c6000f761c7f62250. --- hir-macros/src/operation.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 5b8b7b78a..4cd37781b 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -383,12 +383,11 @@ impl OpDefinition { if self.traits.iter().any(|tr| tr.get_ident().unwrap().to_string() == "Fideos") { let parent_jamon_name = Ident::new("dinosaurio", proc_macro2::Span::call_site()); - let lifetime = syn::Lifetime::new("'a", proc_macro2::Span::call_site()); let c = syn::Type::Reference(syn::TypeReference { and_token: syn::token::And(proc_macro2::Span::call_site()), - lifetime: Some(lifetime), + lifetime: None, mutability: Some(syn::token::Mut(proc_macro2::Span::call_site())), - elem: Box::new(make_type("SymbolManagerMut")), + elem: Box::new(make_type("SymbolTableRef")), }); // let c = make_type("SymbolManagerMut<'_>"); create_params.push(OpCreateParam { From 422adfef0f9843f2e44093f00e86ed43f696468a Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Wed, 21 May 2025 18:45:01 -0300 Subject: [PATCH 22/78] Add comment with explanation Signed-off-by: Tomas Fabrizio Orsi --- hir/src/dialects/builtin/builders/world.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index 15a4248ff..17c937c16 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -42,6 +42,9 @@ impl WorldBuilder { ver: Version, ) -> Result { let builder = PrimComponentBuilder::new(&mut self.builder, name.span()); + // This crashes with the following error + // AliasingViolationError { kind: Mutable, location: Location { file: "hir/src/dialects/builtin/builders/world.rs", line: 47, col: 60 } } + let component_ref = builder(ns, name, ver.clone(), &mut self.world.borrow_mut().as_symbol_table_ref())?; // let a = self.world.borrow_mut(); From 1b5b7f1d6a25bef52e73228120fcfb007aa0e0db Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Wed, 21 May 2025 18:48:31 -0300 Subject: [PATCH 23/78] Add new comment explaining fix Signed-off-by: Tomas Fabrizio Orsi --- hir/src/dialects/builtin/builders/world.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index 17c937c16..0af907f9c 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -45,8 +45,12 @@ impl WorldBuilder { // This crashes with the following error // AliasingViolationError { kind: Mutable, location: Location { file: "hir/src/dialects/builtin/builders/world.rs", line: 47, col: 60 } } - let component_ref = - builder(ns, name, ver.clone(), &mut self.world.borrow_mut().as_symbol_table_ref())?; + // But with this tmp variable, it does not crash. All tests pass. + // I'll procede to check if the symbol table is actually updated. But it's something :D + let tmp = &mut self.world.borrow_mut().as_symbol_table_ref(); + + let component_ref = builder(ns, name, ver.clone(), tmp)?; + // let a = self.world.borrow_mut(); // let component_ref = builder(ns, name, ver.clone())?; // let is_new = self From 202a8b8c51c1808bdb12a4567bdf4de97998ec5d Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 09:53:33 -0300 Subject: [PATCH 24/78] Add assert code in auto-generated after adding an item to the symbol table Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 13 ++++++++++++- hir/src/dialects/builtin/builders/world.rs | 20 ++------------------ 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 4cd37781b..cb26c06e1 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -644,7 +644,18 @@ impl quote::ToTokens for BuildOp<'_> { std::dbg!("ROQUEFORT"); std::dbg!("Hay definido un parent"); tokens.extend(quote! { - op.as_ref().map(|op| #name.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid)); + op.as_ref().map(|op| { + let is_new = #name.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid); + assert!( + is_new, + "component already exists in world" + // ComponentId { + // namespace: ns.name, + // name: name.name, + // version: ver + // } + ); + }); }); } }; diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index 0af907f9c..83a7cddd3 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -42,31 +42,15 @@ impl WorldBuilder { ver: Version, ) -> Result { let builder = PrimComponentBuilder::new(&mut self.builder, name.span()); - // This crashes with the following error + // Without the tmp variable, this crashes with the following error // AliasingViolationError { kind: Mutable, location: Location { file: "hir/src/dialects/builtin/builders/world.rs", line: 47, col: 60 } } - // But with this tmp variable, it does not crash. All tests pass. + // With this tmp variable, it does not crash. All tests pass. // I'll procede to check if the symbol table is actually updated. But it's something :D let tmp = &mut self.world.borrow_mut().as_symbol_table_ref(); let component_ref = builder(ns, name, ver.clone(), tmp)?; - // let a = self.world.borrow_mut(); - // let component_ref = builder(ns, name, ver.clone())?; - // let is_new = self - // .world - // .borrow_mut() - // .symbol_manager_mut() - // .insert_new(component_ref, crate::ProgramPoint::Invalid); - // assert!( - // is_new, - // "component {} already exists in world", - // ComponentId { - // namespace: ns.name, - // name: name.name, - // version: ver - // } - // ); Ok(component_ref) } From ea15723d540370735c1a58a4a0a3294048617d46 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 10:09:40 -0300 Subject: [PATCH 25/78] Remove unused OperationFieldType since now belonging to a symbol table is now a trait Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index cb26c06e1..36ade47ee 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -264,28 +264,6 @@ impl OpDefinition { }); self.operands.push(OpOperandGroup::Named(field_name, field_ty)); } - Some(OperationFieldType::Jamon) => { - // std::dbg!("MANTECA MANTECA"); - // std::dbg!(&field_ty); - create_params.push(OpCreateParam { - param_ty: OpCreateParamType::CustomField(field_name.clone(), field_ty), - r#default: field.attrs.default.is_present(), - }); - // TODO: Remove from fields, only used when building - named_fields.push(syn::Field { - attrs: field.attrs.forwarded, - vis: field.vis, - mutability: syn::FieldMutability::None, - ident: Some(field_name.clone()), - colon_token: Some(syn::token::Colon(field_span)), - ty: field.ty, - }); - self.parent_jamon = Some(OpJamon { - name: field_name, - // span: field_span, - }); - // continue; - } Some(OperationFieldType::Result) => { let result = OpResult { name: field_name.clone(), @@ -2393,8 +2371,6 @@ impl OperationFieldAttrs { self.symbol .as_ref() .map(|sym| sym.map_ref(|sym| OperationFieldType::Symbol(sym.clone()))) - } else if self.jamon.is_present() { - Some(SpannedValue::new(OperationFieldType::Jamon, self.jamon.span())) } else { None } @@ -2418,8 +2394,6 @@ pub enum OperationFieldType { Region, /// A named successor Successor, - /// Parent symbol table - Jamon, /// A named variadic successor group (zero or more successors) Successors(SuccessorsType), /// A symbol operand @@ -2438,7 +2412,6 @@ impl core::fmt::Display for OperationFieldType { Self::Attr(AttrKind::Default) => f.write_str("attr"), Self::Attr(AttrKind::Hidden) => f.write_str("attr(hidden)"), Self::Operand => f.write_str("operand"), - Self::Jamon => f.write_str("jamon"), Self::Operands => f.write_str("operands"), Self::Result => f.write_str("result"), Self::Results => f.write_str("results"), From c0343dcd000f475d9102ca96b59652b43217e093 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 10:49:33 -0300 Subject: [PATCH 26/78] WIP: Rename variables and remove deleted code Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 36ade47ee..c23e735ce 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -358,39 +358,31 @@ impl OpDefinition { } } - if self.traits.iter().any(|tr| tr.get_ident().unwrap().to_string() == "Fideos") { - let parent_jamon_name = Ident::new("dinosaurio", proc_macro2::Span::call_site()); + if self.traits.iter().any(|tr| tr.get_ident().unwrap() == "Fideos") { + let parent_symbol_table = + Ident::new("parent_symbol_table", proc_macro2::Span::call_site()); - let c = syn::Type::Reference(syn::TypeReference { + let parent_symbol_type = syn::Type::Reference(syn::TypeReference { and_token: syn::token::And(proc_macro2::Span::call_site()), lifetime: None, mutability: Some(syn::token::Mut(proc_macro2::Span::call_site())), elem: Box::new(make_type("SymbolTableRef")), }); - // let c = make_type("SymbolManagerMut<'_>"); + create_params.push(OpCreateParam { - param_ty: OpCreateParamType::Mandioca(parent_jamon_name.clone(), c), + param_ty: OpCreateParamType::Mandioca( + parent_symbol_table.clone(), + parent_symbol_type, + ), r#default: false, }); self.parent_jamon = Some(OpJamon { - name: parent_jamon_name, - // span: field_span, + name: parent_symbol_table, }); } self.op_builder_impl.set_create_params(&self.op.generics, create_params); - // for tr in self.traits.iter() { - // std::dbg!("BARRIl"); - // std::dbg!(tr.get_ident().unwrap().to_string()); - // } - // // if *tr.get_ident().unwrap() == <&str as Into>::into("Fideos") { - // // std::dbg!("BANDERA"); - // // } else { - // // std::dbg!("TERMO"); - // // }; - // } - Ok(()) } } @@ -1547,7 +1539,6 @@ pub struct OpResult { #[derive(Debug, Clone)] pub struct OpJamon { pub name: Ident, - // pub span: proc_macro2::Span, } pub type OpResultGroup = EntityGroup; From 7a395a5535ea294c008bd2404f4d91fa7350f8cd Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 10:54:29 -0300 Subject: [PATCH 27/78] Remove un-usued struct decorator, since now a trait is used. Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 21 --------------------- hir/src/dialects/builtin/ops/component.rs | 2 -- 2 files changed, 23 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index c23e735ce..585c93497 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -727,7 +727,6 @@ impl quote::ToTokens for OpCreateFn<'_> { let initialize_custom_fields = InitializeCustomFields(self.op); let with_symbols = WithSymbols(self.op); let with_attrs = WithAttrs(self.op); - let with_jamon = WithJamon(self.op); let with_operands = WithOperands(self.op); let with_results = WithResults(self.op); let with_regions = self.op.regions.iter().map(|_| { @@ -785,7 +784,6 @@ impl quote::ToTokens for OpCreateFn<'_> { )* #with_successors #with_results - // #with_jamon // Finalize construction of this op, verifying it #build_op @@ -2839,22 +2837,3 @@ mod tests { } } } - -struct WithJamon<'a>(&'a OpDefinition); -impl quote::ToTokens for WithJamon<'_> { - fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { - match self.0.parent_jamon.as_ref() { - None => { - std::dbg!("No hay definido un parent"); - } - Some(OpJamon { name }) => { - std::dbg!("Hay definido un parent"); - tokens.extend(quote! { - #name.borrow().as_symbol_table_operation(); - // core::ptr::addr_of_mut!((*__ptr).#id).write(#id); - std::dbg!("DBG quoteado de with_jamon"); - }) - } - } - } -} diff --git a/hir/src/dialects/builtin/ops/component.rs b/hir/src/dialects/builtin/ops/component.rs index 36f450792..31b504fdf 100644 --- a/hir/src/dialects/builtin/ops/component.rs +++ b/hir/src/dialects/builtin/ops/component.rs @@ -82,8 +82,6 @@ pub struct Component { name: Ident, #[attr] version: Version, - // #[jamon] - // crema: SymbolTableRef, #[attr] #[default] visibility: Visibility, From 9d7e716efe1bbc386fd111aebda4bfbf58de07e7 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 12:22:30 -0300 Subject: [PATCH 28/78] Added Option to the SymbolTableRef Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 24 +++++++++++++--------- hir/src/dialects/builtin/builders/world.rs | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 585c93497..0fc3bdfb9 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -369,6 +369,8 @@ impl OpDefinition { elem: Box::new(make_type("SymbolTableRef")), }); + let parent_symbol_type = parse_quote! { Option< #parent_symbol_type >}; + create_params.push(OpCreateParam { param_ty: OpCreateParamType::Mandioca( parent_symbol_table.clone(), @@ -615,16 +617,18 @@ impl quote::ToTokens for BuildOp<'_> { std::dbg!("Hay definido un parent"); tokens.extend(quote! { op.as_ref().map(|op| { - let is_new = #name.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid); - assert!( - is_new, - "component already exists in world" - // ComponentId { - // namespace: ns.name, - // name: name.name, - // version: ver - // } - ); + if let Some(#name) = #name { + let is_new = #name.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid); + assert!( + is_new, + "component already exists in world" + // ComponentId { + // namespace: ns.name, + // name: name.name, + // version: ver + // } + ); + } }); }); } diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index 83a7cddd3..d790cf1b1 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -49,7 +49,7 @@ impl WorldBuilder { // I'll procede to check if the symbol table is actually updated. But it's something :D let tmp = &mut self.world.borrow_mut().as_symbol_table_ref(); - let component_ref = builder(ns, name, ver.clone(), tmp)?; + let component_ref = builder(ns, name, ver.clone(), Some(tmp))?; Ok(component_ref) } From 68b40232dd89edea96372ddebd19307db3afb48e Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 12:31:06 -0300 Subject: [PATCH 29/78] Added Fideos trait to Function, all test passing Signed-off-by: Tomas Fabrizio Orsi --- codegen/masm/src/lower/utils.rs | 3 +++ dialects/scf/src/transforms/cfg_to_scf.rs | 16 ++++++++-------- eval/src/tests.rs | 9 +++++++-- hir-macros/src/operation.rs | 7 +------ hir/src/dialects/builtin/builders.rs | 7 ++++--- hir/src/dialects/builtin/builders/component.rs | 15 ++++++++------- hir/src/dialects/builtin/builders/module.rs | 15 ++++++++------- hir/src/dialects/builtin/ops/function.rs | 10 +++++----- hir/src/matchers/matcher.rs | 4 ++-- hir/src/patterns/pattern.rs | 4 ++-- 10 files changed, 48 insertions(+), 42 deletions(-) diff --git a/codegen/masm/src/lower/utils.rs b/codegen/masm/src/lower/utils.rs index 64b71d032..7c7368029 100644 --- a/codegen/masm/src/lower/utils.rs +++ b/codegen/masm/src/lower/utils.rs @@ -517,6 +517,7 @@ mod tests { [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), + None, )?; let (a, b) = { @@ -604,6 +605,7 @@ mod tests { [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), + None, )?; let (a, b) = { @@ -834,6 +836,7 @@ mod tests { [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), + None, )?; let (a, b) = { diff --git a/dialects/scf/src/transforms/cfg_to_scf.rs b/dialects/scf/src/transforms/cfg_to_scf.rs index f54aa919b..7025ec822 100644 --- a/dialects/scf/src/transforms/cfg_to_scf.rs +++ b/dialects/scf/src/transforms/cfg_to_scf.rs @@ -385,10 +385,10 @@ mod tests { let span = SourceSpan::default(); let mut function = { - let builder = builder.create::(span); + let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature).unwrap() + builder(name, signature, None).unwrap() }; // Define function body @@ -444,10 +444,10 @@ mod tests { let span = SourceSpan::default(); let mut function = { - let builder = builder.create::(span); + let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature).unwrap() + builder(name, signature, None).unwrap() }; // Define function body @@ -505,7 +505,7 @@ mod tests { let span = SourceSpan::default(); let mut function = { - let builder = builder.create::(span); + let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new( [ @@ -515,7 +515,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature).unwrap() + builder(name, signature, None).unwrap() }; // Define function body for the following pseudocode: @@ -620,7 +620,7 @@ mod tests { let span = SourceSpan::default(); let mut function = { - let builder = builder.create::(span); + let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new( [ @@ -630,7 +630,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature).unwrap() + builder(name, signature, None).unwrap() }; // Define function body for the following pseudocode: diff --git a/eval/src/tests.rs b/eval/src/tests.rs index 44c2784cd..8514b3a62 100644 --- a/eval/src/tests.rs +++ b/eval/src/tests.rs @@ -75,6 +75,7 @@ fn eval_callable_test() -> Result<(), Report> { let mut function = builder.create_function( Ident::with_empty_span("test".into()), Signature::new([AbiParam::new(Type::I1)], [AbiParam::new(Type::U32)]), + None, )?; { @@ -129,6 +130,7 @@ fn call_handling_test() -> Result<(), Report> { let mut entry = builder.create_function( Ident::with_empty_span("entrypoint".into()), Signature::new([AbiParam::new(Type::I1)], [AbiParam::new(Type::U32)]), + None, )?; module .borrow_mut() @@ -137,8 +139,11 @@ fn call_handling_test() -> Result<(), Report> { // Define callee let callee_signature = Signature::new([AbiParam::new(Type::I1)], [AbiParam::new(Type::I1)]); - let mut callee = builder - .create_function(Ident::with_empty_span("callee".into()), callee_signature.clone())?; + let mut callee = builder.create_function( + Ident::with_empty_span("callee".into()), + callee_signature.clone(), + None, + )?; module .borrow_mut() .symbol_manager_mut() diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 0fc3bdfb9..fe3fdecfb 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -608,13 +608,8 @@ impl quote::ToTokens for BuildOp<'_> { let op = op_builder.build(); }); match self.0.parent_jamon.as_ref() { - None => { - std::dbg!("No hay definido un parent"); - std::dbg!("PODRIDO"); - } + None => {} Some(OpJamon { name }) => { - std::dbg!("ROQUEFORT"); - std::dbg!("Hay definido un parent"); tokens.extend(quote! { op.as_ref().map(|op| { if let Some(#name) = #name { diff --git a/hir/src/dialects/builtin/builders.rs b/hir/src/dialects/builtin/builders.rs index 5e0bbff28..92a2b8e0a 100644 --- a/hir/src/dialects/builtin/builders.rs +++ b/hir/src/dialects/builtin/builders.rs @@ -7,7 +7,7 @@ pub use self::{component::*, function::*, module::*, world::*}; use super::ops::*; use crate::{ constants::ConstantData, Builder, BuilderExt, Ident, Immediate, OpBuilder, Report, Signature, - SourceSpan, Spanned, Type, UnsafeIntrusiveEntityRef, ValueRef, Visibility, + SourceSpan, Spanned, SymbolTableRef, Type, UnsafeIntrusiveEntityRef, ValueRef, Visibility, }; pub trait BuiltinOpBuilder<'f, B: ?Sized + Builder> { @@ -25,9 +25,10 @@ pub trait BuiltinOpBuilder<'f, B: ?Sized + Builder> { &mut self, name: Ident, signature: Signature, + parent_symbol_table: Option<&mut SymbolTableRef>, ) -> Result { - let op_builder = self.builder_mut().create::(name.span()); - op_builder(name, signature) + let op_builder = self.builder_mut().create::(name.span()); + op_builder(name, signature, parent_symbol_table) } fn create_global_variable( diff --git a/hir/src/dialects/builtin/builders/component.rs b/hir/src/dialects/builtin/builders/component.rs index f6273a0d0..a5b63ee6e 100644 --- a/hir/src/dialects/builtin/builders/component.rs +++ b/hir/src/dialects/builtin/builders/component.rs @@ -66,13 +66,14 @@ impl ComponentBuilder { name: Ident, signature: Signature, ) -> Result { - let function_ref = self.builder.create_function(name, signature)?; - let is_new = self - .component - .borrow_mut() - .symbol_manager_mut() - .insert_new(function_ref, crate::ProgramPoint::Invalid); - assert!(is_new, "function with the name {name} already exists"); + let tmp = &mut self.component.borrow_mut().as_symbol_table_ref(); + let function_ref = self.builder.create_function(name, signature, Some(tmp))?; + // let is_new = self + // .component + // .borrow_mut() + // .symbol_manager_mut() + // .insert_new(function_ref, crate::ProgramPoint::Invalid); + // assert!(is_new, "function with the name {name} already exists"); Ok(function_ref) } } diff --git a/hir/src/dialects/builtin/builders/module.rs b/hir/src/dialects/builtin/builders/module.rs index f61fca08e..38865971a 100644 --- a/hir/src/dialects/builtin/builders/module.rs +++ b/hir/src/dialects/builtin/builders/module.rs @@ -51,13 +51,14 @@ impl ModuleBuilder { name: Ident, signature: Signature, ) -> Result { - let function_ref = self.builder.create_function(name, signature)?; - let is_new = self - .module - .borrow_mut() - .symbol_manager_mut() - .insert_new(function_ref, crate::ProgramPoint::Invalid); - assert!(is_new, "function with the name {name} already exists"); + let tmp = &mut self.module.borrow_mut().as_symbol_table_ref(); + let function_ref = self.builder.create_function(name, signature, Some(tmp))?; + // let is_new = self + // .module + // .borrow_mut() + // .symbol_manager_mut() + // .insert_new(function_ref, crate::ProgramPoint::Invalid); + // assert!(is_new, "function with the name {name} already exists"); Ok(function_ref) } diff --git a/hir/src/dialects/builtin/ops/function.rs b/hir/src/dialects/builtin/ops/function.rs index 95004f693..64d84f489 100644 --- a/hir/src/dialects/builtin/ops/function.rs +++ b/hir/src/dialects/builtin/ops/function.rs @@ -6,11 +6,11 @@ use crate::{ define_attr_type, derive::operation, dialects::builtin::BuiltinDialect, - traits::{AnyType, IsolatedFromAbove, ReturnLike, SingleRegion, Terminator}, + traits::{AnyType, Fideos, IsolatedFromAbove, ReturnLike, SingleRegion, Terminator}, AttrPrinter, BlockRef, CallableOpInterface, Context, Ident, Immediate, Op, OpPrinter, OpPrintingFlags, Operation, RegionKind, RegionKindInterface, RegionRef, Signature, Symbol, - SymbolName, SymbolUse, SymbolUseList, Type, UnsafeIntrusiveEntityRef, Usable, ValueRef, - Visibility, + SymbolName, SymbolTableRef, SymbolUse, SymbolUseList, Type, UnsafeIntrusiveEntityRef, Usable, + ValueRef, Visibility, }; trait UsableSymbol = Usable; @@ -75,13 +75,13 @@ impl AttrPrinter for LocalVariable { #[operation( dialect = BuiltinDialect, - traits(SingleRegion, IsolatedFromAbove), + traits(SingleRegion, IsolatedFromAbove, Fideos), implements( UsableSymbol, Symbol, CallableOpInterface, RegionKindInterface, - OpPrinter + OpPrinter, ) )] pub struct Function { diff --git a/hir/src/matchers/matcher.rs b/hir/src/matchers/matcher.rs index a381e2451..2dbaf531b 100644 --- a/hir/src/matchers/matcher.rs +++ b/hir/src/matchers/matcher.rs @@ -753,10 +753,10 @@ mod tests { let mut builder = OpBuilder::new(Rc::clone(&context)); let mut function = { - let builder = builder.create::(SourceSpan::default()); + let builder = builder.create::(SourceSpan::default()); let name = Ident::new("test".into(), SourceSpan::default()); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature).unwrap() + builder(name, signature, None).unwrap() }; // Define function body diff --git a/hir/src/patterns/pattern.rs b/hir/src/patterns/pattern.rs index 73a71ffa0..e5a4870a2 100644 --- a/hir/src/patterns/pattern.rs +++ b/hir/src/patterns/pattern.rs @@ -328,10 +328,10 @@ mod tests { let mut builder = OpBuilder::new(Rc::clone(&context)); let mut function = { - let builder = builder.create::(SourceSpan::default()); + let builder = builder.create::(SourceSpan::default()); let name = Ident::new("test".into(), SourceSpan::default()); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature).unwrap() + builder(name, signature, None).unwrap() }; // Define function body From 86a97dae34e0bf7cfa7b92afb432a5b52f2ef6a0 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 12:41:25 -0300 Subject: [PATCH 30/78] Added Fideos trait to module Signed-off-by: Tomas Fabrizio Orsi --- eval/src/tests.rs | 2 +- hir/src/dialects/builtin/builders.rs | 10 +++++--- .../dialects/builtin/builders/component.rs | 23 ++++++++++--------- hir/src/dialects/builtin/builders/module.rs | 15 ++++++------ hir/src/dialects/builtin/builders/world.rs | 15 ++++++------ hir/src/dialects/builtin/ops/module.rs | 3 ++- 6 files changed, 38 insertions(+), 30 deletions(-) diff --git a/eval/src/tests.rs b/eval/src/tests.rs index 8514b3a62..5c901f9e9 100644 --- a/eval/src/tests.rs +++ b/eval/src/tests.rs @@ -121,7 +121,7 @@ fn call_handling_test() -> Result<(), Report> { let mut builder = OpBuilder::new(test_context.context.clone()); - let mut module = builder.create_module(Ident::with_empty_span("test".into()))?; + let mut module = builder.create_module(Ident::with_empty_span("test".into()), None)?; let module_body = module.borrow().body().as_region_ref(); builder.create_block(module_body, None, &[]); diff --git a/hir/src/dialects/builtin/builders.rs b/hir/src/dialects/builtin/builders.rs index 92a2b8e0a..7f305afaa 100644 --- a/hir/src/dialects/builtin/builders.rs +++ b/hir/src/dialects/builtin/builders.rs @@ -16,9 +16,13 @@ pub trait BuiltinOpBuilder<'f, B: ?Sized + Builder> { op_builder(name) } - fn create_module(&mut self, name: Ident) -> Result { - let op_builder = self.builder_mut().create::(name.span()); - op_builder(name) + fn create_module( + &mut self, + name: Ident, + parent_symbol_table: Option<&mut SymbolTableRef>, + ) -> Result { + let op_builder = self.builder_mut().create::(name.span()); + op_builder(name, parent_symbol_table) } fn create_function( diff --git a/hir/src/dialects/builtin/builders/component.rs b/hir/src/dialects/builtin/builders/component.rs index a5b63ee6e..0b6f24446 100644 --- a/hir/src/dialects/builtin/builders/component.rs +++ b/hir/src/dialects/builtin/builders/component.rs @@ -31,17 +31,18 @@ impl ComponentBuilder { } pub fn define_module(&mut self, name: Ident) -> Result { - let module_ref = self.builder.create_module(name)?; - let is_new = self - .component - .borrow_mut() - .symbol_manager_mut() - .insert_new(module_ref, crate::ProgramPoint::Invalid); - assert!( - is_new, - "module with the name {name} already exists in component {}", - self.component.borrow().name() - ); + let tmp = &mut self.component.borrow_mut().as_symbol_table_ref(); + let module_ref = self.builder.create_module(name, Some(tmp))?; + // let is_new = self + // .component + // .borrow_mut() + // .symbol_manager_mut() + // .insert_new(module_ref, crate::ProgramPoint::Invalid); + // assert!( + // is_new, + // "module with the name {name} already exists in component {}", + // self.component.borrow().name() + // ); Ok(module_ref) } diff --git a/hir/src/dialects/builtin/builders/module.rs b/hir/src/dialects/builtin/builders/module.rs index 38865971a..14f99a5b0 100644 --- a/hir/src/dialects/builtin/builders/module.rs +++ b/hir/src/dialects/builtin/builders/module.rs @@ -119,13 +119,14 @@ impl ModuleBuilder { /// Declare a new nested module `name` pub fn declare_module(&mut self, name: Ident) -> Result { let builder = PrimModuleBuilder::new(&mut self.builder, name.span()); - let module_ref = builder(name)?; - let is_new = self - .module - .borrow_mut() - .symbol_manager_mut() - .insert_new(module_ref, crate::ProgramPoint::Invalid); - assert!(is_new, "module with the name {name} already exists in world",); + let tmp = &mut self.module.borrow_mut().as_symbol_table_ref(); + let module_ref = builder(name, Some(tmp))?; + // let is_new = self + // .module + // .borrow_mut() + // .symbol_manager_mut() + // .insert_new(module_ref, crate::ProgramPoint::Invalid); + // assert!(is_new, "module with the name {name} already exists in world",); Ok(module_ref) } diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index d790cf1b1..611fea22c 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -66,13 +66,14 @@ impl WorldBuilder { /// Declare a new world-level module `name` pub fn declare_module(&mut self, name: Ident) -> Result { let builder = PrimModuleBuilder::new(&mut self.builder, name.span()); - let module_ref = builder(name)?; - let is_new = self - .world - .borrow_mut() - .symbol_manager_mut() - .insert_new(module_ref, crate::ProgramPoint::Invalid); - assert!(is_new, "module with the name {name} already exists in world",); + let tmp = &mut self.world.borrow_mut().as_symbol_table_ref(); + let module_ref = builder(name, Some(tmp))?; + // let is_new = self + // .world + // .borrow_mut() + // .symbol_manager_mut() + // .insert_new(module_ref, crate::ProgramPoint::Invalid); + // assert!(is_new, "module with the name {name} already exists in world",); Ok(module_ref) } diff --git a/hir/src/dialects/builtin/ops/module.rs b/hir/src/dialects/builtin/ops/module.rs index 8777dc677..55744c2cf 100644 --- a/hir/src/dialects/builtin/ops/module.rs +++ b/hir/src/dialects/builtin/ops/module.rs @@ -2,7 +2,7 @@ use crate::{ derive::operation, dialects::builtin::BuiltinDialect, traits::{ - GraphRegionNoTerminator, HasOnlyGraphRegion, IsolatedFromAbove, NoRegionArguments, + Fideos, GraphRegionNoTerminator, HasOnlyGraphRegion, IsolatedFromAbove, NoRegionArguments, NoTerminator, SingleBlock, SingleRegion, }, Ident, OpPrinter, Operation, RegionKind, RegionKindInterface, Symbol, SymbolManager, @@ -57,6 +57,7 @@ pub type ModuleRef = UnsafeIntrusiveEntityRef; HasOnlyGraphRegion, GraphRegionNoTerminator, IsolatedFromAbove, + Fideos, ), implements(RegionKindInterface, SymbolTable, Symbol, OpPrinter) )] From 788fec672f473791568200924a5ddfa387a4d6d0 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 12:49:26 -0300 Subject: [PATCH 31/78] Add Fideos trait to global trait Signed-off-by: Tomas Fabrizio Orsi --- hir/src/dialects/builtin/builders.rs | 5 +++-- hir/src/dialects/builtin/builders/module.rs | 16 +++++++++------- hir/src/dialects/builtin/ops/global_variable.rs | 7 ++++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/hir/src/dialects/builtin/builders.rs b/hir/src/dialects/builtin/builders.rs index 7f305afaa..ceb677238 100644 --- a/hir/src/dialects/builtin/builders.rs +++ b/hir/src/dialects/builtin/builders.rs @@ -40,9 +40,10 @@ pub trait BuiltinOpBuilder<'f, B: ?Sized + Builder> { name: Ident, visibility: Visibility, ty: Type, + parent_symbol_table: Option<&mut SymbolTableRef>, ) -> Result { - let op_builder = self.builder_mut().create::(name.span()); - op_builder(name, visibility, ty) + let op_builder = self.builder_mut().create::(name.span()); + op_builder(name, visibility, ty, parent_symbol_table) } fn create_data_segment( diff --git a/hir/src/dialects/builtin/builders/module.rs b/hir/src/dialects/builtin/builders/module.rs index 14f99a5b0..be771b90b 100644 --- a/hir/src/dialects/builtin/builders/module.rs +++ b/hir/src/dialects/builtin/builders/module.rs @@ -72,13 +72,15 @@ impl ModuleBuilder { visibility: Visibility, ty: Type, ) -> Result, Report> { - let global_var_ref = self.builder.create_global_variable(name, visibility, ty)?; - let is_new = self - .module - .borrow_mut() - .symbol_manager_mut() - .insert_new(global_var_ref, crate::ProgramPoint::Invalid); - assert!(is_new, "global variable with the name {name} already exists"); + let tmp = &mut self.module.borrow_mut().as_symbol_table_ref(); + let global_var_ref = + self.builder.create_global_variable(name, visibility, ty, Some(tmp))?; + // let is_new = self + // .module + // .borrow_mut() + // .symbol_manager_mut() + // .insert_new(global_var_ref, crate::ProgramPoint::Invalid); + // assert!(is_new, "global variable with the name {name} already exists"); Ok(global_var_ref) } diff --git a/hir/src/dialects/builtin/ops/global_variable.rs b/hir/src/dialects/builtin/ops/global_variable.rs index c46c0cf10..7cb31eba0 100644 --- a/hir/src/dialects/builtin/ops/global_variable.rs +++ b/hir/src/dialects/builtin/ops/global_variable.rs @@ -8,12 +8,12 @@ use crate::{ MemoryEffect, MemoryEffectOpInterface, Pure, }, traits::{ - InferTypeOpInterface, IsolatedFromAbove, NoRegionArguments, PointerOf, SingleBlock, + Fideos, InferTypeOpInterface, IsolatedFromAbove, NoRegionArguments, PointerOf, SingleBlock, SingleRegion, UInt8, }, AsSymbolRef, Context, Ident, Op, OpPrinter, Operation, PointerType, Report, Spanned, Symbol, - SymbolName, SymbolRef, SymbolUseList, Type, UnsafeIntrusiveEntityRef, Usable, Value, - Visibility, + SymbolName, SymbolRef, SymbolTableRef, SymbolUseList, Type, UnsafeIntrusiveEntityRef, Usable, + Value, Visibility, }; pub type GlobalVariableRef = UnsafeIntrusiveEntityRef; @@ -34,6 +34,7 @@ pub type GlobalVariableRef = UnsafeIntrusiveEntityRef; SingleBlock, NoRegionArguments, IsolatedFromAbove, + Fideos, ), implements(Symbol, OpPrinter) )] From 9bdb574c889425f95fac4e062996e2410308d82f Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 14:46:56 -0300 Subject: [PATCH 32/78] Make assert string generic Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index fe3fdecfb..3df0fca90 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -616,12 +616,9 @@ impl quote::ToTokens for BuildOp<'_> { let is_new = #name.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid); assert!( is_new, - "component already exists in world" - // ComponentId { - // namespace: ns.name, - // name: name.name, - // version: ver - // } + "{} already exists in {}", + op.borrow().name(), + #name.borrow().as_symbol_table_operation().name() ); } }); From 7137690e88522f0af12802c4fcac2c5cd0f0c29a Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 14:57:51 -0300 Subject: [PATCH 33/78] Remove dbg prints Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/lib.rs | 3 --- hir-macros/src/operation.rs | 11 ----------- 2 files changed, 14 deletions(-) diff --git a/hir-macros/src/lib.rs b/hir-macros/src/lib.rs index c05857727..7f7119b61 100644 --- a/hir-macros/src/lib.rs +++ b/hir-macros/src/lib.rs @@ -66,7 +66,6 @@ pub fn operation( item: proc_macro::TokenStream, ) -> proc_macro::TokenStream { let attr = proc_macro2::TokenStream::from(attr); - // std::dbg!(&attr); let mut input = syn::parse_macro_input!(item as syn::ItemStruct); let span = input.span(); @@ -87,8 +86,6 @@ pub fn operation( let input = syn::parse_quote! { #input }; - // std::dbg!(&input); - // Sigue estando jamon match operation::derive_operation(input) { Ok(token_stream) => proc_macro::TokenStream::from(token_stream), diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 3df0fca90..d449b7d6b 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -10,9 +10,6 @@ use syn::{parse_quote, spanned::Spanned, Ident, Token}; pub fn derive_operation(input: syn::DeriveInput) -> darling::Result { let op = OpDefinition::from_derive_input(&input)?; - // if op.name == - // std::dbg!(&input); - // Sigue teniendo jamon // This method is implicitly implemented using `to_tokens`, and acts as a // convenience method for consumers of the `ToTokens` trait. @@ -77,10 +74,8 @@ impl OpDefinition { format_ident!("{name}", span = name.span()) }); let traits = core::mem::take(&mut op.traits); - // std::dbg!(&traits); let implements = core::mem::take(&mut op.implements); - // std::dbg!("NUEVOS FIELDS"); let fields = core::mem::replace( &mut op.data, darling::ast::Data::Struct(darling::ast::Fields::new( @@ -90,7 +85,6 @@ impl OpDefinition { ) .take_struct() .unwrap(); - // std::dbg!(&fields); let mut named_fields = syn::punctuated::Punctuated::::new(); // Add the `op` field (which holds the underlying Operation) @@ -145,14 +139,12 @@ impl OpDefinition { } fn hydrate(&mut self, fields: darling::ast::Fields) -> darling::Result<()> { - // std::dbg!(&self.traits); let named_fields = match &mut self.op.fields { syn::Fields::Named(syn::FieldsNamed { ref mut named, .. }) => named, _ => unreachable!(), }; let mut create_params = vec![]; let (_, mut fields) = fields.split(); - // std::dbg!(&fields); // Compute the absolute ordering of op parameters as follows: // // * By default, the ordering is implied by the order of field declarations in the struct @@ -201,8 +193,6 @@ impl OpDefinition { let field_ty = field.ty.clone(); let op_field_ty = field.attrs.pseudo_type(); - // std::dbg!(&field); - // std::dbg!(&op_field_ty); match op_field_ty.as_deref() { // Forwarded field None => { @@ -392,7 +382,6 @@ impl FromDeriveInput for OpDefinition { fn from_derive_input(input: &syn::DeriveInput) -> darling::Result { let span = input.span(); let mut operation = Operation::from_derive_input(input)?; - // std::dbg!(&operation); Self::from_operation(span, &mut operation) } } From d1b3e4d89724ad85ee1de7ea2d8d6935ad5cfc73 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 15:04:26 -0300 Subject: [PATCH 34/78] Remove commented out code Signed-off-by: Tomas Fabrizio Orsi --- hir/src/dialects/builtin/builders/world.rs | 7 +------ hir/src/dialects/builtin/ops/component.rs | 1 - tests/integration/src/rust_masm_tests/mod.rs | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index 611fea22c..730c96fdf 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -68,12 +68,7 @@ impl WorldBuilder { let builder = PrimModuleBuilder::new(&mut self.builder, name.span()); let tmp = &mut self.world.borrow_mut().as_symbol_table_ref(); let module_ref = builder(name, Some(tmp))?; - // let is_new = self - // .world - // .borrow_mut() - // .symbol_manager_mut() - // .insert_new(module_ref, crate::ProgramPoint::Invalid); - // assert!(is_new, "module with the name {name} already exists in world",); + Ok(module_ref) } diff --git a/hir/src/dialects/builtin/ops/component.rs b/hir/src/dialects/builtin/ops/component.rs index 31b504fdf..271de3db1 100644 --- a/hir/src/dialects/builtin/ops/component.rs +++ b/hir/src/dialects/builtin/ops/component.rs @@ -85,7 +85,6 @@ pub struct Component { #[attr] #[default] visibility: Visibility, - /// Reference to the parent symbol table where this operation will be inserted. #[region] body: RegionRef, #[default] diff --git a/tests/integration/src/rust_masm_tests/mod.rs b/tests/integration/src/rust_masm_tests/mod.rs index 35a8c296e..aa40cca4c 100644 --- a/tests/integration/src/rust_masm_tests/mod.rs +++ b/tests/integration/src/rust_masm_tests/mod.rs @@ -28,7 +28,7 @@ where let exec = Executor::for_package(package, args.iter().copied(), session) .map_err(|err| TestCaseError::fail(err.to_string()))?; let output = exec.execute_into(&package.unwrap_program(), session); - // std::dbg!(&output); + std::dbg!(&output); prop_assert_eq!(rust_out.clone(), output, "VM output mismatch"); // TODO: Uncomment after https://github.com/0xMiden/compiler/issues/228 is fixed // let emul_out: T = (*execute_emulator(ir_program.clone(), args).first().unwrap()).into(); From 3699b3df4fae9f2c681ef41a3be0b76131cf9a9d Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 15:13:01 -0300 Subject: [PATCH 35/78] Remove the decorator parsing Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index d449b7d6b..d24de9f31 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -2107,8 +2107,6 @@ pub struct OperationFieldAttrs { results: Flag, /// Was this a `#[region]` field? region: Flag, - /// Was this a `#[jamon]` field? - jamon: Flag, /// Was this a `#[successor]` field? successor: Flag, /// Was this a `#[successors]` field? @@ -2205,15 +2203,6 @@ impl OperationFieldAttrs { } result.region = Flag::from_meta(&attr.meta).unwrap(); } - "jamon" => { - if let Some(prev) = prev_decorator.replace("region") { - return Err(Error::custom(format!( - "#[region] conflicts with a previous #[{prev}] decorator" - )) - .with_span(&attr)); - } - result.jamon = Flag::from_meta(&attr.meta).unwrap(); - } "successor" => { if let Some(prev) = prev_decorator.replace("successor") { return Err(Error::custom(format!( From 2ee35bf6ca27e03637af19560f5f4ea8ba235c33 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 15:53:37 -0300 Subject: [PATCH 36/78] Rename parent_jamon to belongs_in_symbol_table and change it to a boolean Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index d24de9f31..e437ab2e0 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -53,7 +53,11 @@ pub struct OpDefinition { /// Keyed successor groups are handled a bit differently than "normal" successor groups in terms /// of the types expected by the op builder for this type. successors: Vec, - parent_jamon: Option, + /// Indicates whether the current operation could belong to a [`SymbolTable`]. + /// + /// If true, this operation's builder will have an additional parameter of type `Option<&mut + /// SymbolTableRef>`. None should only be used in tests + belongs_in_symbol_table: bool, /// The symbolic references held by this op symbols: Vec, /// The struct definition @@ -126,7 +130,7 @@ impl OpDefinition { operands: vec![], results: None, successors: vec![], - parent_jamon: None, + belongs_in_symbol_table: false, symbols: vec![], op, op_builder_impl, @@ -368,9 +372,7 @@ impl OpDefinition { ), r#default: false, }); - self.parent_jamon = Some(OpJamon { - name: parent_symbol_table, - }); + self.belongs_in_symbol_table = true; } self.op_builder_impl.set_create_params(&self.op.generics, create_params); @@ -596,18 +598,19 @@ impl quote::ToTokens for BuildOp<'_> { tokens.extend(quote! { let op = op_builder.build(); }); - match self.0.parent_jamon.as_ref() { - None => {} - Some(OpJamon { name }) => { + match self.0.belongs_in_symbol_table { + false => {} + // #name will evaluate to + true => { tokens.extend(quote! { op.as_ref().map(|op| { - if let Some(#name) = #name { - let is_new = #name.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid); + if let Some(parent_symbol_table) = parent_symbol_table { + let is_new = parent_symbol_table.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid); assert!( is_new, "{} already exists in {}", op.borrow().name(), - #name.borrow().as_symbol_table_operation().name() + parent_symbol_table.borrow().as_symbol_table_operation().name() ); } }); From e7dd21bf3ec194a9ec28e87b39051a3711d712b2 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 16:16:46 -0300 Subject: [PATCH 37/78] Add some documentation regarding the belong_in_symbol_table member Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index e437ab2e0..bef7046cf 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -55,8 +55,8 @@ pub struct OpDefinition { successors: Vec, /// Indicates whether the current operation could belong to a [`SymbolTable`]. /// - /// If true, this operation's builder will have an additional parameter of type `Option<&mut - /// SymbolTableRef>`. None should only be used in tests + /// If true, this operation's builder will have an additional parameter of type + ///`Option<&mut SymbolTableRef>`. `None` is currently only used in testing. belongs_in_symbol_table: bool, /// The symbolic references held by this op symbols: Vec, From 1c4a29cdbc8136ac407b285b854dafe8fc8b9522 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 16:38:31 -0300 Subject: [PATCH 38/78] Rename trait to BelongsInSymbolTable Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 2 +- hir/src/dialects/builtin/ops/component.rs | 6 +++--- hir/src/dialects/builtin/ops/function.rs | 6 ++++-- hir/src/dialects/builtin/ops/global_variable.rs | 6 +++--- hir/src/dialects/builtin/ops/module.rs | 6 +++--- hir/src/ir/traits.rs | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index bef7046cf..da2e00c91 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -352,7 +352,7 @@ impl OpDefinition { } } - if self.traits.iter().any(|tr| tr.get_ident().unwrap() == "Fideos") { + if self.traits.iter().any(|tr| tr.get_ident().unwrap() == "BelongsInSymbolTable") { let parent_symbol_table = Ident::new("parent_symbol_table", proc_macro2::Span::call_site()); diff --git a/hir/src/dialects/builtin/ops/component.rs b/hir/src/dialects/builtin/ops/component.rs index 271de3db1..e27f35e12 100644 --- a/hir/src/dialects/builtin/ops/component.rs +++ b/hir/src/dialects/builtin/ops/component.rs @@ -9,8 +9,8 @@ use crate::{ derive::operation, dialects::builtin::BuiltinDialect, traits::{ - Fideos, GraphRegionNoTerminator, HasOnlyGraphRegion, IsolatedFromAbove, NoRegionArguments, - NoTerminator, SingleBlock, SingleRegion, + BelongsInSymbolTable, GraphRegionNoTerminator, HasOnlyGraphRegion, IsolatedFromAbove, + NoRegionArguments, NoTerminator, SingleBlock, SingleRegion, }, version::Version, Ident, OpPrinter, Operation, RegionKind, RegionKindInterface, Symbol, SymbolManager, @@ -71,7 +71,7 @@ pub type ComponentRef = UnsafeIntrusiveEntityRef; HasOnlyGraphRegion, GraphRegionNoTerminator, IsolatedFromAbove, - Fideos, + BelongsInSymbolTable, ), implements(RegionKindInterface, SymbolTable, Symbol, OpPrinter) )] diff --git a/hir/src/dialects/builtin/ops/function.rs b/hir/src/dialects/builtin/ops/function.rs index 64d84f489..24c890fc2 100644 --- a/hir/src/dialects/builtin/ops/function.rs +++ b/hir/src/dialects/builtin/ops/function.rs @@ -6,7 +6,9 @@ use crate::{ define_attr_type, derive::operation, dialects::builtin::BuiltinDialect, - traits::{AnyType, Fideos, IsolatedFromAbove, ReturnLike, SingleRegion, Terminator}, + traits::{ + AnyType, BelongsInSymbolTable, IsolatedFromAbove, ReturnLike, SingleRegion, Terminator, + }, AttrPrinter, BlockRef, CallableOpInterface, Context, Ident, Immediate, Op, OpPrinter, OpPrintingFlags, Operation, RegionKind, RegionKindInterface, RegionRef, Signature, Symbol, SymbolName, SymbolTableRef, SymbolUse, SymbolUseList, Type, UnsafeIntrusiveEntityRef, Usable, @@ -75,7 +77,7 @@ impl AttrPrinter for LocalVariable { #[operation( dialect = BuiltinDialect, - traits(SingleRegion, IsolatedFromAbove, Fideos), + traits(SingleRegion, IsolatedFromAbove, BelongsInSymbolTable), implements( UsableSymbol, Symbol, diff --git a/hir/src/dialects/builtin/ops/global_variable.rs b/hir/src/dialects/builtin/ops/global_variable.rs index 7cb31eba0..f53e7c71a 100644 --- a/hir/src/dialects/builtin/ops/global_variable.rs +++ b/hir/src/dialects/builtin/ops/global_variable.rs @@ -8,8 +8,8 @@ use crate::{ MemoryEffect, MemoryEffectOpInterface, Pure, }, traits::{ - Fideos, InferTypeOpInterface, IsolatedFromAbove, NoRegionArguments, PointerOf, SingleBlock, - SingleRegion, UInt8, + BelongsInSymbolTable, InferTypeOpInterface, IsolatedFromAbove, NoRegionArguments, + PointerOf, SingleBlock, SingleRegion, UInt8, }, AsSymbolRef, Context, Ident, Op, OpPrinter, Operation, PointerType, Report, Spanned, Symbol, SymbolName, SymbolRef, SymbolTableRef, SymbolUseList, Type, UnsafeIntrusiveEntityRef, Usable, @@ -34,7 +34,7 @@ pub type GlobalVariableRef = UnsafeIntrusiveEntityRef; SingleBlock, NoRegionArguments, IsolatedFromAbove, - Fideos, + BelongsInSymbolTable, ), implements(Symbol, OpPrinter) )] diff --git a/hir/src/dialects/builtin/ops/module.rs b/hir/src/dialects/builtin/ops/module.rs index 55744c2cf..3867d54c9 100644 --- a/hir/src/dialects/builtin/ops/module.rs +++ b/hir/src/dialects/builtin/ops/module.rs @@ -2,8 +2,8 @@ use crate::{ derive::operation, dialects::builtin::BuiltinDialect, traits::{ - Fideos, GraphRegionNoTerminator, HasOnlyGraphRegion, IsolatedFromAbove, NoRegionArguments, - NoTerminator, SingleBlock, SingleRegion, + BelongsInSymbolTable, GraphRegionNoTerminator, HasOnlyGraphRegion, IsolatedFromAbove, + NoRegionArguments, NoTerminator, SingleBlock, SingleRegion, }, Ident, OpPrinter, Operation, RegionKind, RegionKindInterface, Symbol, SymbolManager, SymbolManagerMut, SymbolMap, SymbolName, SymbolRef, SymbolTable, SymbolTableRef, SymbolUseList, @@ -57,7 +57,7 @@ pub type ModuleRef = UnsafeIntrusiveEntityRef; HasOnlyGraphRegion, GraphRegionNoTerminator, IsolatedFromAbove, - Fideos, + BelongsInSymbolTable, ), implements(RegionKindInterface, SymbolTable, Symbol, OpPrinter) )] diff --git a/hir/src/ir/traits.rs b/hir/src/ir/traits.rs index cc32ab391..b315d0b85 100644 --- a/hir/src/ir/traits.rs +++ b/hir/src/ir/traits.rs @@ -41,7 +41,7 @@ pub trait Involution {} pub trait IsolatedFromAbove {} /// Marker trait for ops whose parent op needs to add them to their own symbol list. -pub trait Fideos {} +pub trait BelongsInSymbolTable {} /// Marker trait for ops which have only regions of [`RegionKind::Graph`] pub trait HasOnlyGraphRegion {} From 76940fa455da825b5d71576935797f9798b2eb77 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 16:45:24 -0300 Subject: [PATCH 39/78] Add documentation regarding the proc macro Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index da2e00c91..23807f541 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -352,6 +352,10 @@ impl OpDefinition { } } + // If the operations has the "BelongsInSymbolTable" trait, then add an additional parameter + // to the Operation::create and OpBuilder function of type: + // parent_symbol_table: Option<&mut SymbolTableRef>, + // This is a reference to the symbol table of the parent where this operation will be added. if self.traits.iter().any(|tr| tr.get_ident().unwrap() == "BelongsInSymbolTable") { let parent_symbol_table = Ident::new("parent_symbol_table", proc_macro2::Span::call_site()); From 4d9b8b01a430a73cbedd20896375c466c616beaa Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 16:49:57 -0300 Subject: [PATCH 40/78] Rename to OpCreateParamType::Mandioca to OpCreateParamType::BuildOnlyParameter Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 23807f541..1306c133c 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -370,7 +370,7 @@ impl OpDefinition { let parent_symbol_type = parse_quote! { Option< #parent_symbol_type >}; create_params.push(OpCreateParam { - param_ty: OpCreateParamType::Mandioca( + param_ty: OpCreateParamType::BuildOnlyParameter( parent_symbol_table.clone(), parent_symbol_type, ), @@ -2425,7 +2425,8 @@ pub enum OpCreateParamType { #[allow(dead_code)] OperandGroup(Ident, syn::Type), CustomField(Ident, syn::Type), - Mandioca(Ident, syn::Type), + /// Parameters that are only used in the Operation::create and are not stored in the resulting Operation + BuildOnlyParameter(Ident, syn::Type), Successor(Ident), SuccessorGroupNamed(Ident), SuccessorGroupKeyed(Ident, syn::Type), @@ -2439,7 +2440,7 @@ impl OpCreateParam { | OpCreateParamType::CustomField(name, _) | OpCreateParamType::Operand(Operand { name, .. }) | OpCreateParamType::OperandGroup(name, _) - | OpCreateParamType::Mandioca(name, _) + | OpCreateParamType::BuildOnlyParameter(name, _) | OpCreateParamType::SuccessorGroupNamed(name) | OpCreateParamType::SuccessorGroupKeyed(name, _) | OpCreateParamType::Symbol(Symbol { name, .. }) => vec![name.clone()], @@ -2465,7 +2466,7 @@ impl OpCreateParam { vec![ty.clone()] } OpCreateParamType::Operand(_) => vec![make_type("::midenc_hir::ValueRef")], - OpCreateParamType::Mandioca(_, ty) => vec![ty.clone()], + OpCreateParamType::BuildOnlyParameter(_, ty) => vec![ty.clone()], OpCreateParamType::OperandGroup(group_name, _) | OpCreateParamType::SuccessorGroupNamed(group_name) | OpCreateParamType::SuccessorGroupKeyed(group_name, _) => { From 5cdf314073379987fe11465488beff140529c156 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 16:51:47 -0300 Subject: [PATCH 41/78] Remove old asserts, now in macro Signed-off-by: Tomas Fabrizio Orsi --- .../dialects/builtin/builders/component.rs | 18 ++-------------- hir/src/dialects/builtin/builders/module.rs | 21 +++---------------- 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/hir/src/dialects/builtin/builders/component.rs b/hir/src/dialects/builtin/builders/component.rs index 0b6f24446..26585e9b2 100644 --- a/hir/src/dialects/builtin/builders/component.rs +++ b/hir/src/dialects/builtin/builders/component.rs @@ -33,16 +33,7 @@ impl ComponentBuilder { pub fn define_module(&mut self, name: Ident) -> Result { let tmp = &mut self.component.borrow_mut().as_symbol_table_ref(); let module_ref = self.builder.create_module(name, Some(tmp))?; - // let is_new = self - // .component - // .borrow_mut() - // .symbol_manager_mut() - // .insert_new(module_ref, crate::ProgramPoint::Invalid); - // assert!( - // is_new, - // "module with the name {name} already exists in component {}", - // self.component.borrow().name() - // ); + Ok(module_ref) } @@ -69,12 +60,7 @@ impl ComponentBuilder { ) -> Result { let tmp = &mut self.component.borrow_mut().as_symbol_table_ref(); let function_ref = self.builder.create_function(name, signature, Some(tmp))?; - // let is_new = self - // .component - // .borrow_mut() - // .symbol_manager_mut() - // .insert_new(function_ref, crate::ProgramPoint::Invalid); - // assert!(is_new, "function with the name {name} already exists"); + Ok(function_ref) } } diff --git a/hir/src/dialects/builtin/builders/module.rs b/hir/src/dialects/builtin/builders/module.rs index be771b90b..94c605841 100644 --- a/hir/src/dialects/builtin/builders/module.rs +++ b/hir/src/dialects/builtin/builders/module.rs @@ -53,12 +53,7 @@ impl ModuleBuilder { ) -> Result { let tmp = &mut self.module.borrow_mut().as_symbol_table_ref(); let function_ref = self.builder.create_function(name, signature, Some(tmp))?; - // let is_new = self - // .module - // .borrow_mut() - // .symbol_manager_mut() - // .insert_new(function_ref, crate::ProgramPoint::Invalid); - // assert!(is_new, "function with the name {name} already exists"); + Ok(function_ref) } @@ -75,12 +70,7 @@ impl ModuleBuilder { let tmp = &mut self.module.borrow_mut().as_symbol_table_ref(); let global_var_ref = self.builder.create_global_variable(name, visibility, ty, Some(tmp))?; - // let is_new = self - // .module - // .borrow_mut() - // .symbol_manager_mut() - // .insert_new(global_var_ref, crate::ProgramPoint::Invalid); - // assert!(is_new, "global variable with the name {name} already exists"); + Ok(global_var_ref) } @@ -123,12 +113,7 @@ impl ModuleBuilder { let builder = PrimModuleBuilder::new(&mut self.builder, name.span()); let tmp = &mut self.module.borrow_mut().as_symbol_table_ref(); let module_ref = builder(name, Some(tmp))?; - // let is_new = self - // .module - // .borrow_mut() - // .symbol_manager_mut() - // .insert_new(module_ref, crate::ProgramPoint::Invalid); - // assert!(is_new, "module with the name {name} already exists in world",); + Ok(module_ref) } From 16026fe23274e29678bb87a312b4163049039197 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 16:56:50 -0300 Subject: [PATCH 42/78] Remove match in favor of if true Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 1306c133c..8b3a7a08e 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -56,7 +56,7 @@ pub struct OpDefinition { /// Indicates whether the current operation could belong to a [`SymbolTable`]. /// /// If true, this operation's builder will have an additional parameter of type - ///`Option<&mut SymbolTableRef>`. `None` is currently only used in testing. + ///`parent_symbol_table: Option<&mut SymbolTableRef>`. `None` is currently only used in testing. belongs_in_symbol_table: bool, /// The symbolic references held by this op symbols: Vec, @@ -602,11 +602,9 @@ impl quote::ToTokens for BuildOp<'_> { tokens.extend(quote! { let op = op_builder.build(); }); - match self.0.belongs_in_symbol_table { - false => {} - // #name will evaluate to - true => { - tokens.extend(quote! { + + if self.0.belongs_in_symbol_table { + tokens.extend(quote! { op.as_ref().map(|op| { if let Some(parent_symbol_table) = parent_symbol_table { let is_new = parent_symbol_table.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid); @@ -619,7 +617,6 @@ impl quote::ToTokens for BuildOp<'_> { } }); }); - } }; tokens.extend(quote! { From bbbad14313a6ece080c977ab88c6de8ad47213df Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 17:24:48 -0300 Subject: [PATCH 43/78] Decouple the current BuildOp into BuildOP + ModifyOp + ReturnOp Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 64 ++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 8b3a7a08e..4a8ce1272 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -602,26 +602,6 @@ impl quote::ToTokens for BuildOp<'_> { tokens.extend(quote! { let op = op_builder.build(); }); - - if self.0.belongs_in_symbol_table { - tokens.extend(quote! { - op.as_ref().map(|op| { - if let Some(parent_symbol_table) = parent_symbol_table { - let is_new = parent_symbol_table.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid); - assert!( - is_new, - "{} already exists in {}", - op.borrow().name(), - parent_symbol_table.borrow().as_symbol_table_operation().name() - ); - } - }); - }); - }; - - tokens.extend(quote! { - op - }); } Some(group) => { let verify_result_constraints = match group { @@ -693,14 +673,44 @@ impl quote::ToTokens for BuildOp<'_> { #verify_result_constraints } - - Ok(op) + // We save the operation in a variable in case it needs to be modified later on + let op = Ok(op); }) } } } } +struct ModifyOp<'a>(&'a OpDefinition); +impl quote::ToTokens for ModifyOp<'_> { + fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { + if self.0.belongs_in_symbol_table { + tokens.extend(quote! { + op.as_ref().map(|op| { + if let Some(parent_symbol_table) = parent_symbol_table { + let is_new = parent_symbol_table.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid); + assert!( + is_new, + "{} already exists in {}", + op.borrow().name(), + parent_symbol_table.borrow().as_symbol_table_operation().name() + ); + } + }); + }); + }; + } +} + +struct ReturnOp<'a>(&'a OpDefinition); +impl quote::ToTokens for ReturnOp<'_> { + fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { + tokens.extend(quote! { + op + }); + } +} + impl quote::ToTokens for OpCreateFn<'_> { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { let dialect = &self.op.dialect; @@ -725,6 +735,8 @@ impl quote::ToTokens for OpCreateFn<'_> { }); let with_successors = WithSuccessors(self.op); let build_op = BuildOp(self.op); + let modify_op = ModifyOp(self.op); + let return_op = ReturnOp(self.op); tokens.extend(quote! { /// Manually construct a new [#op_ident] @@ -774,8 +786,14 @@ impl quote::ToTokens for OpCreateFn<'_> { #with_successors #with_results - // Finalize construction of this op, verifying it + /// Construct the op, verifying it #build_op + + /// Apply modifications to the op + #modify_op + + /// Return the op + #return_op } }); } From d2a0dc5971e61354d510cabbc05ef55e85c20bc3 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 17:31:12 -0300 Subject: [PATCH 44/78] Remove unused code/structs and re-enable -Wwarning Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/lib.rs | 2 +- hir-macros/src/operation.rs | 10 +++------- hir/src/dialects/builtin/ops/component.rs | 2 -- hir/src/lib.rs | 2 +- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/hir-macros/src/lib.rs b/hir-macros/src/lib.rs index 7f7119b61..d41541360 100644 --- a/hir-macros/src/lib.rs +++ b/hir-macros/src/lib.rs @@ -1,4 +1,4 @@ -// #![deny(warnings)] +#![deny(warnings)] extern crate proc_macro; diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 4a8ce1272..410745ee8 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -1,7 +1,7 @@ use std::rc::Rc; use darling::{ - util::{Flag, PathList, SpannedValue}, + util::{Flag, SpannedValue}, Error, FromDeriveInput, FromField, FromMeta, }; use inflector::Inflector; @@ -702,6 +702,7 @@ impl quote::ToTokens for ModifyOp<'_> { } } +#[allow(dead_code)] struct ReturnOp<'a>(&'a OpDefinition); impl quote::ToTokens for ReturnOp<'_> { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { @@ -1541,11 +1542,6 @@ pub struct OpResult { pub constraint: Constraint, } -#[derive(Debug, Clone)] -pub struct OpJamon { - pub name: Ident, -} - pub type OpResultGroup = EntityGroup; #[derive(Debug)] @@ -2090,7 +2086,7 @@ pub struct Operation { #[derive(Debug, FromField)] #[darling(forward_attrs( doc, cfg, allow, attr, operand, operands, region, successor, successors, result, results, - default, order, symbol, jamon + default, order, symbol ))] pub struct OperationField { /// The name of this field. diff --git a/hir/src/dialects/builtin/ops/component.rs b/hir/src/dialects/builtin/ops/component.rs index e27f35e12..6ea6863e0 100644 --- a/hir/src/dialects/builtin/ops/component.rs +++ b/hir/src/dialects/builtin/ops/component.rs @@ -1,7 +1,5 @@ mod interface; -use core::borrow::BorrowMut; - pub use self::interface::{ ComponentExport, ComponentId, ComponentInterface, ModuleExport, ModuleInterface, }; diff --git a/hir/src/lib.rs b/hir/src/lib.rs index d5bcac6d5..51f0af058 100644 --- a/hir/src/lib.rs +++ b/hir/src/lib.rs @@ -41,7 +41,7 @@ // Some of the above features require us to disable these warnings #![allow(incomplete_features)] #![allow(internal_features)] -// #![deny(warnings)] +#![deny(warnings)] extern crate alloc; From 2dd21ec1fa44ca817297a8c9c9763ca87a24457c Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Thu, 22 May 2025 17:56:29 -0300 Subject: [PATCH 45/78] Rename tmp to symbol_table Signed-off-by: Tomas Fabrizio Orsi --- hir/src/dialects/builtin/builders/component.rs | 8 ++++---- hir/src/dialects/builtin/builders/module.rs | 12 ++++++------ hir/src/dialects/builtin/builders/world.rs | 13 ++++--------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/hir/src/dialects/builtin/builders/component.rs b/hir/src/dialects/builtin/builders/component.rs index 26585e9b2..94a3db83d 100644 --- a/hir/src/dialects/builtin/builders/component.rs +++ b/hir/src/dialects/builtin/builders/component.rs @@ -31,8 +31,8 @@ impl ComponentBuilder { } pub fn define_module(&mut self, name: Ident) -> Result { - let tmp = &mut self.component.borrow_mut().as_symbol_table_ref(); - let module_ref = self.builder.create_module(name, Some(tmp))?; + let symbol_table = &mut self.component.borrow_mut().as_symbol_table_ref(); + let module_ref = self.builder.create_module(name, Some(symbol_table))?; Ok(module_ref) } @@ -58,8 +58,8 @@ impl ComponentBuilder { name: Ident, signature: Signature, ) -> Result { - let tmp = &mut self.component.borrow_mut().as_symbol_table_ref(); - let function_ref = self.builder.create_function(name, signature, Some(tmp))?; + let symbol_table = &mut self.component.borrow_mut().as_symbol_table_ref(); + let function_ref = self.builder.create_function(name, signature, Some(symbol_table))?; Ok(function_ref) } diff --git a/hir/src/dialects/builtin/builders/module.rs b/hir/src/dialects/builtin/builders/module.rs index 94c605841..c9cc53681 100644 --- a/hir/src/dialects/builtin/builders/module.rs +++ b/hir/src/dialects/builtin/builders/module.rs @@ -51,8 +51,8 @@ impl ModuleBuilder { name: Ident, signature: Signature, ) -> Result { - let tmp = &mut self.module.borrow_mut().as_symbol_table_ref(); - let function_ref = self.builder.create_function(name, signature, Some(tmp))?; + let symbol_table = &mut self.module.borrow_mut().as_symbol_table_ref(); + let function_ref = self.builder.create_function(name, signature, Some(symbol_table))?; Ok(function_ref) } @@ -67,9 +67,9 @@ impl ModuleBuilder { visibility: Visibility, ty: Type, ) -> Result, Report> { - let tmp = &mut self.module.borrow_mut().as_symbol_table_ref(); + let symbol_table = &mut self.module.borrow_mut().as_symbol_table_ref(); let global_var_ref = - self.builder.create_global_variable(name, visibility, ty, Some(tmp))?; + self.builder.create_global_variable(name, visibility, ty, Some(symbol_table))?; Ok(global_var_ref) } @@ -111,8 +111,8 @@ impl ModuleBuilder { /// Declare a new nested module `name` pub fn declare_module(&mut self, name: Ident) -> Result { let builder = PrimModuleBuilder::new(&mut self.builder, name.span()); - let tmp = &mut self.module.borrow_mut().as_symbol_table_ref(); - let module_ref = builder(name, Some(tmp))?; + let symbol_table = &mut self.module.borrow_mut().as_symbol_table_ref(); + let module_ref = builder(name, Some(symbol_table))?; Ok(module_ref) } diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index 730c96fdf..58b48ce5c 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -42,14 +42,9 @@ impl WorldBuilder { ver: Version, ) -> Result { let builder = PrimComponentBuilder::new(&mut self.builder, name.span()); - // Without the tmp variable, this crashes with the following error - // AliasingViolationError { kind: Mutable, location: Location { file: "hir/src/dialects/builtin/builders/world.rs", line: 47, col: 60 } } + let symbol_table = &mut self.world.borrow_mut().as_symbol_table_ref(); - // With this tmp variable, it does not crash. All tests pass. - // I'll procede to check if the symbol table is actually updated. But it's something :D - let tmp = &mut self.world.borrow_mut().as_symbol_table_ref(); - - let component_ref = builder(ns, name, ver.clone(), Some(tmp))?; + let component_ref = builder(ns, name, ver.clone(), Some(symbol_table))?; Ok(component_ref) } @@ -66,8 +61,8 @@ impl WorldBuilder { /// Declare a new world-level module `name` pub fn declare_module(&mut self, name: Ident) -> Result { let builder = PrimModuleBuilder::new(&mut self.builder, name.span()); - let tmp = &mut self.world.borrow_mut().as_symbol_table_ref(); - let module_ref = builder(name, Some(tmp))?; + let symbol_table = &mut self.world.borrow_mut().as_symbol_table_ref(); + let module_ref = builder(name, Some(symbol_table))?; Ok(module_ref) } From a390f2e66a849c210b8e147847f906c7a099e296 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Fri, 23 May 2025 17:45:49 -0300 Subject: [PATCH 46/78] Remove unused function Signed-off-by: Tomas Fabrizio Orsi --- hir/src/ir/operation/builder.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/hir/src/ir/operation/builder.rs b/hir/src/ir/operation/builder.rs index b7ff61227..251de660a 100644 --- a/hir/src/ir/operation/builder.rs +++ b/hir/src/ir/operation/builder.rs @@ -101,12 +101,6 @@ where op.regions.push_back(region); } - pub fn add_to_symbol_table(&mut self) { - // pub fn add_to_symbol_table(&mut self, _sym_table: SymbolTableRef) { - // let sym_manager = sym_table.borrow_mut().symbol_manager_mut(); - todo!() - } - pub fn with_successor( &mut self, dest: BlockRef, From 2ce70401cc6b016803e1a1034f9d428acbca61f7 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Fri, 23 May 2025 17:59:32 -0300 Subject: [PATCH 47/78] fix: replace in place str with call to stringify! Signed-off-by: Tomas Fabrizio Orsi Suggested-by: Ignacio Amigo --- hir-macros/src/operation.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 410745ee8..b6a166f82 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -356,7 +356,11 @@ impl OpDefinition { // to the Operation::create and OpBuilder function of type: // parent_symbol_table: Option<&mut SymbolTableRef>, // This is a reference to the symbol table of the parent where this operation will be added. - if self.traits.iter().any(|tr| tr.get_ident().unwrap() == "BelongsInSymbolTable") { + if self + .traits + .iter() + .any(|tr| tr.get_ident().unwrap() == stringify!(BelongsInSymbolTable)) + { let parent_symbol_table = Ident::new("parent_symbol_table", proc_macro2::Span::call_site()); From c074344b94f86cd8004c9090e6ee39e881463b09 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Fri, 23 May 2025 18:04:06 -0300 Subject: [PATCH 48/78] Remove Option from parent symbol table type Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 18 ++++++++---------- hir/src/dialects/builtin/builders.rs | 6 +++--- hir/src/dialects/builtin/builders/component.rs | 4 ++-- hir/src/dialects/builtin/builders/module.rs | 6 +++--- hir/src/dialects/builtin/builders/world.rs | 4 ++-- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index b6a166f82..24868bd21 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -371,7 +371,7 @@ impl OpDefinition { elem: Box::new(make_type("SymbolTableRef")), }); - let parent_symbol_type = parse_quote! { Option< #parent_symbol_type >}; + // let parent_symbol_type = parse_quote! { Option< #parent_symbol_type >}; create_params.push(OpCreateParam { param_ty: OpCreateParamType::BuildOnlyParameter( @@ -691,15 +691,13 @@ impl quote::ToTokens for ModifyOp<'_> { if self.0.belongs_in_symbol_table { tokens.extend(quote! { op.as_ref().map(|op| { - if let Some(parent_symbol_table) = parent_symbol_table { - let is_new = parent_symbol_table.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid); - assert!( - is_new, - "{} already exists in {}", - op.borrow().name(), - parent_symbol_table.borrow().as_symbol_table_operation().name() - ); - } + let is_new = parent_symbol_table.borrow_mut().symbol_manager_mut().insert_new(*op, crate::ProgramPoint::Invalid); + assert!( + is_new, + "{} already exists in {}", + op.borrow().name(), + parent_symbol_table.borrow().as_symbol_table_operation().name() + ); }); }); }; diff --git a/hir/src/dialects/builtin/builders.rs b/hir/src/dialects/builtin/builders.rs index ceb677238..2361ef00a 100644 --- a/hir/src/dialects/builtin/builders.rs +++ b/hir/src/dialects/builtin/builders.rs @@ -19,7 +19,7 @@ pub trait BuiltinOpBuilder<'f, B: ?Sized + Builder> { fn create_module( &mut self, name: Ident, - parent_symbol_table: Option<&mut SymbolTableRef>, + parent_symbol_table: &mut SymbolTableRef, ) -> Result { let op_builder = self.builder_mut().create::(name.span()); op_builder(name, parent_symbol_table) @@ -29,7 +29,7 @@ pub trait BuiltinOpBuilder<'f, B: ?Sized + Builder> { &mut self, name: Ident, signature: Signature, - parent_symbol_table: Option<&mut SymbolTableRef>, + parent_symbol_table: &mut SymbolTableRef, ) -> Result { let op_builder = self.builder_mut().create::(name.span()); op_builder(name, signature, parent_symbol_table) @@ -40,7 +40,7 @@ pub trait BuiltinOpBuilder<'f, B: ?Sized + Builder> { name: Ident, visibility: Visibility, ty: Type, - parent_symbol_table: Option<&mut SymbolTableRef>, + parent_symbol_table: &mut SymbolTableRef, ) -> Result { let op_builder = self.builder_mut().create::(name.span()); op_builder(name, visibility, ty, parent_symbol_table) diff --git a/hir/src/dialects/builtin/builders/component.rs b/hir/src/dialects/builtin/builders/component.rs index 94a3db83d..5ed154fca 100644 --- a/hir/src/dialects/builtin/builders/component.rs +++ b/hir/src/dialects/builtin/builders/component.rs @@ -32,7 +32,7 @@ impl ComponentBuilder { pub fn define_module(&mut self, name: Ident) -> Result { let symbol_table = &mut self.component.borrow_mut().as_symbol_table_ref(); - let module_ref = self.builder.create_module(name, Some(symbol_table))?; + let module_ref = self.builder.create_module(name, symbol_table)?; Ok(module_ref) } @@ -59,7 +59,7 @@ impl ComponentBuilder { signature: Signature, ) -> Result { let symbol_table = &mut self.component.borrow_mut().as_symbol_table_ref(); - let function_ref = self.builder.create_function(name, signature, Some(symbol_table))?; + let function_ref = self.builder.create_function(name, signature, symbol_table)?; Ok(function_ref) } diff --git a/hir/src/dialects/builtin/builders/module.rs b/hir/src/dialects/builtin/builders/module.rs index c9cc53681..2ed37d2b0 100644 --- a/hir/src/dialects/builtin/builders/module.rs +++ b/hir/src/dialects/builtin/builders/module.rs @@ -52,7 +52,7 @@ impl ModuleBuilder { signature: Signature, ) -> Result { let symbol_table = &mut self.module.borrow_mut().as_symbol_table_ref(); - let function_ref = self.builder.create_function(name, signature, Some(symbol_table))?; + let function_ref = self.builder.create_function(name, signature, symbol_table)?; Ok(function_ref) } @@ -69,7 +69,7 @@ impl ModuleBuilder { ) -> Result, Report> { let symbol_table = &mut self.module.borrow_mut().as_symbol_table_ref(); let global_var_ref = - self.builder.create_global_variable(name, visibility, ty, Some(symbol_table))?; + self.builder.create_global_variable(name, visibility, ty, symbol_table)?; Ok(global_var_ref) } @@ -112,7 +112,7 @@ impl ModuleBuilder { pub fn declare_module(&mut self, name: Ident) -> Result { let builder = PrimModuleBuilder::new(&mut self.builder, name.span()); let symbol_table = &mut self.module.borrow_mut().as_symbol_table_ref(); - let module_ref = builder(name, Some(symbol_table))?; + let module_ref = builder(name, symbol_table)?; Ok(module_ref) } diff --git a/hir/src/dialects/builtin/builders/world.rs b/hir/src/dialects/builtin/builders/world.rs index 58b48ce5c..3f29632ed 100644 --- a/hir/src/dialects/builtin/builders/world.rs +++ b/hir/src/dialects/builtin/builders/world.rs @@ -44,7 +44,7 @@ impl WorldBuilder { let builder = PrimComponentBuilder::new(&mut self.builder, name.span()); let symbol_table = &mut self.world.borrow_mut().as_symbol_table_ref(); - let component_ref = builder(ns, name, ver.clone(), Some(symbol_table))?; + let component_ref = builder(ns, name, ver.clone(), symbol_table)?; Ok(component_ref) } @@ -62,7 +62,7 @@ impl WorldBuilder { pub fn declare_module(&mut self, name: Ident) -> Result { let builder = PrimModuleBuilder::new(&mut self.builder, name.span()); let symbol_table = &mut self.world.borrow_mut().as_symbol_table_ref(); - let module_ref = builder(name, Some(symbol_table))?; + let module_ref = builder(name, symbol_table)?; Ok(module_ref) } From 0573c5a0c80b2b8f78ccb01648928d9a96c64ec1 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 11:23:22 -0300 Subject: [PATCH 49/78] WIP: SymbolTableHolder Signed-off-by: Tomas Fabrizio Orsi --- codegen/masm/src/lib.rs | 2 +- codegen/masm/src/lower/utils.rs | 39 +++++++++++++++--- dialects/scf/src/lib.rs | 2 +- dialects/scf/src/transforms/cfg_to_scf.rs | 49 +++++++++++++++++++---- eval/src/lib.rs | 2 +- eval/src/tests.rs | 33 +++++++++++---- hir/src/dialects.rs | 2 +- hir/src/dialects/test.rs | 1 + hir/src/dialects/test/ops/constants.rs | 44 ++++++++++++++++++++ hir/src/lib.rs | 2 +- hir/src/matchers/matcher.rs | 9 ++++- hir/src/patterns/pattern.rs | 9 ++++- 12 files changed, 168 insertions(+), 26 deletions(-) diff --git a/codegen/masm/src/lib.rs b/codegen/masm/src/lib.rs index d15414fbd..9b8325595 100644 --- a/codegen/masm/src/lib.rs +++ b/codegen/masm/src/lib.rs @@ -4,7 +4,7 @@ #![feature(array_chunks)] #![feature(iter_array_chunks)] #![feature(iterator_try_collect)] -#![deny(warnings)] +// #![deny(warnings)] extern crate alloc; diff --git a/codegen/masm/src/lower/utils.rs b/codegen/masm/src/lower/utils.rs index d6f881483..a574d25c6 100644 --- a/codegen/masm/src/lower/utils.rs +++ b/codegen/masm/src/lower/utils.rs @@ -1,5 +1,7 @@ use midenc_dialect_scf as scf; -use midenc_hir::{Op, Operation, Region, Report, Spanned, ValueRef}; +use midenc_hir::{ + BuilderExt, Op, Operation, Region, Report, SourceSpan, Spanned, SymbolTable, ValueRef, +}; use smallvec::SmallVec; use crate::{emitter::BlockEmitter, masm, Constraint}; @@ -493,7 +495,10 @@ mod tests { use midenc_dialect_arith::ArithOpBuilder; use midenc_dialect_scf::StructuredControlFlowOpBuilder; use midenc_hir::{ - dialects::builtin::{self, BuiltinOpBuilder, FunctionBuilder, FunctionRef}, + dialects::{ + builtin::{self, BuiltinOpBuilder, FunctionBuilder, FunctionRef}, + test, + }, formatter::PrettyPrint, pass::AnalysisManager, version::Version, @@ -511,13 +516,21 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); + let span = SourceSpan::default(); + let mut sym_builder = builder.create::(span); + + let mut symbol_table_ref = sym_builder() + .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") + .borrow_mut() + .as_symbol_table_ref(); + let function_ref = builder.create_function( Ident::with_empty_span("test".into()), Signature::new( [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), - None, + &mut symbol_table_ref, )?; let (a, b) = { @@ -598,13 +611,21 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); + let span = SourceSpan::default(); + let mut sym_builder = builder.create::(span); + + let mut symbol_table_ref = sym_builder() + .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") + .borrow_mut() + .as_symbol_table_ref(); + let function_ref = builder.create_function( Ident::with_empty_span("test".into()), Signature::new( [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), - None, + &mut symbol_table_ref, )?; let (a, b) = { @@ -828,13 +849,21 @@ mod tests { ) -> Result<(FunctionRef, masm::Block), Report> { let mut builder = OpBuilder::new(context.clone()); + let span = SourceSpan::default(); + let mut sym_builder = builder.create::(span); + + let mut symbol_table_ref = sym_builder() + .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") + .borrow_mut() + .as_symbol_table_ref(); + let function_ref = builder.create_function( Ident::with_empty_span("test".into()), Signature::new( [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), - None, + &mut symbol_table_ref, )?; let (a, b) = { diff --git a/dialects/scf/src/lib.rs b/dialects/scf/src/lib.rs index 86597de17..55103e2d3 100644 --- a/dialects/scf/src/lib.rs +++ b/dialects/scf/src/lib.rs @@ -5,7 +5,7 @@ #![feature(ptr_metadata)] #![feature(specialization)] #![allow(incomplete_features)] -#![deny(warnings)] +// #![deny(warnings)] extern crate alloc; diff --git a/dialects/scf/src/transforms/cfg_to_scf.rs b/dialects/scf/src/transforms/cfg_to_scf.rs index 4fd0e820e..ade633211 100644 --- a/dialects/scf/src/transforms/cfg_to_scf.rs +++ b/dialects/scf/src/transforms/cfg_to_scf.rs @@ -372,8 +372,9 @@ mod tests { use builtin::{BuiltinOpBuilder, FunctionBuilder}; use expect_test::expect_file; use midenc_hir::{ - dialects::builtin, pass, AbiParam, BuilderExt, Context, Ident, OpBuilder, PointerType, - Report, Signature, SourceSpan, Type, + dialects::{builtin, test}, + pass, AbiParam, BuilderExt, Context, Ident, OpBuilder, PointerType, Report, Signature, + SourceSpan, SymbolTable, Type, }; use super::*; @@ -384,11 +385,19 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); let span = SourceSpan::default(); + let function = { + let mut sym_builder = builder.create::(span); + + let mut symbol_table_ref = sym_builder() + .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") + .borrow_mut() + .as_symbol_table_ref(); + let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature, None).unwrap() + builder(name, signature, &mut symbol_table_ref).unwrap() }; // Define function body @@ -449,6 +458,12 @@ mod tests { let span = SourceSpan::default(); let function = { + let mut sym_builder = builder.create::(span); + + let mut symbol_table_ref = sym_builder() + .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") + .borrow_mut() + .as_symbol_table_ref(); let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new( @@ -460,7 +475,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature, None).unwrap() + builder(name, signature, &mut symbol_table_ref).unwrap() }; // Define function body @@ -572,10 +587,17 @@ mod tests { let span = SourceSpan::default(); let function = { + let mut sym_builder = builder.create::(span); + + let mut symbol_table_ref = sym_builder() + .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") + .borrow_mut() + .as_symbol_table_ref(); + let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature, None).unwrap() + builder(name, signature, &mut symbol_table_ref).unwrap() }; // Define function body @@ -631,6 +653,13 @@ mod tests { let span = SourceSpan::default(); let function = { + let mut sym_builder = builder.create::(span); + + let mut symbol_table_ref = sym_builder() + .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") + .borrow_mut() + .as_symbol_table_ref(); + let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new( @@ -641,7 +670,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature, None).unwrap() + builder(name, signature, &mut symbol_table_ref).unwrap() }; // Define function body for the following pseudocode: @@ -744,6 +773,12 @@ mod tests { let span = SourceSpan::default(); let function = { + let mut sym_builder = builder.create::(span); + + let mut symbol_table_ref = sym_builder() + .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") + .borrow_mut() + .as_symbol_table_ref(); let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new( @@ -754,7 +789,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature, None).unwrap() + builder(name, signature, &mut symbol_table_ref).unwrap() }; // Define function body for the following pseudocode: diff --git a/eval/src/lib.rs b/eval/src/lib.rs index bb8313c91..125f2a40a 100644 --- a/eval/src/lib.rs +++ b/eval/src/lib.rs @@ -1,6 +1,6 @@ #![no_std] #![feature(debug_closure_helpers)] -#![deny(warnings)] +// #![deny(warnings)] #[cfg(any(feature = "std", test))] extern crate std; diff --git a/eval/src/tests.rs b/eval/src/tests.rs index b63d30979..f7a71d1c2 100644 --- a/eval/src/tests.rs +++ b/eval/src/tests.rs @@ -5,9 +5,12 @@ use midenc_dialect_cf::ControlFlowOpBuilder; use midenc_dialect_hir::HirOpBuilder; use midenc_dialect_scf::StructuredControlFlowOpBuilder; use midenc_hir::{ - dialects::builtin::{BuiltinOpBuilder, FunctionBuilder}, - AbiParam, Builder, Context, Ident, Op, OpBuilder, ProgramPoint, Report, Signature, SourceSpan, - SymbolTable, Type, ValueRef, + dialects::{ + builtin::{BuiltinOpBuilder, FunctionBuilder}, + test, + }, + AbiParam, Builder, BuilderExt, Context, Ident, Op, OpBuilder, ProgramPoint, Report, Signature, + SourceSpan, SymbolTable, Type, ValueRef, }; use crate::*; @@ -72,10 +75,18 @@ fn eval_callable_test() -> Result<(), Report> { let mut builder = OpBuilder::new(test_context.context.clone()); + let span = SourceSpan::default(); + let mut sym_builder = builder.create::(span); + + let mut symbol_table_ref = sym_builder() + .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") + .borrow_mut() + .as_symbol_table_ref(); + let function = builder.create_function( Ident::with_empty_span("test".into()), Signature::new([AbiParam::new(Type::I1)], [AbiParam::new(Type::U32)]), - None, + &mut symbol_table_ref, )?; { @@ -120,7 +131,15 @@ fn call_handling_test() -> Result<(), Report> { let mut builder = OpBuilder::new(test_context.context.clone()); - let mut module = builder.create_module(Ident::with_empty_span("test".into()), None)?; + let span = SourceSpan::default(); + let mut sym_builder = builder.create::(span); + let mut symbol_table_ref = sym_builder() + .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") + .borrow_mut() + .as_symbol_table_ref(); + + let mut module = + builder.create_module(Ident::with_empty_span("test".into()), &mut symbol_table_ref)?; let module_body = module.borrow().body().as_region_ref(); builder.create_block(module_body, None, &[]); @@ -129,7 +148,7 @@ fn call_handling_test() -> Result<(), Report> { let entry = builder.create_function( Ident::with_empty_span("entrypoint".into()), Signature::new([AbiParam::new(Type::I1)], [AbiParam::new(Type::U32)]), - None, + &mut symbol_table_ref, )?; module .borrow_mut() @@ -141,7 +160,7 @@ fn call_handling_test() -> Result<(), Report> { let callee = builder.create_function( Ident::with_empty_span("callee".into()), callee_signature.clone(), - None, + &mut symbol_table_ref, )?; module .borrow_mut() diff --git a/hir/src/dialects.rs b/hir/src/dialects.rs index c3a0d4999..f1cba7e3e 100644 --- a/hir/src/dialects.rs +++ b/hir/src/dialects.rs @@ -1,3 +1,3 @@ pub mod builtin; -#[cfg(test)] +// #[cfg(test)] pub mod test; diff --git a/hir/src/dialects/test.rs b/hir/src/dialects/test.rs index 40b40b0eb..a1c5e2322 100644 --- a/hir/src/dialects/test.rs +++ b/hir/src/dialects/test.rs @@ -119,5 +119,6 @@ impl DialectRegistration for TestDialect { info.register_operation::(); info.register_operation::(); info.register_operation::(); + info.register_operation::(); } } diff --git a/hir/src/dialects/test/ops/constants.rs b/hir/src/dialects/test/ops/constants.rs index 784b66afd..10461d2b3 100644 --- a/hir/src/dialects/test/ops/constants.rs +++ b/hir/src/dialects/test/ops/constants.rs @@ -48,3 +48,47 @@ impl EffectOpInterface for Constant { EffectIterator::from_smallvec(smallvec![]) } } + +/// An operation that holds a symboltable +/// +#[operation( + dialect = TestDialect, + traits(), + implements(SymbolTable) +)] +pub struct SymbolTableHolder { + #[default] + symbols: SymbolMap, + #[default] + uses: SymbolUseList, +} + +impl SymbolTable for SymbolTableHolder { + #[inline(always)] + fn as_symbol_table_operation(&self) -> &Operation { + &self.op + } + + #[inline(always)] + fn as_symbol_table_ref(&self) -> SymbolTableRef { + unsafe { SymbolTableRef::from_raw(self) } + } + + #[inline(always)] + fn as_symbol_table_operation_mut(&mut self) -> &mut Operation { + &mut self.op + } + + fn symbol_manager(&self) -> SymbolManager<'_> { + SymbolManager::new(&self.op, crate::Symbols::Borrowed(&self.symbols)) + } + + fn symbol_manager_mut(&mut self) -> SymbolManagerMut<'_> { + SymbolManagerMut::new(&mut self.op, crate::SymbolsMut::Borrowed(&mut self.symbols)) + } + + #[inline] + fn get(&self, name: SymbolName) -> Option { + self.symbols.get(name) + } +} diff --git a/hir/src/lib.rs b/hir/src/lib.rs index 51f0af058..d5bcac6d5 100644 --- a/hir/src/lib.rs +++ b/hir/src/lib.rs @@ -41,7 +41,7 @@ // Some of the above features require us to disable these warnings #![allow(incomplete_features)] #![allow(internal_features)] -#![deny(warnings)] +// #![deny(warnings)] extern crate alloc; diff --git a/hir/src/matchers/matcher.rs b/hir/src/matchers/matcher.rs index a3abb9773..3982cc5b0 100644 --- a/hir/src/matchers/matcher.rs +++ b/hir/src/matchers/matcher.rs @@ -752,11 +752,18 @@ mod tests { fn setup(context: Rc) -> (ValueRef, ValueRef, ValueRef) { let mut builder = OpBuilder::new(Rc::clone(&context)); + let span = SourceSpan::default(); + let mut sym_builder = builder.create::(span); + + let mut symbol_table_ref = sym_builder() + .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") + .borrow_mut() + .as_symbol_table_ref(); let function = { let builder = builder.create::(SourceSpan::default()); let name = Ident::new("test".into(), SourceSpan::default()); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature, None).unwrap() + builder(name, signature, &mut symbol_table_ref).unwrap() }; // Define function body diff --git a/hir/src/patterns/pattern.rs b/hir/src/patterns/pattern.rs index c8f534c7a..b557d4411 100644 --- a/hir/src/patterns/pattern.rs +++ b/hir/src/patterns/pattern.rs @@ -327,11 +327,18 @@ mod tests { let pattern = ConvertShiftLeftBy1ToMultiply::new(Rc::clone(&context)); let mut builder = OpBuilder::new(Rc::clone(&context)); + let span = SourceSpan::default(); + let mut sym_builder = builder.create::(span); + + let mut symbol_table_ref = sym_builder() + .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") + .borrow_mut() + .as_symbol_table_ref(); let function = { let builder = builder.create::(SourceSpan::default()); let name = Ident::new("test".into(), SourceSpan::default()); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature, None).unwrap() + builder(name, signature, &mut symbol_table_ref).unwrap() }; // Define function body From 80ac36242ee5503806918bdcd8fe3bae75529ce1 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 16:31:11 -0300 Subject: [PATCH 50/78] WIP: Gotem? Signed-off-by: Tomas Fabrizio Orsi --- hir/src/dialects/test/ops/constants.rs | 12 +++++++++++- hir/src/matchers/matcher.rs | 12 +++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/hir/src/dialects/test/ops/constants.rs b/hir/src/dialects/test/ops/constants.rs index 10461d2b3..0349ce43b 100644 --- a/hir/src/dialects/test/ops/constants.rs +++ b/hir/src/dialects/test/ops/constants.rs @@ -53,10 +53,20 @@ impl EffectOpInterface for Constant { /// #[operation( dialect = TestDialect, - traits(), + traits( + SingleRegion, + SingleBlock, + NoRegionArguments, + NoTerminator, + // HasOnlyGraphRegion, + // GraphRegionNoTerminator, + IsolatedFromAbove, + ), implements(SymbolTable) )] pub struct SymbolTableHolder { + #[region] + body: RegionRef, #[default] symbols: SymbolMap, #[default] diff --git a/hir/src/matchers/matcher.rs b/hir/src/matchers/matcher.rs index 3982cc5b0..8491f1881 100644 --- a/hir/src/matchers/matcher.rs +++ b/hir/src/matchers/matcher.rs @@ -752,18 +752,16 @@ mod tests { fn setup(context: Rc) -> (ValueRef, ValueRef, ValueRef) { let mut builder = OpBuilder::new(Rc::clone(&context)); - let span = SourceSpan::default(); - let mut sym_builder = builder.create::(span); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); - let mut symbol_table_ref = sym_builder() - .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") - .borrow_mut() - .as_symbol_table_ref(); let function = { let builder = builder.create::(SourceSpan::default()); let name = Ident::new("test".into(), SourceSpan::default()); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature, &mut symbol_table_ref).unwrap() + builder(name, signature, world).unwrap() }; // Define function body From 4f1bd7c804f9442e08d113e972ecb2a16779b4dd Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 16:46:06 -0300 Subject: [PATCH 51/78] cfg_to_scf test Signed-off-by: Tomas Fabrizio Orsi --- dialects/scf/src/transforms/cfg_to_scf.rs | 17 ++++++------ ..._scf_lift_conditional_early_exit_after.hir | 26 +++++++++---------- ...scf_lift_conditional_early_exit_before.hir | 26 +++++++++---------- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/dialects/scf/src/transforms/cfg_to_scf.rs b/dialects/scf/src/transforms/cfg_to_scf.rs index ade633211..3360a6c6e 100644 --- a/dialects/scf/src/transforms/cfg_to_scf.rs +++ b/dialects/scf/src/transforms/cfg_to_scf.rs @@ -372,7 +372,7 @@ mod tests { use builtin::{BuiltinOpBuilder, FunctionBuilder}; use expect_test::expect_file; use midenc_hir::{ - dialects::{builtin, test}, + dialects::{builtin, builtin::WorldBuilder, test}, pass, AbiParam, BuilderExt, Context, Ident, OpBuilder, PointerType, Report, Signature, SourceSpan, SymbolTable, Type, }; @@ -455,15 +455,14 @@ mod tests { let context = Rc::new(Context::default()); let mut builder = OpBuilder::new(context.clone()); - let span = SourceSpan::default(); - let function = { - let mut sym_builder = builder.create::(span); - let mut symbol_table_ref = sym_builder() - .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") - .borrow_mut() - .as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + + let function = { let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new( @@ -475,7 +474,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature, &mut symbol_table_ref).unwrap() + builder(name, signature, world).unwrap() }; // Define function body diff --git a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_conditional_early_exit_after.hir b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_conditional_early_exit_after.hir index aee2ec449..945ea7a66 100644 --- a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_conditional_early_exit_after.hir +++ b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_conditional_early_exit_after.hir @@ -1,51 +1,51 @@ public builtin.function @test(v0: u32, v1: u32, v2: u32, v3: u32) -> u32 { -^block0(v0: u32, v1: u32, v2: u32, v3: u32): +^block1(v0: u32, v1: u32, v2: u32, v3: u32): v18 = arith.constant 1 : u32; v17 = ub.poison u32 : u32; v13 = arith.constant 0 : u32; v5 = arith.constant 0 : u32; v6 = arith.neq v1, v5 : i1; v22, v23, v24 = scf.if v6 : u32, u32, u32 { - ^block2: + ^block3: v9 = arith.incr v0 : u32; scf.yield v9, v17, v13; } else { - ^block3: + ^block4: v10 = arith.neq v3, v5 : i1; v33, v34, v35 = scf.if v10 : u32, u32, u32 { - ^block4: + ^block5: v11 = arith.incr v3 : u32; scf.yield v11, v17, v13; } else { - ^block5: + ^block6: scf.yield v17, v2, v18; }; scf.yield v33, v34, v35; }; v29, v30 = scf.index_switch v24 : u32, u32 case 0 { - ^block1: + ^block2: v7 = arith.eq v22, v5 : i1; v8 = arith.neq v7, v5 : i1; v31, v32 = scf.if v8 : u32, u32 { - ^block6: + ^block7: scf.yield v17, v18; } else { - ^block7: + ^block8: scf.yield v22, v13; }; scf.yield v31, v32; } default { - ^block13: + ^block14: scf.yield v23, v13; }; cf.switch v30 { - case 0 => ^block8(v29) - default => ^block9 + case 0 => ^block9(v29) + default => ^block10 }; -^block8(v12: u32): +^block9(v12: u32): builtin.ret v12; -^block9: +^block10: ub.unreachable ; }; \ No newline at end of file diff --git a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_conditional_early_exit_before.hir b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_conditional_early_exit_before.hir index 446f88e2e..b4dbe170e 100644 --- a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_conditional_early_exit_before.hir +++ b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_conditional_early_exit_before.hir @@ -1,25 +1,25 @@ public builtin.function @test(v0: u32, v1: u32, v2: u32, v3: u32) -> u32 { -^block0(v0: u32, v1: u32, v2: u32, v3: u32): +^block1(v0: u32, v1: u32, v2: u32, v3: u32): v5 = arith.constant 0 : u32; v6 = arith.neq v1, v5 : i1; - cf.cond_br v6 ^block2, ^block3; -^block1(v4: u32): + cf.cond_br v6 ^block3, ^block4; +^block2(v4: u32): v7 = arith.eq v4, v5 : i1; v8 = arith.neq v7, v5 : i1; - cf.cond_br v8 ^block6, ^block7; -^block2: - v9 = arith.incr v0 : u32; - cf.br ^block1(v9); + cf.cond_br v8 ^block7, ^block8; ^block3: - v10 = arith.neq v3, v5 : i1; - cf.cond_br v10 ^block4, ^block5; + v9 = arith.incr v0 : u32; + cf.br ^block2(v9); ^block4: - v11 = arith.incr v3 : u32; - cf.br ^block1(v11); + v10 = arith.neq v3, v5 : i1; + cf.cond_br v10 ^block5, ^block6; ^block5: - builtin.ret v2; + v11 = arith.incr v3 : u32; + cf.br ^block2(v11); ^block6: - ub.unreachable ; + builtin.ret v2; ^block7: + ub.unreachable ; +^block8: builtin.ret v4; }; \ No newline at end of file From 40e55ecc4c96d8c99dee767fe449f91021fab490 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 16:51:38 -0300 Subject: [PATCH 52/78] WIP: Fix tests Signed-off-by: Tomas Fabrizio Orsi --- dialects/scf/src/transforms/cfg_to_scf.rs | 13 +++++----- ...fg_to_scf_lift_nested_while_loop_after.hir | 18 ++++++------- ...g_to_scf_lift_nested_while_loop_before.hir | 26 +++++++++---------- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/dialects/scf/src/transforms/cfg_to_scf.rs b/dialects/scf/src/transforms/cfg_to_scf.rs index 3360a6c6e..871840d6b 100644 --- a/dialects/scf/src/transforms/cfg_to_scf.rs +++ b/dialects/scf/src/transforms/cfg_to_scf.rs @@ -651,14 +651,13 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); let span = SourceSpan::default(); - let function = { - let mut sym_builder = builder.create::(span); - let mut symbol_table_ref = sym_builder() - .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") - .borrow_mut() - .as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let function = { let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new( @@ -669,7 +668,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature, &mut symbol_table_ref).unwrap() + builder(name, signature, world).unwrap() }; // Define function body for the following pseudocode: diff --git a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_nested_while_loop_after.hir b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_nested_while_loop_after.hir index cfce15343..b69cf3656 100644 --- a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_nested_while_loop_after.hir +++ b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_nested_while_loop_after.hir @@ -1,26 +1,26 @@ public builtin.function @test(v0: ptr, v1: u32, v2: u32) -> u32 { -^block0(v0: ptr, v1: u32, v2: u32): +^block1(v0: ptr, v1: u32, v2: u32): v26 = ub.poison u32 : u32; v25 = arith.constant 1 : u32; v20 = arith.constant 0 : u32; v7 = arith.constant 0 : u32; v34, v35, v36 = scf.while v7, v7, v26 : u32, u32, u32 { - ^block1(v3: u32, v4: u32, v30: u32): + ^block2(v3: u32, v4: u32, v30: u32): v8 = arith.lt v3, v1 : i1; v65, v66, v67, v68 = scf.if v8 : u32, u32, u32, u32 { - ^block18: + ^block19: scf.yield v26, v26, v25, v20; } else { - ^block3: + ^block4: v9 = arith.mul v3, v2 : u32 #[overflow = unchecked]; v55, v56, v57 = scf.while v7, v4, v26 : u32, u32, u32 { - ^block2(v5: u32, v6: u32, v51: u32): + ^block3(v5: u32, v6: u32, v51: u32): v10 = arith.lt v5, v2 : i1; v69, v70, v71, v72 = scf.if v10 : u32, u32, u32, u32 { - ^block19: + ^block20: scf.yield v26, v26, v25, v20; } else { - ^block5: + ^block6: v12 = arith.add v9, v5 : u32 #[overflow = unchecked]; v13 = builtin.unrealized_conversion_cast v0 : u32; v14 = arith.add v13, v12 : u32 #[overflow = unchecked]; @@ -33,7 +33,7 @@ public builtin.function @test(v0: ptr, v1: u32, v2: u32) -> u32 { v64 = arith.trunc v72 : i1; scf.condition v64, v69, v70, v6; } do { - ^block17(v61: u32, v62: u32, v63: u32): + ^block18(v61: u32, v62: u32, v63: u32): scf.yield v61, v62, v63; }; v11 = arith.incr v3 : u32; @@ -42,7 +42,7 @@ public builtin.function @test(v0: ptr, v1: u32, v2: u32) -> u32 { v43 = arith.trunc v68 : i1; scf.condition v43, v65, v66, v4; } do { - ^block12(v40: u32, v41: u32, v42: u32): + ^block13(v40: u32, v41: u32, v42: u32): scf.yield v40, v41, v42; }; builtin.ret v36; diff --git a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_nested_while_loop_before.hir b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_nested_while_loop_before.hir index 5f5e41efa..fa746727f 100644 --- a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_nested_while_loop_before.hir +++ b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_nested_while_loop_before.hir @@ -1,19 +1,19 @@ public builtin.function @test(v0: ptr, v1: u32, v2: u32) -> u32 { -^block0(v0: ptr, v1: u32, v2: u32): +^block1(v0: ptr, v1: u32, v2: u32): v7 = arith.constant 0 : u32; - cf.br ^block1(v7, v7); -^block1(v3: u32, v4: u32): + cf.br ^block2(v7, v7); +^block2(v3: u32, v4: u32): v8 = arith.lt v3, v1 : i1; - cf.cond_br v8 ^block4, ^block3(v4); -^block2(v5: u32, v6: u32): + cf.cond_br v8 ^block5, ^block4(v4); +^block3(v5: u32, v6: u32): v10 = arith.lt v5, v2 : i1; - cf.cond_br v10 ^block6, ^block5(v6); -^block3: - v9 = arith.mul v3, v2 : u32 #[overflow = unchecked]; - cf.br ^block2(v7, v4); + cf.cond_br v10 ^block7, ^block6(v6); ^block4: - builtin.ret v4; + v9 = arith.mul v3, v2 : u32 #[overflow = unchecked]; + cf.br ^block3(v7, v4); ^block5: + builtin.ret v4; +^block6: v12 = arith.add v9, v5 : u32 #[overflow = unchecked]; v13 = builtin.unrealized_conversion_cast v0 : u32; v14 = arith.add v13, v12 : u32 #[overflow = unchecked]; @@ -21,8 +21,8 @@ public builtin.function @test(v0: ptr, v1: u32, v2: u32) -> u32 { v16 = builtin.unrealized_conversion_cast v15 : u32; v17 = arith.incr v5 : u32; v18 = arith.add v6, v16 : u32 #[overflow = unchecked]; - cf.br ^block2(v17, v18); -^block6: + cf.br ^block3(v17, v18); +^block7: v11 = arith.incr v3 : u32; - cf.br ^block1(v11, v6); + cf.br ^block2(v11, v6); }; \ No newline at end of file From 892f20f57b3b3b9720c618481e41331175801ca2 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 16:52:20 -0300 Subject: [PATCH 53/78] WIP: Fix tests Signed-off-by: Tomas Fabrizio Orsi --- dialects/scf/src/transforms/cfg_to_scf.rs | 14 ++++++-------- .../cfg_to_scf_lift_simple_conditional_after.hir | 6 +++--- .../cfg_to_scf_lift_simple_conditional_before.hir | 14 +++++++------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/dialects/scf/src/transforms/cfg_to_scf.rs b/dialects/scf/src/transforms/cfg_to_scf.rs index 871840d6b..b093717c6 100644 --- a/dialects/scf/src/transforms/cfg_to_scf.rs +++ b/dialects/scf/src/transforms/cfg_to_scf.rs @@ -386,18 +386,16 @@ mod tests { let span = SourceSpan::default(); - let function = { - let mut sym_builder = builder.create::(span); - - let mut symbol_table_ref = sym_builder() - .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") - .borrow_mut() - .as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let function = { let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature, &mut symbol_table_ref).unwrap() + builder(name, signature, world).unwrap() }; // Define function body diff --git a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_conditional_after.hir b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_conditional_after.hir index 6ee59e782..f5aec2ce4 100644 --- a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_conditional_after.hir +++ b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_conditional_after.hir @@ -1,13 +1,13 @@ public builtin.function @test(v0: u32) -> u32 { -^block0(v0: u32): +^block1(v0: u32): v2 = arith.constant 0 : u32; v3 = arith.eq v0, v2 : i1; v8 = scf.if v3 : u32 { - ^block1: + ^block2: v4 = arith.incr v0 : u32; scf.yield v4; } else { - ^block2: + ^block3: v5 = arith.mul v0, v0 : u32 #[overflow = checked]; scf.yield v5; }; diff --git a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_conditional_before.hir b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_conditional_before.hir index 2ad7c035d..7c1114f89 100644 --- a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_conditional_before.hir +++ b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_conditional_before.hir @@ -1,14 +1,14 @@ public builtin.function @test(v0: u32) -> u32 { -^block0(v0: u32): +^block1(v0: u32): v2 = arith.constant 0 : u32; v3 = arith.eq v0, v2 : i1; - cf.cond_br v3 ^block1, ^block2; -^block1: - v4 = arith.incr v0 : u32; - cf.br ^block3(v4); + cf.cond_br v3 ^block2, ^block3; ^block2: + v4 = arith.incr v0 : u32; + cf.br ^block4(v4); +^block3: v5 = arith.mul v0, v0 : u32 #[overflow = checked]; - cf.br ^block3(v5); -^block3(v1: u32): + cf.br ^block4(v5); +^block4(v1: u32): builtin.ret v1; }; \ No newline at end of file From 3b7a75192121d8fd7218c54ec02b750508d087c9 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 11:23:22 -0300 Subject: [PATCH 54/78] WIP: Fix test Signed-off-by: Tomas Fabrizio Orsi --- dialects/scf/src/transforms/cfg_to_scf.rs | 13 ++++++------- .../cfg_to_scf_lift_simple_while_loop_after.hir | 10 +++++----- .../cfg_to_scf_lift_simple_while_loop_before.hir | 14 +++++++------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/dialects/scf/src/transforms/cfg_to_scf.rs b/dialects/scf/src/transforms/cfg_to_scf.rs index b093717c6..b68786bd0 100644 --- a/dialects/scf/src/transforms/cfg_to_scf.rs +++ b/dialects/scf/src/transforms/cfg_to_scf.rs @@ -583,18 +583,17 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); let span = SourceSpan::default(); - let function = { - let mut sym_builder = builder.create::(span); - let mut symbol_table_ref = sym_builder() - .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") - .borrow_mut() - .as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let function = { let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature, &mut symbol_table_ref).unwrap() + builder(name, signature, world).unwrap() }; // Define function body diff --git a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_while_loop_after.hir b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_while_loop_after.hir index ce156c761..799767b8a 100644 --- a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_while_loop_after.hir +++ b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_while_loop_after.hir @@ -1,18 +1,18 @@ public builtin.function @test(v0: u32) -> u32 { -^block0(v0: u32): +^block1(v0: u32): v15 = ub.poison u32 : u32; v14 = arith.constant 1 : u32; v9 = arith.constant 0 : u32; v3 = arith.constant 0 : u32; v4 = arith.constant 1 : u32; v23, v24, v25 = scf.while v0, v3, v15 : u32, u32, u32 { - ^block1(v1: u32, v2: u32, v19: u32): + ^block2(v1: u32, v2: u32, v19: u32): v5 = arith.eq v1, v3 : i1; v33, v34, v35, v36 = scf.if v5 : u32, u32, u32, u32 { - ^block10: + ^block11: scf.yield v15, v15, v14, v9; } else { - ^block3: + ^block4: v6 = arith.sub v1, v4 : u32 #[overflow = unchecked]; v7 = arith.incr v2 : u32; scf.yield v6, v7, v9, v14; @@ -20,7 +20,7 @@ public builtin.function @test(v0: u32) -> u32 { v32 = arith.trunc v36 : i1; scf.condition v32, v33, v34, v2; } do { - ^block9(v29: u32, v30: u32, v31: u32): + ^block10(v29: u32, v30: u32, v31: u32): scf.yield v29, v30, v31; }; builtin.ret v25; diff --git a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_while_loop_before.hir b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_while_loop_before.hir index c744417e2..031c7cb9f 100644 --- a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_while_loop_before.hir +++ b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_simple_while_loop_before.hir @@ -1,15 +1,15 @@ public builtin.function @test(v0: u32) -> u32 { -^block0(v0: u32): +^block1(v0: u32): v3 = arith.constant 0 : u32; v4 = arith.constant 1 : u32; - cf.br ^block1(v0, v3); -^block1(v1: u32, v2: u32): + cf.br ^block2(v0, v3); +^block2(v1: u32, v2: u32): v5 = arith.eq v1, v3 : i1; - cf.cond_br v5 ^block2, ^block3; -^block2: - builtin.ret v2; + cf.cond_br v5 ^block3, ^block4; ^block3: + builtin.ret v2; +^block4: v6 = arith.sub v1, v4 : u32 #[overflow = unchecked]; v7 = arith.incr v2 : u32; - cf.br ^block1(v6, v7); + cf.br ^block2(v6, v7); }; \ No newline at end of file From 1eaa233887a298c82e341a43e3880c08c8be4743 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 16:56:09 -0300 Subject: [PATCH 55/78] WIP: Fix tests Signed-off-by: Tomas Fabrizio Orsi --- dialects/scf/src/transforms/cfg_to_scf.rs | 14 ++++---- ..._multiple_exit_nested_while_loop_after.hir | 32 +++++++++---------- ...multiple_exit_nested_while_loop_before.hir | 28 ++++++++-------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/dialects/scf/src/transforms/cfg_to_scf.rs b/dialects/scf/src/transforms/cfg_to_scf.rs index b68786bd0..17f7bd6c8 100644 --- a/dialects/scf/src/transforms/cfg_to_scf.rs +++ b/dialects/scf/src/transforms/cfg_to_scf.rs @@ -767,13 +767,13 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); let span = SourceSpan::default(); - let function = { - let mut sym_builder = builder.create::(span); - let mut symbol_table_ref = sym_builder() - .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") - .borrow_mut() - .as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + + let function = { let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new( @@ -784,7 +784,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature, &mut symbol_table_ref).unwrap() + builder(name, signature, world).unwrap() }; // Define function body for the following pseudocode: diff --git a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_multiple_exit_nested_while_loop_after.hir b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_multiple_exit_nested_while_loop_after.hir index 3ed535312..7ce0a98a4 100644 --- a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_multiple_exit_nested_while_loop_after.hir +++ b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_multiple_exit_nested_while_loop_after.hir @@ -1,20 +1,20 @@ public builtin.function @test(v0: ptr, v1: u32, v2: u32) -> u32 { -^block0(v0: ptr, v1: u32, v2: u32): +^block1(v0: ptr, v1: u32, v2: u32): v28 = arith.constant 2 : u32; v27 = ub.poison u32 : u32; v26 = arith.constant 1 : u32; v21 = arith.constant 0 : u32; v39, v40, v41, v42 = scf.while v21, v21, v27, v27 : u32, u32, u32, u32 { - ^block1(v3: u32, v4: u32, v32: u32, v34: u32): + ^block2(v3: u32, v4: u32, v32: u32, v34: u32): v8 = arith.lt v3, v1 : i1; v111, v112, v113, v114 = scf.if v8 : u32, u32, u32, u32 { - ^block3: + ^block4: v9 = arith.mul v3, v2 : u32 #[overflow = unchecked]; v82, v83, v84, v85, v86, v87, v88, v89 = scf.while v21, v4, v27, v27, v27, v27, v27, v27 : u32, u32, u32, u32, u32, u32, u32, u32 { - ^block2(v5: u32, v6: u32, v63: u32, v65: u32, v67: u32, v69: u32, v71: u32, v73: u32): + ^block3(v5: u32, v6: u32, v63: u32, v65: u32, v67: u32, v69: u32, v71: u32, v73: u32): v10 = arith.lt v5, v2 : i1; v127, v128, v129, v130, v131, v132, v133, v134 = scf.if v10 : u32, u32, u32, u32, u32, u32, u32, u32 { - ^block5: + ^block6: v12 = arith.add v9, v5 : u32 #[overflow = unchecked]; v13 = builtin.unrealized_conversion_cast v0 : u32; v14 = arith.add v13, v12 : u32 #[overflow = unchecked]; @@ -23,48 +23,48 @@ public builtin.function @test(v0: ptr, v1: u32, v2: u32) -> u32 { v17 = arith.incr v5 : u32; v18, v19 = arith.add_overflowing v6, v16 : i1, u32; v135, v136, v137, v138, v139, v140, v141, v142 = scf.if v18 : u32, u32, u32, u32, u32, u32, u32, u32 { - ^block25: + ^block26: scf.yield v27, v27, v27, v27, v26, v21, v26, v21; } else { - ^block26: + ^block27: scf.yield v17, v19, v27, v27, v27, v27, v21, v26; }; scf.yield v135, v136, v137, v138, v139, v140, v141, v142; } else { - ^block24: + ^block25: scf.yield v27, v27, v27, v27, v27, v27, v28, v21; }; v106 = arith.trunc v134 : i1; scf.condition v106, v127, v128, v6, v129, v130, v131, v132, v133; } do { - ^block19(v98: u32, v99: u32, v100: u32, v101: u32, v102: u32, v103: u32, v104: u32, v105: u32): + ^block20(v98: u32, v99: u32, v100: u32, v101: u32, v102: u32, v103: u32, v104: u32, v105: u32): scf.yield v98, v99, v100, v101, v102, v103, v104, v105; }; v115, v116, v117, v118 = scf.index_switch v89 : u32, u32, u32, u32 case 1 { - ^block22: + ^block23: scf.yield v85, v86, v87, v88; } default { - ^block6: + ^block7: v11 = arith.incr v3 : u32; scf.yield v11, v84, v21, v26; }; scf.yield v115, v116, v117, v118; } else { - ^block21: + ^block22: scf.yield v27, v27, v28, v21; }; v51 = arith.trunc v114 : i1; scf.condition v51, v111, v112, v4, v113; } do { - ^block14(v47: u32, v48: u32, v49: u32, v50: u32): + ^block15(v47: u32, v48: u32, v49: u32, v50: u32): scf.yield v47, v48, v49, v50; }; v144 = arith.eq v42, v26 : i1; - cf.cond_br v144 ^block7, ^block4; -^block4: + cf.cond_br v144 ^block8, ^block5; +^block5: builtin.ret v41; -^block7: +^block8: builtin.ret_imm 4294967295; }; \ No newline at end of file diff --git a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_multiple_exit_nested_while_loop_before.hir b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_multiple_exit_nested_while_loop_before.hir index 7e4ed12b2..8b7445f3d 100644 --- a/dialects/scf/src/transforms/expected/cfg_to_scf_lift_multiple_exit_nested_while_loop_before.hir +++ b/dialects/scf/src/transforms/expected/cfg_to_scf_lift_multiple_exit_nested_while_loop_before.hir @@ -1,19 +1,19 @@ public builtin.function @test(v0: ptr, v1: u32, v2: u32) -> u32 { -^block0(v0: ptr, v1: u32, v2: u32): +^block1(v0: ptr, v1: u32, v2: u32): v7 = arith.constant 0 : u32; - cf.br ^block1(v7, v7); -^block1(v3: u32, v4: u32): + cf.br ^block2(v7, v7); +^block2(v3: u32, v4: u32): v8 = arith.lt v3, v1 : i1; - cf.cond_br v8 ^block3(v4), ^block4; -^block2(v5: u32, v6: u32): + cf.cond_br v8 ^block4(v4), ^block5; +^block3(v5: u32, v6: u32): v10 = arith.lt v5, v2 : i1; - cf.cond_br v10 ^block5(v6), ^block6; -^block3: - v9 = arith.mul v3, v2 : u32 #[overflow = unchecked]; - cf.br ^block2(v7, v4); + cf.cond_br v10 ^block6(v6), ^block7; ^block4: - builtin.ret v4; + v9 = arith.mul v3, v2 : u32 #[overflow = unchecked]; + cf.br ^block3(v7, v4); ^block5: + builtin.ret v4; +^block6: v12 = arith.add v9, v5 : u32 #[overflow = unchecked]; v13 = builtin.unrealized_conversion_cast v0 : u32; v14 = arith.add v13, v12 : u32 #[overflow = unchecked]; @@ -21,10 +21,10 @@ public builtin.function @test(v0: ptr, v1: u32, v2: u32) -> u32 { v16 = builtin.unrealized_conversion_cast v15 : u32; v17 = arith.incr v5 : u32; v18, v19 = arith.add_overflowing v6, v16 : i1, u32; - cf.cond_br v18 ^block7, ^block2(v17, v19); -^block6: - v11 = arith.incr v3 : u32; - cf.br ^block1(v11, v6); + cf.cond_br v18 ^block8, ^block3(v17, v19); ^block7: + v11 = arith.incr v3 : u32; + cf.br ^block2(v11, v6); +^block8: builtin.ret_imm 4294967295; }; \ No newline at end of file From e7bff1dc7036e46a50708fe3f48ffec3c95b47d7 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 17:00:48 -0300 Subject: [PATCH 56/78] WIP: fix tests Signed-off-by: Tomas Fabrizio Orsi --- .../utils_emit_binary_search_1_case.hir | 6 +++--- .../utils_emit_binary_search_2_cases.hir | 8 ++++---- .../utils_emit_binary_search_3_cases.hir | 10 +++++----- .../utils_emit_binary_search_4_cases.hir | 12 ++++++------ .../utils_emit_binary_search_5_cases.hir | 14 +++++++------- .../utils_emit_binary_search_7_cases.hir | 18 +++++++++--------- codegen/masm/src/lower/utils.rs | 15 ++++++--------- 7 files changed, 40 insertions(+), 43 deletions(-) diff --git a/codegen/masm/src/lower/expected/utils_emit_binary_search_1_case.hir b/codegen/masm/src/lower/expected/utils_emit_binary_search_1_case.hir index f2d45ac2d..69c0eb58b 100644 --- a/codegen/masm/src/lower/expected/utils_emit_binary_search_1_case.hir +++ b/codegen/masm/src/lower/expected/utils_emit_binary_search_1_case.hir @@ -1,13 +1,13 @@ public builtin.function @test(v0: u32, v1: u32) -> u32 { -^block0(v0: u32, v1: u32): +^block1(v0: u32, v1: u32): v2 = scf.index_switch v0 : u32 case 0 { - ^block1: + ^block2: v3 = arith.constant 0 : u32; scf.yield v3; } default { - ^block2: + ^block3: v4 = arith.mul v0, v1 : u32 #[overflow = checked]; scf.yield v4; }; diff --git a/codegen/masm/src/lower/expected/utils_emit_binary_search_2_cases.hir b/codegen/masm/src/lower/expected/utils_emit_binary_search_2_cases.hir index e08c6b981..679fa22ef 100644 --- a/codegen/masm/src/lower/expected/utils_emit_binary_search_2_cases.hir +++ b/codegen/masm/src/lower/expected/utils_emit_binary_search_2_cases.hir @@ -1,18 +1,18 @@ public builtin.function @test(v0: u32, v1: u32) -> u32 { -^block0(v0: u32, v1: u32): +^block1(v0: u32, v1: u32): v2 = scf.index_switch v0 : u32 case 0 { - ^block1: + ^block2: v3 = arith.constant 0 : u32; scf.yield v3; } case 1 { - ^block2: + ^block3: v4 = arith.constant 1 : u32; scf.yield v4; } default { - ^block3: + ^block4: v5 = arith.mul v0, v1 : u32 #[overflow = checked]; scf.yield v5; }; diff --git a/codegen/masm/src/lower/expected/utils_emit_binary_search_3_cases.hir b/codegen/masm/src/lower/expected/utils_emit_binary_search_3_cases.hir index 3d43af5b5..d4a214516 100644 --- a/codegen/masm/src/lower/expected/utils_emit_binary_search_3_cases.hir +++ b/codegen/masm/src/lower/expected/utils_emit_binary_search_3_cases.hir @@ -1,23 +1,23 @@ public builtin.function @test(v0: u32, v1: u32) -> u32 { -^block0(v0: u32, v1: u32): +^block1(v0: u32, v1: u32): v2 = scf.index_switch v0 : u32 case 0 { - ^block1: + ^block2: v3 = arith.constant 0 : u32; scf.yield v3; } case 1 { - ^block2: + ^block3: v4 = arith.constant 1 : u32; scf.yield v4; } case 2 { - ^block3: + ^block4: v5 = arith.constant 2 : u32; scf.yield v5; } default { - ^block4: + ^block5: v6 = arith.mul v0, v1 : u32 #[overflow = checked]; scf.yield v6; }; diff --git a/codegen/masm/src/lower/expected/utils_emit_binary_search_4_cases.hir b/codegen/masm/src/lower/expected/utils_emit_binary_search_4_cases.hir index 3dc46fe2c..0e5fed5ea 100644 --- a/codegen/masm/src/lower/expected/utils_emit_binary_search_4_cases.hir +++ b/codegen/masm/src/lower/expected/utils_emit_binary_search_4_cases.hir @@ -1,28 +1,28 @@ public builtin.function @test(v0: u32, v1: u32) -> u32 { -^block0(v0: u32, v1: u32): +^block1(v0: u32, v1: u32): v2 = scf.index_switch v0 : u32 case 0 { - ^block1: + ^block2: v3 = arith.constant 0 : u32; scf.yield v3; } case 1 { - ^block2: + ^block3: v4 = arith.constant 1 : u32; scf.yield v4; } case 2 { - ^block3: + ^block4: v5 = arith.constant 2 : u32; scf.yield v5; } case 3 { - ^block4: + ^block5: v6 = arith.constant 3 : u32; scf.yield v6; } default { - ^block5: + ^block6: v7 = arith.mul v0, v1 : u32 #[overflow = checked]; scf.yield v7; }; diff --git a/codegen/masm/src/lower/expected/utils_emit_binary_search_5_cases.hir b/codegen/masm/src/lower/expected/utils_emit_binary_search_5_cases.hir index 17a279636..014e7b023 100644 --- a/codegen/masm/src/lower/expected/utils_emit_binary_search_5_cases.hir +++ b/codegen/masm/src/lower/expected/utils_emit_binary_search_5_cases.hir @@ -1,33 +1,33 @@ public builtin.function @test(v0: u32, v1: u32) -> u32 { -^block0(v0: u32, v1: u32): +^block1(v0: u32, v1: u32): v2 = scf.index_switch v0 : u32 case 0 { - ^block1: + ^block2: v3 = arith.constant 0 : u32; scf.yield v3; } case 1 { - ^block2: + ^block3: v4 = arith.constant 1 : u32; scf.yield v4; } case 2 { - ^block3: + ^block4: v5 = arith.constant 2 : u32; scf.yield v5; } case 3 { - ^block4: + ^block5: v6 = arith.constant 3 : u32; scf.yield v6; } case 4 { - ^block5: + ^block6: v7 = arith.constant 4 : u32; scf.yield v7; } default { - ^block6: + ^block7: v8 = arith.mul v0, v1 : u32 #[overflow = checked]; scf.yield v8; }; diff --git a/codegen/masm/src/lower/expected/utils_emit_binary_search_7_cases.hir b/codegen/masm/src/lower/expected/utils_emit_binary_search_7_cases.hir index a671639e2..9396b6f00 100644 --- a/codegen/masm/src/lower/expected/utils_emit_binary_search_7_cases.hir +++ b/codegen/masm/src/lower/expected/utils_emit_binary_search_7_cases.hir @@ -1,43 +1,43 @@ public builtin.function @test(v0: u32, v1: u32) -> u32 { -^block0(v0: u32, v1: u32): +^block1(v0: u32, v1: u32): v2 = scf.index_switch v0 : u32 case 0 { - ^block1: + ^block2: v3 = arith.constant 0 : u32; scf.yield v3; } case 1 { - ^block2: + ^block3: v4 = arith.constant 1 : u32; scf.yield v4; } case 2 { - ^block3: + ^block4: v5 = arith.constant 2 : u32; scf.yield v5; } case 3 { - ^block4: + ^block5: v6 = arith.constant 3 : u32; scf.yield v6; } case 4 { - ^block5: + ^block6: v7 = arith.constant 4 : u32; scf.yield v7; } case 5 { - ^block6: + ^block7: v8 = arith.constant 5 : u32; scf.yield v8; } case 6 { - ^block7: + ^block8: v9 = arith.constant 6 : u32; scf.yield v9; } default { - ^block8: + ^block9: v10 = arith.mul v0, v1 : u32 #[overflow = checked]; scf.yield v10; }; diff --git a/codegen/masm/src/lower/utils.rs b/codegen/masm/src/lower/utils.rs index a574d25c6..e175ff5a6 100644 --- a/codegen/masm/src/lower/utils.rs +++ b/codegen/masm/src/lower/utils.rs @@ -496,7 +496,7 @@ mod tests { use midenc_dialect_scf::StructuredControlFlowOpBuilder; use midenc_hir::{ dialects::{ - builtin::{self, BuiltinOpBuilder, FunctionBuilder, FunctionRef}, + builtin::{self, BuiltinOpBuilder, FunctionBuilder, FunctionRef, WorldBuilder}, test, }, formatter::PrettyPrint, @@ -849,13 +849,10 @@ mod tests { ) -> Result<(FunctionRef, masm::Block), Report> { let mut builder = OpBuilder::new(context.clone()); - let span = SourceSpan::default(); - let mut sym_builder = builder.create::(span); - - let mut symbol_table_ref = sym_builder() - .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") - .borrow_mut() - .as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function_ref = builder.create_function( Ident::with_empty_span("test".into()), @@ -863,7 +860,7 @@ mod tests { [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), - &mut symbol_table_ref, + world, )?; let (a, b) = { From 7fef78270c7d113d72a9d1eb481a0772895c859f Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 17:04:17 -0300 Subject: [PATCH 57/78] WIP: Fix tests Signed-off-by: Tomas Fabrizio Orsi --- eval/src/tests.rs | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/eval/src/tests.rs b/eval/src/tests.rs index f7a71d1c2..33336f996 100644 --- a/eval/src/tests.rs +++ b/eval/src/tests.rs @@ -6,7 +6,7 @@ use midenc_dialect_hir::HirOpBuilder; use midenc_dialect_scf::StructuredControlFlowOpBuilder; use midenc_hir::{ dialects::{ - builtin::{BuiltinOpBuilder, FunctionBuilder}, + builtin::{BuiltinOpBuilder, FunctionBuilder, World, WorldBuilder}, test, }, AbiParam, Builder, BuilderExt, Context, Ident, Op, OpBuilder, ProgramPoint, Report, Signature, @@ -75,18 +75,15 @@ fn eval_callable_test() -> Result<(), Report> { let mut builder = OpBuilder::new(test_context.context.clone()); - let span = SourceSpan::default(); - let mut sym_builder = builder.create::(span); - - let mut symbol_table_ref = sym_builder() - .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") - .borrow_mut() - .as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function = builder.create_function( Ident::with_empty_span("test".into()), Signature::new([AbiParam::new(Type::I1)], [AbiParam::new(Type::U32)]), - &mut symbol_table_ref, + world, )?; { @@ -131,15 +128,12 @@ fn call_handling_test() -> Result<(), Report> { let mut builder = OpBuilder::new(test_context.context.clone()); - let span = SourceSpan::default(); - let mut sym_builder = builder.create::(span); - let mut symbol_table_ref = sym_builder() - .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") - .borrow_mut() - .as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); - let mut module = - builder.create_module(Ident::with_empty_span("test".into()), &mut symbol_table_ref)?; + let mut module = builder.create_module(Ident::with_empty_span("test".into()), world)?; let module_body = module.borrow().body().as_region_ref(); builder.create_block(module_body, None, &[]); @@ -148,7 +142,7 @@ fn call_handling_test() -> Result<(), Report> { let entry = builder.create_function( Ident::with_empty_span("entrypoint".into()), Signature::new([AbiParam::new(Type::I1)], [AbiParam::new(Type::U32)]), - &mut symbol_table_ref, + world, )?; module .borrow_mut() @@ -160,7 +154,7 @@ fn call_handling_test() -> Result<(), Report> { let callee = builder.create_function( Ident::with_empty_span("callee".into()), callee_signature.clone(), - &mut symbol_table_ref, + world, )?; module .borrow_mut() From 7d93ff6e40678eb4a0db4bfe042020191fe383b2 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 17:10:15 -0300 Subject: [PATCH 58/78] WIP: Fix tests Signed-off-by: Tomas Fabrizio Orsi --- .../masm/src/lower/expected/utils_emit_if.hir | 6 ++--- .../lower/expected/utils_emit_if_nested.hir | 10 +++---- codegen/masm/src/lower/utils.rs | 26 +++++++------------ 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/codegen/masm/src/lower/expected/utils_emit_if.hir b/codegen/masm/src/lower/expected/utils_emit_if.hir index bf547b88f..19b72f4a2 100644 --- a/codegen/masm/src/lower/expected/utils_emit_if.hir +++ b/codegen/masm/src/lower/expected/utils_emit_if.hir @@ -1,13 +1,13 @@ public builtin.function @test(v0: u32, v1: u32) -> u32 { -^block0(v0: u32, v1: u32): +^block1(v0: u32, v1: u32): v2 = arith.constant 0 : u32; v3 = arith.eq v0, v1 : i1; v4 = scf.if v3 : u32 { - ^block1: + ^block2: v5 = arith.constant 1 : u32; scf.yield v5; } else { - ^block2: + ^block3: v6 = arith.mul v0, v2 : u32 #[overflow = checked]; scf.yield v6; }; diff --git a/codegen/masm/src/lower/expected/utils_emit_if_nested.hir b/codegen/masm/src/lower/expected/utils_emit_if_nested.hir index 12b4722bf..2ae841239 100644 --- a/codegen/masm/src/lower/expected/utils_emit_if_nested.hir +++ b/codegen/masm/src/lower/expected/utils_emit_if_nested.hir @@ -1,19 +1,19 @@ public builtin.function @test(v0: u32, v1: u32) -> u32 { -^block0(v0: u32, v1: u32): +^block1(v0: u32, v1: u32): v2 = arith.eq v0, v1 : i1; v3 = scf.if v2 : u32 { - ^block1: + ^block2: v4 = arith.constant 1 : u32; scf.yield v4; } else { - ^block2: + ^block3: v5 = arith.lt v0, v1 : i1; v6 = scf.if v5 : u32 { - ^block3: + ^block4: v7 = arith.constant 2 : u32; scf.yield v7; } else { - ^block4: + ^block5: v8 = arith.mul v0, v1 : u32 #[overflow = checked]; scf.yield v8; }; diff --git a/codegen/masm/src/lower/utils.rs b/codegen/masm/src/lower/utils.rs index e175ff5a6..80bbcac3f 100644 --- a/codegen/masm/src/lower/utils.rs +++ b/codegen/masm/src/lower/utils.rs @@ -516,13 +516,10 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); - let span = SourceSpan::default(); - let mut sym_builder = builder.create::(span); - - let mut symbol_table_ref = sym_builder() - .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") - .borrow_mut() - .as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function_ref = builder.create_function( Ident::with_empty_span("test".into()), @@ -530,7 +527,7 @@ mod tests { [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), - &mut symbol_table_ref, + world, )?; let (a, b) = { @@ -611,13 +608,10 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); - let span = SourceSpan::default(); - let mut sym_builder = builder.create::(span); - - let mut symbol_table_ref = sym_builder() - .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") - .borrow_mut() - .as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function_ref = builder.create_function( Ident::with_empty_span("test".into()), @@ -625,7 +619,7 @@ mod tests { [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), - &mut symbol_table_ref, + world, )?; let (a, b) = { From 15435490292cd63d626e273cf27a63496be4b2f9 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 17:14:26 -0300 Subject: [PATCH 59/78] WIP: Fix tests Signed-off-by: Tomas Fabrizio Orsi --- hir/src/patterns/pattern.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/hir/src/patterns/pattern.rs b/hir/src/patterns/pattern.rs index b557d4411..5c4b10cc9 100644 --- a/hir/src/patterns/pattern.rs +++ b/hir/src/patterns/pattern.rs @@ -327,18 +327,17 @@ mod tests { let pattern = ConvertShiftLeftBy1ToMultiply::new(Rc::clone(&context)); let mut builder = OpBuilder::new(Rc::clone(&context)); - let span = SourceSpan::default(); - let mut sym_builder = builder.create::(span); - let mut symbol_table_ref = sym_builder() - .expect("Error unrelated to test itself. Failed to build SymbolTableHolder.") - .borrow_mut() - .as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let function = { let builder = builder.create::(SourceSpan::default()); let name = Ident::new("test".into(), SourceSpan::default()); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature, &mut symbol_table_ref).unwrap() + builder(name, signature, world).unwrap() }; // Define function body @@ -370,7 +369,7 @@ mod tests { let output = func.as_operation().to_string(); let expected = "\ public builtin.function @test(v0: u32) -> u32 { -^block0(v0: u32): +^block1(v0: u32): v3 = test.constant 2 : u32; v4 = test.mul v0, v3 : u32 #[overflow = wrapping]; builtin.ret v4; From af3609184748372bf85856846dc5bb45dac8c0f8 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 17:33:44 -0300 Subject: [PATCH 60/78] WIP: Fix tests Signed-off-by: Tomas Fabrizio Orsi --- eval/src/tests.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/eval/src/tests.rs b/eval/src/tests.rs index 33336f996..a1384f193 100644 --- a/eval/src/tests.rs +++ b/eval/src/tests.rs @@ -138,28 +138,26 @@ fn call_handling_test() -> Result<(), Report> { let module_body = module.borrow().body().as_region_ref(); builder.create_block(module_body, None, &[]); + // let world_ref = builder.create::(Default::default())() + // .expect("Error unrelated to test: Failed to build world."); + // let mut world_builder = WorldBuilder::new(world_ref); + // let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let module_ref = &mut module.borrow_mut().as_symbol_table_ref(); + // Define entry let entry = builder.create_function( Ident::with_empty_span("entrypoint".into()), Signature::new([AbiParam::new(Type::I1)], [AbiParam::new(Type::U32)]), - world, + module_ref, )?; - module - .borrow_mut() - .symbol_manager_mut() - .insert_new(entry, ProgramPoint::Invalid); // Define callee let callee_signature = Signature::new([AbiParam::new(Type::I1)], [AbiParam::new(Type::I1)]); let callee = builder.create_function( Ident::with_empty_span("callee".into()), callee_signature.clone(), - world, + module_ref, )?; - module - .borrow_mut() - .symbol_manager_mut() - .insert_new(callee, ProgramPoint::Invalid); { let mut builder = FunctionBuilder::new(entry, &mut builder); From 7c387016f12a17372cebc216c457480a25559e97 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 17:43:48 -0300 Subject: [PATCH 61/78] chore: update OperationBuilder documentation now that an Option is no longer passed. Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 24868bd21..3fddb98b4 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -56,7 +56,7 @@ pub struct OpDefinition { /// Indicates whether the current operation could belong to a [`SymbolTable`]. /// /// If true, this operation's builder will have an additional parameter of type - ///`parent_symbol_table: Option<&mut SymbolTableRef>`. `None` is currently only used in testing. + ///`parent_symbol_table: &mut SymbolTableRef`. belongs_in_symbol_table: bool, /// The symbolic references held by this op symbols: Vec, @@ -149,6 +149,7 @@ impl OpDefinition { }; let mut create_params = vec![]; let (_, mut fields) = fields.split(); + // Compute the absolute ordering of op parameters as follows: // // * By default, the ordering is implied by the order of field declarations in the struct @@ -352,9 +353,9 @@ impl OpDefinition { } } - // If the operations has the "BelongsInSymbolTable" trait, then add an additional parameter - // to the Operation::create and OpBuilder function of type: - // parent_symbol_table: Option<&mut SymbolTableRef>, + // If the operations has the "BelongsInSymbolTable" trait, then an additional parameter is + // added to the Operation::create and OpBuilder function of type: + // parent_symbol_table: &mut SymbolTableRef, // This is a reference to the symbol table of the parent where this operation will be added. if self .traits From 619d8389a305ad9e29f58079ea61ef8e1d8173db Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 17:47:11 -0300 Subject: [PATCH 62/78] Remove Option parse_quote now that A symbol table reference is always used. Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 3fddb98b4..87451221b 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -372,8 +372,6 @@ impl OpDefinition { elem: Box::new(make_type("SymbolTableRef")), }); - // let parent_symbol_type = parse_quote! { Option< #parent_symbol_type >}; - create_params.push(OpCreateParam { param_ty: OpCreateParamType::BuildOnlyParameter( parent_symbol_table.clone(), From c918d40479242d51df658653e40f69d3a748f699 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 17:50:04 -0300 Subject: [PATCH 63/78] chore: Remove commented out code Signed-off-by: Tomas Fabrizio Orsi --- eval/src/tests.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/eval/src/tests.rs b/eval/src/tests.rs index a1384f193..9928a3354 100644 --- a/eval/src/tests.rs +++ b/eval/src/tests.rs @@ -138,10 +138,6 @@ fn call_handling_test() -> Result<(), Report> { let module_body = module.borrow().body().as_region_ref(); builder.create_block(module_body, None, &[]); - // let world_ref = builder.create::(Default::default())() - // .expect("Error unrelated to test: Failed to build world."); - // let mut world_builder = WorldBuilder::new(world_ref); - // let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let module_ref = &mut module.borrow_mut().as_symbol_table_ref(); // Define entry From 1883c0f12cd8b594b11730d05252123aa4771b0a Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 17:53:30 -0300 Subject: [PATCH 64/78] Replace inline str "SymbolTableRef" with call to stringify! and the trait Signed-off-by: Tomas Fabrizio Orsi --- hir-macros/src/operation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hir-macros/src/operation.rs b/hir-macros/src/operation.rs index 87451221b..448d1b039 100644 --- a/hir-macros/src/operation.rs +++ b/hir-macros/src/operation.rs @@ -369,7 +369,7 @@ impl OpDefinition { and_token: syn::token::And(proc_macro2::Span::call_site()), lifetime: None, mutability: Some(syn::token::Mut(proc_macro2::Span::call_site())), - elem: Box::new(make_type("SymbolTableRef")), + elem: Box::new(make_type(stringify!(SymbolTableRef))), }); create_params.push(OpCreateParam { From 21eab6e7f8b92292d6191c802382673f18cc4b79 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 18:35:59 -0300 Subject: [PATCH 65/78] WIP: Change World in favor of SymbolTableHolder in tests Signed-off-by: Tomas Fabrizio Orsi --- codegen/masm/src/lower/utils.rs | 13 +++-- hir/src/dialects/test/ops/mem.rs | 83 ++++++++++++++++++++++++++++++++ hir/src/matchers/matcher.rs | 6 +-- 3 files changed, 94 insertions(+), 8 deletions(-) diff --git a/codegen/masm/src/lower/utils.rs b/codegen/masm/src/lower/utils.rs index 80bbcac3f..7c74dad74 100644 --- a/codegen/masm/src/lower/utils.rs +++ b/codegen/masm/src/lower/utils.rs @@ -516,10 +516,13 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); - let world_ref = builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); - let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let symbol_table_holder = + builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build symbol table holder."); + let mut prim_symbol_table_builder = + test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); + let symbol_table_ref = + &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); let function_ref = builder.create_function( Ident::with_empty_span("test".into()), @@ -527,7 +530,7 @@ mod tests { [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), - world, + symbol_table_ref, )?; let (a, b) = { diff --git a/hir/src/dialects/test/ops/mem.rs b/hir/src/dialects/test/ops/mem.rs index 079ba8728..3a6693490 100644 --- a/hir/src/dialects/test/ops/mem.rs +++ b/hir/src/dialects/test/ops/mem.rs @@ -80,3 +80,86 @@ impl InferTypeOpInterface for Load { } } } + +pub type SymbolTableHolderRef = UnsafeIntrusiveEntityRef; + +/// An operation that holds a symboltable +/// +#[operation( + dialect = TestDialect, + traits( + SingleRegion, + SingleBlock, + NoRegionArguments, + NoTerminator, + // HasOnlyGraphRegion, + // GraphRegionNoTerminator, + IsolatedFromAbove, + ), + implements(SymbolTable) +)] +pub struct SymbolTableHolder { + #[region] + body: RegionRef, + #[default] + symbols: SymbolMap, + #[default] + uses: SymbolUseList, +} + +impl SymbolTable for SymbolTableHolder { + #[inline(always)] + fn as_symbol_table_operation(&self) -> &Operation { + &self.op + } + + #[inline(always)] + fn as_symbol_table_ref(&self) -> SymbolTableRef { + unsafe { SymbolTableRef::from_raw(self) } + } + + #[inline(always)] + fn as_symbol_table_operation_mut(&mut self) -> &mut Operation { + &mut self.op + } + + fn symbol_manager(&self) -> SymbolManager<'_> { + SymbolManager::new(&self.op, crate::Symbols::Borrowed(&self.symbols)) + } + + fn symbol_manager_mut(&mut self) -> SymbolManagerMut<'_> { + SymbolManagerMut::new(&mut self.op, crate::SymbolsMut::Borrowed(&mut self.symbols)) + } + + #[inline] + fn get(&self, name: SymbolName) -> Option { + self.symbols.get(name) + } +} + +pub struct PrimSymbolTableHolderBuilder { + pub sym_table_holder: SymbolTableHolderRef, + builder: OpBuilder, +} + +impl PrimSymbolTableHolderBuilder { + pub fn new(sym_table_ref: SymbolTableHolderRef) -> Self { + let sym_table_holder = sym_table_ref.borrow(); + let context = sym_table_holder.as_operation().context_rc(); + let mut builder = OpBuilder::new(context); + + let body = sym_table_holder.body(); + if let Some(current_block) = body.entry_block_ref() { + builder.set_insertion_point_to_end(current_block); + } else { + let body_ref = body.as_region_ref(); + drop(body); + builder.create_block(body_ref, None, &[]); + } + + Self { + sym_table_holder: sym_table_ref, + builder, + } + } +} diff --git a/hir/src/matchers/matcher.rs b/hir/src/matchers/matcher.rs index 8491f1881..915f2cc2c 100644 --- a/hir/src/matchers/matcher.rs +++ b/hir/src/matchers/matcher.rs @@ -752,10 +752,10 @@ mod tests { fn setup(context: Rc) -> (ValueRef, ValueRef, ValueRef) { let mut builder = OpBuilder::new(Rc::clone(&context)); - let world_ref = builder.create::(Default::default())() + let world_ref = builder.create::(Default::default())() .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); - let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let mut world_builder = PrimSymbolTableHolderBuilder::new(world_ref); + let world = &mut world_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); let function = { let builder = builder.create::(SourceSpan::default()); From 5c13e5dbf368729c27fd81b58c20150d90c3a721 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 18:39:56 -0300 Subject: [PATCH 66/78] WIP: Change World in favor of SymbolTableHolder Signed-off-by: Tomas Fabrizio Orsi --- codegen/masm/src/lower/utils.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/codegen/masm/src/lower/utils.rs b/codegen/masm/src/lower/utils.rs index 7c74dad74..fda210f60 100644 --- a/codegen/masm/src/lower/utils.rs +++ b/codegen/masm/src/lower/utils.rs @@ -611,10 +611,13 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); - let world_ref = builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); - let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let symbol_table_holder = + builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build symbol table holder."); + let mut prim_symbol_table_builder = + test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); + let symbol_table_ref = + &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); let function_ref = builder.create_function( Ident::with_empty_span("test".into()), @@ -622,7 +625,7 @@ mod tests { [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), - world, + symbol_table_ref, )?; let (a, b) = { @@ -846,10 +849,13 @@ mod tests { ) -> Result<(FunctionRef, masm::Block), Report> { let mut builder = OpBuilder::new(context.clone()); - let world_ref = builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); - let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let symbol_table_holder = + builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build symbol table holder."); + let mut prim_symbol_table_builder = + test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); + let symbol_table_ref = + &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); let function_ref = builder.create_function( Ident::with_empty_span("test".into()), @@ -857,7 +863,7 @@ mod tests { [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), - world, + symbol_table_ref, )?; let (a, b) = { From edf7a65adf79c77bb95992f5bd734c9dfa273675 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 18:47:38 -0300 Subject: [PATCH 67/78] WIP: Replace World in favor of SymbolTableHolder Signed-off-by: Tomas Fabrizio Orsi --- dialects/scf/src/transforms/cfg_to_scf.rs | 65 ++++++++++++++--------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/dialects/scf/src/transforms/cfg_to_scf.rs b/dialects/scf/src/transforms/cfg_to_scf.rs index 17f7bd6c8..9ad05079e 100644 --- a/dialects/scf/src/transforms/cfg_to_scf.rs +++ b/dialects/scf/src/transforms/cfg_to_scf.rs @@ -386,16 +386,19 @@ mod tests { let span = SourceSpan::default(); - let world_ref = builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); - let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let symbol_table_holder = + builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build symbol table holder."); + let mut prim_symbol_table_builder = + test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); + let symbol_table_ref = + &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); let function = { let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature, world).unwrap() + builder(name, signature, symbol_table_ref).unwrap() }; // Define function body @@ -455,10 +458,13 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); let span = SourceSpan::default(); - let world_ref = builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); - let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let symbol_table_holder = + builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build symbol table holder."); + let mut prim_symbol_table_builder = + test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); + let symbol_table_ref = + &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); let function = { let builder = builder.create::(span); @@ -472,7 +478,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature, world).unwrap() + builder(name, signature, symbol_table_ref).unwrap() }; // Define function body @@ -584,16 +590,19 @@ mod tests { let span = SourceSpan::default(); - let world_ref = builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); - let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let symbol_table_holder = + builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build symbol table holder."); + let mut prim_symbol_table_builder = + test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); + let symbol_table_ref = + &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); let function = { let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature, world).unwrap() + builder(name, signature, symbol_table_ref).unwrap() }; // Define function body @@ -649,10 +658,13 @@ mod tests { let span = SourceSpan::default(); - let world_ref = builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); - let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let symbol_table_holder = + builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build symbol table holder."); + let mut prim_symbol_table_builder = + test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); + let symbol_table_ref = + &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); let function = { let builder = builder.create::(span); @@ -665,7 +677,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature, world).unwrap() + builder(name, signature, symbol_table_ref).unwrap() }; // Define function body for the following pseudocode: @@ -768,10 +780,13 @@ mod tests { let span = SourceSpan::default(); - let world_ref = builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); - let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let symbol_table_holder = + builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build symbol table holder."); + let mut prim_symbol_table_builder = + test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); + let symbol_table_ref = + &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); let function = { let builder = builder.create::(span); @@ -784,7 +799,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature, world).unwrap() + builder(name, signature, symbol_table_ref).unwrap() }; // Define function body for the following pseudocode: From bdefabe03ce48efcba72eff6dbbe0f965f5173c3 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 18:51:46 -0300 Subject: [PATCH 68/78] WIP: Replace World in favor of SymbolTableHolder Signed-off-by: Tomas Fabrizio Orsi --- eval/src/tests.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/eval/src/tests.rs b/eval/src/tests.rs index 9928a3354..6a91caca3 100644 --- a/eval/src/tests.rs +++ b/eval/src/tests.rs @@ -75,15 +75,17 @@ fn eval_callable_test() -> Result<(), Report> { let mut builder = OpBuilder::new(test_context.context.clone()); - let world_ref = builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); - let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let symbol_table_holder = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build symbol table holder."); + let mut prim_symbol_table_builder = + test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); + let symbol_table_ref = + &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); let function = builder.create_function( Ident::with_empty_span("test".into()), Signature::new([AbiParam::new(Type::I1)], [AbiParam::new(Type::U32)]), - world, + symbol_table_ref, )?; { @@ -128,12 +130,15 @@ fn call_handling_test() -> Result<(), Report> { let mut builder = OpBuilder::new(test_context.context.clone()); - let world_ref = builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); - let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); + let symbol_table_holder = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build symbol table holder."); + let mut prim_symbol_table_builder = + test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); + let symbol_table_ref = + &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); - let mut module = builder.create_module(Ident::with_empty_span("test".into()), world)?; + let mut module = + builder.create_module(Ident::with_empty_span("test".into()), symbol_table_ref)?; let module_body = module.borrow().body().as_region_ref(); builder.create_block(module_body, None, &[]); From 7f1ffa4285aa0260b2dfef778590de703c501092 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 26 May 2025 18:52:02 -0300 Subject: [PATCH 69/78] Remove SymbolTableHolderl from constants file Signed-off-by: Tomas Fabrizio Orsi --- hir/src/dialects/test/builders.rs | 2 +- hir/src/dialects/test/ops/constants.rs | 54 -------------------------- 2 files changed, 1 insertion(+), 55 deletions(-) diff --git a/hir/src/dialects/test/builders.rs b/hir/src/dialects/test/builders.rs index 65cc8e6db..6f93edf4e 100644 --- a/hir/src/dialects/test/builders.rs +++ b/hir/src/dialects/test/builders.rs @@ -1,6 +1,6 @@ use crate::{ dialects::{builtin::FunctionBuilder, test::*}, - Builder, BuilderExt, OpBuilder, Report, UnsafeIntrusiveEntityRef, ValueRef, + Builder, BuilderExt, Op, OpBuilder, Report, UnsafeIntrusiveEntityRef, ValueRef, }; pub trait TestOpBuilder<'f, B: ?Sized + Builder> { diff --git a/hir/src/dialects/test/ops/constants.rs b/hir/src/dialects/test/ops/constants.rs index 0349ce43b..784b66afd 100644 --- a/hir/src/dialects/test/ops/constants.rs +++ b/hir/src/dialects/test/ops/constants.rs @@ -48,57 +48,3 @@ impl EffectOpInterface for Constant { EffectIterator::from_smallvec(smallvec![]) } } - -/// An operation that holds a symboltable -/// -#[operation( - dialect = TestDialect, - traits( - SingleRegion, - SingleBlock, - NoRegionArguments, - NoTerminator, - // HasOnlyGraphRegion, - // GraphRegionNoTerminator, - IsolatedFromAbove, - ), - implements(SymbolTable) -)] -pub struct SymbolTableHolder { - #[region] - body: RegionRef, - #[default] - symbols: SymbolMap, - #[default] - uses: SymbolUseList, -} - -impl SymbolTable for SymbolTableHolder { - #[inline(always)] - fn as_symbol_table_operation(&self) -> &Operation { - &self.op - } - - #[inline(always)] - fn as_symbol_table_ref(&self) -> SymbolTableRef { - unsafe { SymbolTableRef::from_raw(self) } - } - - #[inline(always)] - fn as_symbol_table_operation_mut(&mut self) -> &mut Operation { - &mut self.op - } - - fn symbol_manager(&self) -> SymbolManager<'_> { - SymbolManager::new(&self.op, crate::Symbols::Borrowed(&self.symbols)) - } - - fn symbol_manager_mut(&mut self) -> SymbolManagerMut<'_> { - SymbolManagerMut::new(&mut self.op, crate::SymbolsMut::Borrowed(&mut self.symbols)) - } - - #[inline] - fn get(&self, name: SymbolName) -> Option { - self.symbols.get(name) - } -} From 1df638bd5e979699e74102646299f5aae2616ce8 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 27 May 2025 09:48:45 -0300 Subject: [PATCH 70/78] De-comment #[deny(warning)]s Signed-off-by: Tomas Fabrizio Orsi --- dialects/scf/src/lib.rs | 2 +- dialects/scf/src/transforms/cfg_to_scf.rs | 2 +- eval/src/lib.rs | 2 +- eval/src/tests.rs | 6 +++--- hir/src/dialects/test/builders.rs | 2 +- hir/src/dialects/test/ops/mem.rs | 2 ++ hir/src/lib.rs | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dialects/scf/src/lib.rs b/dialects/scf/src/lib.rs index 55103e2d3..86597de17 100644 --- a/dialects/scf/src/lib.rs +++ b/dialects/scf/src/lib.rs @@ -5,7 +5,7 @@ #![feature(ptr_metadata)] #![feature(specialization)] #![allow(incomplete_features)] -// #![deny(warnings)] +#![deny(warnings)] extern crate alloc; diff --git a/dialects/scf/src/transforms/cfg_to_scf.rs b/dialects/scf/src/transforms/cfg_to_scf.rs index 9ad05079e..a4e58403f 100644 --- a/dialects/scf/src/transforms/cfg_to_scf.rs +++ b/dialects/scf/src/transforms/cfg_to_scf.rs @@ -372,7 +372,7 @@ mod tests { use builtin::{BuiltinOpBuilder, FunctionBuilder}; use expect_test::expect_file; use midenc_hir::{ - dialects::{builtin, builtin::WorldBuilder, test}, + dialects::{builtin, test}, pass, AbiParam, BuilderExt, Context, Ident, OpBuilder, PointerType, Report, Signature, SourceSpan, SymbolTable, Type, }; diff --git a/eval/src/lib.rs b/eval/src/lib.rs index 125f2a40a..bb8313c91 100644 --- a/eval/src/lib.rs +++ b/eval/src/lib.rs @@ -1,6 +1,6 @@ #![no_std] #![feature(debug_closure_helpers)] -// #![deny(warnings)] +#![deny(warnings)] #[cfg(any(feature = "std", test))] extern crate std; diff --git a/eval/src/tests.rs b/eval/src/tests.rs index 6a91caca3..4d8fbb3e9 100644 --- a/eval/src/tests.rs +++ b/eval/src/tests.rs @@ -6,11 +6,11 @@ use midenc_dialect_hir::HirOpBuilder; use midenc_dialect_scf::StructuredControlFlowOpBuilder; use midenc_hir::{ dialects::{ - builtin::{BuiltinOpBuilder, FunctionBuilder, World, WorldBuilder}, + builtin::{BuiltinOpBuilder, FunctionBuilder}, test, }, - AbiParam, Builder, BuilderExt, Context, Ident, Op, OpBuilder, ProgramPoint, Report, Signature, - SourceSpan, SymbolTable, Type, ValueRef, + AbiParam, Builder, BuilderExt, Context, Ident, Op, OpBuilder, Report, Signature, SourceSpan, + SymbolTable, Type, ValueRef, }; use crate::*; diff --git a/hir/src/dialects/test/builders.rs b/hir/src/dialects/test/builders.rs index 6f93edf4e..65cc8e6db 100644 --- a/hir/src/dialects/test/builders.rs +++ b/hir/src/dialects/test/builders.rs @@ -1,6 +1,6 @@ use crate::{ dialects::{builtin::FunctionBuilder, test::*}, - Builder, BuilderExt, Op, OpBuilder, Report, UnsafeIntrusiveEntityRef, ValueRef, + Builder, BuilderExt, OpBuilder, Report, UnsafeIntrusiveEntityRef, ValueRef, }; pub trait TestOpBuilder<'f, B: ?Sized + Builder> { diff --git a/hir/src/dialects/test/ops/mem.rs b/hir/src/dialects/test/ops/mem.rs index 3a6693490..ea47be0f4 100644 --- a/hir/src/dialects/test/ops/mem.rs +++ b/hir/src/dialects/test/ops/mem.rs @@ -137,6 +137,8 @@ impl SymbolTable for SymbolTableHolder { } } +// The builder is not used; however is kept in order to maintain consitency with the other builders +#[allow(dead_code)] pub struct PrimSymbolTableHolderBuilder { pub sym_table_holder: SymbolTableHolderRef, builder: OpBuilder, diff --git a/hir/src/lib.rs b/hir/src/lib.rs index d5bcac6d5..51f0af058 100644 --- a/hir/src/lib.rs +++ b/hir/src/lib.rs @@ -41,7 +41,7 @@ // Some of the above features require us to disable these warnings #![allow(incomplete_features)] #![allow(internal_features)] -// #![deny(warnings)] +#![deny(warnings)] extern crate alloc; From 64358ec133e9cc3d48a718f6308cff976a5bf771 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 27 May 2025 09:56:24 -0300 Subject: [PATCH 71/78] Remove unused traits from SymbolTableHolder struct Signed-off-by: Tomas Fabrizio Orsi --- hir/src/dialects/test/ops/mem.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/hir/src/dialects/test/ops/mem.rs b/hir/src/dialects/test/ops/mem.rs index ea47be0f4..2ddae3c1c 100644 --- a/hir/src/dialects/test/ops/mem.rs +++ b/hir/src/dialects/test/ops/mem.rs @@ -88,12 +88,7 @@ pub type SymbolTableHolderRef = UnsafeIntrusiveEntityRef; #[operation( dialect = TestDialect, traits( - SingleRegion, - SingleBlock, - NoRegionArguments, NoTerminator, - // HasOnlyGraphRegion, - // GraphRegionNoTerminator, IsolatedFromAbove, ), implements(SymbolTable) From e224ec12573f80abb012f0ec2a52803ab7e123e6 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 27 May 2025 10:07:51 -0300 Subject: [PATCH 72/78] De-comment #[deny(warning)]s Signed-off-by: Tomas Fabrizio Orsi --- codegen/masm/src/lib.rs | 2 +- codegen/masm/src/lower/utils.rs | 8 +++----- tests/integration/src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/codegen/masm/src/lib.rs b/codegen/masm/src/lib.rs index 9b8325595..d15414fbd 100644 --- a/codegen/masm/src/lib.rs +++ b/codegen/masm/src/lib.rs @@ -4,7 +4,7 @@ #![feature(array_chunks)] #![feature(iter_array_chunks)] #![feature(iterator_try_collect)] -// #![deny(warnings)] +#![deny(warnings)] extern crate alloc; diff --git a/codegen/masm/src/lower/utils.rs b/codegen/masm/src/lower/utils.rs index fda210f60..3ebf83ca0 100644 --- a/codegen/masm/src/lower/utils.rs +++ b/codegen/masm/src/lower/utils.rs @@ -1,7 +1,5 @@ use midenc_dialect_scf as scf; -use midenc_hir::{ - BuilderExt, Op, Operation, Region, Report, SourceSpan, Spanned, SymbolTable, ValueRef, -}; +use midenc_hir::{Op, Operation, Region, Report, Spanned, ValueRef}; use smallvec::SmallVec; use crate::{emitter::BlockEmitter, masm, Constraint}; @@ -496,13 +494,13 @@ mod tests { use midenc_dialect_scf::StructuredControlFlowOpBuilder; use midenc_hir::{ dialects::{ - builtin::{self, BuiltinOpBuilder, FunctionBuilder, FunctionRef, WorldBuilder}, + builtin::{self, BuiltinOpBuilder, FunctionBuilder, FunctionRef}, test, }, formatter::PrettyPrint, pass::AnalysisManager, version::Version, - AbiParam, Context, Ident, OpBuilder, Signature, Type, + AbiParam, BuilderExt, Context, Ident, OpBuilder, Signature, SymbolTable, Type, }; use midenc_hir_analysis::analyses::LivenessAnalysis; diff --git a/tests/integration/src/lib.rs b/tests/integration/src/lib.rs index 332c4a177..3a7da5321 100644 --- a/tests/integration/src/lib.rs +++ b/tests/integration/src/lib.rs @@ -1,7 +1,7 @@ //! Compilation and semantic tests for the whole compiler pipeline #![feature(iter_array_chunks)] #![feature(debug_closure_helpers)] -//#![deny(warnings)] +#![deny(warnings)] #![deny(missing_docs)] mod cargo_proj; From 72dd12ce24925671d4dce5ececb06f02550a3ce4 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 27 May 2025 12:10:29 -0300 Subject: [PATCH 73/78] Revert "WIP: Replace World in favor of SymbolTableHolder" This reverts commit bdefabe03ce48efcba72eff6dbbe0f965f5173c3. --- eval/src/tests.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/eval/src/tests.rs b/eval/src/tests.rs index 4d8fbb3e9..03c917de0 100644 --- a/eval/src/tests.rs +++ b/eval/src/tests.rs @@ -75,17 +75,15 @@ fn eval_callable_test() -> Result<(), Report> { let mut builder = OpBuilder::new(test_context.context.clone()); - let symbol_table_holder = builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build symbol table holder."); - let mut prim_symbol_table_builder = - test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); - let symbol_table_ref = - &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function = builder.create_function( Ident::with_empty_span("test".into()), Signature::new([AbiParam::new(Type::I1)], [AbiParam::new(Type::U32)]), - symbol_table_ref, + world, )?; { @@ -130,15 +128,12 @@ fn call_handling_test() -> Result<(), Report> { let mut builder = OpBuilder::new(test_context.context.clone()); - let symbol_table_holder = builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build symbol table holder."); - let mut prim_symbol_table_builder = - test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); - let symbol_table_ref = - &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); - let mut module = - builder.create_module(Ident::with_empty_span("test".into()), symbol_table_ref)?; + let mut module = builder.create_module(Ident::with_empty_span("test".into()), world)?; let module_body = module.borrow().body().as_region_ref(); builder.create_block(module_body, None, &[]); From 8340482031e46d08a6469e7a1d0b96c4d16b10e3 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 27 May 2025 12:11:25 -0300 Subject: [PATCH 74/78] Revert "WIP: Replace World in favor of SymbolTableHolder" This reverts commit edf7a65adf79c77bb95992f5bd734c9dfa273675. --- dialects/scf/src/transforms/cfg_to_scf.rs | 65 +++++++++-------------- 1 file changed, 25 insertions(+), 40 deletions(-) diff --git a/dialects/scf/src/transforms/cfg_to_scf.rs b/dialects/scf/src/transforms/cfg_to_scf.rs index a4e58403f..62ac6162d 100644 --- a/dialects/scf/src/transforms/cfg_to_scf.rs +++ b/dialects/scf/src/transforms/cfg_to_scf.rs @@ -386,19 +386,16 @@ mod tests { let span = SourceSpan::default(); - let symbol_table_holder = - builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build symbol table holder."); - let mut prim_symbol_table_builder = - test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); - let symbol_table_ref = - &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function = { let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature, symbol_table_ref).unwrap() + builder(name, signature, world).unwrap() }; // Define function body @@ -458,13 +455,10 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); let span = SourceSpan::default(); - let symbol_table_holder = - builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build symbol table holder."); - let mut prim_symbol_table_builder = - test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); - let symbol_table_ref = - &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function = { let builder = builder.create::(span); @@ -478,7 +472,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature, symbol_table_ref).unwrap() + builder(name, signature, world).unwrap() }; // Define function body @@ -590,19 +584,16 @@ mod tests { let span = SourceSpan::default(); - let symbol_table_holder = - builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build symbol table holder."); - let mut prim_symbol_table_builder = - test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); - let symbol_table_ref = - &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function = { let builder = builder.create::(span); let name = Ident::new("test".into(), span); let signature = Signature::new([AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)]); - builder(name, signature, symbol_table_ref).unwrap() + builder(name, signature, world).unwrap() }; // Define function body @@ -658,13 +649,10 @@ mod tests { let span = SourceSpan::default(); - let symbol_table_holder = - builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build symbol table holder."); - let mut prim_symbol_table_builder = - test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); - let symbol_table_ref = - &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function = { let builder = builder.create::(span); @@ -677,7 +665,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature, symbol_table_ref).unwrap() + builder(name, signature, world).unwrap() }; // Define function body for the following pseudocode: @@ -780,13 +768,10 @@ mod tests { let span = SourceSpan::default(); - let symbol_table_holder = - builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build symbol table holder."); - let mut prim_symbol_table_builder = - test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); - let symbol_table_ref = - &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function = { let builder = builder.create::(span); @@ -799,7 +784,7 @@ mod tests { ], [AbiParam::new(Type::U32)], ); - builder(name, signature, symbol_table_ref).unwrap() + builder(name, signature, world).unwrap() }; // Define function body for the following pseudocode: From f69e539095f048babd07caf2499befc57451cf8e Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 27 May 2025 12:11:29 -0300 Subject: [PATCH 75/78] Revert "WIP: Change World in favor of SymbolTableHolder" This reverts commit 5c13e5dbf368729c27fd81b58c20150d90c3a721. --- codegen/masm/src/lower/utils.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/codegen/masm/src/lower/utils.rs b/codegen/masm/src/lower/utils.rs index 3ebf83ca0..259f9a061 100644 --- a/codegen/masm/src/lower/utils.rs +++ b/codegen/masm/src/lower/utils.rs @@ -609,13 +609,10 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); - let symbol_table_holder = - builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build symbol table holder."); - let mut prim_symbol_table_builder = - test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); - let symbol_table_ref = - &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function_ref = builder.create_function( Ident::with_empty_span("test".into()), @@ -623,7 +620,7 @@ mod tests { [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), - symbol_table_ref, + world, )?; let (a, b) = { @@ -847,13 +844,10 @@ mod tests { ) -> Result<(FunctionRef, masm::Block), Report> { let mut builder = OpBuilder::new(context.clone()); - let symbol_table_holder = - builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build symbol table holder."); - let mut prim_symbol_table_builder = - test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); - let symbol_table_ref = - &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function_ref = builder.create_function( Ident::with_empty_span("test".into()), @@ -861,7 +855,7 @@ mod tests { [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), - symbol_table_ref, + world, )?; let (a, b) = { From 8290c78eb45bc1fc0e555101d9048b7a71d8e9bc Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 27 May 2025 12:12:02 -0300 Subject: [PATCH 76/78] Revert "WIP: Change World in favor of SymbolTableHolder in tests" This reverts commit 21eab6e7f8b92292d6191c802382673f18cc4b79. Signed-off-by: Tomas Fabrizio Orsi --- codegen/masm/src/lower/utils.rs | 13 ++---- hir/src/dialects/test/ops/mem.rs | 80 -------------------------------- hir/src/matchers/matcher.rs | 6 +-- 3 files changed, 8 insertions(+), 91 deletions(-) diff --git a/codegen/masm/src/lower/utils.rs b/codegen/masm/src/lower/utils.rs index 259f9a061..4c95fcf17 100644 --- a/codegen/masm/src/lower/utils.rs +++ b/codegen/masm/src/lower/utils.rs @@ -514,13 +514,10 @@ mod tests { let mut builder = OpBuilder::new(context.clone()); - let symbol_table_holder = - builder.create::(Default::default())() - .expect("Error unrelated to test: Failed to build symbol table holder."); - let mut prim_symbol_table_builder = - test::PrimSymbolTableHolderBuilder::new(symbol_table_holder); - let symbol_table_ref = - &mut prim_symbol_table_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); + let world_ref = builder.create::(Default::default())() + .expect("Error unrelated to test: Failed to build world."); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function_ref = builder.create_function( Ident::with_empty_span("test".into()), @@ -528,7 +525,7 @@ mod tests { [AbiParam::new(Type::U32), AbiParam::new(Type::U32)], [AbiParam::new(Type::U32)], ), - symbol_table_ref, + world, )?; let (a, b) = { diff --git a/hir/src/dialects/test/ops/mem.rs b/hir/src/dialects/test/ops/mem.rs index 2ddae3c1c..079ba8728 100644 --- a/hir/src/dialects/test/ops/mem.rs +++ b/hir/src/dialects/test/ops/mem.rs @@ -80,83 +80,3 @@ impl InferTypeOpInterface for Load { } } } - -pub type SymbolTableHolderRef = UnsafeIntrusiveEntityRef; - -/// An operation that holds a symboltable -/// -#[operation( - dialect = TestDialect, - traits( - NoTerminator, - IsolatedFromAbove, - ), - implements(SymbolTable) -)] -pub struct SymbolTableHolder { - #[region] - body: RegionRef, - #[default] - symbols: SymbolMap, - #[default] - uses: SymbolUseList, -} - -impl SymbolTable for SymbolTableHolder { - #[inline(always)] - fn as_symbol_table_operation(&self) -> &Operation { - &self.op - } - - #[inline(always)] - fn as_symbol_table_ref(&self) -> SymbolTableRef { - unsafe { SymbolTableRef::from_raw(self) } - } - - #[inline(always)] - fn as_symbol_table_operation_mut(&mut self) -> &mut Operation { - &mut self.op - } - - fn symbol_manager(&self) -> SymbolManager<'_> { - SymbolManager::new(&self.op, crate::Symbols::Borrowed(&self.symbols)) - } - - fn symbol_manager_mut(&mut self) -> SymbolManagerMut<'_> { - SymbolManagerMut::new(&mut self.op, crate::SymbolsMut::Borrowed(&mut self.symbols)) - } - - #[inline] - fn get(&self, name: SymbolName) -> Option { - self.symbols.get(name) - } -} - -// The builder is not used; however is kept in order to maintain consitency with the other builders -#[allow(dead_code)] -pub struct PrimSymbolTableHolderBuilder { - pub sym_table_holder: SymbolTableHolderRef, - builder: OpBuilder, -} - -impl PrimSymbolTableHolderBuilder { - pub fn new(sym_table_ref: SymbolTableHolderRef) -> Self { - let sym_table_holder = sym_table_ref.borrow(); - let context = sym_table_holder.as_operation().context_rc(); - let mut builder = OpBuilder::new(context); - - let body = sym_table_holder.body(); - if let Some(current_block) = body.entry_block_ref() { - builder.set_insertion_point_to_end(current_block); - } else { - let body_ref = body.as_region_ref(); - drop(body); - builder.create_block(body_ref, None, &[]); - } - - Self { - sym_table_holder: sym_table_ref, - builder, - } - } -} diff --git a/hir/src/matchers/matcher.rs b/hir/src/matchers/matcher.rs index 915f2cc2c..8491f1881 100644 --- a/hir/src/matchers/matcher.rs +++ b/hir/src/matchers/matcher.rs @@ -752,10 +752,10 @@ mod tests { fn setup(context: Rc) -> (ValueRef, ValueRef, ValueRef) { let mut builder = OpBuilder::new(Rc::clone(&context)); - let world_ref = builder.create::(Default::default())() + let world_ref = builder.create::(Default::default())() .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = PrimSymbolTableHolderBuilder::new(world_ref); - let world = &mut world_builder.sym_table_holder.borrow_mut().as_symbol_table_ref(); + let mut world_builder = WorldBuilder::new(world_ref); + let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function = { let builder = builder.create::(SourceSpan::default()); From 50e8faa2b33af0387d3570553a504c7a2dee11df Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 27 May 2025 12:16:35 -0300 Subject: [PATCH 77/78] Remove calls to SymbolTableHolder Signed-off-by: Tomas Fabrizio Orsi --- codegen/masm/src/lower/utils.rs | 5 +---- dialects/scf/src/transforms/cfg_to_scf.rs | 15 +++++++-------- eval/src/tests.rs | 5 +---- hir/src/dialects.rs | 2 +- hir/src/dialects/test.rs | 1 - 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/codegen/masm/src/lower/utils.rs b/codegen/masm/src/lower/utils.rs index 4c95fcf17..a8a8c9e58 100644 --- a/codegen/masm/src/lower/utils.rs +++ b/codegen/masm/src/lower/utils.rs @@ -493,10 +493,7 @@ mod tests { use midenc_dialect_arith::ArithOpBuilder; use midenc_dialect_scf::StructuredControlFlowOpBuilder; use midenc_hir::{ - dialects::{ - builtin::{self, BuiltinOpBuilder, FunctionBuilder, FunctionRef}, - test, - }, + dialects::builtin::{self, BuiltinOpBuilder, FunctionBuilder, FunctionRef, WorldBuilder}, formatter::PrettyPrint, pass::AnalysisManager, version::Version, diff --git a/dialects/scf/src/transforms/cfg_to_scf.rs b/dialects/scf/src/transforms/cfg_to_scf.rs index 62ac6162d..a03fbe710 100644 --- a/dialects/scf/src/transforms/cfg_to_scf.rs +++ b/dialects/scf/src/transforms/cfg_to_scf.rs @@ -372,9 +372,8 @@ mod tests { use builtin::{BuiltinOpBuilder, FunctionBuilder}; use expect_test::expect_file; use midenc_hir::{ - dialects::{builtin, test}, - pass, AbiParam, BuilderExt, Context, Ident, OpBuilder, PointerType, Report, Signature, - SourceSpan, SymbolTable, Type, + dialects::builtin, pass, AbiParam, BuilderExt, Context, Ident, OpBuilder, PointerType, + Report, Signature, SourceSpan, SymbolTable, Type, }; use super::*; @@ -388,7 +387,7 @@ mod tests { let world_ref = builder.create::(Default::default())() .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); + let mut world_builder = builtin::WorldBuilder::new(world_ref); let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function = { @@ -457,7 +456,7 @@ mod tests { let world_ref = builder.create::(Default::default())() .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); + let mut world_builder = builtin::WorldBuilder::new(world_ref); let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function = { @@ -586,7 +585,7 @@ mod tests { let world_ref = builder.create::(Default::default())() .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); + let mut world_builder = builtin::WorldBuilder::new(world_ref); let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function = { @@ -651,7 +650,7 @@ mod tests { let world_ref = builder.create::(Default::default())() .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); + let mut world_builder = builtin::WorldBuilder::new(world_ref); let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function = { @@ -770,7 +769,7 @@ mod tests { let world_ref = builder.create::(Default::default())() .expect("Error unrelated to test: Failed to build world."); - let mut world_builder = WorldBuilder::new(world_ref); + let mut world_builder = builtin::WorldBuilder::new(world_ref); let world = &mut world_builder.world.borrow_mut().as_symbol_table_ref(); let function = { diff --git a/eval/src/tests.rs b/eval/src/tests.rs index 03c917de0..640505997 100644 --- a/eval/src/tests.rs +++ b/eval/src/tests.rs @@ -5,10 +5,7 @@ use midenc_dialect_cf::ControlFlowOpBuilder; use midenc_dialect_hir::HirOpBuilder; use midenc_dialect_scf::StructuredControlFlowOpBuilder; use midenc_hir::{ - dialects::{ - builtin::{BuiltinOpBuilder, FunctionBuilder}, - test, - }, + dialects::builtin::{BuiltinOpBuilder, FunctionBuilder, World, WorldBuilder}, AbiParam, Builder, BuilderExt, Context, Ident, Op, OpBuilder, Report, Signature, SourceSpan, SymbolTable, Type, ValueRef, }; diff --git a/hir/src/dialects.rs b/hir/src/dialects.rs index f1cba7e3e..c3a0d4999 100644 --- a/hir/src/dialects.rs +++ b/hir/src/dialects.rs @@ -1,3 +1,3 @@ pub mod builtin; -// #[cfg(test)] +#[cfg(test)] pub mod test; diff --git a/hir/src/dialects/test.rs b/hir/src/dialects/test.rs index a1c5e2322..40b40b0eb 100644 --- a/hir/src/dialects/test.rs +++ b/hir/src/dialects/test.rs @@ -119,6 +119,5 @@ impl DialectRegistration for TestDialect { info.register_operation::(); info.register_operation::(); info.register_operation::(); - info.register_operation::(); } } From 8f650dad175d5cf78624c00b78a9c3ef571bd387 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 27 May 2025 16:38:51 -0300 Subject: [PATCH 78/78] Update as_symbol_table_ref documentation Signed-off-by: Tomas Fabrizio Orsi --- hir/src/ir/symbols/table.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hir/src/ir/symbols/table.rs b/hir/src/ir/symbols/table.rs index fba3c5f9d..ea4017c14 100644 --- a/hir/src/ir/symbols/table.rs +++ b/hir/src/ir/symbols/table.rs @@ -23,7 +23,7 @@ pub trait SymbolTable { /// Get a reference to the underlying [Operation] fn as_symbol_table_operation(&self) -> &Operation; - // /// Get a reference to the underlying [Operation] + /// Get a reference to the underlying [Operation] as a SymbolTable fn as_symbol_table_ref(&self) -> SymbolTableRef; /// Get a mutable reference to the underlying [Operation]