@@ -99,13 +99,10 @@ let transl_alloc_mode alloc_mode =
99
99
| Global -> alloc_heap
100
100
| Local -> alloc_local
101
101
102
- let transl_value_mode mode =
103
- let alloc_mode= Btype.Value_mode. regional_to_global_allocmode in
102
+ let transl_exp_mode e =
103
+ let alloc_mode= Btype.Value_mode. regional_to_global_alloce.exp_mode in
104
104
transl_alloc_mode alloc_mode
105
105
106
- let transl_exp_mode e = transl_value_mode e.exp_mode
107
- let transl_pat_mode p = transl_value_mode p.pat_mode
108
-
109
106
let transl_apply_position position =
110
107
match positionwith
111
108
| Default ->Rc_normal
@@ -176,12 +173,13 @@ let rec push_defaults loc bindings cases partial warnings =
176
173
match caseswith
177
174
[{c_lhs= pat; c_guard= None ;
178
175
c_rhs= {exp_desc=
179
- Texp_function { arg_label; param; cases; partial; region; warnings }}
176
+ Texp_function { arg_label; param; cases; partial;
177
+ region; curry; warnings }}
180
178
as exp}] ->
181
179
let cases= push_defaults exp.exp_loc bindings cases partial warningsin
182
180
[{c_lhs= pat; c_guard= None ;
183
181
c_rhs= {expwith exp_desc= Texp_function { arg_label; param; cases;
184
- partial; region; warnings }}}]
182
+ partial; region;curry; warnings }}}]
185
183
| [{c_lhs= pat; c_guard= None ;
186
184
c_rhs= {exp_attributes= [{Parsetree. attr_name= {txt= " #default" };_}];
187
185
exp_desc= Texp_let
@@ -352,12 +350,13 @@ and transl_exp0 ~in_new_scope ~scopes e =
352
350
let body_kind= Typeopt. value_kind body.exp_env body.exp_typein
353
351
transl_let~scopes rec_flag pat_expr_list
354
352
body_kind (event_before~scopes body (transl_exp~scopes body))
355
- | Texp_function {arg_label =_ ; param; cases; partial; region; warnings } ->
353
+ | Texp_function { arg_label= _; param; cases; partial;
354
+ region; curry; warnings } ->
356
355
let scopes=
357
356
if in_new_scopethen scopes
358
357
else enter_anonymous_function~scopes
359
358
in
360
- transl_function~scopes e param cases partial warnings region
359
+ transl_function~scopes e param cases partial warnings region curry
361
360
| Texp_apply ({ exp_desc= Texp_ident (path, _, {val_kind= Val_prim p},
362
361
Id_prim pmode);
363
362
exp_type= prim_type }as funct, oargs, pos)
@@ -1027,37 +1026,34 @@ and transl_apply ~scopes
1027
1026
1028
1027
and transl_curried_function
1029
1028
~scopes loc return
1030
- repr ~mode ~ region partial warnings (param :Ident.t )cases =
1029
+ repr ~region ~ curry partial warnings (param :Ident.t )cases =
1031
1030
let max_arity= Lambda. max_arity() in
1032
- let rec loop ~scopes loc return ~arity ~mode ~region partial warnings
1033
- (param :Ident.t )cases =
1034
- match caseswith
1031
+ let rec loop ~scopes loc return ~arity ~region ~curry
1032
+ partial warnings (param :Ident.t )cases =
1033
+ match curry, caseswith
1034
+ More_args {partial_mode} ,
1035
1035
[{c_lhs= pat; c_guard= None ;
1036
1036
c_rhs= {exp_desc=
1037
1037
Texp_function
1038
1038
{ arg_label= _; param= param'; cases= cases';
1039
1039
partial= partial'; region= region';
1040
+ curry= curry';
1040
1041
warnings= warnings' };
1041
- exp_env; exp_type; exp_loc; exp_mode }}]
1042
+ exp_env; exp_type; exp_loc }}]
1042
1043
when arity< max_arity ->
1043
- let arg_mode= transl_pat_mode patin
1044
- let curry_mode= transl_value_mode exp_modein
1045
1044
(* Lfunctions must have local returns after the first local arg/ret*)
1046
- if not (sub_mode mode curry_mode&& sub_mode arg_mode curry_mode)then
1047
- (* Cannot curry here*)
1048
- transl_tupled_function~scopes ~arity ~mode ~region
1049
- loc return repr partial param cases
1050
- else if Parmatch. inactive~partial pat
1045
+ if Parmatch. inactive~partial pat
1051
1046
then
1047
+ let partial_mode= transl_alloc_mode partial_modein
1052
1048
let kind= value_kind pat.pat_env pat.pat_typein
1053
1049
let return_kind= function_return_value_kind exp_env exp_typein
1054
1050
let ((fnkind, params, return, region), body)=
1055
1051
loop~scopes exp_loc return_kind
1056
- ~arity: (arity+ 1 )~mode: curry_mode ~region: region '
1052
+ ~arity: (arity+ 1 )~region: region' ~curry: curry '
1057
1053
partial' warnings' param' cases'
1058
1054
in
1059
1055
let fnkind=
1060
- match curry_mode , fnkindwith
1056
+ match partial_mode , fnkindwith
1061
1057
| _ ,Tupled ->
1062
1058
(* arity > 1 prevents this*)
1063
1059
assert false
@@ -1080,24 +1076,28 @@ and transl_curried_function
1080
1076
Warnings. restore prev
1081
1077
| Partial ->()
1082
1078
end ;
1083
- transl_tupled_function~scopes ~arity ~mode ~region
1079
+ transl_tupled_function~scopes ~arity ~region ~curry
1084
1080
loc return repr partial param cases
1085
1081
end
1086
- | cases ->
1087
- transl_tupled_function~scopes ~arity ~mode ~region
1082
+ | curry , cases ->
1083
+ transl_tupled_function~scopes ~arity ~region ~curry
1088
1084
loc return repr partial param cases
1089
1085
in
1090
- loop~scopes loc return~arity: 1 ~mode ~region partial warnings param cases
1086
+ loop~scopes loc return~arity: 1 ~region ~curry
1087
+ partial warnings param cases
1091
1088
1092
1089
and transl_tupled_function
1093
- ~scopes ~arity ~mode ~ region loc return
1090
+ ~scopes ~arity ~region ~ curry loc return
1094
1091
repr partial (param :Ident.t )cases =
1095
- match caseswith
1096
- | {c_lhs= {pat_desc= Tpat_tuple pl; pat_mode }} :: _
1092
+ let partial_mode=
1093
+ match currywith
1094
+ | More_args {partial_mode} | Final_arg {partial_mode} ->
1095
+ transl_alloc_mode partial_mode
1096
+ in
1097
+ match partial_mode, caseswith
1098
+ | Alloc_heap , {c_lhs= {pat_desc= Tpat_tuple pl }} :: _
1097
1099
when ! Clflags. native_code
1098
1100
&& arity= 1
1099
- && is_heap_mode mode
1100
- && is_heap_mode (transl_value_mode pat_mode)
1101
1101
&& List. length pl< = (Lambda. max_arity() ) ->
1102
1102
begin try
1103
1103
let size= List. length plin
@@ -1134,27 +1134,24 @@ and transl_tupled_function
1134
1134
let region= region|| not (may_allocate_in_region body)in
1135
1135
((Tupled , tparams, return, region), body)
1136
1136
with Matching. Cannot_flatten ->
1137
- transl_function0~scopes loc~mode ~region
1137
+ transl_function0~scopes loc~region ~partial_mode
1138
1138
return repr partial param cases
1139
1139
end
1140
- | _ -> transl_function0~scopes loc~mode ~region
1140
+ | _ -> transl_function0~scopes loc~region ~partial_mode
1141
1141
return repr partial param cases
1142
1142
1143
1143
and transl_function0
1144
- ~scopes loc ~mode ~ region return
1144
+ ~scopes loc ~region ~ partial_mode return
1145
1145
repr partial (param :Ident.t )cases =
1146
- let arg_mode, kind=
1146
+ let kind=
1147
1147
match caseswith
1148
1148
| [] ->
1149
1149
(* With Camlp4, a pattern matching might be empty*)
1150
- alloc_heap, Pgenval
1150
+ Pgenval
1151
1151
| {c_lhs =pat } ::other_cases ->
1152
1152
(* All the patterns might not share the same types. We must take the
1153
1153
union of the patterns types*)
1154
- let arg_mode= transl_pat_mode patin
1155
- arg_mode,
1156
1154
List. fold_left (fun k {c_lhs =pat } ->
1157
- assert (transl_pat_mode pat= arg_mode);
1158
1155
Typeopt. value_kind_union k
1159
1156
(value_kind pat.pat_env pat.pat_type))
1160
1157
(value_kind pat.pat_env pat.pat_type) other_cases
@@ -1166,21 +1163,21 @@ and transl_function0
1166
1163
let region= region|| not (may_allocate_in_region body)in
1167
1164
let nlocal=
1168
1165
if not regionthen 1
1169
- else match join_mode mode arg_mode with
1166
+ else match partial_mode with
1170
1167
| Alloc_local ->1
1171
1168
| Alloc_heap ->0
1172
1169
in
1173
1170
((Curried {nlocal}, [param, kind], return, region), body)
1174
1171
1175
- and transl_function ~scopes e param cases partial warnings region =
1172
+ and transl_function ~scopes e param cases partial warnings region curry =
1176
1173
let mode= transl_exp_mode ein
1177
1174
let ((kind, params, return, region), body)=
1178
1175
event_function~scopes e
1179
1176
(function repr ->
1180
1177
let pl= push_defaults e.exp_loc[] cases partial warningsin
1181
1178
let return_kind= function_return_value_kind e.exp_env e.exp_typein
1182
1179
transl_curried_function~scopes e.exp_loc return_kind
1183
- repr~mode ~region partial warnings param pl)
1180
+ repr~region ~curry partial warnings param pl)
1184
1181
in
1185
1182
let attr= default_function_attributein
1186
1183
let loc= of_location~scopes e.exp_locin
@@ -1497,11 +1494,12 @@ and transl_letop ~scopes loc env let_ ands param case partial warnings =
1497
1494
let exp= loop (transl_exp~scopes let_.bop_exp) andsin
1498
1495
let func=
1499
1496
let return_kind= value_kind case.c_rhs.exp_env case.c_rhs.exp_typein
1497
+ let curry= More_args { partial_mode= Btype.Alloc_mode. global }in
1500
1498
let (kind, params, return, _region), body=
1501
1499
event_function~scopes case.c_rhs
1502
1500
(function repr ->
1503
1501
transl_curried_function~scopes case.c_rhs.exp_loc return_kind
1504
- repr~mode: alloc_heap ~ region:true partial warnings param [case])
1502
+ repr~region: true ~curry partial warnings param [case])
1505
1503
in
1506
1504
let attr= default_function_attributein
1507
1505
let loc= of_location~scopes case.c_rhs.exp_locin