@@ -654,10 +654,12 @@ let rec substitute loc fpc sb rn ulam =
654654 let new_nfail = next_raise_count () in
655655 new_nfail, Some (Int.Map. add nfail new_nfail rn)
656656 | None -> nfail, rn in
657- let ids' = List. map VP. rename ids in
657+ let ids' = List. map ( fun ( id , k ) -> VP. rename id, k) ids in
658658 let sb' =
659659 List. fold_right2
660- (fun id id' s -> V.Map. add (VP. var id) (Uvar (VP. var id')) s)
660+ (fun (id , _ ) (id' , _ ) s ->
661+ V.Map. add (VP. var id) (Uvar (VP. var id')) s
662+ )
661663 ids ids' sb
662664 in
663665 Ucatch (nfail, ids', substitute loc fpc sb rn u1,
@@ -923,7 +925,8 @@ let rec close fenv cenv = function
923925 let (new_fun, approx) = close fenv cenv
924926 (Lfunction {
925927 kind = Curried ;
926- params = final_args;
928+ return = Pgenval ;
929+ params = List. map (fun v -> v, Pgenval ) final_args;
927930 body = Lapply {ap_should_be_tailcall= false ;
928931 ap_loc= loc;
929932 ap_func= (Lvar funct_var);
@@ -1102,7 +1105,7 @@ let rec close fenv cenv = function
11021105 | Lstaticcatch (body , (i , vars ), handler ) ->
11031106 let (ubody, _) = close fenv cenv body in
11041107 let (uhandler, _) = close fenv cenv handler in
1105- let vars = List. map (fun var -> VP. create var) vars in
1108+ let vars = List. map (fun ( var , k ) -> VP. create var, k ) vars in
11061109 (Ucatch (i, vars, ubody, uhandler), Value_unknown )
11071110 | Ltrywith (body , id , handler ) ->
11081111 let (ubody, _) = close fenv cenv body in
@@ -1165,9 +1168,9 @@ and close_functions fenv cenv fun_defs =
11651168 List. flatten
11661169 (List. map
11671170 (function
1168- | (id , Lfunction{kind; params; body; attr; loc} ) ->
1171+ | (id , Lfunction{kind; params; return; body; attr; loc} ) ->
11691172 Simplif. split_default_wrapper ~id ~kind ~params
1170- ~body ~attr ~loc
1173+ ~body ~attr ~loc ~return
11711174 | _ -> assert false
11721175 )
11731176 fun_defs)
@@ -1189,7 +1192,7 @@ and close_functions fenv cenv fun_defs =
11891192 let uncurried_defs =
11901193 List. map
11911194 (function
1192- (id , Lfunction{kind; params; body; loc} ) ->
1195+ (id , Lfunction{kind; params; return; body; loc} ) ->
11931196 let label = Compilenv. make_symbol (Some (V. unique_name id)) in
11941197 let arity = List. length params in
11951198 let fundesc =
@@ -1199,20 +1202,20 @@ and close_functions fenv cenv fun_defs =
11991202 fun_inline = None ;
12001203 fun_float_const_prop = ! Clflags. float_const_prop } in
12011204 let dbg = Debuginfo. from_location loc in
1202- (id, params, body, fundesc, dbg)
1205+ (id, params, return, body, fundesc, dbg)
12031206 | (_ , _ ) -> fatal_error " Closure.close_functions" )
12041207 fun_defs in
12051208 (* Build an approximate fenv for compiling the functions *)
12061209 let fenv_rec =
12071210 List. fold_right
1208- (fun (id , _params , _body , fundesc , _dbg ) fenv ->
1211+ (fun (id , _params , _return , _body , fundesc , _dbg ) fenv ->
12091212 V.Map. add id (Value_closure (fundesc, Value_unknown )) fenv)
12101213 uncurried_defs fenv in
12111214 (* Determine the offsets of each function's closure in the shared block *)
12121215 let env_pos = ref (- 1 ) in
12131216 let clos_offsets =
12141217 List. map
1215- (fun (_id , _params , _body , fundesc , _dbg ) ->
1218+ (fun (_id , _params , _return , _body , fundesc , _dbg ) ->
12161219 let pos = ! env_pos + 1 in
12171220 env_pos := ! env_pos + 1 + (if fundesc.fun_arity <> 1 then 3 else 2 );
12181221 pos)
@@ -1222,23 +1225,28 @@ and close_functions fenv cenv fun_defs =
12221225 does not use its environment parameter is invalidated. *)
12231226 let useless_env = ref initially_closed in
12241227 (* Translate each function definition *)
1225- let clos_fundef (id , params , body , fundesc , dbg ) env_pos =
1228+ let clos_fundef (id , params , return , body , fundesc , dbg ) env_pos =
12261229 let env_param = V. create_local " env" in
12271230 let cenv_fv =
12281231 build_closure_env env_param (fv_pos - env_pos) fv in
12291232 let cenv_body =
12301233 List. fold_right2
1231- (fun (id , _params , _body , _fundesc , _dbg ) pos env ->
1234+ (fun (id , _params , _return , _body , _fundesc , _dbg ) pos env ->
12321235 V.Map. add id (Uoffset (Uvar env_param, pos - env_pos)) env)
12331236 uncurried_defs clos_offsets cenv_fv in
12341237 let (ubody, approx) = close fenv_rec cenv_body body in
12351238 if ! useless_env && occurs_var env_param ubody then raise NotClosed ;
1236- let fun_params = if ! useless_env then params else params @ [env_param] in
1239+ let fun_params =
1240+ if ! useless_env
1241+ then params
1242+ else params @ [env_param, Pgenval ]
1243+ in
12371244 let f =
12381245 {
12391246 label = fundesc.fun_label;
12401247 arity = fundesc.fun_arity;
1241- params = List. map (fun var -> VP. create var) fun_params;
1248+ params = List. map (fun (var , kind ) -> VP. create var, kind) fun_params;
1249+ return;
12421250 body = ubody;
12431251 dbg;
12441252 env = Some env_param;
@@ -1248,7 +1256,7 @@ and close_functions fenv cenv fun_defs =
12481256 their wrapper functions) to be inlined *)
12491257 let n =
12501258 List. fold_left
1251- (fun n id -> n + if V. name id = " *opt*" then 8 else 1 )
1259+ (fun n ( id , _ ) -> n + if V. name id = " *opt*" then 8 else 1 )
12521260 0
12531261 fun_params
12541262 in
@@ -1264,7 +1272,7 @@ and close_functions fenv cenv fun_defs =
12641272 | Never_inline -> min_int
12651273 | Unroll _ -> assert false
12661274 in
1267- let fun_params = List. map (fun var -> VP. create var) fun_params in
1275+ let fun_params = List. map (fun ( var , _ ) -> VP. create var) fun_params in
12681276 if lambda_smaller ubody threshold
12691277 then fundesc.fun_inline < - Some (fun_params, ubody);
12701278
@@ -1280,7 +1288,7 @@ and close_functions fenv cenv fun_defs =
12801288 recompile *)
12811289 Compilenv. backtrack snap; (* PR#6337 *)
12821290 List. iter
1283- (fun (_id , _params , _body , fundesc , _dbg ) ->
1291+ (fun (_id , _params , _return , _body , fundesc , _dbg ) ->
12841292 fundesc.fun_closed < - false ;
12851293 fundesc.fun_inline < - None ;
12861294 )
0 commit comments