diff --git a/CHANGELOG.md b/CHANGELOG.md index cc12ffd0..d59e7ff0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ - **aiken-lang**: forced new line in formatter for assignments - **aiken-lang**: Incorrect parsing of generic type annotation prefixed with module - **aiken-lang**: Incorrect handling of comments at end of a file when newline not present +- **aiken-lang**: Record update in code gen is now flexible enough to support fields being passed in any order. +- **aiken-lang**: Record update now produces better uplc code then creating a record by the normal instantiation. +- **aiken-lang**: Issue with Constructors being passed as functions to other function arguments was fixed. + ## v1.0.6-alpha - 2023-05-17 diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index 51e3c378..c808d9f9 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -206,6 +206,7 @@ impl<'a> CodeGenerator<'a> { version: (1, 0, 0), term, }; + program = aiken_optimize_and_intern(program); // This is very important to call here. @@ -4777,11 +4778,16 @@ impl<'a> CodeGenerator<'a> { Air::RecordUpdate { highest_index, indices, + tipo, .. } => { self.needs_field_access = true; let tail_name_prefix = "__tail_index"; + let data_type = lookup_data_type_by_tipo(&self.data_types, &tipo) + .unwrap_or_else(|| panic!("HOW DID YOU DO THIS ON BOOL OR VOID")); + + let constructor_field_count = data_type.constructors[0].arguments.len(); let record = arg_stack.pop().unwrap(); let mut args = IndexMap::new(); @@ -4842,11 +4848,13 @@ impl<'a> CodeGenerator<'a> { let mut tail_list = Term::var(tail); if index < prev_index { - for _ in index..prev_index { - tail_list = Term::tail_list().apply(tail_list); - } + tail_list = tail_list.repeat_tail_list(prev_index - index); - term = term.lambda(suffix_tail).apply(tail_list); + if prev_index == constructor_field_count { + term = term.lambda(suffix_tail).apply(Term::empty_list()); + } else { + term = term.lambda(suffix_tail).apply(tail_list); + } } prev_index = index; } diff --git a/crates/aiken-project/src/tests/gen_uplc.rs b/crates/aiken-project/src/tests/gen_uplc.rs index 3577442e..f11ff7ae 100644 --- a/crates/aiken-project/src/tests/gen_uplc.rs +++ b/crates/aiken-project/src/tests/gen_uplc.rs @@ -2783,7 +2783,7 @@ fn record_update_output_first_last_val() { } let next_output = - Output { ..prev_output, address: Address{thing: "script_hash_0"}, script_ref: None } + Output { ..prev_output, script_ref: None, address: Address{thing: "script_hash_0"} } prev_output == next_output } @@ -2821,9 +2821,7 @@ fn record_update_output_first_last_val() { ), ) .lambda("tail_index_4") - .apply( - Term::tail_list().apply(Term::tail_list().apply(Term::var("tail_index_2"))), - ) + .apply(Term::empty_list()) .lambda("tail_index_2") .apply(Term::tail_list().apply(Term::var("tail_index_1"))) .lambda("tail_index_1")