From 9177267570bda8bae4fab09d2ba051dae973ad8c Mon Sep 17 00:00:00 2001 From: Kasey White Date: Tue, 20 Dec 2022 02:20:22 -0500 Subject: [PATCH] feat: test 24 passes fixed issue with is_tuple in types minor monomorphize change --- crates/lang/src/builder.rs | 1 + crates/lang/src/tipo.rs | 15 ++++++++- crates/lang/src/uplc.rs | 63 +++++++++++++++++++++----------------- 3 files changed, 50 insertions(+), 29 deletions(-) diff --git a/crates/lang/src/builder.rs b/crates/lang/src/builder.rs index 1cb7ff46..ffa7719f 100644 --- a/crates/lang/src/builder.rs +++ b/crates/lang/src/builder.rs @@ -825,6 +825,7 @@ pub fn get_generics_and_type(tipo: &Type, param: &Type) -> Vec<(u64, Arc)> if let Some(id) = tipo.get_generic() { generics_ids.push((id, param.clone().into())); + return generics_ids; } for (tipo, param_type) in tipo diff --git a/crates/lang/src/tipo.rs b/crates/lang/src/tipo.rs index bc87262d..493cd468 100644 --- a/crates/lang/src/tipo.rs +++ b/crates/lang/src/tipo.rs @@ -162,7 +162,11 @@ impl Type { } pub fn is_tuple(&self) -> bool { - matches!(self, Self::Tuple { .. }) + match self { + Type::Var { tipo } => tipo.borrow().is_tuple(), + Type::Tuple { .. } => true, + _ => false, + } } pub fn is_generic(&self) -> bool { @@ -218,6 +222,7 @@ impl Type { } else if self.is_tuple() { match self { Self::Tuple { elems } => elems.to_vec(), + Self::Var { tipo } => tipo.borrow().get_inner_type(), _ => vec![], } } else if matches!(self.get_uplc_type(), UplcType::Data) { @@ -258,6 +263,7 @@ impl Type { UplcType::List(UplcType::Data.into()) } } + Self::Var { tipo } => tipo.borrow().get_uplc_type().unwrap(), _ => todo!(), } } else { @@ -450,6 +456,13 @@ impl TypeVar { } } + pub fn is_tuple(&self) -> bool { + match self { + Self::Link { tipo } => tipo.is_tuple(), + _ => false, + } + } + pub fn is_generic(&self) -> bool { match self { TypeVar::Generic { .. } => true, diff --git a/crates/lang/src/uplc.rs b/crates/lang/src/uplc.rs index 1ea55556..bd4d1d68 100644 --- a/crates/lang/src/uplc.rs +++ b/crates/lang/src/uplc.rs @@ -1598,17 +1598,18 @@ impl<'a> CodeGenerator<'a> { ir_stack: &mut [Air], func_components: &mut IndexMap, func_index_map: &mut IndexMap>, - recursion_func_map: IndexMap, + mut recursion_func_map: IndexMap, ) { self.process_define_ir(ir_stack, func_components, func_index_map); - let mut recursion_func_map = recursion_func_map; + let mut recursion_func_map_to_add = recursion_func_map.clone(); for func_index in func_index_map.clone().iter() { let func = func_index.0; let function_components = func_components.get(func).unwrap(); let mut function_ir = function_components.ir.clone(); + let mut skip = false; for ir in function_ir.clone() { if let Air::Var { @@ -1630,10 +1631,16 @@ impl<'a> CodeGenerator<'a> { module_name: module.clone(), function_name: func_name.clone(), variant_name: variant_name.clone(), - }) { - return; + }) && func.clone() + == (FunctionAccessKey { + module_name: module.clone(), + function_name: func_name.clone(), + variant_name: variant_name.clone(), + }) + { + skip = true; } else { - recursion_func_map.insert( + recursion_func_map_to_add.insert( FunctionAccessKey { module_name: module.clone(), function_name: func_name.clone(), @@ -1645,29 +1652,32 @@ impl<'a> CodeGenerator<'a> { } } - let mut inner_func_components = IndexMap::new(); + recursion_func_map = recursion_func_map_to_add.clone(); + if !skip { + let mut inner_func_components = IndexMap::new(); - let mut inner_func_index_map = IndexMap::new(); + let mut inner_func_index_map = IndexMap::new(); - self.define_recurse_ir( - &mut function_ir, - &mut inner_func_components, - &mut inner_func_index_map, - recursion_func_map.clone(), - ); + self.define_recurse_ir( + &mut function_ir, + &mut inner_func_components, + &mut inner_func_index_map, + recursion_func_map.clone(), + ); - //now unify - for item in inner_func_components { - if !func_components.contains_key(&item.0) { - func_components.insert(item.0, item.1); + //now unify + for item in inner_func_components { + if !func_components.contains_key(&item.0) { + func_components.insert(item.0, item.1); + } } - } - for item in inner_func_index_map { - if let Some(entry) = func_index_map.get_mut(&item.0) { - *entry = get_common_ancestor(entry, &item.1); - } else { - func_index_map.insert(item.0, item.1); + for item in inner_func_index_map { + if let Some(entry) = func_index_map.get_mut(&item.0) { + *entry = get_common_ancestor(entry, &item.1); + } else { + func_index_map.insert(item.0, item.1); + } } } } @@ -1996,17 +2006,14 @@ impl<'a> CodeGenerator<'a> { let tipo = constructor.tipo; - let args_type = match tipo.as_ref() { - Type::Fn { args, .. } | Type::App { args, .. } => args, - _ => unreachable!(), - }; + let args_type = tipo.arg_types().unwrap(); if let Some(field_map) = field_map.clone() { for field in field_map .fields .iter() .sorted_by(|item1, item2| item1.1.cmp(item2.1)) - .zip(args_type) + .zip(&args_type) .rev() { // TODO revisit