Skip to content

Commit

Permalink
checkpoint commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroProofs committed Sep 5, 2023
1 parent 8c92bf0 commit b93a3ee
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
74 changes: 40 additions & 34 deletions crates/aiken-lang/src/gen_uplc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,7 @@ impl<'a> CodeGenerator<'a> {
AirTree::list_expose(
defined_heads
.into_iter()
.zip(defined_tails.into_iter())
.zip(defined_tails)
.filter(|(head, _)| head != "_")
.map(|(head, tail)| (tail, head))
.collect_vec(),
Expand Down Expand Up @@ -2670,7 +2670,7 @@ impl<'a> CodeGenerator<'a> {

let strong_connections = algo::tarjan_scc(&graph);

for connections in strong_connections {
for (index, connections) in strong_connections.into_iter().enumerate() {
// If there's only one function, then it's only self recursive
if connections.len() < 2 {
continue;
Expand All @@ -2680,6 +2680,11 @@ impl<'a> CodeGenerator<'a> {
.iter()
.map(|index| values.get(index).unwrap())
.collect_vec();

let function_key = FunctionAccessKey {
function_name: format!("__cyclic_function_{}", index),
module_name: "".to_string(),
};
}

// Rest of code is for hoisting functions
Expand All @@ -2696,39 +2701,41 @@ impl<'a> CodeGenerator<'a> {
.get(&variant)
.unwrap_or_else(|| panic!("Missing Function Variant Definition"));

if let HoistableFunction::Function { deps, params, .. } = function {
if !params.is_empty() {
for (dep_generic_func, dep_variant) in deps.iter() {
if !(dep_generic_func == &generic_func && dep_variant == &variant) {
validator_hoistable
.insert(0, (dep_generic_func.clone(), dep_variant.clone()));

sorted_function_vec.retain(|(generic_func, variant)| {
!(generic_func == dep_generic_func && variant == dep_variant)
});
match function {
HoistableFunction::Function { deps, params, .. } => {
if !params.is_empty() {
for (dep_generic_func, dep_variant) in deps.iter() {
if !(dep_generic_func == &generic_func && dep_variant == &variant) {
validator_hoistable
.insert(0, (dep_generic_func.clone(), dep_variant.clone()));

sorted_function_vec.retain(|(generic_func, variant)| {
!(generic_func == dep_generic_func && variant == dep_variant)
});
}
}
}
}

// Fix dependencies path to be updated to common ancestor
for (dep_key, dep_variant) in deps {
let (func_tree_path, _) = functions_to_hoist
.get(&generic_func)
.unwrap()
.get(&variant)
.unwrap()
.clone();

let (dep_path, _) = functions_to_hoist
.get_mut(dep_key)
.unwrap()
.get_mut(dep_variant)
.unwrap();
// Fix dependencies path to be updated to common ancestor
for (dep_key, dep_variant) in deps {
let (func_tree_path, _) = functions_to_hoist
.get(&generic_func)
.unwrap()
.get(&variant)
.unwrap()
.clone();

let (dep_path, _) = functions_to_hoist
.get_mut(dep_key)
.unwrap()
.get_mut(dep_variant)
.unwrap();

*dep_path = func_tree_path.common_ancestor(dep_path);
*dep_path = func_tree_path.common_ancestor(dep_path);
}
}
} else {
todo!("Deal with Link later")
HoistableFunction::Link(_) => todo!("Deal with Link later"),
HoistableFunction::CyclicLink(_) => {}
}

sorted_function_vec.push((generic_func, variant));
Expand Down Expand Up @@ -3049,8 +3056,7 @@ impl<'a> CodeGenerator<'a> {

let function_def = self.functions.get(&generic_function_key);

let Some(function_def) = function_def
else {
let Some(function_def) = function_def else {
let code_gen_func = self
.code_gen_functions
.get(&generic_function_key.function_name)
Expand Down Expand Up @@ -3124,7 +3130,7 @@ impl<'a> CodeGenerator<'a> {
let mono_types: IndexMap<u64, Arc<Type>> = if !function_def_types.is_empty() {
function_def_types
.into_iter()
.zip(function_var_types.into_iter())
.zip(function_var_types)
.flat_map(|(func_tipo, var_tipo)| {
get_generic_id_and_type(&func_tipo, &var_tipo)
})
Expand Down Expand Up @@ -3430,7 +3436,7 @@ impl<'a> CodeGenerator<'a> {
UplcType::Pair(UplcType::Data.into(), UplcType::Data.into()),
convert_keys
.into_iter()
.zip(convert_values.into_iter())
.zip(convert_values)
.map(|(key, value)| {
UplcConstant::ProtoPair(
UplcType::Data,
Expand Down
2 changes: 1 addition & 1 deletion crates/aiken-lang/src/gen_uplc/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ impl AirTree {
module_name: module_name.clone(),
variant_name: variant_name.clone(),
contained_functions: contained_functions
.into_iter()
.iter()
.map(|(params, _)| params.clone())
.collect_vec(),
});
Expand Down

0 comments on commit b93a3ee

Please sign in to comment.