Skip to content

Commit

Permalink
fix: function hoisting errors --
Browse files Browse the repository at this point in the history
One involving zero args being hoisted instead of compiled and replaced.
Second involving not updating a function's dependeny function scope. Which then hoisted to a lower scope and caused free unique
  • Loading branch information
MicroProofs committed Mar 27, 2023
1 parent 07cff39 commit d86c17e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions crates/aiken-lang/src/gen_uplc.rs
Expand Up @@ -2522,7 +2522,7 @@ impl<'a> CodeGenerator<'a> {
if dependency_map.contains_key(&function.0) {
dependency_map.shift_remove(&function.0);
}
dependency_map.insert(function.0, function.1);

func_keys.extend(
funct_comp
.dependencies
Expand All @@ -2535,6 +2535,15 @@ impl<'a> CodeGenerator<'a> {
})
.collect_vec(),
);

let func_scope = func_index_map.get(&function.0).unwrap().clone();

for dep in funct_comp.dependencies.iter() {
let Some(dep_scope) = func_index_map.get_mut(dep) else { unreachable!("Missing dependency scope.")};

*dep_scope = dep_scope.common_ancestor(&func_scope);
}
dependency_map.insert(function.0, function.1);
}

dependency_vec.extend(
Expand Down Expand Up @@ -2816,9 +2825,7 @@ impl<'a> CodeGenerator<'a> {
for (index, ir) in ir_stack.to_vec().iter().enumerate().rev() {
match ir {
Air::Var {
scope,
constructor,
..
scope, constructor, ..
} => {
if let ValueConstructorVariant::ModuleFn {
name,
Expand Down
2 changes: 1 addition & 1 deletion crates/aiken-lang/src/gen_uplc/builder.rs
Expand Up @@ -1473,7 +1473,7 @@ pub fn handle_func_dependencies(

let dep_scope = func_index_map.get(&dependency).unwrap();

if dep_scope.common_ancestor(func_scope) == *func_scope
if (dep_scope.common_ancestor(func_scope) == *func_scope && !depend_comp.args.is_empty())
|| function_component.args.is_empty()
{
let mut recursion_ir = vec![];
Expand Down

0 comments on commit d86c17e

Please sign in to comment.