Rework generate_raw to avoid need to intern in prop tests

Also, this commit makes `apply_term` automatically re-intern the
  program since it isn't safe to apply any term onto a UPLC program. In
  particular, terms that introduce new let-bindings (via lambdas) will
  mess with the already generated DeBruijn indices.

  The problem doesn't occur for pure constant terms like Data. So we
  still have a safe and fast version 'apply_data' when needed.
This commit is contained in:
KtorZ
2024-03-03 19:24:35 +01:00
parent 1134b8d7d0
commit 30841fe000
9 changed files with 127 additions and 120 deletions

View File

@@ -184,8 +184,13 @@ impl<'a> CodeGenerator<'a> {
self.finalize(term)
}
pub fn generate_raw(&mut self, test_body: &TypedExpr, module_name: &str) -> Program<Name> {
let mut air_tree = self.build(test_body, module_name, &[]);
pub fn generate_raw(
&mut self,
body: &TypedExpr,
args: &[TypedArg],
module_name: &str,
) -> Program<Name> {
let mut air_tree = self.build(body, module_name, &[]);
air_tree = AirTree::no_op(air_tree);
@@ -194,7 +199,13 @@ impl<'a> CodeGenerator<'a> {
// optimizations on air tree
let full_vec = full_tree.to_vec();
let term = self.uplc_code_gen(full_vec);
let mut term = self.uplc_code_gen(full_vec);
term = if args.is_empty() {
term
} else {
cast_validator_args(term, args)
};
self.finalize(term)
}