diff --git a/crates/aiken-lang/src/builder.rs b/crates/aiken-lang/src/builder.rs index a5322170..39d7d263 100644 --- a/crates/aiken-lang/src/builder.rs +++ b/crates/aiken-lang/src/builder.rs @@ -509,9 +509,9 @@ pub fn list_access_to_uplc( ))) .delayed_choose_list( term, - Term::Error.trace( - "List/Tuple/Constr contains more items than expected".to_string(), - ), + Term::Error.trace(Term::string( + "List/Tuple/Constr contains more items than expected", + )), ) } else { term @@ -530,9 +530,9 @@ pub fn list_access_to_uplc( ))) .delayed_choose_list( term, - Term::Error.trace( - "List/Tuple/Constr contains more items than expected".to_string(), - ), + Term::Error.trace(Term::string( + "List/Tuple/Constr contains more items than expected", + )), ) } else { term diff --git a/crates/aiken-lang/src/uplc.rs b/crates/aiken-lang/src/uplc.rs index 8dd76485..ab4241f6 100644 --- a/crates/aiken-lang/src/uplc.rs +++ b/crates/aiken-lang/src/uplc.rs @@ -879,7 +879,10 @@ impl<'a> CodeGenerator<'a> { // reset complex clause setting per clause back to default *clause_properties.is_complex_clause() = false; - self.build_ir(&clause.then, &mut clause_then_vec, scope.clone()); + let mut clause_scope = scope.clone(); + clause_scope.push(self.id_gen.next()); + + self.build_ir(&clause.then, &mut clause_then_vec, clause_scope); if let Some(clause_guard) = &clause.guard { let mut clause_guard_vec = vec![]; @@ -921,13 +924,16 @@ impl<'a> CodeGenerator<'a> { .. } => { let subject_name = original_subject_name.clone(); + + let mut clause_scope = scope.clone(); + clause_scope.push(self.id_gen.next()); self.when_ir( &clause.pattern, &mut clause_subject_vec, &mut clause_then_vec, subject_type, clause_properties, - scope.clone(), + clause_scope, ); let data_type = lookup_data_type_by_tipo(self.data_types.clone(), subject_type); @@ -947,6 +953,8 @@ impl<'a> CodeGenerator<'a> { complex_clause: *clause_properties.is_complex_clause(), subject_name, }); + let mut scope = scope; + scope.push(self.id_gen.next()); ir_stack.push(Air::Int { scope, @@ -2088,13 +2096,15 @@ impl<'a> CodeGenerator<'a> { } else { index }; + let mut inner_scope = scope.clone(); + inner_scope.push(self.id_gen.next()); self.extract_arg_and_index( &item.value, field_index, &mut nested_pattern, type_map.get(&field_index).unwrap(), &assignment_properties, - &scope, + &inner_scope, ) .map_or(Some(("_".to_string(), index)), Some) }) @@ -2202,13 +2212,15 @@ impl<'a> CodeGenerator<'a> { .iter() .enumerate() .filter_map(|(tuple_index, item)| { + let mut inner_scope = scope.clone(); + inner_scope.push(self.id_gen.next()); self.extract_arg_and_index( item, tuple_index, &mut nested_pattern, type_map.get(&tuple_index).unwrap(), &assignment_properties, - &scope, + &inner_scope, ) }) .sorted_by(|item1, item2| item1.1.cmp(&item2.1)) @@ -2364,13 +2376,15 @@ impl<'a> CodeGenerator<'a> { .filter_map(|item| { let label = item.label.clone().unwrap_or_default(); let field_index = field_map.fields.get(&label).map(|x| &x.0).unwrap_or(&0); + let mut inner_scope = scope.clone(); + inner_scope.push(self.id_gen.next()); self.extract_arg_and_index( &item.value, *field_index, &mut nested_pattern, type_map.get(field_index).unwrap(), &assignment_properties, - &scope, + &inner_scope, ) }) .sorted_by(|item1, item2| item1.1.cmp(&item2.1)) @@ -2466,13 +2480,15 @@ impl<'a> CodeGenerator<'a> { .enumerate() .filter_map(|(index, item)| { let field_index = index; + let mut inner_scope = scope.clone(); + inner_scope.push(self.id_gen.next()); self.extract_arg_and_index( item, field_index, &mut nested_pattern, type_map.get(&field_index).unwrap(), &assignment_properties, - &scope, + &inner_scope, ) }) .sorted_by(|item1, item2| item1.1.cmp(&item2.1)) @@ -4595,7 +4611,7 @@ impl<'a> CodeGenerator<'a> { let mut term = arg_stack.pop().unwrap(); let error_term = - Term::Error.trace("Expected on incorrect constructor variant.".to_string()); + Term::Error.trace(Term::string("Expected on incorrect constructor variant.")); term = Term::equals_integer() .apply(Term::integer(constr_index.into())) @@ -4609,7 +4625,7 @@ impl<'a> CodeGenerator<'a> { let mut term = arg_stack.pop().unwrap(); let error_term = - Term::Error.trace("Expected on incorrect boolean variant".to_string()); + Term::Error.trace(Term::string("Expected on incorrect boolean variant")); if is_true { term = value.delayed_if_else(term, error_term) @@ -5190,7 +5206,7 @@ impl<'a> CodeGenerator<'a> { let term = arg_stack.pop().unwrap(); - let term = term.trace(text.to_string()); + let term = term.trace(text); arg_stack.push(term); } diff --git a/crates/uplc/src/ast/builder.rs b/crates/uplc/src/ast/builder.rs index be2b7ad1..c4b4b302 100644 --- a/crates/uplc/src/ast/builder.rs +++ b/crates/uplc/src/ast/builder.rs @@ -38,8 +38,8 @@ impl Term { Term::Constant(Constant::Integer(i).into()) } - pub fn string(s: String) -> Self { - Term::Constant(Constant::String(s).into()) + pub fn string(s: impl ToString) -> Self { + Term::Constant(Constant::String(s.to_string()).into()) } pub fn byte_string(b: Vec) -> Self { @@ -203,10 +203,10 @@ impl Term { .force() } - pub fn trace(self, msg: String) -> Self { + pub fn trace(self, msg_term: Term) -> Self { Term::Builtin(DefaultFunction::Trace) .force() - .apply(Term::string(msg)) + .apply(msg_term) .apply(self.delay()) .force() } diff --git a/examples/acceptance_tests/script_context/plutus.json b/examples/acceptance_tests/script_context/plutus.json index bed3b3ef..13895cdb 100644 --- a/examples/acceptance_tests/script_context/plutus.json +++ b/examples/acceptance_tests/script_context/plutus.json @@ -36,8 +36,8 @@ "$ref": "#/definitions/Data" } }, - "compiledCode": "5903ee010000323232323232323232323232323232222533300a32323230020013301233300c32323375e0040026601c93260103d87980000054c103d87a80004c0103d87980003301233300c32323232323232330143253330143370e900000089919299980d980f0010a4c2a66030921334c6973742f5475706c652f436f6e73747220636f6e7461696e73206d6f7265206974656d73207468616e2065787065637465640016375a603800260240042a6602c9213a28636f6e20737472696e672022436f6e73747220696e64657820646964206e6f74206d6174636820616e7920747970652076617269616e7422290016301200153330133375e98106d8799f182aff0000113370e64600a00200690020a503019001300f3253330123370e9000180880088008a9980a24812a4578706563746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e00163322330060020010013237280026ecd30106d8799f182aff00375666018601c66018601c00e900024028600200244a66602a0022900009919b8048008cc00c00c004c060004c0040048894ccc0500084cdd2a400497ae013232323253330133371e00a002266e952000330190024bd7009998038038018029bae30150033015002301800330160024c0103d87a80004c0103d87980003301233300c32533301200116132533301300116132323232533301232323009001330193330133375e6601e6022002900226126d87a9f5820fcaa61fb85676101d9e3398a484674e71c45c3fd41b492682f3b0054f4cf3273ff004c0103d87a80004c0103d8798000330193330133375e6601e60220029003260122d8799f581ce37db487fbd58c45d059bcbf5cd6b1604d3bec16cf888f1395a4ebc4ff004c0103d87a80004c0103d87980004bd700010991918048009980c99980999baf3300f30113300f30110014800120024c012ad8799fd8799fd8799f581c66666666666666666666666666666666666666666666666666666666ffffff004c0103d87a80004c0103d879800033019333013323253330153370e900200089925130130021630130013300f30110014801130103d87a80004c0103d87980004bd700008a503018004301700416301600130150013758660106014660106014006900024008980103d87a80004c0103d87980004bd7018008009129998088008a5113232533300e00213300400400114a0602a00466e1d2002300f375460260022930b180080091129998068010a4c2660126002601e00466600600660200040026600200290001111199980399b8700100300e233330050053370000890011808000801001118039baa001230053754002ae695cdab9c5573aaae7955cfaba05742ae881", - "hash": "9e256628a3020d60ff765f9761b896c8be331ae383631f3d7038bee8" + "compiledCode": "5903df010000323232323232323232323232323232222533300a32323230020013301233300c32323375e0040026601c93260103d87980000054c103d87a80004c0103d87980003301233300c32323232323232330143253330143370e900000089919299980d980f0010a4c2a66030921334c6973742f5475706c652f436f6e73747220636f6e7461696e73206d6f7265206974656d73207468616e2065787065637465640016375a603800260240042a6602c9212b436f6e73747220696e64657820646964206e6f74206d6174636820616e7920747970652076617269616e740016301200153330133375e98106d8799f182aff0000113370e64600a00200690020a503019001300f3253330123370e9000180880088008a9980a24812a4578706563746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e00163322330060020010013237280026ecd30106d8799f182aff00375666018601c66018601c00e900024028600200244a66602a0022900009919b8048008cc00c00c004c060004c0040048894ccc0500084cdd2a400497ae013232323253330133371e00a002266e952000330190024bd7009998038038018029bae30150033015002301800330160024c0103d87a80004c0103d87980003301233300c32533301200116132533301300116132323232533301232323009001330193330133375e6601e6022002900226126d87a9f5820fcaa61fb85676101d9e3398a484674e71c45c3fd41b492682f3b0054f4cf3273ff004c0103d87a80004c0103d8798000330193330133375e6601e60220029003260122d8799f581ce37db487fbd58c45d059bcbf5cd6b1604d3bec16cf888f1395a4ebc4ff004c0103d87a80004c0103d87980004bd700010991918048009980c99980999baf3300f30113300f30110014800120024c012ad8799fd8799fd8799f581c66666666666666666666666666666666666666666666666666666666ffffff004c0103d87a80004c0103d879800033019333013323253330153370e900200089925130130021630130013300f30110014801130103d87a80004c0103d87980004bd700008a503018004301700416301600130150013758660106014660106014006900024008980103d87a80004c0103d87980004bd7018008009129998088008a5113232533300e00213300400400114a0602a00466e1d2002300f375460260022930b180080091129998068010a4c2660126002601e00466600600660200040026600200290001111199980399b8700100300e233330050053370000890011808000801001118039baa001230053754002ae695cdab9c5573aaae7955cfaba05742ae881", + "hash": "8ed0a918d0bec1b8ddaaf305564c088cdc13ad7e7a547afa6c2b1309" }, { "title": "mint.mint",