@@ -1355,7 +1355,7 @@ let trans_visitor
1355
1355
Asm. WORD (word_ty_mach, Asm. IMM 0L );
1356
1356
Asm. WORD (word_ty_mach, Asm. IMM sz);
1357
1357
Asm. WORD (word_ty_mach, Asm. IMM align);
1358
- fix (get_copy_glue t);
1358
+ fix (get_take_glue t);
1359
1359
fix (get_drop_glue t);
1360
1360
begin
1361
1361
match ty_mem_ctrl cx t with
@@ -2022,34 +2022,18 @@ let trans_visitor
2022
2022
get_typed_mem_glue g fty inner
2023
2023
2024
2024
2025
- and get_copy_glue
2025
+ and get_take_glue
2026
2026
(ty :Ast.ty )
2027
2027
: fixup =
2028
2028
let ty = get_genericized_ty ty in
2029
2029
let arg_ty_params_alias = 0 in
2030
2030
let arg_src_alias = 1 in
2031
- let arg_initflag = 2 in
2032
2031
2033
- let g = GLUE_copy ty in
2034
- let inner (out_ptr :Il.cell ) (args :Il.cell ) =
2035
- let dst = deref out_ptr in
2032
+ let g = GLUE_take ty in
2033
+ let inner (_ :Il.cell ) (args :Il.cell ) =
2036
2034
let ty_params = deref (get_element_ptr args arg_ty_params_alias) in
2037
2035
let src = deref (get_element_ptr args arg_src_alias) in
2038
-
2039
- (* Translate copy code for the dst-initializing and
2040
- * dst-non-initializing cases and branch accordingly. *)
2041
- let initflag = get_element_ptr args arg_initflag in
2042
- let jmps = trans_compare_simple Il. JNE (Il. Cell initflag) one in
2043
-
2044
- trans_copy_ty_full true ty_params true dst ty src ty;
2045
-
2046
- let skip_noninit_jmp = mark() in
2047
- emit (Il. jmp Il. JMP Il. CodeNone );
2048
- List. iter patch jmps;
2049
-
2050
- trans_copy_ty_full true ty_params false dst ty src ty;
2051
-
2052
- patch skip_noninit_jmp;
2036
+ trans_take_ty true ty_params src ty;
2053
2037
in
2054
2038
let ty_params_ptr = ty_params_covering ty in
2055
2039
let fty =
@@ -2186,17 +2170,23 @@ let trans_visitor
2186
2170
get_tydesc_params ty_params_cell elt_td_ptr_cell
2187
2171
in
2188
2172
2189
- let initflag = Il. Reg (force_to_reg one) in
2190
-
2173
+ (* Take all *)
2191
2174
copy_loop dst_buf src_buf (Il. Cell fill) (Il. Cell elt_sz)
2192
2175
begin
2193
- fun dptr sptr ->
2176
+ fun _ sptr ->
2194
2177
trans_call_dynamic_glue
2195
2178
elt_td_ptr_cell
2196
- Abi. tydesc_field_copy_glue
2197
- (Some (deref dptr))
2198
- [| ty_params_ptr; sptr; initflag |]
2179
+ Abi. tydesc_field_take_glue
2199
2180
None
2181
+ [| ty_params_ptr; sptr |]
2182
+ None ;
2183
+ end;
2184
+
2185
+ (* Memcpy all *)
2186
+ copy_loop dst_buf src_buf (Il. Cell fill) one
2187
+ begin
2188
+ fun dptr sptr ->
2189
+ mov (deref dptr) (Il. Cell (deref sptr))
2200
2190
end;
2201
2191
2202
2192
(* Set the new vec's fill to the original vec's fill *)
@@ -3734,17 +3724,58 @@ let trans_visitor
3734
3724
end
3735
3725
tys
3736
3726
3737
- and trans_copy_ty
3727
+ and trans_take_ty
3728
+ (force_inline :bool )
3738
3729
(ty_params :Il.cell )
3739
- (initializing :bool )
3740
- (dst :Il.cell ) (dst_ty :Ast.ty )
3741
- (src :Il.cell ) (src_ty :Ast.ty )
3730
+ (v :Il.cell )
3731
+ (ty :Ast.ty )
3742
3732
: unit =
3743
- trans_copy_ty_full
3744
- false ty_params initializing dst dst_ty src src_ty
3733
+ let ty = strip_mutable_or_constrained_ty ty in
3734
+ match ty_mem_ctrl cx ty with
3735
+ MEM_rc_opaque | MEM_gc | MEM_rc_struct -> incr_refcount v
3736
+ | _ ->
3737
+ begin
3738
+ match ty with
3739
+ Ast. TY_fn _
3740
+ | Ast. TY_obj _ ->
3741
+ let binding =
3742
+ get_element_ptr v Abi. binding_field_bound_data
3743
+ in
3744
+ let null_jmp = null_check binding in
3745
+ incr_refcount binding;
3746
+ patch null_jmp
3745
3747
3746
- and trans_copy_ty_full
3747
- (force_inline :bool )
3748
+ | Ast. TY_param (i , _ ) ->
3749
+ aliasing false v
3750
+ begin
3751
+ fun v ->
3752
+ let td = get_ty_param ty_params i in
3753
+ let ty_params_ptr = get_tydesc_params ty_params td in
3754
+ trans_call_dynamic_glue
3755
+ td Abi. tydesc_field_take_glue
3756
+ None
3757
+ [| ty_params_ptr; v; |]
3758
+ None
3759
+ end
3760
+
3761
+ | Ast. TY_rec _
3762
+ | Ast. TY_tag _
3763
+ | Ast. TY_tup _ ->
3764
+ if force_inline
3765
+ then
3766
+ iter_ty_parts ty_params v ty
3767
+ (trans_take_ty force_inline ty_params)
3768
+ else
3769
+ trans_call_static_glue
3770
+ (code_fixup_to_ptr_operand (get_take_glue ty))
3771
+ None
3772
+ [| alias ty_params; alias v; |]
3773
+ None
3774
+
3775
+ | _ -> ()
3776
+ end
3777
+
3778
+ and trans_copy_ty
3748
3779
(ty_params :Il.cell )
3749
3780
(initializing :bool )
3750
3781
(dst :Il.cell ) (dst_ty :Ast.ty )
@@ -3789,7 +3820,7 @@ let trans_visitor
3789
3820
| _ ->
3790
3821
(* Heavyweight copy: duplicate 1 level of the referent. *)
3791
3822
anno " heavy" ;
3792
- trans_copy_ty_heavy force_inline ty_params initializing
3823
+ trans_copy_ty_heavy ty_params initializing
3793
3824
dst dst_ty src src_ty
3794
3825
end
3795
3826
@@ -3821,7 +3852,6 @@ let trans_visitor
3821
3852
*)
3822
3853
3823
3854
and trans_copy_ty_heavy
3824
- (force_inline :bool )
3825
3855
(ty_params :Il.cell )
3826
3856
(initializing :bool )
3827
3857
(dst :Il.cell ) (dst_ty :Ast.ty )
@@ -3863,68 +3893,14 @@ let trans_visitor
3863
3893
(ty_sz cx ty)));
3864
3894
mov dst (Il. Cell src)
3865
3895
3866
- | Ast. TY_param (i , _ ) ->
3867
- iflog
3868
- (fun _ -> annotate
3869
- (Printf. sprintf " copy_ty: parametric copy %#d" i));
3870
- let initflag = Il. Reg (force_to_reg one) in
3871
- aliasing false src
3872
- begin
3873
- fun src ->
3874
- let td = get_ty_param ty_params i in
3875
- let ty_params_ptr = get_tydesc_params ty_params td in
3876
- trans_call_dynamic_glue
3877
- td Abi. tydesc_field_copy_glue
3878
- (Some dst)
3879
- [| ty_params_ptr; src; initflag |]
3880
- None
3881
- end
3882
-
3883
- | Ast. TY_fn _
3884
- | Ast. TY_obj _ ->
3885
- begin
3886
- let src_item =
3887
- get_element_ptr src Abi. binding_field_dispatch
3888
- in
3889
- let dst_item =
3890
- get_element_ptr dst Abi. binding_field_dispatch
3891
- in
3892
- let src_binding =
3893
- get_element_ptr src Abi. binding_field_bound_data
3894
- in
3895
- let dst_binding =
3896
- get_element_ptr dst Abi. binding_field_bound_data
3897
- in
3898
- mov dst_item (Il. Cell src_item);
3899
- mov dst_binding zero;
3900
- let null_jmp = null_check src_binding in
3901
- (* Copy if we have a src binding. *)
3902
- (* FIXME (issue #58): this is completely wrong, call
3903
- * through to the binding's self-copy fptr. For now
3904
- * this only works by accident.
3905
- *)
3906
- trans_copy_ty ty_params true
3907
- dst_binding (Ast. TY_box Ast. TY_int )
3908
- src_binding (Ast. TY_box Ast. TY_int );
3909
- patch null_jmp
3910
- end
3911
-
3912
3896
| _ ->
3913
- if force_inline || should_inline_structure_helpers ty
3914
- then
3915
- iter_ty_parts_full ty_params dst src ty
3916
- (fun dst src ty ->
3917
- trans_copy_ty ty_params initializing
3918
- dst ty src ty)
3919
- else
3920
- let initflag = Il. Reg (force_to_reg one) in
3921
- trans_call_static_glue
3922
- (code_fixup_to_ptr_operand (get_copy_glue ty))
3923
- (Some dst)
3924
- [| alias ty_params;
3925
- alias src;
3926
- initflag |]
3927
- None
3897
+ trans_take_ty false ty_params src ty;
3898
+ if not initializing
3899
+ then drop_ty ty_params dst ty;
3900
+ let sz = ty_sz_with_ty_params ty_params ty in
3901
+ copy_loop dst src sz (imm 1L )
3902
+ (fun dptr sptr ->
3903
+ mov (deref dptr) (Il. Cell (deref sptr)))
3928
3904
3929
3905
3930
3906
and trans_copy
0 commit comments