mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Merge pull request #6887 from roc-lang/in-layout-unit
This commit is contained in:
commit
eca229e3d1
1 changed files with 27 additions and 23 deletions
|
@ -3362,32 +3362,36 @@ fn layout_from_flat_type<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sortables.sort_by(|(label1, layout1), (label2, layout2)| {
|
if sortables.is_empty() {
|
||||||
cmp_fields(&env.cache.interner, label1, *layout1, label2, *layout2)
|
Cacheable(Ok(Layout::UNIT), criteria)
|
||||||
});
|
|
||||||
|
|
||||||
let ordered_field_names = Vec::from_iter_in(
|
|
||||||
sortables
|
|
||||||
.iter()
|
|
||||||
.map(|(label, _)| &*arena.alloc_str(label.as_str())),
|
|
||||||
arena,
|
|
||||||
)
|
|
||||||
.into_bump_slice();
|
|
||||||
let semantic = SemanticRepr::record(ordered_field_names);
|
|
||||||
|
|
||||||
let repr = if sortables.len() == 1 {
|
|
||||||
// If the record has only one field that isn't zero-sized,
|
|
||||||
// unwrap it.
|
|
||||||
let inner_repr = sortables.pop().unwrap().1;
|
|
||||||
inner_repr.newtype()
|
|
||||||
} else {
|
} else {
|
||||||
let layouts = Vec::from_iter_in(sortables.into_iter().map(|t| t.1), arena);
|
sortables.sort_by(|(label1, layout1), (label2, layout2)| {
|
||||||
LayoutRepr::Struct(layouts.into_bump_slice()).direct()
|
cmp_fields(&env.cache.interner, label1, *layout1, label2, *layout2)
|
||||||
};
|
});
|
||||||
|
|
||||||
let result = Ok(env.cache.put_in(Layout { repr, semantic }));
|
let ordered_field_names = Vec::from_iter_in(
|
||||||
|
sortables
|
||||||
|
.iter()
|
||||||
|
.map(|(label, _)| &*arena.alloc_str(label.as_str())),
|
||||||
|
arena,
|
||||||
|
)
|
||||||
|
.into_bump_slice();
|
||||||
|
let semantic = SemanticRepr::record(ordered_field_names);
|
||||||
|
|
||||||
Cacheable(result, criteria)
|
let repr = if sortables.len() == 1 {
|
||||||
|
// If the record has only one field that isn't zero-sized,
|
||||||
|
// unwrap it.
|
||||||
|
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);
|
||||||
|
LayoutRepr::struct_(layouts.into_bump_slice()).direct()
|
||||||
|
};
|
||||||
|
|
||||||
|
let result = Ok(env.cache.put_in(Layout { repr, semantic }));
|
||||||
|
|
||||||
|
Cacheable(result, criteria)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Tuple(elems, ext_var) => {
|
Tuple(elems, ext_var) => {
|
||||||
let mut criteria = CACHEABLE;
|
let mut criteria = CACHEABLE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue