remove union_size from Tag expr

This commit is contained in:
Folkert 2021-07-02 10:48:03 +02:00
parent 28520b2cf4
commit 6e3a2cd94d
5 changed files with 17 additions and 17 deletions

View file

@ -973,10 +973,9 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
Tag { Tag {
arguments, arguments,
tag_layout: union_layout, tag_layout: union_layout,
union_size,
tag_id, tag_id,
.. ..
} => build_tag(env, scope, union_layout, *union_size, *tag_id, arguments), } => build_tag(env, scope, union_layout, *tag_id, arguments),
Reset(_) => todo!(), Reset(_) => todo!(),
Reuse { .. } => todo!(), Reuse { .. } => todo!(),
@ -1174,12 +1173,13 @@ pub fn build_tag<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
scope: &Scope<'a, 'ctx>, scope: &Scope<'a, 'ctx>,
union_layout: &UnionLayout<'a>, union_layout: &UnionLayout<'a>,
union_size: u8,
tag_id: u8, tag_id: u8,
arguments: &[Symbol], arguments: &[Symbol],
) -> BasicValueEnum<'ctx> { ) -> BasicValueEnum<'ctx> {
let tag_id_layout = union_layout.tag_id_layout(); let tag_id_layout = union_layout.tag_id_layout();
let union_size = union_layout.number_of_tags();
match union_layout { match union_layout {
UnionLayout::NonRecursive(tags) => { UnionLayout::NonRecursive(tags) => {
debug_assert!(union_size > 1); debug_assert!(union_size > 1);

View file

@ -836,7 +836,6 @@ fn expr_spec(
tag_layout, tag_layout,
tag_name: _, tag_name: _,
tag_id, tag_id,
union_size: _,
arguments, arguments,
} => match tag_layout { } => match tag_layout {
UnionLayout::NonRecursive(_) => { UnionLayout::NonRecursive(_) => {

View file

@ -1129,7 +1129,6 @@ pub enum Expr<'a> {
tag_layout: UnionLayout<'a>, tag_layout: UnionLayout<'a>,
tag_name: TagName, tag_name: TagName,
tag_id: u8, tag_id: u8,
union_size: u8,
arguments: &'a [Symbol], arguments: &'a [Symbol],
}, },
Struct(&'a [Symbol]), Struct(&'a [Symbol]),
@ -1160,6 +1159,9 @@ pub enum Expr<'a> {
Reuse { Reuse {
symbol: Symbol, symbol: Symbol,
update_tag_id: bool,
// normal Tag fields
tag_layout: UnionLayout<'a>,
tag_name: TagName, tag_name: TagName,
tag_id: u8, tag_id: u8,
arguments: &'a [Symbol], arguments: &'a [Symbol],
@ -4031,14 +4033,12 @@ fn construct_closure_data<'a>(
ClosureRepresentation::Union { ClosureRepresentation::Union {
tag_id, tag_id,
tag_layout: _, tag_layout: _,
union_size,
tag_name, tag_name,
union_layout, union_layout,
} => { } => {
let expr = Expr::Tag { let expr = Expr::Tag {
tag_id, tag_id,
tag_layout: union_layout, tag_layout: union_layout,
union_size,
tag_name, tag_name,
arguments: symbols, arguments: symbols,
}; };
@ -4167,7 +4167,6 @@ fn convert_tag_union<'a>(
assign_to_symbols(env, procs, layout_cache, iter, stmt) assign_to_symbols(env, procs, layout_cache, iter, stmt)
} }
Wrapped(variant) => { Wrapped(variant) => {
let union_size = variant.number_of_tags() as u8;
let (tag_id, _) = variant.tag_name_to_id(&tag_name); let (tag_id, _) = variant.tag_name_to_id(&tag_name);
let field_symbols_temp = sorted_field_symbols(env, procs, layout_cache, args); 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_layout: union_layout,
tag_name, tag_name,
tag_id: tag_id as u8, tag_id: tag_id as u8,
union_size,
arguments: field_symbols, arguments: field_symbols,
}; };
@ -4231,7 +4229,6 @@ fn convert_tag_union<'a>(
tag_layout: union_layout, tag_layout: union_layout,
tag_name, tag_name,
tag_id: tag_id as u8, tag_id: tag_id as u8,
union_size,
arguments: field_symbols, arguments: field_symbols,
}; };
@ -4261,7 +4258,6 @@ fn convert_tag_union<'a>(
tag_layout: union_layout, tag_layout: union_layout,
tag_name, tag_name,
tag_id: tag_id as u8, tag_id: tag_id as u8,
union_size,
arguments: field_symbols, arguments: field_symbols,
}; };
@ -4298,7 +4294,6 @@ fn convert_tag_union<'a>(
tag_layout: union_layout, tag_layout: union_layout,
tag_name, tag_name,
tag_id: tag_id as u8, tag_id: tag_id as u8,
union_size,
arguments: field_symbols, arguments: field_symbols,
}; };
@ -4331,7 +4326,6 @@ fn convert_tag_union<'a>(
tag_layout: union_layout, tag_layout: union_layout,
tag_name, tag_name,
tag_id: tag_id as u8, tag_id: tag_id as u8,
union_size,
arguments: field_symbols, arguments: field_symbols,
}; };
@ -5381,7 +5375,6 @@ fn substitute_in_expr<'a>(
tag_layout, tag_layout,
tag_name, tag_name,
tag_id, tag_id,
union_size,
arguments: args, arguments: args,
} => { } => {
let mut did_change = false; let mut did_change = false;
@ -5403,7 +5396,6 @@ fn substitute_in_expr<'a>(
tag_layout: *tag_layout, tag_layout: *tag_layout,
tag_name: tag_name.clone(), tag_name: tag_name.clone(),
tag_id: *tag_id, tag_id: *tag_id,
union_size: *union_size,
arguments, arguments,
}) })
} else { } else {

View file

@ -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> { fn tag_id_builtin_help(union_size: usize) -> Builtin<'a> {
if union_size <= u8::MAX as usize { if union_size <= u8::MAX as usize {
Builtin::Int8 Builtin::Int8
@ -204,7 +214,6 @@ pub enum ClosureRepresentation<'a> {
tag_layout: &'a [Layout<'a>], tag_layout: &'a [Layout<'a>],
tag_name: TagName, tag_name: TagName,
tag_id: u8, tag_id: u8,
union_size: u8,
union_layout: UnionLayout<'a>, union_layout: UnionLayout<'a>,
}, },
/// the representation is anything but a union /// the representation is anything but a union
@ -243,7 +252,6 @@ impl<'a> LambdaSet<'a> {
.unwrap(); .unwrap();
ClosureRepresentation::Union { ClosureRepresentation::Union {
union_size: self.set.len() as u8,
tag_id: index as u8, tag_id: index as u8,
tag_layout: tags[index], tag_layout: tags[index],
tag_name: TagName::Closure(function_symbol), tag_name: TagName::Closure(function_symbol),

View file

@ -8,6 +8,7 @@ pub mod expand_rc;
pub mod inc_dec; pub mod inc_dec;
pub mod ir; pub mod ir;
pub mod layout; pub mod layout;
// pub mod reset_reuse;
pub mod tail_recursion; pub mod tail_recursion;
// Temporary, while we can build up test cases and optimize the exhaustiveness checking. // Temporary, while we can build up test cases and optimize the exhaustiveness checking.