unboxing of non-recursive tag unions

This commit is contained in:
Folkert 2023-04-26 22:17:18 +02:00
parent 0f058c8b46
commit f6ebeff298
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 33 additions and 5 deletions

View file

@ -3032,7 +3032,7 @@ impl<
if size - copied >= 8 { if size - copied >= 8 {
for _ in (0..(size - copied)).step_by(8) { for _ in (0..(size - copied)).step_by(8) {
ASM::mov_reg64_mem64_offset32(buf, tmp_reg, ptr_reg, copied); ASM::mov_reg64_mem64_offset32(buf, tmp_reg, ptr_reg, copied);
ASM::mov_base32_reg64(buf, base_offset, tmp_reg); ASM::mov_base32_reg64(buf, base_offset + copied, tmp_reg);
copied += 8; copied += 8;
} }
@ -3041,7 +3041,7 @@ impl<
if size - copied >= 4 { if size - copied >= 4 {
for _ in (0..(size - copied)).step_by(4) { for _ in (0..(size - copied)).step_by(4) {
ASM::mov_reg32_mem32_offset32(buf, tmp_reg, ptr_reg, copied); ASM::mov_reg32_mem32_offset32(buf, tmp_reg, ptr_reg, copied);
ASM::mov_base32_reg32(buf, base_offset, tmp_reg); ASM::mov_base32_reg32(buf, base_offset + copied, tmp_reg);
copied += 4; copied += 4;
} }
@ -3050,7 +3050,7 @@ impl<
if size - copied >= 2 { if size - copied >= 2 {
for _ in (0..(size - copied)).step_by(2) { for _ in (0..(size - copied)).step_by(2) {
ASM::mov_reg16_mem16_offset32(buf, tmp_reg, ptr_reg, copied); ASM::mov_reg16_mem16_offset32(buf, tmp_reg, ptr_reg, copied);
ASM::mov_base32_reg16(buf, base_offset, tmp_reg); ASM::mov_base32_reg16(buf, base_offset + copied, tmp_reg);
copied += 2; copied += 2;
} }
@ -3059,7 +3059,7 @@ impl<
if size - copied >= 1 { if size - copied >= 1 {
for _ in (0..(size - copied)).step_by(1) { for _ in (0..(size - copied)).step_by(1) {
ASM::mov_reg8_mem8_offset32(buf, tmp_reg, ptr_reg, copied); ASM::mov_reg8_mem8_offset32(buf, tmp_reg, ptr_reg, copied);
ASM::mov_base32_reg8(buf, base_offset, tmp_reg); ASM::mov_base32_reg8(buf, base_offset + copied, tmp_reg);
copied += 1; copied += 1;
} }
@ -3132,6 +3132,15 @@ impl<
}); });
} }
Layout::Union(UnionLayout::NonRecursive(_)) => {
// put it on the stack
let stack_size = layout_interner.stack_size(element_in_layout);
storage_manager.with_tmp_general_reg(buf, |storage_manager, buf, tmp_reg| {
Self::unbox_to_stack(buf, storage_manager, dst, stack_size, ptr_reg, tmp_reg);
});
}
_ => todo!("unboxing of {:?}", layout_interner.dbg(element_in_layout)), _ => todo!("unboxing of {:?}", layout_interner.dbg(element_in_layout)),
} }
} }

View file

@ -483,7 +483,7 @@ impl X64_64SystemVStoreArgs {
} }
} }
x if layout_interner.stack_size(x) == 0 => {} x if layout_interner.stack_size(x) == 0 => {}
x if layout_interner.stack_size(x) == 16 => { x if layout_interner.stack_size(x) > 16 => {
// TODO: Double check this. // TODO: Double check this.
// Just copy onto the stack. // Just copy onto the stack.
// Use return reg as buffer because it will be empty right now. // Use return reg as buffer because it will be empty right now.

View file

@ -3288,6 +3288,25 @@ fn box_and_unbox_big_string() {
) )
} }
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn box_and_unbox_nonrecursive_tag() {
assert_evals_to!(
indoc!(
r#"
result : Result U64 U64
result = Ok 42
result
|> Box.box
|> Box.unbox
"#
),
roc_std::RocResult::ok(42),
roc_std::RocResult<u64, u64>
)
}
#[test] #[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn box_num() { fn box_num() {