From a67c148be74fa833d304f605871b0656e3e350d5 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 10 May 2023 16:41:13 -0500 Subject: [PATCH] Convert LayoutRepr::Struct into a tuple variant --- crates/compiler/alias_analysis/src/lib.rs | 6 +-- crates/compiler/gen_dev/src/generic64/mod.rs | 19 ++++---- .../compiler/gen_dev/src/generic64/storage.rs | 2 +- crates/compiler/gen_dev/src/lib.rs | 2 +- crates/compiler/gen_llvm/src/llvm/bitcode.rs | 4 +- crates/compiler/gen_llvm/src/llvm/build.rs | 2 +- crates/compiler/gen_llvm/src/llvm/compare.rs | 4 +- crates/compiler/gen_llvm/src/llvm/convert.rs | 5 +-- crates/compiler/gen_llvm/src/llvm/expect.rs | 2 +- crates/compiler/gen_llvm/src/llvm/lowlevel.rs | 4 +- .../compiler/gen_llvm/src/llvm/refcounting.rs | 2 +- crates/compiler/gen_wasm/src/backend.rs | 5 +-- crates/compiler/gen_wasm/src/low_level.rs | 44 ++++++------------- .../mono/src/code_gen_help/equality.rs | 4 +- crates/compiler/mono/src/code_gen_help/mod.rs | 6 +-- .../mono/src/code_gen_help/refcount.rs | 2 +- crates/compiler/mono/src/debug/checker.rs | 2 +- .../compiler/mono/src/drop_specialization.rs | 2 +- crates/compiler/mono/src/ir.rs | 8 ++-- crates/compiler/mono/src/ir/decision_tree.rs | 10 +---- crates/compiler/mono/src/layout.rs | 30 ++++++------- crates/compiler/mono/src/layout/intern.rs | 38 ++++++++-------- crates/glue/src/types.rs | 6 +-- crates/repl_eval/src/eval.rs | 4 +- 24 files changed, 85 insertions(+), 128 deletions(-) diff --git a/crates/compiler/alias_analysis/src/lib.rs b/crates/compiler/alias_analysis/src/lib.rs index 5efbaaf3b8..b4d1afdc2c 100644 --- a/crates/compiler/alias_analysis/src/lib.rs +++ b/crates/compiler/alias_analysis/src/lib.rs @@ -1112,7 +1112,7 @@ fn lowlevel_spec<'a>( // depending on the types, the list or value will come first in the struct let fields = match interner.get(layout).repr { - LayoutRepr::Struct { field_layouts, .. } => field_layouts, + LayoutRepr::Struct(field_layouts) => field_layouts, _ => unreachable!(), }; @@ -1541,9 +1541,7 @@ fn layout_spec_help<'a>( match interner.get(layout).repr { Builtin(builtin) => builtin_spec(env, builder, interner, &builtin), - Struct { field_layouts, .. } => { - build_recursive_tuple_type(env, builder, interner, field_layouts) - } + Struct(field_layouts) => build_recursive_tuple_type(env, builder, interner, field_layouts), LambdaSet(lambda_set) => { layout_spec_help(env, builder, interner, lambda_set.runtime_representation()) } diff --git a/crates/compiler/gen_dev/src/generic64/mod.rs b/crates/compiler/gen_dev/src/generic64/mod.rs index d3669b9ba4..9095100906 100644 --- a/crates/compiler/gen_dev/src/generic64/mod.rs +++ b/crates/compiler/gen_dev/src/generic64/mod.rs @@ -2261,16 +2261,15 @@ impl< .storage_manager .claim_stack_area(dst, self.layout_interner.stack_size(*ret_layout)); - let ret_fields = if let LayoutRepr::Struct { field_layouts, .. } = - self.layout_interner.get(*ret_layout).repr - { - field_layouts - } else { - internal_error!( - "Expected replace to return a struct instead found: {:?}", - ret_layout - ) - }; + let ret_fields = + if let LayoutRepr::Struct(field_layouts) = self.layout_interner.get(*ret_layout).repr { + field_layouts + } else { + internal_error!( + "Expected replace to return a struct instead found: {:?}", + ret_layout + ) + }; // Only return list and old element. debug_assert_eq!(ret_fields.len(), 2); diff --git a/crates/compiler/gen_dev/src/generic64/storage.rs b/crates/compiler/gen_dev/src/generic64/storage.rs index 29a7ac849e..799224493d 100644 --- a/crates/compiler/gen_dev/src/generic64/storage.rs +++ b/crates/compiler/gen_dev/src/generic64/storage.rs @@ -674,7 +674,7 @@ impl< } }; - if let LayoutRepr::Struct { field_layouts, .. } = layout { + if let LayoutRepr::Struct(field_layouts) = layout { let mut current_offset = base_offset; for (field, field_layout) in fields.iter().zip(field_layouts.iter()) { self.copy_symbol_to_stack_offset( diff --git a/crates/compiler/gen_dev/src/lib.rs b/crates/compiler/gen_dev/src/lib.rs index a8679cc236..077c663218 100644 --- a/crates/compiler/gen_dev/src/lib.rs +++ b/crates/compiler/gen_dev/src/lib.rs @@ -1481,7 +1481,7 @@ trait Backend<'a> { ), LowLevel::StrToNum => { let number_layout = match self.interner().get(*ret_layout).repr { - LayoutRepr::Struct { field_layouts, .. } => field_layouts[0], // TODO: why is it sometimes a struct? + LayoutRepr::Struct(field_layouts) => field_layouts[0], // TODO: why is it sometimes a struct? _ => unreachable!(), }; diff --git a/crates/compiler/gen_llvm/src/llvm/bitcode.rs b/crates/compiler/gen_llvm/src/llvm/bitcode.rs index 5cfde67adb..125b1e5c82 100644 --- a/crates/compiler/gen_llvm/src/llvm/bitcode.rs +++ b/crates/compiler/gen_llvm/src/llvm/bitcode.rs @@ -611,9 +611,7 @@ pub fn build_compare_wrapper<'a, 'ctx>( let closure_data_repr = closure_data_layout.runtime_representation(); let arguments_cast = match layout_interner.get(closure_data_repr).repr { - LayoutRepr::Struct { - field_layouts: &[], .. - } => { + LayoutRepr::Struct(&[]) => { // nothing to add &default } diff --git a/crates/compiler/gen_llvm/src/llvm/build.rs b/crates/compiler/gen_llvm/src/llvm/build.rs index 36fdc400a4..c63cd0a249 100644 --- a/crates/compiler/gen_llvm/src/llvm/build.rs +++ b/crates/compiler/gen_llvm/src/llvm/build.rs @@ -1332,7 +1332,7 @@ pub fn build_exp_expr<'a, 'ctx>( // extract field from a record match (value, layout_interner.get(layout).repr) { - (StructValue(argument), LayoutRepr::Struct { field_layouts, .. }) => { + (StructValue(argument), LayoutRepr::Struct(field_layouts)) => { debug_assert!(!field_layouts.is_empty()); let field_value = env diff --git a/crates/compiler/gen_llvm/src/llvm/compare.rs b/crates/compiler/gen_llvm/src/llvm/compare.rs index 90fdb55b27..7f26425897 100644 --- a/crates/compiler/gen_llvm/src/llvm/compare.rs +++ b/crates/compiler/gen_llvm/src/llvm/compare.rs @@ -165,7 +165,7 @@ fn build_eq<'a, 'ctx>( &builtin, ), - LayoutRepr::Struct { field_layouts, .. } => build_struct_eq( + LayoutRepr::Struct(field_layouts) => build_struct_eq( env, layout_interner, layout_ids, @@ -353,7 +353,7 @@ fn build_neq<'a, 'ctx>( &builtin, ), - LayoutRepr::Struct { field_layouts, .. } => { + LayoutRepr::Struct(field_layouts) => { let is_equal = build_struct_eq( env, layout_interner, diff --git a/crates/compiler/gen_llvm/src/llvm/convert.rs b/crates/compiler/gen_llvm/src/llvm/convert.rs index da3e98949e..cd9ba9b7b5 100644 --- a/crates/compiler/gen_llvm/src/llvm/convert.rs +++ b/crates/compiler/gen_llvm/src/llvm/convert.rs @@ -37,10 +37,7 @@ pub fn basic_type_from_layout<'a, 'ctx, 'env>( use LayoutRepr::*; match layout_interner.get(layout).repr { - Struct { - field_layouts: sorted_fields, - .. - } => basic_type_from_record(env, layout_interner, sorted_fields), + Struct(sorted_fields, ..) => basic_type_from_record(env, layout_interner, sorted_fields), LambdaSet(lambda_set) => { basic_type_from_layout(env, layout_interner, lambda_set.runtime_representation()) } diff --git a/crates/compiler/gen_llvm/src/llvm/expect.rs b/crates/compiler/gen_llvm/src/llvm/expect.rs index b41ce5359d..0b6c2e21b1 100644 --- a/crates/compiler/gen_llvm/src/llvm/expect.rs +++ b/crates/compiler/gen_llvm/src/llvm/expect.rs @@ -307,7 +307,7 @@ fn build_clone<'a, 'ctx>( builtin, ), - LayoutRepr::Struct { field_layouts, .. } => build_clone_struct( + LayoutRepr::Struct(field_layouts) => build_clone_struct( env, layout_interner, layout_ids, diff --git a/crates/compiler/gen_llvm/src/llvm/lowlevel.rs b/crates/compiler/gen_llvm/src/llvm/lowlevel.rs index ce2fc6d791..3ebe280211 100644 --- a/crates/compiler/gen_llvm/src/llvm/lowlevel.rs +++ b/crates/compiler/gen_llvm/src/llvm/lowlevel.rs @@ -197,7 +197,7 @@ pub(crate) fn run_low_level<'a, 'ctx>( arguments!(string); let number_layout = match layout_interner.get(layout).repr { - LayoutRepr::Struct { field_layouts, .. } => field_layouts[0], // TODO: why is it sometimes a struct? + LayoutRepr::Struct(field_layouts) => field_layouts[0], // TODO: why is it sometimes a struct? _ => unreachable!(), }; @@ -2013,7 +2013,7 @@ fn build_int_unary_op<'a, 'ctx, 'env>( // return_layout : Result N [OutOfBounds]* ~ { result: N, out_of_bounds: bool } let target_int_width = match layout_interner.get(return_layout).repr { - LayoutRepr::Struct { field_layouts, .. } if field_layouts.len() == 2 => { + LayoutRepr::Struct(field_layouts) if field_layouts.len() == 2 => { debug_assert!(layout_interner.eq_repr(field_layouts[1], Layout::BOOL)); field_layouts[0].to_int_width() } diff --git a/crates/compiler/gen_llvm/src/llvm/refcounting.rs b/crates/compiler/gen_llvm/src/llvm/refcounting.rs index 7e324ba5e4..501a6128f2 100644 --- a/crates/compiler/gen_llvm/src/llvm/refcounting.rs +++ b/crates/compiler/gen_llvm/src/llvm/refcounting.rs @@ -562,7 +562,7 @@ fn modify_refcount_layout_build_function<'a, 'ctx>( } } - Struct { field_layouts, .. } => { + Struct(field_layouts) => { let function = modify_refcount_struct(env, layout_interner, layout_ids, field_layouts, mode); diff --git a/crates/compiler/gen_wasm/src/backend.rs b/crates/compiler/gen_wasm/src/backend.rs index bca02a0f71..bc4277aec6 100644 --- a/crates/compiler/gen_wasm/src/backend.rs +++ b/crates/compiler/gen_wasm/src/backend.rs @@ -560,10 +560,7 @@ impl<'a, 'r> WasmBackend<'a, 'r> { // one-element struct. let inner_closure_data_layout = match self.layout_interner.get(closure_data_layout).repr { - LayoutRepr::Struct { - field_layouts: [inner], - .. - } => inner, + LayoutRepr::Struct([inner]) => inner, other => internal_error!( "Expected a boxed layout for wrapped closure data, got {:?}", other diff --git a/crates/compiler/gen_wasm/src/low_level.rs b/crates/compiler/gen_wasm/src/low_level.rs index 7c846e9940..5336c3f46c 100644 --- a/crates/compiler/gen_wasm/src/low_level.rs +++ b/crates/compiler/gen_wasm/src/low_level.rs @@ -238,7 +238,7 @@ impl<'a> LowLevelCall<'a> { StrGetCapacity => self.load_args_and_call_zig(backend, bitcode::STR_CAPACITY), StrToNum => { let number_layout = match backend.layout_interner.get(self.ret_layout).repr { - LayoutRepr::Struct { field_layouts, .. } => field_layouts[0], + LayoutRepr::Struct(field_layouts) => field_layouts[0], _ => { internal_error!("Unexpected mono layout {:?} for StrToNum", self.ret_layout) } @@ -390,10 +390,7 @@ impl<'a> LowLevelCall<'a> { // Byte offsets of each field in the return struct let (ret_list_offset, ret_elem_offset, elem_layout) = match self.ret_layout_raw.repr { - LayoutRepr::Struct { - field_layouts: &[f1, f2], - .. - } => { + LayoutRepr::Struct(&[f1, f2]) => { let l1 = backend.layout_interner.get(f1); let l2 = backend.layout_interner.get(f2); match (l1.repr, l2.repr) { @@ -693,12 +690,9 @@ impl<'a> LowLevelCall<'a> { // The refcount function receives a pointer to an element in the list // This is the same as a Struct containing the element - let in_memory_layout = - backend - .layout_interner - .insert_no_semantic(LayoutRepr::Struct { - field_layouts: backend.env.arena.alloc([elem_layout]), - }); + let in_memory_layout = backend + .layout_interner + .insert_no_semantic(LayoutRepr::Struct(backend.env.arena.alloc([elem_layout]))); let dec_fn = backend.get_refcount_fn_index(in_memory_layout, HelperOp::Dec); let dec_fn_ptr = backend.get_fn_ptr(dec_fn); @@ -741,12 +735,9 @@ impl<'a> LowLevelCall<'a> { // The refcount function receives a pointer to an element in the list // This is the same as a Struct containing the element - let in_memory_layout = - backend - .layout_interner - .insert_no_semantic(LayoutRepr::Struct { - field_layouts: backend.env.arena.alloc([elem_layout]), - }); + let in_memory_layout = backend + .layout_interner + .insert_no_semantic(LayoutRepr::Struct(backend.env.arena.alloc([elem_layout]))); let dec_fn = backend.get_refcount_fn_index(in_memory_layout, HelperOp::Dec); let dec_fn_ptr = backend.get_fn_ptr(dec_fn); @@ -1909,10 +1900,7 @@ impl<'a> LowLevelCall<'a> { ) { ( LayoutRepr::Builtin(Builtin::Int(arg_width)), - LayoutRepr::Struct { - field_layouts: &[ret, ..], - .. - }, + LayoutRepr::Struct(&[ret, ..]), ) => match backend.layout_interner.get(ret).repr { LayoutRepr::Builtin(Builtin::Int(ret_width)) => (arg_width, ret_width), _ => { @@ -2029,7 +2017,7 @@ impl<'a> LowLevelCall<'a> { // Empty record is always equal to empty record. // There are no runtime arguments to check, so just emit true or false. - LayoutRepr::Struct { field_layouts, .. } if field_layouts.is_empty() => { + LayoutRepr::Struct(field_layouts) if field_layouts.is_empty() => { backend.code_builder.i32_const(!invert_result as i32); } @@ -2378,9 +2366,7 @@ pub fn call_higher_order_lowlevel<'a>( (Layout::UNIT, false) } } - LayoutRepr::Struct { - field_layouts: &[], .. - } => (Layout::UNIT, false), + LayoutRepr::Struct(&[]) => (Layout::UNIT, false), x => internal_error!("Closure data has an invalid layout\n{:?}", x), }; @@ -2673,9 +2659,7 @@ fn list_map_n<'a>( // Here we wrap the layout in a Struct to ensure we get the right code gen let el_ptr = backend .layout_interner - .insert_no_semantic(LayoutRepr::Struct { - field_layouts: backend.env.arena.alloc([*el]), - }); + .insert_no_semantic(LayoutRepr::Struct(backend.env.arena.alloc([*el]))); let idx = backend.get_refcount_fn_index(el_ptr, HelperOp::Dec); let ptr = backend.get_fn_ptr(idx); backend.code_builder.i32_const(ptr); @@ -2714,9 +2698,7 @@ fn ensure_symbol_is_in_memory<'a>( ); let in_memory_layout = backend .layout_interner - .insert_no_semantic(LayoutRepr::Struct { - field_layouts: arena.alloc([layout]), - }); + .insert_no_semantic(LayoutRepr::Struct(arena.alloc([layout]))); (frame_ptr, offset, in_memory_layout) } } diff --git a/crates/compiler/mono/src/code_gen_help/equality.rs b/crates/compiler/mono/src/code_gen_help/equality.rs index 7bcd4ab6e5..6a82b7ea97 100644 --- a/crates/compiler/mono/src/code_gen_help/equality.rs +++ b/crates/compiler/mono/src/code_gen_help/equality.rs @@ -35,9 +35,7 @@ pub fn eq_generic<'a>( unreachable!("No generated helper proc for `==` on Str. Use Zig function.") } Builtin(List(elem_layout)) => eq_list(root, ident_ids, ctx, layout_interner, elem_layout), - Struct { field_layouts, .. } => { - eq_struct(root, ident_ids, ctx, layout_interner, field_layouts) - } + Struct(field_layouts) => eq_struct(root, ident_ids, ctx, layout_interner, field_layouts), Union(union_layout) => eq_tag_union(root, ident_ids, ctx, layout_interner, union_layout), Boxed(inner_layout) => eq_boxed(root, ident_ids, ctx, layout_interner, inner_layout), LambdaSet(_) => unreachable!("`==` is not defined on functions"), diff --git a/crates/compiler/mono/src/code_gen_help/mod.rs b/crates/compiler/mono/src/code_gen_help/mod.rs index 63fc6d67e6..d6eb380b37 100644 --- a/crates/compiler/mono/src/code_gen_help/mod.rs +++ b/crates/compiler/mono/src/code_gen_help/mod.rs @@ -541,14 +541,12 @@ impl<'a> CodeGenHelp<'a> { LayoutRepr::Builtin(_) => return layout, - LayoutRepr::Struct { field_layouts } => { + LayoutRepr::Struct(field_layouts) => { let mut new_field_layouts = Vec::with_capacity_in(field_layouts.len(), self.arena); for f in field_layouts.iter() { new_field_layouts.push(self.replace_rec_ptr(ctx, layout_interner, *f)); } - LayoutRepr::Struct { - field_layouts: new_field_layouts.into_bump_slice(), - } + LayoutRepr::Struct(new_field_layouts.into_bump_slice()) } LayoutRepr::Union(UnionLayout::NonRecursive(tags)) => { diff --git a/crates/compiler/mono/src/code_gen_help/refcount.rs b/crates/compiler/mono/src/code_gen_help/refcount.rs index f3fc7801b3..637d0b8b85 100644 --- a/crates/compiler/mono/src/code_gen_help/refcount.rs +++ b/crates/compiler/mono/src/code_gen_help/refcount.rs @@ -199,7 +199,7 @@ pub fn refcount_generic<'a>( elem_layout, structure, ), - LayoutRepr::Struct { field_layouts, .. } => refcount_struct( + LayoutRepr::Struct(field_layouts) => refcount_struct( root, ident_ids, ctx, diff --git a/crates/compiler/mono/src/debug/checker.rs b/crates/compiler/mono/src/debug/checker.rs index e23e942c91..688fe91412 100644 --- a/crates/compiler/mono/src/debug/checker.rs +++ b/crates/compiler/mono/src/debug/checker.rs @@ -495,7 +495,7 @@ impl<'a, 'r> Ctx<'a, 'r> { self.with_sym_layout(structure, |ctx, def_line, layout| { let layout = ctx.resolve(layout); match ctx.interner.get(layout).repr { - LayoutRepr::Struct { field_layouts, .. } => { + LayoutRepr::Struct(field_layouts) => { if index as usize >= field_layouts.len() { ctx.problem(ProblemKind::StructIndexOOB { structure, diff --git a/crates/compiler/mono/src/drop_specialization.rs b/crates/compiler/mono/src/drop_specialization.rs index d289d72fb0..45f0d0a91b 100644 --- a/crates/compiler/mono/src/drop_specialization.rs +++ b/crates/compiler/mono/src/drop_specialization.rs @@ -336,7 +336,7 @@ fn specialize_drops_stmt<'a, 'i>( let new_dec = match runtime_layout.repr { // Layout has children, try to inline them. - LayoutRepr::Struct { field_layouts, .. } => specialize_struct( + LayoutRepr::Struct(field_layouts) => specialize_struct( arena, layout_interner, ident_ids, diff --git a/crates/compiler/mono/src/ir.rs b/crates/compiler/mono/src/ir.rs index 916874fd2e..7c47bcbb8a 100644 --- a/crates/compiler/mono/src/ir.rs +++ b/crates/compiler/mono/src/ir.rs @@ -4981,7 +4981,7 @@ pub fn with_hole<'a>( .unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {:?}", err)); let field_layouts = match layout_cache.get_in(record_layout).repr { - LayoutRepr::Struct { field_layouts, .. } => field_layouts, + LayoutRepr::Struct(field_layouts) => field_layouts, _ => arena.alloc([record_layout]), }; @@ -9061,7 +9061,7 @@ fn match_on_lambda_set<'a>( env.arena.alloc(result), ) } - ClosureCallOptions::Struct { field_layouts } => { + ClosureCallOptions::Struct(field_layouts) => { let function_symbol = match lambda_set.iter_set().next() { Some(function_symbol) => function_symbol, None => { @@ -9726,7 +9726,7 @@ where | Builtin::Str => { /* do nothing */ } Builtin::List(element) => stack.push(layout_interner.get(element)), }, - LayoutRepr::Struct { field_layouts, .. } => { + LayoutRepr::Struct(field_layouts) => { if field_layouts.iter().any(|l| { layout_interner .get(*l) @@ -9825,7 +9825,7 @@ where let mut answer = bumpalo::collections::Vec::with_capacity_in(field_layouts.len(), arena); let field_layouts = match layout_interner.get(interned_unboxed_struct_layout).repr { - LayoutRepr::Struct { field_layouts, .. } => field_layouts, + LayoutRepr::Struct(field_layouts) => field_layouts, other => { unreachable!( "{:?} {:?}", diff --git a/crates/compiler/mono/src/ir/decision_tree.rs b/crates/compiler/mono/src/ir/decision_tree.rs index 813814195c..b233ab8099 100644 --- a/crates/compiler/mono/src/ir/decision_tree.rs +++ b/crates/compiler/mono/src/ir/decision_tree.rs @@ -1014,13 +1014,7 @@ fn to_relevant_branch_help<'a>( // the test matches the constructor of this pattern match layout { UnionLayout::NonRecursive([[arg]]) - if matches!( - interner.get(*arg).repr, - LayoutRepr::Struct { - field_layouts: [_], - .. - } - ) => + if matches!(interner.get(*arg).repr, LayoutRepr::Struct([_],)) => { // a one-element record equivalent // Theory: Unbox doesn't have any value for us @@ -1600,7 +1594,7 @@ fn path_to_expr_help<'a>( layout = inner_layout; } - LayoutRepr::Struct { field_layouts, .. } => { + LayoutRepr::Struct(field_layouts) => { debug_assert!(field_layouts.len() > 1); let inner_expr = Expr::StructAtIndex { diff --git a/crates/compiler/mono/src/layout.rs b/crates/compiler/mono/src/layout.rs index e78ba5a1d8..379ec31b64 100644 --- a/crates/compiler/mono/src/layout.rs +++ b/crates/compiler/mono/src/layout.rs @@ -664,7 +664,7 @@ pub struct Layout<'a> { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum LayoutRepr<'a> { Builtin(Builtin<'a>), - Struct { field_layouts: &'a [InLayout<'a>] }, + Struct(&'a [InLayout<'a>]), Boxed(InLayout<'a>), Union(UnionLayout<'a>), LambdaSet(LambdaSet<'a>), @@ -1389,7 +1389,7 @@ pub enum ClosureCallOptions<'a> { /// One of a few capturing functions can be called to Union(UnionLayout<'a>), /// The closure is one function, whose captures are represented as a struct. - Struct { field_layouts: &'a [InLayout<'a>] }, + Struct(&'a [InLayout<'a>]), /// The closure is one function that captures a single identifier, whose value is unwrapped. UnwrappedCapture(InLayout<'a>), /// The closure dispatches to multiple possible functions, none of which capture. @@ -1418,9 +1418,7 @@ impl<'a> LambdaSet<'a> { } else { let repr = self.representation; match interner.get(repr).repr { - LayoutRepr::Struct { - field_layouts: &[], .. - } => None, + LayoutRepr::Struct(&[]) => None, _ => Some(repr), } } @@ -1670,9 +1668,9 @@ impl<'a> LambdaSet<'a> { } ClosureCallOptions::Union(union_layout) } - LayoutRepr::Struct { field_layouts } => { + LayoutRepr::Struct(field_layouts) => { debug_assert_eq!(self.set.len(), 1); - ClosureCallOptions::Struct { field_layouts } + ClosureCallOptions::Struct(field_layouts) } layout => { debug_assert!(self.has_enum_dispatch_repr()); @@ -2524,7 +2522,7 @@ impl<'a> LayoutRepr<'a> { pub const OPAQUE_PTR: Self = LayoutRepr::Boxed(Layout::VOID); pub const fn struct_(field_layouts: &'a [InLayout<'a>]) -> Self { - Self::Struct { field_layouts } + Self::Struct(field_layouts) } pub fn safe_to_memcpy(&self, interner: &I) -> bool @@ -2535,7 +2533,7 @@ impl<'a> LayoutRepr<'a> { match self { Builtin(builtin) => builtin.safe_to_memcpy(), - Struct { field_layouts, .. } => field_layouts + Struct(field_layouts) => field_layouts .iter() .all(|field_layout| interner.get(*field_layout).safe_to_memcpy(interner)), Union(variant) => { @@ -2630,7 +2628,7 @@ impl<'a> LayoutRepr<'a> { match self { Builtin(builtin) => builtin.stack_size(target_info), - Struct { field_layouts, .. } => { + Struct(field_layouts) => { let mut sum = 0; for field_layout in *field_layouts { @@ -2656,7 +2654,7 @@ impl<'a> LayoutRepr<'a> { { use LayoutRepr::*; match self { - Struct { field_layouts, .. } => field_layouts + Struct(field_layouts) => field_layouts .iter() .map(|x| interner.get(*x).alignment_bytes(interner, target_info)) .max() @@ -2755,7 +2753,7 @@ impl<'a> LayoutRepr<'a> { match self { Builtin(builtin) => builtin.is_refcounted(), - Struct { field_layouts, .. } => field_layouts + Struct(field_layouts) => field_layouts .iter() .any(|f| interner.get(*f).contains_refcounted(interner)), Union(variant) => { @@ -2804,7 +2802,7 @@ impl<'a> LayoutRepr<'a> { } } // If there's any layer of indirection (behind a pointer), then it doesn't vary! - Struct { field_layouts, .. } => stack.extend( + Struct(field_layouts) => stack.extend( field_layouts .iter() .map(|interned| interner.get(*interned).repr), @@ -3244,9 +3242,7 @@ fn layout_from_flat_type<'a>( } else { let layouts = Vec::from_iter_in(sortables.into_iter().map(|t| t.1), arena); let struct_layout = Layout { - repr: LayoutRepr::Struct { - field_layouts: layouts.into_bump_slice(), - }, + repr: LayoutRepr::Struct(layouts.into_bump_slice()), semantic: SemanticRepr::record(ordered_field_names.into_bump_slice()), }; @@ -3289,7 +3285,7 @@ fn layout_from_flat_type<'a>( let field_layouts = Vec::from_iter_in(sortables.into_iter().map(|t| t.1), arena).into_bump_slice(); let struct_layout = Layout { - repr: LayoutRepr::Struct { field_layouts }, + repr: LayoutRepr::Struct(field_layouts), semantic: SemanticRepr::tuple(field_layouts.len()), }; diff --git a/crates/compiler/mono/src/layout/intern.rs b/crates/compiler/mono/src/layout/intern.rs index 05b9b3be02..6a0b4f678f 100644 --- a/crates/compiler/mono/src/layout/intern.rs +++ b/crates/compiler/mono/src/layout/intern.rs @@ -123,7 +123,7 @@ impl<'a> Layout<'a> { semantic: SemanticRepr::NONE, }; pub(super) const UNIT_NAKED: Self = Layout { - repr: LayoutRepr::Struct { field_layouts: &[] }, + repr: LayoutRepr::Struct(&[]), semantic: SemanticRepr::EMPTY_RECORD, }; @@ -300,7 +300,7 @@ pub trait LayoutInterner<'a>: Sized { match self.get(layout).repr { Builtin(builtin) => builtin.to_doc(alloc, self, seen_rec, parens), - Struct { field_layouts, .. } => { + Struct(field_layouts) => { let fields_doc = field_layouts .iter() .map(|x| self.to_doc(*x, alloc, seen_rec, parens)); @@ -1050,9 +1050,9 @@ mod reify { LayoutRepr::Builtin(builtin) => { LayoutRepr::Builtin(reify_builtin(arena, interner, slot, builtin)) } - LayoutRepr::Struct { field_layouts } => LayoutRepr::Struct { - field_layouts: reify_layout_slice(arena, interner, slot, field_layouts), - }, + LayoutRepr::Struct(field_layouts) => { + LayoutRepr::Struct(reify_layout_slice(arena, interner, slot, field_layouts)) + } LayoutRepr::Boxed(lay) => LayoutRepr::Boxed(reify_layout(arena, interner, slot, lay)), LayoutRepr::Union(un) => LayoutRepr::Union(reify_union(arena, interner, slot, un)), LayoutRepr::LambdaSet(ls) => { @@ -1258,7 +1258,7 @@ mod equiv { } } } - (Struct { field_layouts: fl1 }, Struct { field_layouts: fl2 }) => { + (Struct(fl1), Struct(fl2)) => { equiv_fields!(fl1, fl2) } (Boxed(b1), Boxed(b2)) => stack.push((b1, b2)), @@ -1376,7 +1376,7 @@ pub mod dbg { .debug_tuple("Builtin") .field(&DbgBuiltin(self.0, *b)) .finish(), - LayoutRepr::Struct { field_layouts } => f + LayoutRepr::Struct(field_layouts) => f .debug_struct("Struct") .field("fields", &DbgFields(self.0, field_layouts)) .finish(), @@ -1622,19 +1622,19 @@ mod insert_recursive_layout { match interner.chase_recursive(layout).repr { LayoutRepr::Union(UnionLayout::Recursive(&[&[l1], &[l2]])) => { match (interner.get(l1).repr, interner.get(l2).repr) { - ( - LayoutRepr::Builtin(Builtin::List(l1)), - LayoutRepr::Struct { - field_layouts: &[l2], - }, - ) => match (interner.get(l1).repr, interner.get(l2).repr) { - (LayoutRepr::RecursivePointer(i1), LayoutRepr::RecursivePointer(i2)) => { - assert_eq!(i1, i2); - assert_ne!(i1, Layout::VOID); - i1.0 + (LayoutRepr::Builtin(Builtin::List(l1)), LayoutRepr::Struct(&[l2])) => { + match (interner.get(l1).repr, interner.get(l2).repr) { + ( + LayoutRepr::RecursivePointer(i1), + LayoutRepr::RecursivePointer(i2), + ) => { + assert_eq!(i1, i2); + assert_ne!(i1, Layout::VOID); + i1.0 + } + _ => unreachable!(), } - _ => unreachable!(), - }, + } _ => unreachable!(), } } diff --git a/crates/glue/src/types.rs b/crates/glue/src/types.rs index 95eea5b0cd..c69be783a5 100644 --- a/crates/glue/src/types.rs +++ b/crates/glue/src/types.rs @@ -1691,7 +1691,7 @@ fn add_builtin_type<'a>( env.subs.get_content_without_compacting(*alias_var), ) { ( - LayoutRepr::Struct { field_layouts, .. }, + LayoutRepr::Struct(field_layouts), Content::Structure(FlatType::Apply(Symbol::LIST_LIST, args_subs_slice)), ) => { let (key_var, val_var) = { @@ -1741,7 +1741,7 @@ fn add_builtin_type<'a>( env.subs.get_content_without_compacting(*alias_var), ) { ( - LayoutRepr::Struct { field_layouts, .. }, + LayoutRepr::Struct(field_layouts), Alias(Symbol::DICT_DICT, alias_args, _alias_var, AliasKind::Opaque), ) => { let dict_type_vars = env.subs.get_subs_slice(alias_args.type_variables()); @@ -2058,7 +2058,7 @@ fn tag_union_type_from_layout<'a>( LayoutRepr::Builtin(Builtin::Int(int_width)) => { add_int_enumeration(union_tags, subs, &name, int_width) } - LayoutRepr::Struct { field_layouts, .. } => { + LayoutRepr::Struct(field_layouts) => { let (tag_name, payload) = single_tag_payload_fields(env, union_tags, subs, layout, field_layouts, types); diff --git a/crates/repl_eval/src/eval.rs b/crates/repl_eval/src/eval.rs index 8475dd9b3c..ea4f90624e 100644 --- a/crates/repl_eval/src/eval.rs +++ b/crates/repl_eval/src/eval.rs @@ -417,7 +417,7 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>( ) }, ), - LayoutRepr::Struct { field_layouts, .. } => { + LayoutRepr::Struct(field_layouts) => { let fields = [Layout::U64, layout]; let result_stack_size = LayoutRepr::struct_(env.arena.alloc(fields)) @@ -615,7 +615,7 @@ fn addr_to_ast<'a, M: ReplAppMemory>( let arena_str = env.arena.alloc_str(string); Expr::Str(StrLiteral::PlainLine(arena_str)) } - (_, LayoutRepr::Struct { field_layouts, .. }) => match raw_content { + (_, LayoutRepr::Struct (field_layouts)) => match raw_content { Content::Structure(FlatType::Record(fields, _)) => { struct_to_ast(env, mem, addr, *fields) }