mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +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) => {
|
||||
|
|
|
@ -97,7 +97,7 @@ procedure Test.2 (Test.6):
|
|||
decref Test.6;
|
||||
jump #Derived_gen.0;
|
||||
else
|
||||
let Test.9 : List [<r>C List *self, C *self] = UnionAtIndex (Id 0) (Index 0) Test.6;
|
||||
let Test.9 : List [<r>C List [<r>C List *self, C *self], C [<r>C List *self, C *self]] = UnionAtIndex (Id 0) (Index 0) Test.6;
|
||||
joinpoint #Derived_gen.2:
|
||||
let Test.24 : {} = Struct {};
|
||||
let Test.23 : List Str = CallByName List.5 Test.9 Test.24;
|
||||
|
@ -116,7 +116,7 @@ procedure Test.2 (Test.6):
|
|||
jump #Derived_gen.2;
|
||||
|
||||
procedure Test.0 ():
|
||||
let Test.32 : List [<r>C List *self, C *self] = Array [];
|
||||
let Test.32 : List [<r>C List [<r>C List *self, C *self], C [<r>C List *self, C *self]] = Array [];
|
||||
let Test.15 : [<r>C List *self, C *self] = TagId(0) Test.32;
|
||||
let Test.14 : Str = CallByName Test.2 Test.15;
|
||||
ret Test.14;
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
procedure Test.1 (Test.4):
|
||||
ret Test.4;
|
||||
let Test.13 : [C Str, C Str] = TagId(0) Test.4;
|
||||
ret Test.13;
|
||||
|
||||
procedure Test.5 (Test.12, Test.4):
|
||||
procedure Test.1 (Test.4):
|
||||
let Test.18 : [C Str, C Str] = TagId(0) Test.4;
|
||||
ret Test.18;
|
||||
|
||||
procedure Test.5 (Test.12, #Attr.12):
|
||||
let Test.4 : Str = UnionAtIndex (Id 0) (Index 0) #Attr.12;
|
||||
dec Test.4;
|
||||
let Test.14 : Str = "";
|
||||
ret Test.14;
|
||||
|
@ -11,13 +17,13 @@ procedure Test.0 ():
|
|||
joinpoint Test.9 Test.3:
|
||||
ret Test.3;
|
||||
in
|
||||
let Test.19 : Int1 = true;
|
||||
let Test.20 : Int1 = lowlevel Eq Test.19 Test.2;
|
||||
if Test.20 then
|
||||
let Test.20 : Int1 = true;
|
||||
let Test.21 : Int1 = lowlevel Eq Test.20 Test.2;
|
||||
if Test.21 then
|
||||
let Test.15 : Str = "";
|
||||
let Test.10 : Str = CallByName Test.1 Test.15;
|
||||
let Test.10 : [C Str, C Str] = CallByName Test.1 Test.15;
|
||||
jump Test.9 Test.10;
|
||||
else
|
||||
let Test.18 : Str = "";
|
||||
let Test.16 : Str = CallByName Test.1 Test.18;
|
||||
let Test.19 : Str = "";
|
||||
let Test.16 : [C Str, C Str] = CallByName Test.1 Test.19;
|
||||
jump Test.9 Test.16;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue