mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
fix ptr returned by wasm reset
This commit is contained in:
parent
cabbfa52d5
commit
fa6d5c6955
2 changed files with 46 additions and 35 deletions
|
@ -257,40 +257,6 @@ pub fn refcount_reset_proc_body<'a>(
|
|||
)
|
||||
};
|
||||
|
||||
let alloc_addr_stmt = {
|
||||
let alignment = root.create_symbol(ident_ids, "alignment");
|
||||
let alignment_int = layout_interner
|
||||
.get(layout)
|
||||
.allocation_alignment_bytes(layout_interner, root.target_info);
|
||||
let alignment_expr = Expr::Literal(Literal::Int((alignment_int as i128).to_ne_bytes()));
|
||||
let alloc_addr = root.create_symbol(ident_ids, "alloc_addr");
|
||||
let alloc_addr_expr = Expr::Call(Call {
|
||||
call_type: CallType::LowLevel {
|
||||
op: LowLevel::NumSubWrap,
|
||||
update_mode: UpdateModeId::BACKEND_DUMMY,
|
||||
},
|
||||
arguments: root.arena.alloc([addr, alignment]),
|
||||
});
|
||||
|
||||
Stmt::Let(
|
||||
alignment,
|
||||
alignment_expr,
|
||||
root.layout_isize,
|
||||
root.arena.alloc(
|
||||
//
|
||||
Stmt::Let(
|
||||
alloc_addr,
|
||||
alloc_addr_expr,
|
||||
root.layout_isize,
|
||||
root.arena.alloc(
|
||||
//
|
||||
Stmt::Ret(alloc_addr),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
};
|
||||
|
||||
let rc_contents_stmt = refcount_union_contents(
|
||||
root,
|
||||
ident_ids,
|
||||
|
@ -302,7 +268,7 @@ pub fn refcount_reset_proc_body<'a>(
|
|||
structure,
|
||||
tag_id_sym,
|
||||
tag_id_layout,
|
||||
alloc_addr_stmt,
|
||||
Stmt::Ret(addr),
|
||||
);
|
||||
|
||||
tag_id_stmt(root.arena.alloc(
|
||||
|
|
|
@ -526,3 +526,48 @@ fn non_nullable_unwrapped_alignment_8() {
|
|||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-wasm"))]
|
||||
fn reset_reuse_alignment_8() {
|
||||
assert_refcounts!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
Expr : [ZAdd Expr Expr, Val I64, Var I64]
|
||||
|
||||
eval : Expr -> I64
|
||||
eval = \e ->
|
||||
when e is
|
||||
Var _ -> 0
|
||||
Val v -> v
|
||||
ZAdd l r -> eval l + eval r
|
||||
|
||||
constFolding : Expr -> Expr
|
||||
constFolding = \e ->
|
||||
when e is
|
||||
ZAdd e1 e2 ->
|
||||
when Pair e1 e2 is
|
||||
Pair (Val a) (Val b) -> Val (a+b)
|
||||
Pair _ _ -> ZAdd e1 e2
|
||||
|
||||
|
||||
_ -> e
|
||||
|
||||
|
||||
expr : Expr
|
||||
expr = ZAdd (Val 4) (Val 5)
|
||||
|
||||
main : I64
|
||||
main = eval (constFolding expr)
|
||||
"#
|
||||
),
|
||||
i64,
|
||||
&[
|
||||
Deallocated, // Val 4
|
||||
Deallocated, // Val 5
|
||||
Deallocated, // ZAdd _ _
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue