mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Add alignment argument to Zig decref call
This commit is contained in:
parent
7b5fb2577b
commit
f4d52f7084
2 changed files with 18 additions and 6 deletions
|
@ -859,10 +859,11 @@ impl<'a> WasmBackend<'a> {
|
||||||
|
|
||||||
None => {
|
None => {
|
||||||
// Wasm function signature
|
// Wasm function signature
|
||||||
let signature_index = self.module.types.insert(Signature {
|
let signature = Signature {
|
||||||
param_types,
|
param_types,
|
||||||
ret_type,
|
ret_type,
|
||||||
});
|
};
|
||||||
|
let signature_index = self.module.types.insert(signature);
|
||||||
|
|
||||||
// Declare it as an import since it comes from a different .o file
|
// Declare it as an import since it comes from a different .o file
|
||||||
let import_index = self.module.import.entries.len() as u32;
|
let import_index = self.module.import.entries.len() as u32;
|
||||||
|
|
|
@ -18,6 +18,7 @@ use crate::layout::{Builtin, Layout};
|
||||||
const LAYOUT_BOOL: Layout = Layout::Builtin(Builtin::Bool);
|
const LAYOUT_BOOL: Layout = Layout::Builtin(Builtin::Bool);
|
||||||
const LAYOUT_UNIT: Layout = Layout::Struct(&[]);
|
const LAYOUT_UNIT: Layout = Layout::Struct(&[]);
|
||||||
const LAYOUT_PTR: Layout = Layout::RecursivePointer;
|
const LAYOUT_PTR: Layout = Layout::RecursivePointer;
|
||||||
|
const LAYOUT_U32: Layout = Layout::Builtin(Builtin::Int(IntWidth::U32));
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum RefcountOp {
|
pub enum RefcountOp {
|
||||||
|
@ -30,6 +31,7 @@ pub struct RefcountProcGenerator<'a> {
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
home: ModuleId,
|
home: ModuleId,
|
||||||
next_symbol_id: u32,
|
next_symbol_id: u32,
|
||||||
|
ptr_size: u32,
|
||||||
layout_isize: Layout<'a>,
|
layout_isize: Layout<'a>,
|
||||||
/// List of refcounting procs to generate, specialised by Layout and RefCountOp
|
/// List of refcounting procs to generate, specialised by Layout and RefCountOp
|
||||||
/// Order of insertion is preserved, since it is important for Wasm backend
|
/// Order of insertion is preserved, since it is important for Wasm backend
|
||||||
|
@ -42,6 +44,7 @@ impl<'a> RefcountProcGenerator<'a> {
|
||||||
arena,
|
arena,
|
||||||
home,
|
home,
|
||||||
next_symbol_id: 0,
|
next_symbol_id: 0,
|
||||||
|
ptr_size: intwidth_isize.stack_size(),
|
||||||
layout_isize: Layout::Builtin(Builtin::Int(intwidth_isize)),
|
layout_isize: Layout::Builtin(Builtin::Int(intwidth_isize)),
|
||||||
procs_to_generate: Vec::with_capacity_in(16, arena),
|
procs_to_generate: Vec::with_capacity_in(16, arena),
|
||||||
}
|
}
|
||||||
|
@ -268,6 +271,11 @@ impl<'a> RefcountProcGenerator<'a> {
|
||||||
});
|
});
|
||||||
let rc_ptr_stmt = |next| Stmt::Let(rc_ptr, rc_ptr_expr, LAYOUT_PTR, next);
|
let rc_ptr_stmt = |next| Stmt::Let(rc_ptr, rc_ptr_expr, LAYOUT_PTR, next);
|
||||||
|
|
||||||
|
// Alignment constant
|
||||||
|
let alignment = self.unique_symbol();
|
||||||
|
let alignment_expr = Expr::Literal(Literal::Int(self.ptr_size as i128));
|
||||||
|
let alignment_stmt = |next| Stmt::Let(alignment, alignment_expr, LAYOUT_U32, next);
|
||||||
|
|
||||||
// Call the relevant Zig lowlevel to actually modify the refcount
|
// Call the relevant Zig lowlevel to actually modify the refcount
|
||||||
let zig_call_result = self.unique_symbol();
|
let zig_call_result = self.unique_symbol();
|
||||||
let zig_call_expr = match op {
|
let zig_call_expr = match op {
|
||||||
|
@ -283,21 +291,24 @@ impl<'a> RefcountProcGenerator<'a> {
|
||||||
op: LowLevel::RefCountDec,
|
op: LowLevel::RefCountDec,
|
||||||
update_mode: UpdateModeId::BACKEND_DUMMY,
|
update_mode: UpdateModeId::BACKEND_DUMMY,
|
||||||
},
|
},
|
||||||
arguments: self.arena.alloc([rc_ptr]),
|
arguments: self.arena.alloc([rc_ptr, alignment]),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
let zig_call_stmt = |next| Stmt::Let(zig_call_result, zig_call_expr, LAYOUT_BOOL, next);
|
let zig_call_stmt = |next| Stmt::Let(zig_call_result, zig_call_expr, LAYOUT_UNIT, next);
|
||||||
|
|
||||||
// Generate an `if` to skip small strings but modify big strings
|
// Generate an `if` to skip small strings but modify big strings
|
||||||
let then_branch = elements_stmt(self.arena.alloc(
|
let then_branch = elements_stmt(self.arena.alloc(
|
||||||
//
|
//
|
||||||
rc_ptr_stmt(self.arena.alloc(
|
rc_ptr_stmt(self.arena.alloc(
|
||||||
|
//
|
||||||
|
alignment_stmt(self.arena.alloc(
|
||||||
//
|
//
|
||||||
zig_call_stmt(self.arena.alloc(
|
zig_call_stmt(self.arena.alloc(
|
||||||
//
|
//
|
||||||
Stmt::Ret(zig_call_result),
|
Stmt::Ret(zig_call_result),
|
||||||
)),
|
)),
|
||||||
)),
|
)),
|
||||||
|
)),
|
||||||
));
|
));
|
||||||
let if_stmt = Stmt::Switch {
|
let if_stmt = Stmt::Switch {
|
||||||
cond_symbol: is_big_str,
|
cond_symbol: is_big_str,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue