mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Begin generating newtype wrappers for struct layouts
This commit is contained in:
parent
57bd0d29d6
commit
a6b3656471
3 changed files with 28 additions and 20 deletions
|
@ -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) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue