From 0ec1c4904277bf9eb7672eca0ffa2a4e4faf73b5 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 5 May 2021 15:01:49 +0200 Subject: [PATCH] slightly optimize rank calculation --- compiler/solve/src/solve.rs | 12 ++++++++---- editor/src/lang/solve.rs | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 33632009e6..f176dec94b 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1135,16 +1135,20 @@ fn adjust_rank_content( } RecursiveTagUnion(rec_var, tags, ext_var) => { - let mut rank = adjust_rank(subs, young_mark, visit_mark, group_rank, *rec_var); - rank = rank.max(adjust_rank( - subs, young_mark, visit_mark, group_rank, *ext_var, - )); + let mut rank = adjust_rank(subs, young_mark, visit_mark, group_rank, *ext_var); for var in tags.values().flatten() { rank = 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 } diff --git a/editor/src/lang/solve.rs b/editor/src/lang/solve.rs index d8da164ef8..b0c50c4e99 100644 --- a/editor/src/lang/solve.rs +++ b/editor/src/lang/solve.rs @@ -1214,16 +1214,20 @@ fn adjust_rank_content( } RecursiveTagUnion(rec_var, tags, ext_var) => { - let mut rank = adjust_rank(subs, young_mark, visit_mark, group_rank, *rec_var); - rank = rank.max(adjust_rank( - subs, young_mark, visit_mark, group_rank, *ext_var, - )); + let mut rank = adjust_rank(subs, young_mark, visit_mark, group_rank, *ext_var); for var in tags.values().flatten() { rank = 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 }