Add placeholders for new terms in optimize
Update tests to check optimization is applied properly
This commit is contained in:
parent
5e2a78173b
commit
335560b81f
|
@ -2786,10 +2786,7 @@ fn when_tuple_deconstruction() {
|
||||||
Term::equals_integer()
|
Term::equals_integer()
|
||||||
.apply(
|
.apply(
|
||||||
Term::un_i_data().apply(
|
Term::un_i_data().apply(
|
||||||
Term::head_list()
|
Term::head_list().apply(
|
||||||
.apply(Term::var("__fields"))
|
|
||||||
.lambda("__fields")
|
|
||||||
.apply(
|
|
||||||
Term::var(CONSTR_FIELDS_EXPOSER).apply(Term::var("a")),
|
Term::var(CONSTR_FIELDS_EXPOSER).apply(Term::var("a")),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -3773,15 +3770,9 @@ fn foldl_type_mismatch() {
|
||||||
.apply(Term::var("mb_b_index"))
|
.apply(Term::var("mb_b_index"))
|
||||||
.delayed_if_else(
|
.delayed_if_else(
|
||||||
Term::equals_data()
|
Term::equals_data()
|
||||||
.apply(
|
.apply(Term::head_list().apply(
|
||||||
Term::head_list()
|
Term::var(CONSTR_FIELDS_EXPOSER).apply(Term::var("o")),
|
||||||
.apply(Term::var("__fields"))
|
))
|
||||||
.lambda("__fields")
|
|
||||||
.apply(
|
|
||||||
Term::var(CONSTR_FIELDS_EXPOSER)
|
|
||||||
.apply(Term::var("o")),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.apply(Term::var("addr1"))
|
.apply(Term::var("addr1"))
|
||||||
.delayed_if_else(
|
.delayed_if_else(
|
||||||
Term::constr_data().apply(Term::integer(0.into())).apply(
|
Term::constr_data().apply(Term::integer(0.into())).apply(
|
||||||
|
@ -5141,14 +5132,9 @@ fn opaque_value_in_test() {
|
||||||
.lambda("tuple_item_0")
|
.lambda("tuple_item_0")
|
||||||
.apply(Term::head_list().apply(Term::var("val")))
|
.apply(Term::head_list().apply(Term::var("val")))
|
||||||
.lambda("val")
|
.lambda("val")
|
||||||
.apply(
|
.apply(Term::unmap_data().apply(Term::head_list().apply(
|
||||||
Term::unmap_data().apply(
|
Term::tail_list().apply(Term::var(CONSTR_FIELDS_EXPOSER).apply(Term::var("dat"))),
|
||||||
Term::head_list()
|
)))
|
||||||
.apply(Term::tail_list().apply(Term::var("__fields")))
|
|
||||||
.lambda("__fields")
|
|
||||||
.apply(Term::var(CONSTR_FIELDS_EXPOSER).apply(Term::var("dat"))),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.lambda("dat")
|
.lambda("dat")
|
||||||
.apply(Term::Constant(
|
.apply(Term::Constant(
|
||||||
Constant::Data(Data::constr(
|
Constant::Data(Data::constr(
|
||||||
|
|
|
@ -129,6 +129,8 @@ fn builtin_force_reduce(term: &mut Term<Name>, builtin_map: &mut IndexMap<u8, ()
|
||||||
let arg = Rc::make_mut(argument);
|
let arg = Rc::make_mut(argument);
|
||||||
builtin_force_reduce(arg, builtin_map);
|
builtin_force_reduce(arg, builtin_map);
|
||||||
}
|
}
|
||||||
|
Term::Case { .. } => todo!(),
|
||||||
|
Term::Constr { .. } => todo!(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,6 +162,8 @@ fn force_delay_reduce(term: &mut Term<Name>) {
|
||||||
let arg = Rc::make_mut(argument);
|
let arg = Rc::make_mut(argument);
|
||||||
force_delay_reduce(arg);
|
force_delay_reduce(arg);
|
||||||
}
|
}
|
||||||
|
Term::Case { .. } => todo!(),
|
||||||
|
Term::Constr { .. } => todo!(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,6 +205,8 @@ fn inline_direct_reduce(term: &mut Term<Name>) {
|
||||||
let f = Rc::make_mut(f);
|
let f = Rc::make_mut(f);
|
||||||
inline_direct_reduce(f);
|
inline_direct_reduce(f);
|
||||||
}
|
}
|
||||||
|
Term::Case { .. } => todo!(),
|
||||||
|
Term::Constr { .. } => todo!(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,6 +262,8 @@ fn inline_identity_reduce(term: &mut Term<Name>) {
|
||||||
let f = Rc::make_mut(f);
|
let f = Rc::make_mut(f);
|
||||||
inline_identity_reduce(f);
|
inline_identity_reduce(f);
|
||||||
}
|
}
|
||||||
|
Term::Case { .. } => todo!(),
|
||||||
|
Term::Constr { .. } => todo!(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,6 +322,8 @@ fn inline_basic_reduce(term: &mut Term<Name>) {
|
||||||
let f = Rc::make_mut(f);
|
let f = Rc::make_mut(f);
|
||||||
inline_basic_reduce(f);
|
inline_basic_reduce(f);
|
||||||
}
|
}
|
||||||
|
Term::Case { .. } => todo!(),
|
||||||
|
Term::Constr { .. } => todo!(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -435,6 +445,8 @@ fn wrap_data_reduce(term: &mut Term<Name>) {
|
||||||
Term::Force(f) => {
|
Term::Force(f) => {
|
||||||
wrap_data_reduce(Rc::make_mut(f));
|
wrap_data_reduce(Rc::make_mut(f));
|
||||||
}
|
}
|
||||||
|
Term::Case { .. } => todo!(),
|
||||||
|
Term::Constr { .. } => todo!(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -464,6 +476,8 @@ fn var_occurrences(term: &Term<Name>, search_for: Rc<Name>) -> usize {
|
||||||
+ var_occurrences(argument.as_ref(), search_for)
|
+ var_occurrences(argument.as_ref(), search_for)
|
||||||
}
|
}
|
||||||
Term::Force(x) => var_occurrences(x.as_ref(), search_for),
|
Term::Force(x) => var_occurrences(x.as_ref(), search_for),
|
||||||
|
Term::Case { .. } => todo!(),
|
||||||
|
Term::Constr { .. } => todo!(),
|
||||||
_ => 0,
|
_ => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -476,6 +490,15 @@ fn delayed_execution(term: &Term<Name>) -> usize {
|
||||||
delayed_execution(function.as_ref()) + delayed_execution(argument.as_ref())
|
delayed_execution(function.as_ref()) + delayed_execution(argument.as_ref())
|
||||||
}
|
}
|
||||||
Term::Force(x) => delayed_execution(x.as_ref()),
|
Term::Force(x) => delayed_execution(x.as_ref()),
|
||||||
|
Term::Case { constr, branches } => {
|
||||||
|
1 + delayed_execution(constr.as_ref())
|
||||||
|
+ branches
|
||||||
|
.iter()
|
||||||
|
.fold(0, |acc, branch| acc + delayed_execution(branch))
|
||||||
|
}
|
||||||
|
Term::Constr { fields, .. } => fields
|
||||||
|
.iter()
|
||||||
|
.fold(0, |acc, field| acc + delayed_execution(field)),
|
||||||
_ => 0,
|
_ => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -512,6 +535,8 @@ fn lambda_reduce(term: &mut Term<Name>) {
|
||||||
let f = Rc::make_mut(f);
|
let f = Rc::make_mut(f);
|
||||||
lambda_reduce(f);
|
lambda_reduce(f);
|
||||||
}
|
}
|
||||||
|
Term::Case { .. } => todo!(),
|
||||||
|
Term::Constr { .. } => todo!(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -553,6 +578,8 @@ fn substitute_term(term: &Term<Name>, original: Rc<Name>, replace_with: &Term<Na
|
||||||
argument: Rc::new(substitute_term(argument.as_ref(), original, replace_with)),
|
argument: Rc::new(substitute_term(argument.as_ref(), original, replace_with)),
|
||||||
},
|
},
|
||||||
Term::Force(x) => Term::Force(Rc::new(substitute_term(x.as_ref(), original, replace_with))),
|
Term::Force(x) => Term::Force(Rc::new(substitute_term(x.as_ref(), original, replace_with))),
|
||||||
|
Term::Case { .. } => todo!(),
|
||||||
|
Term::Constr { .. } => todo!(),
|
||||||
x => x.clone(),
|
x => x.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -600,6 +627,8 @@ fn replace_identity_usage(term: &Term<Name>, original: Rc<Name>) -> Term<Name> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Term::Force(x) => Term::Force(Rc::new(replace_identity_usage(x.as_ref(), original))),
|
Term::Force(x) => Term::Force(Rc::new(replace_identity_usage(x.as_ref(), original))),
|
||||||
|
Term::Case { .. } => todo!(),
|
||||||
|
Term::Constr { .. } => todo!(),
|
||||||
x => x.clone(),
|
x => x.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue