attempt to correct list refcount generation in dev backends

This commit is contained in:
Brendan Hansknecht 2024-07-07 16:16:16 -07:00
parent 94fe0820d5
commit 36bc8bfac4
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
9 changed files with 56 additions and 24 deletions

View file

@ -953,7 +953,7 @@ fn refcount_list<'a>(
ctx: &mut Context<'a>,
layout_interner: &mut STLayoutInterner<'a>,
element_layout: InLayout<'a>,
structure: Symbol,
_structure: Symbol,
) -> Stmt<'a> {
let arena = root.arena;
let layout_isize = root.layout_isize;
@ -1016,27 +1016,36 @@ fn refcount_list<'a>(
Expr::Literal(Literal::Int((element_alignment as u128).to_ne_bytes()));
let alignment_stmt = |next| Stmt::Let(alignment, alignment_expr, LAYOUT_U32, next);
// let orig_op = ctx.op;
// ctx.op = HelperOp::IndirectDec;
// let dec_elem_fn =
// root.find_or_create_proc(ident_ids, ctx, layout_interner, element_layout);
// ctx.op = orig_op;
// TODO: How do I load a proc symbol to a pointer???
let dec_elem_ptr = root.create_symbol(ident_ids, "dec_elem_ptr");
let dec_elem_ptr_expr = Expr::Call(Call {
call_type: CallType::LowLevel {
op: LowLevel::ListElemDecFnPtr,
update_mode: UpdateModeId::BACKEND_DUMMY,
},
arguments: root.arena.alloc([list]),
});
let dec_elem_ptr_stmt =
|next| Stmt::Let(dec_elem_ptr, dec_elem_ptr_expr, Layout::OPAQUE_PTR, next);
let rc_list_expr = Expr::Call(Call {
call_type: CallType::LowLevel {
op: LowLevel::ListDecref,
update_mode: UpdateModeId::BACKEND_DUMMY,
},
arguments: root.arena.alloc([list, alignment, width, is_refcounted]),
arguments: root
.arena
.alloc([list, alignment, width, is_refcounted, dec_elem_ptr]),
});
width_stmt(arena.alloc(
//
alignment_stmt(arena.alloc(
//
is_refcounted_stmt(arena.alloc(
dec_elem_ptr_stmt(arena.alloc(
//
Stmt::Let(rc_list_unit, rc_list_expr, LAYOUT_UNIT, ret_stmt),
is_refcounted_stmt(arena.alloc(
//
Stmt::Let(rc_list_unit, rc_list_expr, LAYOUT_UNIT, ret_stmt),
)),
)),
)),
))

View file

@ -1621,8 +1621,8 @@ fn low_level_no_rc(lowlevel: &LowLevel) -> RC {
PtrLoad => RC::NoRc,
PtrCast => RC::NoRc,
PtrClearTagId | RefCountIncRcPtr | RefCountDecRcPtr | RefCountIncDataPtr
| RefCountDecDataPtr | RefCountIsUnique => {
ListElemDecFnPtr | PtrClearTagId | RefCountIncRcPtr | RefCountDecRcPtr
| RefCountIncDataPtr | RefCountDecDataPtr | RefCountIsUnique => {
unreachable!("Only inserted *after* borrow checking: {:?}", lowlevel);
}

View file

@ -1357,6 +1357,8 @@ pub(crate) fn lowlevel_borrow_signature(op: LowLevel) -> &'static [Ownership] {
StrReleaseExcessCapacity => &[OWNED],
ListIncref => &[OWNED],
ListDecref => &[OWNED],
// This doesn't really use the list. It just generates a functions from the layout.
ListElemDecFnPtr => &[BORROWED],
Eq | NotEq => &[BORROWED, BORROWED],