@@ -456,6 +456,15 @@ let trans_visitor
456
456
Il. Mem (fp_imm out_mem_disp, args_rty)
457
457
in
458
458
459
+ let get_obj_box_from_calltup (args_cell :Il.cell ) =
460
+ let indirect_args =
461
+ get_element_ptr args_cell Abi. calltup_elt_indirect_args
462
+ in
463
+ deref (ptr_cast
464
+ (get_element_ptr indirect_args Abi. indirect_args_elt_closure)
465
+ (Il. ScalarTy (Il. AddrTy (obj_closure_rty word_bits))))
466
+ in
467
+
459
468
let fp_to_args (fp :Il.cell ) (args_rty :Il.referent_ty ): Il.cell =
460
469
let (reg, _) = force_to_reg (Il. Cell fp) in
461
470
Il. Mem (based_imm reg out_mem_disp, args_rty)
@@ -465,11 +474,43 @@ let trans_visitor
465
474
get_element_ptr ty_params param_idx
466
475
in
467
476
468
- let get_ty_params_of_frame (fp :Il.reg ) (n_params :int ) : Il.cell =
469
- let fn_ty = mk_simple_ty_fn [| |] in
470
- let fn_rty = call_args_referent_type cx n_params fn_ty None in
471
- let args_cell = Il. Mem (based_imm fp out_mem_disp, fn_rty) in
472
- get_element_ptr args_cell Abi. calltup_elt_ty_params
477
+ let get_ty_params_of_frame
478
+ (fnid :node_id )
479
+ (fp :Il.reg )
480
+ (n_ty_params :int )
481
+ : Il.cell =
482
+
483
+ let fn_ty = mk_simple_ty_fn [| |] in
484
+ let fn_rty =
485
+ call_args_referent_type cx n_ty_params fn_ty (Some Il. OpaqueTy )
486
+ in
487
+ let args_cell = Il. Mem (based_imm fp out_mem_disp, fn_rty) in
488
+
489
+ if defn_id_is_obj_fn_or_drop cx fnid
490
+ then
491
+ (*
492
+ * To get the typarams in an obj fn, we must go to the
493
+ * implicit obj's captured type descriptor.
494
+ *)
495
+ let obj_box =
496
+ get_obj_box_from_calltup args_cell
497
+ in
498
+ let obj = get_element_ptr obj_box Abi. box_rc_field_body in
499
+ let tydesc = get_element_ptr obj Abi. obj_body_elt_tydesc in
500
+ let ty_params_ty = Ast. TY_tup (make_tydesc_tys n_ty_params) in
501
+ let ty_params_rty = referent_type word_bits ty_params_ty in
502
+ let ty_params =
503
+ get_element_ptr (deref tydesc) Abi. tydesc_field_first_param
504
+ in
505
+ let ty_params =
506
+ ptr_cast ty_params (Il. ScalarTy (Il. AddrTy ty_params_rty))
507
+ in
508
+ deref ty_params
509
+ else
510
+ (*
511
+ * Regular function --- typarams are right in the frame calltup.
512
+ *)
513
+ get_element_ptr args_cell Abi. calltup_elt_ty_params
473
514
in
474
515
475
516
let get_args_for_current_frame _ =
@@ -516,34 +557,10 @@ let trans_visitor
516
557
Abi. iterator_args_elt_outer_frame_ptr
517
558
in
518
559
519
- let get_obj_for_current_frame _ =
520
- deref (ptr_cast
521
- (get_closure_for_current_frame () )
522
- (Il. ScalarTy (Il. AddrTy (obj_closure_rty word_bits))))
523
- in
524
-
525
560
let get_ty_params_of_current_frame _ : Il.cell =
526
- let id = current_fn() in
527
- let n_ty_params = n_item_ty_params cx id in
528
- if defn_id_is_obj_fn_or_drop cx id
529
- then
530
- begin
531
- let obj_box = get_obj_for_current_frame() in
532
- let obj = get_element_ptr obj_box Abi. box_rc_field_body in
533
- let tydesc = get_element_ptr obj Abi. obj_body_elt_tydesc in
534
- let ty_params_ty = Ast. TY_tup (make_tydesc_tys n_ty_params) in
535
- let ty_params_rty = referent_type word_bits ty_params_ty in
536
- let ty_params =
537
- get_element_ptr (deref tydesc) Abi. tydesc_field_first_param
538
- in
539
- let ty_params =
540
- ptr_cast ty_params (Il. ScalarTy (Il. AddrTy ty_params_rty))
541
- in
542
- deref ty_params
543
- end
544
-
545
- else
546
- get_ty_params_of_frame abi.Abi. abi_fp_reg n_ty_params
561
+ let fnid = current_fn() in
562
+ let n_ty_params = n_item_ty_params cx fnid in
563
+ get_ty_params_of_frame fnid abi.Abi. abi_fp_reg n_ty_params
547
564
in
548
565
549
566
let get_ty_param_in_current_frame (param_idx :int ) : Il.cell =
@@ -4709,17 +4726,28 @@ let trans_visitor
4709
4726
let get_frame_glue glue inner =
4710
4727
get_mem_glue glue
4711
4728
begin
4729
+ (* `mem` here is a pointer to the frame we are marking, dropping,
4730
+ or relocing, etc. *)
4712
4731
fun mem ->
4713
4732
iter_frame_and_arg_slots cx fnid
4714
4733
begin
4715
4734
fun key slot_id slot ->
4716
4735
match htab_search cx.ctxt_slot_offsets slot_id with
4717
4736
Some off when not (slot_is_obj_state cx slot_id) ->
4718
4737
let referent_type = slot_id_referent_type slot_id in
4738
+ (*
4739
+ * This might look as though we're always taking the
4740
+ * pointer-to-frame and giving it the type of the
4741
+ * frame/arg of interest, but this is because our
4742
+ * deref_off a few lines later takes the referent
4743
+ * type of the given poiinter (`st`) as the referent
4744
+ * type of the mem-offset-from-the-given-pointer
4745
+ * that it returns.
4746
+ *)
4719
4747
let fp_cell = rty_ptr_at mem referent_type in
4720
4748
let (fp, st) = force_to_reg (Il. Cell fp_cell) in
4721
4749
let ty_params =
4722
- get_ty_params_of_frame fp n_ty_params
4750
+ get_ty_params_of_frame fnid fp n_ty_params
4723
4751
in
4724
4752
let slot_cell =
4725
4753
deref_off_sz ty_params (Il. Reg (fp,st)) off
0 commit comments