Skip to content

Commit fd0750b

Browse files
committed
Get object's captured typarams when querying for an object method's typarams in Trans. Together with commit 982dcc2 this... Closes rust-lang#138.
1 parent 982dcc2 commit fd0750b

File tree

1 file changed

+61
-33
lines changed

1 file changed

+61
-33
lines changed

src/boot/me/trans.ml

+61-33
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,15 @@ let trans_visitor
456456
Il.Mem (fp_imm out_mem_disp, args_rty)
457457
in
458458

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+
459468
let fp_to_args (fp:Il.cell) (args_rty:Il.referent_ty): Il.cell =
460469
let (reg, _) = force_to_reg (Il.Cell fp) in
461470
Il.Mem(based_imm reg out_mem_disp, args_rty)
@@ -465,11 +474,43 @@ let trans_visitor
465474
get_element_ptr ty_params param_idx
466475
in
467476

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
473514
in
474515

475516
let get_args_for_current_frame _ =
@@ -516,34 +557,10 @@ let trans_visitor
516557
Abi.iterator_args_elt_outer_frame_ptr
517558
in
518559

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-
525560
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
547564
in
548565

549566
let get_ty_param_in_current_frame (param_idx:int) : Il.cell =
@@ -4709,17 +4726,28 @@ let trans_visitor
47094726
let get_frame_glue glue inner =
47104727
get_mem_glue glue
47114728
begin
4729+
(* `mem` here is a pointer to the frame we are marking, dropping,
4730+
or relocing, etc. *)
47124731
fun mem ->
47134732
iter_frame_and_arg_slots cx fnid
47144733
begin
47154734
fun key slot_id slot ->
47164735
match htab_search cx.ctxt_slot_offsets slot_id with
47174736
Some off when not (slot_is_obj_state cx slot_id) ->
47184737
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+
*)
47194747
let fp_cell = rty_ptr_at mem referent_type in
47204748
let (fp, st) = force_to_reg (Il.Cell fp_cell) in
47214749
let ty_params =
4722-
get_ty_params_of_frame fp n_ty_params
4750+
get_ty_params_of_frame fnid fp n_ty_params
47234751
in
47244752
let slot_cell =
47254753
deref_off_sz ty_params (Il.Reg (fp,st)) off

0 commit comments

Comments
 (0)