Chase recursive layouts as appropriate

This commit is contained in:
Ayaz Hafiz 2023-01-25 15:10:56 -06:00
parent 673ca9a02f
commit 3382be6cb9
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58
3 changed files with 10 additions and 9 deletions

View File

@ -1406,7 +1406,7 @@ fn path_to_expr_help<'a>(
PathInstruction::TagIndex { index, tag_id } => {
let index = *index;
match layout_interner.get(layout) {
match layout_interner.chase_recursive(layout) {
Layout::Union(union_layout) => {
let inner_expr = Expr::UnionAtIndex {
tag_id: *tag_id,
@ -1506,7 +1506,7 @@ fn test_to_comparison<'a>(
// (e.g. record pattern guard matches)
debug_assert!(union.alternatives.len() > 1);
match layout_interner.get(test_layout) {
match layout_interner.chase_recursive(test_layout) {
Layout::Union(union_layout) => {
let lhs = Expr::Literal(Literal::Int((tag_id as i128).to_ne_bytes()));
@ -2108,7 +2108,7 @@ fn decide_to_branching<'a>(
// We have learned more about the exact layout of the cond (based on the path)
// but tests are still relative to the original cond symbol
let inner_cond_layout_raw = layout_cache.get_in(inner_cond_layout);
let inner_cond_layout_raw = layout_cache.interner.chase_recursive(inner_cond_layout);
let mut switch = if let Layout::Union(union_layout) = inner_cond_layout_raw {
let tag_id_symbol = env.unique_symbol();

View File

@ -5927,7 +5927,7 @@ fn convert_tag_union<'a>(
layout_cache.from_var(env.arena, variant_var, env.subs),
"Wrapped"
);
let union_layout = match layout_cache.get_in(variant_layout) {
let union_layout = match layout_cache.interner.chase_recursive(variant_layout) {
Layout::Union(ul) => ul,
other => internal_error!(
"unexpected layout {:?} for {:?}",
@ -9466,10 +9466,11 @@ fn from_can_pattern_help<'a>(
// problems down the line because we hash layouts and an unrolled
// version is not the same as the minimal version.
let whole_var_layout = layout_cache.from_var(env.arena, *whole_var, env.subs);
let layout = match whole_var_layout.map(|l| layout_cache.get_in(l)) {
Ok(Layout::Union(ul)) => ul,
_ => unreachable!(),
};
let layout =
match whole_var_layout.map(|l| layout_cache.interner.chase_recursive(l)) {
Ok(Layout::Union(ul)) => ul,
_ => internal_error!(),
};
use WrappedVariant::*;
match variant {

View File

@ -615,7 +615,7 @@ fn function_r_branch_body<'a, 'i>(
scrutinee,
layout,
tag_id,
} => match env.interner.get(*layout) {
} => match env.interner.chase_recursive(*layout) {
Layout::Union(UnionLayout::NonRecursive(_)) => temp,
Layout::Union(union_layout) if !union_layout.tag_is_null(*tag_id) => {
let ctor_info = CtorInfo {