diff --git a/compiler/gen/src/llvm/refcounting.rs b/compiler/gen/src/llvm/refcounting.rs index cb1fa0a5a5..80eeee2ce6 100644 --- a/compiler/gen/src/llvm/refcounting.rs +++ b/compiler/gen/src/llvm/refcounting.rs @@ -724,7 +724,7 @@ fn modify_refcount_layout_build_function<'a, 'ctx, 'env>( Layout::RecursivePointer => match when_recursive { WhenRecursive::Unreachable => { - unreachable!("recursion pointers should never be hashed directly") + unreachable!("recursion pointers cannot be in/decremented directly") } WhenRecursive::Loop(union_layout) => { let layout = Layout::Union(*union_layout); diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index 5a266857ad..79176a02b5 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -1113,7 +1113,6 @@ fn layout_from_flat_type<'a>( // That means none of the optimizations for enums or single tag tag unions apply let rec_var = subs.get_root_key_without_compacting(rec_var); - env.insert_seen(rec_var); let mut tag_layouts = Vec::with_capacity_in(tags.len(), arena); // VERY IMPORTANT: sort the tags @@ -1131,6 +1130,7 @@ fn layout_from_flat_type<'a>( } } + env.insert_seen(rec_var); for (index, (_name, variables)) in tags_vec.into_iter().enumerate() { if matches!(nullable, Some(i) if i == index as i64) { // don't add the @@ -1163,6 +1163,7 @@ fn layout_from_flat_type<'a>( tag_layouts.push(tag_layout.into_bump_slice()); } + env.remove_seen(rec_var); let union_layout = if let Some(tag_id) = nullable { match tag_layouts.into_bump_slice() { @@ -1186,8 +1187,6 @@ fn layout_from_flat_type<'a>( UnionLayout::Recursive(tag_layouts.into_bump_slice()) }; - env.remove_seen(rec_var); - Ok(Layout::Union(union_layout)) } EmptyTagUnion => { @@ -1422,10 +1421,6 @@ pub fn union_sorted_tags_help<'a>( seen: MutSet::default(), }; - if let Some(rec_var) = opt_rec_var { - env.insert_seen(rec_var); - } - match tags_vec.len() { 0 => { // trying to instantiate a type with no values diff --git a/compiler/test_mono/generated/let_with_record_pattern_list.txt b/compiler/test_mono/generated/let_with_record_pattern_list.txt index d7763fed7c..1b7ae1ec45 100644 --- a/compiler/test_mono/generated/let_with_record_pattern_list.txt +++ b/compiler/test_mono/generated/let_with_record_pattern_list.txt @@ -6,5 +6,6 @@ procedure Test.0 (): let Test.5 = 3.14f64; let Test.3 = Struct {Test.4, Test.5}; let Test.1 = Index 0 Test.3; - decref Test.3; + inc Test.1; + dec Test.3; ret Test.1; diff --git a/compiler/test_mono/generated/peano2.txt b/compiler/test_mono/generated/peano2.txt index 65764f2fe8..03ba41ecf0 100644 --- a/compiler/test_mono/generated/peano2.txt +++ b/compiler/test_mono/generated/peano2.txt @@ -12,10 +12,11 @@ procedure Test.0 (): let Test.17 = lowlevel Eq Test.15 Test.16; if Test.17 then let Test.11 = Index 1 Test.2; + inc Test.11; + dec Test.2; let Test.12 = 0i64; let Test.13 = Index 0 Test.11; dec Test.11; - decref Test.2; let Test.14 = lowlevel Eq Test.12 Test.13; if Test.14 then let Test.7 = 1i64; @@ -24,5 +25,6 @@ procedure Test.0 (): let Test.9 = 0i64; ret Test.9; else + dec Test.2; let Test.10 = 0i64; ret Test.10;