Remove 'Todo' from the AST & AIR

Todo is fundamentally just a trace and an error. The only reason we kept it as a separate element in the AST is for the formatter to work out whether it should format something back to a todo or something else.

  However, this introduces redundancy in the code internally and makes the AIR more complicated than it needs to be. Both todo and errors can actually be represented as trace + errors, and we only need to record their preferred shape when parsing so that we can format them back to what's expected.
This commit is contained in:
KtorZ
2023-02-15 21:53:11 +01:00
parent 7b676643bd
commit 6525f21712
10 changed files with 179 additions and 171 deletions

View File

@@ -587,13 +587,6 @@ impl<'a> CodeGenerator<'a> {
constants_ir(literal, ir_stack, scope);
}
},
TypedExpr::Todo { label, tipo, .. } => {
ir_stack.push(Air::Todo {
scope,
label: label.clone(),
tipo: tipo.clone(),
});
}
TypedExpr::RecordUpdate {
spread, args, tipo, ..
} => {
@@ -3494,16 +3487,6 @@ impl<'a> CodeGenerator<'a> {
tuple_index,
};
}
Air::Todo { tipo, scope, label } => {
let mut replaced_type = tipo.clone();
replace_opaque_type(&mut replaced_type, self.data_types.clone());
ir_stack[index] = Air::Todo {
scope,
label,
tipo: replaced_type,
};
}
Air::ErrorTerm { tipo, scope } => {
let mut replaced_type = tipo.clone();
replace_opaque_type(&mut replaced_type, self.data_types.clone());
@@ -5286,23 +5269,6 @@ impl<'a> CodeGenerator<'a> {
arg_stack.push(term);
}
}
Air::Todo { label, .. } => {
let term = apply_wrap(
apply_wrap(
Term::Builtin(DefaultFunction::Trace).force_wrap(),
Term::Constant(
UplcConstant::String(
label.unwrap_or_else(|| "aiken::todo".to_string()),
)
.into(),
),
),
Term::Delay(Term::Error.into()),
)
.force_wrap();
arg_stack.push(term);
}
Air::RecordUpdate {
highest_index,
indices,