diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index 815e636473..9100f2bc64 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -973,10 +973,9 @@ pub fn build_exp_expr<'a, 'ctx, 'env>( Tag { arguments, tag_layout: union_layout, - union_size, tag_id, .. - } => build_tag(env, scope, union_layout, *union_size, *tag_id, arguments), + } => build_tag(env, scope, union_layout, *tag_id, arguments), Reset(_) => todo!(), Reuse { .. } => todo!(), @@ -1174,12 +1173,13 @@ pub fn build_tag<'a, 'ctx, 'env>( env: &Env<'a, 'ctx, 'env>, scope: &Scope<'a, 'ctx>, union_layout: &UnionLayout<'a>, - union_size: u8, tag_id: u8, arguments: &[Symbol], ) -> BasicValueEnum<'ctx> { let tag_id_layout = union_layout.tag_id_layout(); + let union_size = union_layout.number_of_tags(); + match union_layout { UnionLayout::NonRecursive(tags) => { debug_assert!(union_size > 1); diff --git a/compiler/mono/src/alias_analysis.rs b/compiler/mono/src/alias_analysis.rs index 2b4354d26e..a439cd62e0 100644 --- a/compiler/mono/src/alias_analysis.rs +++ b/compiler/mono/src/alias_analysis.rs @@ -836,7 +836,6 @@ fn expr_spec( tag_layout, tag_name: _, tag_id, - union_size: _, arguments, } => match tag_layout { UnionLayout::NonRecursive(_) => { diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 94877e4ad0..9c8a498389 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -1129,7 +1129,6 @@ pub enum Expr<'a> { tag_layout: UnionLayout<'a>, tag_name: TagName, tag_id: u8, - union_size: u8, arguments: &'a [Symbol], }, Struct(&'a [Symbol]), @@ -1160,6 +1159,9 @@ pub enum Expr<'a> { Reuse { symbol: Symbol, + update_tag_id: bool, + // normal Tag fields + tag_layout: UnionLayout<'a>, tag_name: TagName, tag_id: u8, arguments: &'a [Symbol], @@ -4031,14 +4033,12 @@ fn construct_closure_data<'a>( ClosureRepresentation::Union { tag_id, tag_layout: _, - union_size, tag_name, union_layout, } => { let expr = Expr::Tag { tag_id, tag_layout: union_layout, - union_size, tag_name, arguments: symbols, }; @@ -4167,7 +4167,6 @@ fn convert_tag_union<'a>( assign_to_symbols(env, procs, layout_cache, iter, stmt) } Wrapped(variant) => { - let union_size = variant.number_of_tags() as u8; let (tag_id, _) = variant.tag_name_to_id(&tag_name); let field_symbols_temp = sorted_field_symbols(env, procs, layout_cache, args); @@ -4203,7 +4202,6 @@ fn convert_tag_union<'a>( tag_layout: union_layout, tag_name, tag_id: tag_id as u8, - union_size, arguments: field_symbols, }; @@ -4231,7 +4229,6 @@ fn convert_tag_union<'a>( tag_layout: union_layout, tag_name, tag_id: tag_id as u8, - union_size, arguments: field_symbols, }; @@ -4261,7 +4258,6 @@ fn convert_tag_union<'a>( tag_layout: union_layout, tag_name, tag_id: tag_id as u8, - union_size, arguments: field_symbols, }; @@ -4298,7 +4294,6 @@ fn convert_tag_union<'a>( tag_layout: union_layout, tag_name, tag_id: tag_id as u8, - union_size, arguments: field_symbols, }; @@ -4331,7 +4326,6 @@ fn convert_tag_union<'a>( tag_layout: union_layout, tag_name, tag_id: tag_id as u8, - union_size, arguments: field_symbols, }; @@ -5381,7 +5375,6 @@ fn substitute_in_expr<'a>( tag_layout, tag_name, tag_id, - union_size, arguments: args, } => { let mut did_change = false; @@ -5403,7 +5396,6 @@ fn substitute_in_expr<'a>( tag_layout: *tag_layout, tag_name: tag_name.clone(), tag_id: *tag_id, - union_size: *union_size, arguments, }) } else { diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index 6152b73304..89ea62d0b2 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -148,6 +148,16 @@ impl<'a> UnionLayout<'a> { } } + pub fn number_of_tags(&'a self) -> usize { + match self { + UnionLayout::NonRecursive(tags) | UnionLayout::Recursive(tags) => tags.len(), + + UnionLayout::NullableWrapped { other_tags, .. } => other_tags.len() + 1, + UnionLayout::NonNullableUnwrapped(_) => 1, + UnionLayout::NullableUnwrapped { .. } => 2, + } + } + fn tag_id_builtin_help(union_size: usize) -> Builtin<'a> { if union_size <= u8::MAX as usize { Builtin::Int8 @@ -204,7 +214,6 @@ pub enum ClosureRepresentation<'a> { tag_layout: &'a [Layout<'a>], tag_name: TagName, tag_id: u8, - union_size: u8, union_layout: UnionLayout<'a>, }, /// the representation is anything but a union @@ -243,7 +252,6 @@ impl<'a> LambdaSet<'a> { .unwrap(); ClosureRepresentation::Union { - union_size: self.set.len() as u8, tag_id: index as u8, tag_layout: tags[index], tag_name: TagName::Closure(function_symbol), diff --git a/compiler/mono/src/lib.rs b/compiler/mono/src/lib.rs index 831ff3d8c1..9a79927aec 100644 --- a/compiler/mono/src/lib.rs +++ b/compiler/mono/src/lib.rs @@ -8,6 +8,7 @@ pub mod expand_rc; pub mod inc_dec; pub mod ir; pub mod layout; +// pub mod reset_reuse; pub mod tail_recursion; // Temporary, while we can build up test cases and optimize the exhaustiveness checking.