Implement TraceIfFalse type-checking and AST transformation.

This caused me some trouble. In my first approach, I ended up having
  multiple traces because nested values would be evaluated twice; once
  as condition, and once as part of the continuation.

  To prevent this, we can simply evaluate the condition once, and return
  plain True / False boolean as outcome. So this effectively transforms any
  expression:

  ```
  expr
  ```

  as

  ```
  if expr { True } else { trace("...", False) }
  ```
This commit is contained in:
KtorZ
2023-02-16 13:53:05 +01:00
committed by Lucas
parent 6a50bde666
commit e9e3f4f50a
6 changed files with 130 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
use crate::{
ast::{ModuleKind, TypedModule, UntypedModule},
ast::{ModuleKind, Tracing, TypedModule, UntypedModule},
builtins, parser,
tipo::error::{Error, Warning},
IdGenerator,
@@ -24,7 +24,14 @@ fn check_module(
module_types.insert("aiken".to_string(), builtins::prelude(&id_gen));
module_types.insert("aiken/builtin".to_string(), builtins::plutus(&id_gen));
let result = ast.infer(&id_gen, kind, "test/project", &module_types, &mut warnings);
let result = ast.infer(
&id_gen,
kind,
"test/project",
&module_types,
Tracing::KeepTraces,
&mut warnings,
);
result
.map(|o| (warnings.clone(), o))