Skip to content

Commit 373f904

Browse files
committed
Explicitly provide an optional closure/obj pointer to trans_call_glue so that it can push one in the right position when calling glue, instead of always pushing a null. As far as I can tell this only affects calls to obj drop glue, since only that makes use of an object binding passed as closure/obj, so pass the binding there as needed.
1 parent df75165 commit 373f904

File tree

1 file changed

+81
-38
lines changed

1 file changed

+81
-38
lines changed

Diff for: src/boot/me/trans.ml

+81-38
Original file line numberDiff line numberDiff line change
@@ -1228,8 +1228,8 @@ let trans_visitor
12281228
(sorted_htab_keys fns))
12291229
end
12301230

1231-
and trans_init_str (dst:Ast.lval) (s:string) : unit =
1232-
(* Include null byte. *)
1231+
and trans_init_str (dst:Ast.lval) (s:string) : unit =
1232+
(* Include null byte. *)
12331233
let init_sz = Int64.of_int ((String.length s) + 1) in
12341234
let static = trans_static_string s in
12351235
let (dst, _) = trans_lval_init dst in
@@ -1715,51 +1715,63 @@ let trans_visitor
17151715
(code:Il.code)
17161716
(dst:Il.cell option)
17171717
(args:Il.cell array)
1718+
(clo:Il.cell option)
17181719
: unit =
1719-
let inner dst =
1720+
let inner dst cloptr =
17201721
let scratch = next_vreg_cell Il.voidptr_t in
17211722
let pop _ = emit (Il.Pop scratch) in
17221723
for i = ((Array.length args) - 1) downto 0
17231724
do
17241725
emit (Il.Push (Il.Cell args.(i)))
17251726
done;
1726-
emit (Il.Push zero);
1727+
emit (Il.Push cloptr);
17271728
emit (Il.Push (Il.Cell abi.Abi.abi_tp_cell));
17281729
emit (Il.Push dst);
17291730
call_code code;
17301731
pop ();
17311732
pop ();
17321733
pop ();
17331734
Array.iter (fun _ -> pop()) args;
1735+
in
1736+
let cloptr =
1737+
match clo with
1738+
None -> zero
1739+
| Some cloptr -> Il.Cell cloptr
17341740
in
17351741
match dst with
1736-
None -> inner zero
1737-
| Some dst -> aliasing true dst (fun dst -> inner (Il.Cell dst))
1742+
None -> inner zero cloptr
1743+
| Some dst ->
1744+
aliasing true dst (fun dst -> inner (Il.Cell dst) cloptr)
17381745

17391746
and trans_call_static_glue
17401747
(callee:Il.operand)
17411748
(dst:Il.cell option)
17421749
(args:Il.cell array)
1750+
(clo:Il.cell option)
17431751
: unit =
1744-
trans_call_glue (code_of_operand callee) dst args
1752+
trans_call_glue (code_of_operand callee) dst args clo
17451753

17461754
and trans_call_dynamic_glue
17471755
(tydesc:Il.cell)
17481756
(idx:int)
17491757
(dst:Il.cell option)
17501758
(args:Il.cell array)
1759+
(clo:Il.cell option)
17511760
: unit =
17521761
let fptr = get_vtbl_entry_idx tydesc idx in
1753-
trans_call_glue (code_of_operand (Il.Cell fptr)) dst args
1762+
trans_call_glue (code_of_operand (Il.Cell fptr)) dst args clo
17541763

17551764
and trans_call_simple_static_glue
17561765
(fix:fixup)
17571766
(ty_params:Il.cell)
1758-
(arg:Il.cell)
1767+
(args:Il.cell array)
1768+
(clo:Il.cell option)
17591769
: unit =
17601770
trans_call_static_glue
17611771
(code_fixup_to_ptr_operand fix)
1762-
None [| alias ty_params; arg |]
1772+
None
1773+
(Array.append [| alias ty_params |] args)
1774+
clo
17631775

17641776
and get_tydesc_params
17651777
(outer_ty_params:Il.cell)
@@ -1781,16 +1793,20 @@ let trans_visitor
17811793
(ty_param:int)
17821794
(vtbl_idx:int)
17831795
(ty_params:Il.cell)
1784-
(arg:Il.cell)
1796+
(args:Il.cell array)
1797+
(clo:Il.cell option)
17851798
: unit =
17861799
iflog (fun _ ->
17871800
annotate (Printf.sprintf "calling tydesc[%d].glue[%d]"
17881801
ty_param vtbl_idx));
17891802
let td = get_ty_param ty_params ty_param in
17901803
let ty_params_ptr = get_tydesc_params ty_params td in
17911804
trans_call_dynamic_glue
1792-
td vtbl_idx
1793-
None [| ty_params_ptr; arg; |]
1805+
td
1806+
vtbl_idx
1807+
None
1808+
(Array.append [| ty_params_ptr |] args)
1809+
clo
17941810

17951811
(* trans_compare returns a quad number of the cjmp, which the caller
17961812
patches to the cjmp destination. *)
@@ -2467,23 +2483,31 @@ let trans_visitor
24672483
in
24682484
let null_dtor_jmp = null_check dtor in
24692485
(* Call any dtor, if present. *)
2470-
note_drop_step ty "drop_ty: calling obj dtor";
2471-
trans_call_dynamic_glue tydesc
2472-
Abi.tydesc_field_obj_drop_glue None [| binding |];
2473-
patch null_dtor_jmp;
2474-
(* Drop the body. *)
2475-
note_drop_step ty "drop_ty: dropping obj body";
2476-
trans_call_dynamic_glue tydesc
2477-
Abi.tydesc_field_drop_glue None [| ty_params; alias body |];
2478-
(* FIXME: this will fail if the user has lied about the
2479-
* state-ness of their obj. We need to store state-ness in the
2480-
* captured tydesc, and use that. *)
2481-
note_drop_step ty "drop_ty: freeing obj body";
2482-
trans_free binding (type_has_state ty);
2483-
mov binding zero;
2484-
patch rc_jmp;
2485-
patch null_jmp;
2486-
note_drop_step ty "drop_ty: done obj path";
2486+
note_drop_step ty "drop_ty: calling obj dtor";
2487+
trans_call_dynamic_glue
2488+
tydesc
2489+
Abi.tydesc_field_obj_drop_glue
2490+
None
2491+
[| binding |]
2492+
(Some binding);
2493+
patch null_dtor_jmp;
2494+
(* Drop the body. *)
2495+
note_drop_step ty "drop_ty: dropping obj body";
2496+
trans_call_dynamic_glue
2497+
tydesc
2498+
Abi.tydesc_field_drop_glue
2499+
None
2500+
[| ty_params; alias body |]
2501+
None;
2502+
(* FIXME: this will fail if the user has lied about the
2503+
* state-ness of their obj. We need to store state-ness in the
2504+
* captured tydesc, and use that. *)
2505+
note_drop_step ty "drop_ty: freeing obj body";
2506+
trans_free binding (type_has_state ty);
2507+
mov binding zero;
2508+
patch rc_jmp;
2509+
patch null_jmp;
2510+
note_drop_step ty "drop_ty: done obj path";
24872511

24882512

24892513
| Ast.TY_param (i, _) ->
@@ -2492,7 +2516,11 @@ let trans_visitor
24922516
begin
24932517
fun cell ->
24942518
trans_call_simple_dynamic_glue
2495-
i Abi.tydesc_field_drop_glue ty_params cell
2519+
i
2520+
Abi.tydesc_field_drop_glue
2521+
ty_params
2522+
[| cell |]
2523+
None
24962524
end;
24972525
note_drop_step ty "drop_ty: done parametric-ty path";
24982526

@@ -2514,7 +2542,9 @@ let trans_visitor
25142542

25152543
trans_call_simple_static_glue
25162544
(get_free_glue ty (mctrl = MEM_gc) curr_iso)
2517-
ty_params cell;
2545+
ty_params
2546+
[| cell |]
2547+
None;
25182548

25192549
(* Null the slot out to prevent double-free if the frame
25202550
* unwinds.
@@ -2603,7 +2633,7 @@ let trans_visitor
26032633
trans_call_static_glue
26042634
(code_fixup_to_ptr_operand glue_fix)
26052635
(Some dst)
2606-
[| alias ty_params; src; clone_task |]
2636+
[| alias ty_params; src; clone_task |] None
26072637
| _ ->
26082638
iter_ty_parts_full ty_params dst src ty
26092639
(clone_ty ty_params clone_task) curr_iso
@@ -2640,7 +2670,10 @@ let trans_visitor
26402670
lea vr body_mem;
26412671
trace_word cx.ctxt_sess.Session.sess_trace_drop vr;
26422672
trans_call_simple_static_glue
2643-
(get_drop_glue body_ty curr_iso) ty_params vr;
2673+
(get_drop_glue body_ty curr_iso)
2674+
ty_params
2675+
[| vr |]
2676+
None;
26442677
note_drop_step ty "in free-ty, calling free";
26452678
trans_free cell is_gc;
26462679
end;
@@ -2700,7 +2733,9 @@ let trans_visitor
27002733
lea tmp body_mem;
27012734
trans_call_simple_static_glue
27022735
(get_mark_glue ty curr_iso)
2703-
ty_params tmp;
2736+
ty_params
2737+
[| tmp |]
2738+
None;
27042739
List.iter patch marked_jump;
27052740

27062741
| MEM_interior when type_is_structured ty ->
@@ -2714,7 +2749,9 @@ let trans_visitor
27142749
lea tmp mem;
27152750
trans_call_simple_static_glue
27162751
(get_mark_glue ty curr_iso)
2717-
ty_params tmp
2752+
ty_params
2753+
[| tmp |]
2754+
None
27182755

27192756
| _ -> ()
27202757

@@ -3033,7 +3070,9 @@ let trans_visitor
30333070
let ty_params_ptr = get_tydesc_params ty_params td in
30343071
trans_call_dynamic_glue
30353072
td Abi.tydesc_field_copy_glue
3036-
(Some dst) [| ty_params_ptr; src; |]
3073+
(Some dst)
3074+
[| ty_params_ptr; src; |]
3075+
None
30373076
end
30383077

30393078
| Ast.TY_fn _
@@ -4090,7 +4129,11 @@ let trans_visitor
40904129
let fp = get_iter_outer_frame_ptr_for_current_frame () in
40914130
let vr = next_vreg_cell Il.voidptr_t in
40924131
mov vr zero;
4093-
trans_call_glue (code_of_operand block_fptr) None [| vr; fp |]
4132+
trans_call_glue
4133+
(code_of_operand block_fptr)
4134+
None
4135+
[| vr; fp |]
4136+
None
40944137

40954138
and trans_vec_append dst_cell dst_ty src_oper src_ty =
40964139
let elt_ty = seq_unit_ty dst_ty in

0 commit comments

Comments
 (0)