Skip to content

Commit

Permalink
fix: the final clause of a when expecting another clause afterwards i…
Browse files Browse the repository at this point in the history
…n nested list cases.

fix: all elements were being destructured in tuple clauses even if not used
  • Loading branch information
MicroProofs committed Jun 20, 2023
1 parent e1f788b commit 24f5c4d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 37 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
compare_with(a, >=, b) == compare_with(a, fn(l, r) { l >= r }, b)
```

### Fixed

- **aiken-lang**: Fix for the final clause of a when expecting another clause
afterwards in nested list cases.
- **aiken-lang**: Fix for all elements were being destructured in tuple clauses
even if not used.

## v1.0.10-alpha - 2023-06-13

### Added
Expand Down
88 changes: 55 additions & 33 deletions crates/aiken-lang/src/gen_uplc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,11 @@ impl<'a> CodeGenerator<'a> {
pattern_stack.merge_child(value_stack);
}
}

// final clause can not be complex
if *(clause_properties.is_final_clause()) {
*clause_properties.is_complex_clause() = false;
}
}

fn expose_elements(
Expand Down Expand Up @@ -1375,20 +1380,24 @@ impl<'a> CodeGenerator<'a> {
pattern_stack.merge_child(nested_pattern);
}
Pattern::Tuple { elems, .. } => {
let mut names = vec![];
let mut nested_pattern = pattern_stack.empty_with_scope();
let items_type = &tipo.get_inner_types();

for (index, element) in elems.iter().enumerate() {
let name = self.nested_pattern_ir_and_label(
element,
&mut nested_pattern,
&items_type[index],
*clause_properties.is_final_clause(),
);
let names = elems
.iter()
.enumerate()
.filter_map(|(index, element)| {
let name = self.nested_pattern_ir_and_label(
element,
&mut nested_pattern,
&items_type[index],
*clause_properties.is_final_clause(),
);

name.map(|name| (name, index))
})
.collect_vec();

names.push((name.unwrap_or_else(|| "_".to_string()), index))
}
let mut defined_indices = match clause_properties.clone() {
ClauseProperties::TupleClause {
defined_tuple_indices,
Expand Down Expand Up @@ -1456,6 +1465,11 @@ impl<'a> CodeGenerator<'a> {
let new_tail_name = "__tail".to_string();

if elements.is_empty() {
assert!(
!final_clause,
"Why do you have a last clause with [] in it?"
);

let mut void_stack = pattern_stack.empty_with_scope();

void_stack.void();
Expand Down Expand Up @@ -1498,13 +1512,17 @@ impl<'a> CodeGenerator<'a> {
&mut clause_properties,
);

pattern_stack.list_clause_guard(
pattern_type.clone().into(),
prev_tail_name,
None,
true,
elements_stack,
);
if !final_clause {
pattern_stack.list_clause_guard(
pattern_type.clone().into(),
prev_tail_name,
None,
true,
elements_stack,
);
} else {
pattern_stack.finally(elements_stack)
}
} else {
let mut elements_stack = pattern_stack.empty_with_scope();

Expand All @@ -1520,23 +1538,27 @@ impl<'a> CodeGenerator<'a> {
&mut clause_properties,
);

void_stack.list_clause_guard(
pattern_type.clone().into(),
&tail_name,
None,
false,
elements_stack,
);

pattern_stack.list_clause_guard(
pattern_type.clone().into(),
prev_tail_name,
Some(tail_name),
true,
void_stack,
);
if !final_clause {
void_stack.list_clause_guard(
pattern_type.clone().into(),
&tail_name,
None,
false,
elements_stack,
);

pattern_stack.list_clause_guard(
pattern_type.clone().into(),
prev_tail_name,
Some(tail_name),
true,
void_stack,
);
} else {
pattern_stack.finally(elements_stack);
}
}
} else {
} else if !final_clause {
let mut void_stack = pattern_stack.empty_with_scope();

void_stack.void();
Expand Down
8 changes: 4 additions & 4 deletions examples/acceptance_tests/script_context/plutus.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"$ref": "#/definitions/Data"
}
},
"compiledCode": "59043b01000032323232323232323232323222533300732332300100122533300e00114a226464a6660180042660080080022940c048008cdc3a400460186ea8c040004004cc030ccc01ccc8c8c8c88c8c94ccc048c0540084c8c8cdc78018009bae3015001300c32533300f3370e9000180700088008a998082492a4578706563746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e00163300a300c0034800854cc03d2401334c6973742f5475706c652f436f6e73747220636f6e7461696e73206d6f7265206974656d73207468616e2065787065637465640016375c6026002646460080026600a0029101003756660106014660106014002900024010600200244a66601e002297ae01323232323301437520026600c00c0066eb8c04000cdd5980800118098011808800980080091129998070010a5eb7bdb1804c8c8c8c94ccc038cdc7802800880189980999bb037520026e98008ccc01c01c00c014dd718078019bab300f002301200330100020014c0103d87a80004c0103d87980003300c333007333232323222323232323253330123370e90010008b0991919b87001483c850dd6980c8009808001180800099803000a44103666f6f003322323253330133370e90010008a5eb7bdb1804c8dd5980d00098088011808800998048010009bab3300b300d00348020004dd7180a0009805a99980699b8748000c030008400854cc03924012a4578706563746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e00163001001222533301000214c103d87a800013232323253330103371e00a002266e95200033015375000497ae01333007007003005375c60220066eb4c044008c05000cc048008c0040048894ccc038008530103d87a8000132323232533300e3371e00a002266e95200033013374c00497ae01333007007003005375c601e0066eacc03c008c04800cc040008cc00cc01400520023300330050014800130103d87a80004c0103d87980003300c3330073332323232223232533300f3375e006002266e1cc8c018004dd5998059806998059806802240009009240042940c050004c02cc94ccc038cdc3a4000601a00220022a6601e9212a4578706563746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e00163322330070020013756660126016660126016004900024024660126016004900118008009129998078008a400026466e0120023300300300130120013001001222533300e00214c103d87a8000132323232533300e3375e00a002266e952000330130024bd7009998038038018029807801980780118090019808001000801260103d87a80004c0103d87980004bd700a4c2c6600200290001111199980399b8700100300d233330050053370000890011807800801001118031baa001230043754002ae695ce2ab9d5573caae7d5d02ba157441",
"hash": "a2021347cc09e6b75285dd60adf40232ae1fa92c1cd813760412444f"
"compiledCode": "59043401000032323232323232323232323222533300732332300100122533300e00114a226464a6660180042660080080022940c048008cdc3a400460186ea8c040004004cc030ccc01ccc8c8c8c88c8c94ccc048c0540084c8c8cdc78018009bae3015001300c32533300f3370e9000180700088008a998082492a4578706563746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e00163300a300c0034800854cc03d2401334c6973742f5475706c652f436f6e73747220636f6e7461696e73206d6f7265206974656d73207468616e2065787065637465640016375c6026002646460080026600a0029101003756660106014660106014002900024010600200244a66601e002297ae013232323301337520026600a00a0046eb8c03c008c04c008c044004c0040048894ccc03800852f5bded8c0264646464a66601c66e3c014004400c4cc04ccdd81ba9001374c00466600e00e00600a6eb8c03c00cdd5980780118090019808001000a6103d87a80004c0103d87980003300c333007333232323222323232323253330123370e90010008b0991919b87001483c850dd6980c8009808001180800099803000a44103666f6f003322323253330133370e90010008a5eb7bdb1804c8dd5980d00098088011808800998048010009bab3300b300d00348020004dd7180a0009805a99980699b8748000c030008400854cc03924012a4578706563746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e00163001001222533301000214c103d87a800013232323253330103371e00a002266e95200033015375000497ae01333007007003005375c60220066eb4c044008c05000cc048008c0040048894ccc038008530103d87a8000132323232533300e3371e00a002266e95200033013374c00497ae01333007007003005375c601e0066eacc03c008c04800cc040008cc00cc01400520023300330050014800130103d87a80004c0103d87980003300c3330073332323232223232533300f3375e006002266e1cc8c018004dd5998059806998059806802240009009240042940c050004c02cc94ccc038cdc3a4000601a00220022a6601e9212a4578706563746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e00163322330070020013756660126016660126016004900024024660126016004900118008009129998078008a400026466e0120023300300300130120013001001222533300e00214c103d87a8000132323232533300e3375e00a002266e952000330130024bd7009998038038018029807801980780118090019808001000801260103d87a80004c0103d87980004bd700a4c2c6600200290001111199980399b8700100300d233330050053370000890011807800801001118031baa001230043754002ae695ce2ab9d5573caae7d5d02ba157441",
"hash": "0323607667c44dd282e59f9e3ae4049235264933be9e8404a641b81a"
},
{
"title": "withdrawals.spend",
Expand All @@ -64,8 +64,8 @@
"$ref": "#/definitions/Void"
}
},
"compiledCode": "59026e0100003232323232323232323232222533300832332300100122533300e00114a226464a66601a0042660080080022940c048008cdc3a400460186ea8c040004004c8c8c8cc03cccc02cc8c94ccc034cdc3a40040022c2646466e1c0052054375a602600260160046016002660026eaccc01cc024cc01cc024011200048031300126d8799fd8799f581c22222222222222222222222222222222222222222222222222222222ffff004c0103d87a80004c0103d87980003300f33300b3232533300d3370e90010008b0991919b8700148070dd6980980098058011805800998009bab33007300933007300900448001200c4c126d8799fd87a9f581cafddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72ffff004c0103d87a80004c0103d87980003300f33300b3375e6e9ccc8c88c008004c004004894ccc04000452f5c02646464646602a0026600c00c00660220066eb4c044008c050008c048004dd59980398049980398048022400090061ba73300f4c0126d8799fd8799f581c22222222222222222222222222222222222222222222222222222222ffff003300f4c126d8799fd87a9f581cafddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72ffff004bd7026103d87a80004c0103d87980004bd701119801801000980080091129998070010a6103d87a8000132323232533300f3375e00a002266e95200033013375000497ae01333007007003005300f003375a601e004602400660200042930b19800800a40004444666600e66e1c00400c0308cccc014014cdc000224004601c0020040044600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae89",
"hash": "4c1e29d1a38f1674004f2760ff0f124450b44238351640b9e5fe744f"
"compiledCode": "5902670100003232323232323232323232222533300832332300100122533300e00114a226464a66601a0042660080080022940c048008cdc3a400460186ea8c040004004c8c8c8cc03cccc02cc8c94ccc034cdc3a40040022c2646466e1c0052054375a602600260160046016002660026eaccc01cc024cc01cc024011200048031300126d8799fd8799f581c22222222222222222222222222222222222222222222222222222222ffff004c0103d87a80004c0103d87980003300f33300b3232533300d3370e90010008b0991919b8700148070dd6980980098058011805800998009bab33007300933007300900448001200c4c126d8799fd87a9f581cafddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72ffff004c0103d87a80004c0103d87980003300f33300b3375e6e9ccc8c88c008004c004004894ccc04000452f5c02646464660280026600a00a0046020004602800460240026eaccc01cc024cc01cc024011200048030dd399807a6126d8799fd8799f581c22222222222222222222222222222222222222222222222222222222ffff003300f4c126d8799fd87a9f581cafddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72ffff004bd7026103d87a80004c0103d87980004bd701119801801000980080091129998070010a6103d87a8000132323232533300f3375e00a002266e95200033013375000497ae01333007007003005300f003375a601e004602400660200042930b19800800a40004444666600e66e1c00400c0308cccc014014cdc000224004601c0020040044600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae89",
"hash": "5db9f7f98b689165b3ca293c48e3b1d482f90649641f294aa5a9fd7e"
}
],
"definitions": {
Expand Down

0 comments on commit 24f5c4d

Please sign in to comment.