Begin generating newtype wrappers for struct layouts

This commit is contained in:
Ayaz Hafiz 2023-05-11 13:14:20 -05:00
parent 57bd0d29d6
commit a6b3656471
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 28 additions and 20 deletions

View file

@ -666,7 +666,6 @@ pub struct Layout<'a> {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub(crate) enum LayoutWrapper<'a> {
Direct(LayoutRepr<'a>),
#[allow(unused)] // for now
Newtype(InLayout<'a>),
}
@ -3259,22 +3258,25 @@ fn layout_from_flat_type<'a>(
.iter()
.map(|(label, _)| &*arena.alloc_str(label.as_str())),
arena,
);
)
.into_bump_slice();
let semantic = SemanticRepr::record(ordered_field_names);
let result = if sortables.len() == 1 {
let repr = if sortables.len() == 1 {
// If the record has only one field that isn't zero-sized,
// unwrap it.
Ok(sortables.pop().unwrap().1)
let inner_repr = sortables.pop().unwrap().1;
inner_repr.newtype()
} else {
let layouts = Vec::from_iter_in(sortables.into_iter().map(|t| t.1), arena);
let struct_layout = Layout {
repr: LayoutRepr::Struct(layouts.into_bump_slice()).direct(),
semantic: SemanticRepr::record(ordered_field_names.into_bump_slice()),
};
Ok(env.cache.put_in(struct_layout))
LayoutRepr::Struct {
field_layouts: layouts.into_bump_slice(),
}
.direct()
};
let result = Ok(env.cache.put_in(Layout { repr, semantic }));
Cacheable(result, criteria)
}
Tuple(elems, ext_var) => {