Skip to content

Commit ef6d357

Browse files
committed
Remember the location of return statements
1 parent d39334e commit ef6d357

11 files changed

+38
-20
lines changed

Diff for: compiler/src/compile.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ let compile (type reg regx xreg rflag cond asm_op extra_op)
196196
let (_, va) = Hv.find harrs (L.unloc x) in
197197
List.init (Array.length va) (fun _ -> [])
198198
with Not_found -> [a] in
199-
let f_outannot = List.flatten (List.map2 do_outannot fd.f_ret fd.f_outannot) in
200-
let finfo = fd.f_loc, fd.f_annot, f_cc, f_outannot in
199+
let ret_annot = List.flatten (List.map2 do_outannot fd.f_ret fd.f_ret_info.ret_annot) in
200+
let finfo = fd.f_loc, fd.f_annot, f_cc, { fd.f_ret_info with ret_annot } in
201201
{ Array_expansion.vars; arrs = !arrs; finfo }
202202
in
203203

Diff for: compiler/src/conv.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ and stmt_of_cstmt c =
228228
(* ------------------------------------------------------------------------ *)
229229
let cufdef_of_fdef fd =
230230
let fn = fd.f_name in
231-
let f_info = fd.f_loc, fd.f_annot, fd.f_cc, fd.f_outannot in
231+
let f_info = fd.f_loc, fd.f_annot, fd.f_cc, fd.f_ret_info in
232232
let f_params =
233233
List.map (fun x -> cvari_of_vari (L.mk_loc L._dummy x)) fd.f_args in
234234
let f_body = cstmt_of_stmt fd.f_body in
@@ -244,7 +244,7 @@ let cufdef_of_fdef fd =
244244

245245

246246
let fdef_of_cufdef (fn, fd) =
247-
let f_loc, f_annot, f_cc, f_outannot = fd.C.f_info in
247+
let f_loc, f_annot, f_cc, f_ret_info = fd.C.f_info in
248248
{ f_loc;
249249
f_annot;
250250
f_cc;
@@ -254,7 +254,7 @@ let fdef_of_cufdef (fn, fd) =
254254
f_args = List.map (fun v -> L.unloc (vari_of_cvari v)) fd.C.f_params;
255255
f_body = stmt_of_cstmt fd.C.f_body;
256256
f_tyout = List.map ty_of_cty fd.C.f_tyout;
257-
f_outannot;
257+
f_ret_info;
258258
f_ret = List.map (vari_of_cvari) fd.C.f_res;
259259
}
260260

Diff for: compiler/src/ct_checker_forward.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ let get_annot ensure_annot f =
415415
in
416416
let ain = List.mapi process_argument f.f_args in
417417
let ainlevels = List.map (fun (_, x) -> x) ain in
418-
let aout = List.mapi process_result f.f_outannot in
418+
let aout = List.mapi process_result f.f_ret_info.ret_annot in
419419

420420
let check_defined msg l =
421421
if List.exists (fun a -> a = None) l then

Diff for: compiler/src/fInfo.ml

+12-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,16 @@ let is_export = function
4242
| Export _ -> true
4343
| _ -> false
4444

45+
(* ------------------------------------------------------------------------ *)
46+
type return_info = {
47+
ret_annot : Annotations.annotations list;
48+
(* annotation attached to return type *)
49+
ret_loc : Location.t; (* location of the return statement *)
50+
}
51+
52+
(* ------------------------------------------------------------------------ *)
4553
type t =
46-
Location.t * f_annot * call_conv * Annotations.annotations list
54+
Location.t * f_annot * call_conv * return_info
55+
56+
let ret_info (fi: t) : IInfo.t =
57+
let (_, _, _, ri) = fi in (Location.i_loc0 ri.ret_loc, [])

Diff for: compiler/src/latex_printer.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ let pp_funbody fmt { pdb_instr ; pdb_ret } =
387387
indent 1
388388
kw "return"
389389
(pp_list ", " pp_var) ret;
390-
) fmt pdb_ret
390+
) fmt (L.unloc pdb_ret)
391391

392392
let pp_fundef fmt { pdf_cc ; pdf_name ; pdf_args ; pdf_rty ; pdf_body ; pdf_annot } =
393393
F.fprintf

Diff for: compiler/src/parser.mly

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ annot_pparamdecl:
445445
pfunbody :
446446
| LBRACE
447447
is = pinstr*
448-
rt = option(RETURN vs=tuple(var) SEMICOLON { vs })
448+
rt = loc(option(RETURN vs=tuple(var) SEMICOLON { vs }))
449449
RBRACE
450450
{ { pdb_instr = is;
451451
pdb_ret = rt; } }

Diff for: compiler/src/pretyping.ml

