Convert LayoutRepr::Struct into a tuple variant

This commit is contained in:
Ayaz Hafiz 2023-05-10 16:41:13 -05:00
parent a6bda6eccf
commit a67c148be7
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
24 changed files with 85 additions and 128 deletions

View file

@ -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"),

View file

@ -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)) => {

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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!(
"{:?} {:?}",

View file

@ -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 {

View file

@ -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<I>(&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()),
};

View file

@ -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!(),
}
}