slightly optimize rank calculation

This commit is contained in:
Folkert 2021-05-05 15:01:49 +02:00
parent 5372c45cdd
commit 0ec1c49042
2 changed files with 16 additions and 8 deletions

View File

@ -1135,16 +1135,20 @@ fn adjust_rank_content(
} }
RecursiveTagUnion(rec_var, tags, ext_var) => { RecursiveTagUnion(rec_var, tags, ext_var) => {
let mut rank = adjust_rank(subs, young_mark, visit_mark, group_rank, *rec_var); let mut rank = adjust_rank(subs, young_mark, visit_mark, group_rank, *ext_var);
rank = rank.max(adjust_rank(
subs, young_mark, visit_mark, group_rank, *ext_var,
));
for var in tags.values().flatten() { for var in tags.values().flatten() {
rank = rank =
rank.max(adjust_rank(subs, young_mark, visit_mark, group_rank, *var)); rank.max(adjust_rank(subs, young_mark, visit_mark, group_rank, *var));
} }
// THEORY: the recursion var has the same rank as the tag union itself
// all types it uses are also in the tags already, so it cannot influence the
// rank
debug_assert!(
rank >= adjust_rank(subs, young_mark, visit_mark, group_rank, *rec_var)
);
rank rank
} }

View File

@ -1214,16 +1214,20 @@ fn adjust_rank_content(
} }
RecursiveTagUnion(rec_var, tags, ext_var) => { RecursiveTagUnion(rec_var, tags, ext_var) => {
let mut rank = adjust_rank(subs, young_mark, visit_mark, group_rank, *rec_var); let mut rank = adjust_rank(subs, young_mark, visit_mark, group_rank, *ext_var);
rank = rank.max(adjust_rank(
subs, young_mark, visit_mark, group_rank, *ext_var,
));
for var in tags.values().flatten() { for var in tags.values().flatten() {
rank = rank =
rank.max(adjust_rank(subs, young_mark, visit_mark, group_rank, *var)); rank.max(adjust_rank(subs, young_mark, visit_mark, group_rank, *var));
} }
// THEORY: the recursion var has the same rank as the tag union itself
// all types it uses are also in the tags already, so it cannot influence the
// rank
debug_assert!(
rank >= adjust_rank(subs, young_mark, visit_mark, group_rank, *rec_var)
);
rank rank
} }