Skip to content

Commit

Permalink
change redundant if branches
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroProofs committed Jan 23, 2024
1 parent dc0707a commit 355bc29
Showing 1 changed file with 17 additions and 33 deletions.
50 changes: 17 additions & 33 deletions crates/aiken-lang/src/gen_uplc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3770,6 +3770,14 @@ impl<'a> CodeGenerator<'a> {
}
};

let convert_data_to_type = |term, tipo| {
if error_term == Term::Error {
builder::convert_data_to_type(term, tipo)
} else {
builder::convert_data_to_type_debug(term, tipo, error_term.clone())
}
};

match ir {
Air::Int { value } => Some(Term::integer(value.parse().unwrap())),
Air::String { value } => Some(Term::string(value)),
Expand Down Expand Up @@ -4506,11 +4514,7 @@ impl<'a> CodeGenerator<'a> {
Air::CastFromData { tipo, .. } => {
let mut term = arg_stack.pop().unwrap();

term = if error_term == Term::Error {
builder::convert_data_to_type(term, &tipo)
} else {
builder::convert_data_to_type_debug(term, &tipo, error_term)
};
term = convert_data_to_type(term, &tipo);

if extract_constant(&term).is_some() {
let mut program: Program<Name> = Program {
Expand Down Expand Up @@ -5221,37 +5225,17 @@ impl<'a> CodeGenerator<'a> {
assert!(names.len() == 2);

if names[1] != "_" {
term = term
.lambda(names[1].clone())
.apply(if error_term == Term::Error {
builder::convert_data_to_type(
Term::snd_pair().apply(Term::var(format!("__tuple_{list_id}"))),
&inner_types[1],
)
} else {
builder::convert_data_to_type_debug(
Term::snd_pair().apply(Term::var(format!("__tuple_{list_id}"))),
&inner_types[1],
error_term.clone(),
)
});
term = term.lambda(names[1].clone()).apply(convert_data_to_type(
Term::snd_pair().apply(Term::var(format!("__tuple_{list_id}"))),
&inner_types[1],
));
}

if names[0] != "_" {
term = term
.lambda(names[0].clone())
.apply(if error_term == Term::Error {
builder::convert_data_to_type(
Term::fst_pair().apply(Term::var(format!("__tuple_{list_id}"))),
&inner_types[0],
)
} else {
builder::convert_data_to_type_debug(
Term::fst_pair().apply(Term::var(format!("__tuple_{list_id}"))),
&inner_types[0],
error_term,
)
})
term = term.lambda(names[0].clone()).apply(convert_data_to_type(
Term::fst_pair().apply(Term::var(format!("__tuple_{list_id}"))),
&inner_types[0],
))
}

term = term.lambda(format!("__tuple_{list_id}")).apply(value);
Expand Down

0 comments on commit 355bc29

Please sign in to comment.