Wrap layouts in a LayoutRepr constructor

Part 1 of support semantic layout representations.
This commit is contained in:
Ayaz Hafiz 2023-05-10 13:22:10 -05:00
parent c2d2bd4bb9
commit c3eeb5e2cc
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
32 changed files with 1254 additions and 1021 deletions

View file

@ -12,8 +12,8 @@ use roc_mono::ir::{
Param, Proc, ProcLayout, Stmt,
};
use roc_mono::layout::{
Builtin, InLayout, Layout, LayoutIds, LayoutInterner, STLayoutInterner, TagIdIntType,
UnionLayout,
Builtin, InLayout, Layout, LayoutIds, LayoutInterner, LayoutRepr, STLayoutInterner,
TagIdIntType, UnionLayout,
};
use roc_std::RocDec;
@ -507,9 +507,9 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
let heap_return_ptr_id = LocalId(wrapper_arg_layouts.len() as u32 - 1);
let inner_ret_layout = match wrapper_arg_layouts
.last()
.map(|l| self.layout_interner.get(*l))
.map(|l| self.layout_interner.get(*l).repr)
{
Some(Layout::Boxed(inner)) => WasmLayout::new(self.layout_interner, inner),
Some(LayoutRepr::Boxed(inner)) => WasmLayout::new(self.layout_interner, inner),
x => internal_error!("Higher-order wrapper: invalid return layout {:?}", x),
};
@ -539,8 +539,8 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
continue;
}
let inner_layout = match self.layout_interner.get(*wrapper_arg) {
Layout::Boxed(inner) => inner,
let inner_layout = match self.layout_interner.get(*wrapper_arg).repr {
LayoutRepr::Boxed(inner) => inner,
x => internal_error!("Expected a Boxed layout, got {:?}", x),
};
if self.layout_interner.stack_size(inner_layout) == 0 {
@ -558,8 +558,9 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
if self.layout_interner.stack_size(closure_data_layout) > 0 {
// The closure data exists, and will have been passed in to the wrapper as a
// one-element struct.
let inner_closure_data_layout = match self.layout_interner.get(closure_data_layout) {
Layout::Struct {
let inner_closure_data_layout = match self.layout_interner.get(closure_data_layout).repr
{
LayoutRepr::Struct {
field_layouts: [inner],
..
} => inner,
@ -635,8 +636,8 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
n_inner_args += 1;
}
let inner_layout = match self.layout_interner.get(value_layout) {
Layout::Boxed(inner) => inner,
let inner_layout = match self.layout_interner.get(value_layout).repr {
LayoutRepr::Boxed(inner) => inner,
x => internal_error!("Expected a Boxed layout, got {:?}", x),
};
self.code_builder.get_local(LocalId(1));
@ -664,26 +665,26 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
fn dereference_boxed_value(&mut self, inner: InLayout) {
use Align::*;
match self.layout_interner.get(inner) {
Layout::Builtin(Builtin::Int(IntWidth::U8 | IntWidth::I8)) => {
match self.layout_interner.get(inner).repr {
LayoutRepr::Builtin(Builtin::Int(IntWidth::U8 | IntWidth::I8)) => {
self.code_builder.i32_load8_u(Bytes1, 0);
}
Layout::Builtin(Builtin::Int(IntWidth::U16 | IntWidth::I16)) => {
LayoutRepr::Builtin(Builtin::Int(IntWidth::U16 | IntWidth::I16)) => {
self.code_builder.i32_load16_u(Bytes2, 0);
}
Layout::Builtin(Builtin::Int(IntWidth::U32 | IntWidth::I32)) => {
LayoutRepr::Builtin(Builtin::Int(IntWidth::U32 | IntWidth::I32)) => {
self.code_builder.i32_load(Bytes4, 0);
}
Layout::Builtin(Builtin::Int(IntWidth::U64 | IntWidth::I64)) => {
LayoutRepr::Builtin(Builtin::Int(IntWidth::U64 | IntWidth::I64)) => {
self.code_builder.i64_load(Bytes8, 0);
}
Layout::Builtin(Builtin::Float(FloatWidth::F32)) => {
LayoutRepr::Builtin(Builtin::Float(FloatWidth::F32)) => {
self.code_builder.f32_load(Bytes4, 0);
}
Layout::Builtin(Builtin::Float(FloatWidth::F64)) => {
LayoutRepr::Builtin(Builtin::Float(FloatWidth::F64)) => {
self.code_builder.f64_load(Bytes8, 0);
}
Layout::Builtin(Builtin::Bool) => {
LayoutRepr::Builtin(Builtin::Bool) => {
self.code_builder.i32_load8_u(Bytes1, 0);
}
_ => {
@ -1442,8 +1443,8 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
storage: &StoredValue,
fields: &'a [Symbol],
) {
match self.layout_interner.get(layout) {
Layout::Struct { .. } => {
match self.layout_interner.get(layout).repr {
LayoutRepr::Struct { .. } => {
match storage {
StoredValue::StackMemory { location, size, .. } => {
if *size > 0 {
@ -1468,7 +1469,7 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
}
};
}
Layout::LambdaSet(lambdaset) => {
LayoutRepr::LambdaSet(lambdaset) => {
self.expr_struct(sym, lambdaset.runtime_representation(), storage, fields)
}
_ => {
@ -1900,8 +1901,8 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
};
// allocate heap memory and load its data address onto the value stack
let arg_layout = match self.layout_interner.get(layout) {
Layout::Boxed(arg) => arg,
let arg_layout = match self.layout_interner.get(layout).repr {
LayoutRepr::Boxed(arg) => arg,
_ => internal_error!("ExprBox should always produce a Boxed layout"),
};
let (size, alignment) = self.layout_interner.stack_size_and_alignment(arg_layout);