+7-6
Original file line numberDiff line numberDiff line change
@@ -1983,10 +1983,11 @@ and tt_cmd arch_info env c =
19831983
(* -------------------------------------------------------------------- *)
19841984
let tt_funbody arch_info env (pb : S.pfunbody) =
19851985
let env, bdy = tt_cmd arch_info env pb.S.pdb_instr in
1986+
let ret_loc = L.loc pb.pdb_ret in
19861987
let ret =
19871988
let for1 x = L.mk_loc (L.loc x) (tt_var `AllVar env x) in
1988-
List.map for1 (Option.default [] pb.pdb_ret) in
1989-
(bdy, ret)
1989+
List.map for1 (Option.default [] (L.unloc pb.pdb_ret)) in
1990+
(bdy, ret_loc, ret)
19901991

19911992

19921993
(* -------------------------------------------------------------------- *)
@@ -2155,16 +2156,16 @@ let tt_fundef arch_info (env0 : 'asm Env.env) loc (pf : S.pfundef) : 'asm Env.en
21552156
let env = Env.Vars.clear_locals env0 in
21562157
if is_combine_flags pf.pdf_name then
21572158
rs_tyerror ~loc:(L.loc pf.pdf_name) (string_error "invalid function name");
2158-
let inret = Option.map_default (List.map L.unloc) [] pf.pdf_body.pdb_ret in
2159+
let inret = Option.map_default (List.map L.unloc) [] (L.unloc pf.pdf_body.pdb_ret) in
21592160
let dfl_mut x = List.mem x inret in
21602161

21612162
let envb, args =
21622163
let env, args = List.map_fold (tt_annot_paramdecls dfl_mut arch_info.pd) env pf.pdf_args in
21632164
let env = add_known_implicits arch_info env pf.pdf_body.pdb_instr in
21642165
env, List.flatten args in
21652166
let rty = Option.map_default (List.map (tt_type arch_info.pd env |- snd |- snd)) [] pf.pdf_rty in
2166-
let oannot = Option.map_default (List.map fst) [] pf.pdf_rty in
2167-
let body, xret = tt_funbody arch_info envb pf.pdf_body in
2167+
let ret_annot = Option.map_default (List.map fst) [] pf.pdf_rty in
2168+
let body, ret_loc, xret = tt_funbody arch_info envb pf.pdf_body in
21682169
let f_cc = tt_call_conv loc args xret pf.pdf_cc in
21692170
let args = List.map L.unloc args in
21702171
let name = L.unloc pf.pdf_name in
@@ -2178,7 +2179,7 @@ let tt_fundef arch_info (env0 : 'asm Env.env) loc (pf : S.pfundef) : 'asm Env.en
21782179
P.f_args = args;
21792180
P.f_body = body;
21802181
P.f_tyout = rty;
2181-
P.f_outannot = oannot;
2182+
P.f_ret_info = { ret_annot; ret_loc };
21822183
P.f_ret = xret; } in
21832184

21842185
check_return_statement ~loc fdef.P.f_name rty

Diff for: compiler/src/prog.ml

+7-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ and ('len,'info,'asm) ginstr = {
111111

112112
and ('len,'info,'asm) gstmt = ('len,'info,'asm) ginstr list
113113

114+
(* ------------------------------------------------------------------------ *)
115+
type return_info = {
116+
ret_annot : Annotations.annotations list; (* annotation attached to return type *)
117+
ret_loc : Location.t; (* location of the return statement *)
118+
}
119+
114120
(* ------------------------------------------------------------------------ *)
115121
type ('len,'info,'asm) gfunc = {
116122
f_loc : L.t;
@@ -122,7 +128,7 @@ type ('len,'info,'asm) gfunc = {
122128
f_args : 'len gvar list;
123129
f_body : ('len,'info,'asm) gstmt;
124130
f_tyout : 'len gty list;
125-
f_outannot : Annotations.annotations list; (* annotation attach to return type *)
131+
f_ret_info : FInfo.return_info;
126132
f_ret : 'len gvar_i list
127133
}
128134

Diff for: compiler/src/prog.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type ('len,'info,'asm) gfunc = {
8686
f_args : 'len gvar list;
8787
f_body : ('len,'info,'asm) gstmt;
8888
f_tyout : 'len gty list;
89-
f_outannot : Annotations.annotations list; (* annotation attach to return type *)
89+
f_ret_info : FInfo.return_info;
9090
f_ret : 'len gvar_i list
9191
}
9292

Diff for: compiler/src/sct_checker_forward.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ let init_constraint fenv f =
13091309
mk_vty ~is_local:false loc ~msf:(not export) x ls an in
13101310

13111311
(* process function outputs *)
1312-
let tyout = List.map2i process_return f.f_ret f.f_outannot in
1312+
let tyout = List.map2i process_return f.f_ret f.f_ret_info.ret_annot in
13131313

13141314
(* infer msf_oracle info *)
13151315
let msfs =
@@ -1511,7 +1511,7 @@ let compile_infer_msf (prog:('info, 'asm) prog) =
15111511
in
15121512

15131513
(* process function outputs *)
1514-
let tyout = List.mapi process_return f.f_outannot in
1514+
let tyout = List.mapi process_return f.f_ret_info.ret_annot in
15151515

15161516
(* infer the set of input variables that need to be msf *)
15171517
let msfin =

Diff for: compiler/src/syntax.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ type pparam = {
271271
(* -------------------------------------------------------------------- *)
272272
type pfunbody = {
273273
pdb_instr : pinstr list;
274-
pdb_ret : pident list option;
274+
pdb_ret : pident list option L.located;
275275
}
276276

277277
(* -------------------------------------------------------------------- *)

0 commit comments

Comments
 (0)