Skip to content

Commit 2986bea

Browse files
committed
Replace Location.t with Lambda.scoped_location in Lambda code
This commit threads scopes through translation from Typedtree to Lambda, extending the scopes when entering functions, modules, classes and methods.
1 parent a529280 commit 2986bea

34 files changed

+870
-666
lines changed

Diff for: .depend

+4-8
Original file line numberDiff line numberDiff line change
@@ -3218,14 +3218,17 @@ middle_end/variable.cmi : \
32183218
middle_end/compilation_unit.cmi
32193219
lambda/debuginfo.cmo : \
32203220
parsing/location.cmi \
3221+
lambda/lambda.cmi \
32213222
utils/int_replace_polymorphic_compare.cmi \
32223223
lambda/debuginfo.cmi
32233224
lambda/debuginfo.cmx : \
32243225
parsing/location.cmx \
3226+
lambda/lambda.cmx \
32253227
utils/int_replace_polymorphic_compare.cmx \
32263228
lambda/debuginfo.cmi
32273229
lambda/debuginfo.cmi : \
3228-
parsing/location.cmi
3230+
parsing/location.cmi \
3231+
lambda/lambda.cmi
32293232
lambda/lambda.cmo : \
32303233
typing/types.cmi \
32313234
typing/primitive.cmi \
@@ -3298,7 +3301,6 @@ lambda/matching.cmx : \
32983301
lambda/matching.cmi
32993302
lambda/matching.cmi : \
33003303
typing/typedtree.cmi \
3301-
parsing/location.cmi \
33023304
lambda/lambda.cmi \
33033305
typing/ident.cmi
33043306
lambda/printlambda.cmo : \
@@ -3348,7 +3350,6 @@ lambda/simplif.cmx : \
33483350
parsing/asttypes.cmi \
33493351
lambda/simplif.cmi
33503352
lambda/simplif.cmi : \
3351-
parsing/location.cmi \
33523353
lambda/lambda.cmi \
33533354
typing/ident.cmi
33543355
lambda/switch.cmo : \
@@ -3533,7 +3534,6 @@ lambda/translmod.cmi : \
35333534
lambda/translobj.cmo : \
35343535
typing/primitive.cmi \
35353536
utils/misc.cmi \
3536-
parsing/location.cmi \
35373537
lambda/lambda.cmi \
35383538
typing/ident.cmi \
35393539
typing/env.cmi \
@@ -3545,7 +3545,6 @@ lambda/translobj.cmo : \
35453545
lambda/translobj.cmx : \
35463546
typing/primitive.cmx \
35473547
utils/misc.cmx \
3548-
parsing/location.cmx \
35493548
lambda/lambda.cmx \
35503549
typing/ident.cmx \
35513550
typing/env.cmx \
@@ -3936,7 +3935,6 @@ middle_end/flambda/closure_conversion_aux.cmo : \
39363935
utils/numbers.cmi \
39373936
middle_end/flambda/base_types/mutable_variable.cmi \
39383937
utils/misc.cmi \
3939-
parsing/location.cmi \
39403938
lambda/lambda.cmi \
39413939
utils/int_replace_polymorphic_compare.cmi \
39423940
typing/ident.cmi \
@@ -3948,7 +3946,6 @@ middle_end/flambda/closure_conversion_aux.cmx : \
39483946
utils/numbers.cmx \
39493947
middle_end/flambda/base_types/mutable_variable.cmx \
39503948
utils/misc.cmx \
3951-
parsing/location.cmx \
39523949
lambda/lambda.cmx \
39533950
utils/int_replace_polymorphic_compare.cmx \
39543951
typing/ident.cmx \
@@ -3958,7 +3955,6 @@ middle_end/flambda/closure_conversion_aux.cmi : \
39583955
middle_end/symbol.cmi \
39593956
middle_end/flambda/base_types/static_exception.cmi \
39603957
middle_end/flambda/base_types/mutable_variable.cmi \
3961-
parsing/location.cmi \
39623958
lambda/lambda.cmi \
39633959
typing/ident.cmi
39643960
middle_end/flambda/closure_offsets.cmo : \

Diff for: asmcomp/cmm_helpers.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,7 @@ struct
14751475
let gtint = Ccmpi Cgt
14761476

14771477
type act = expression
1478+
type loc = Debuginfo.t
14781479

14791480
(* CR mshinwell: GPR#2294 will fix the Debuginfo here *)
14801481

@@ -1486,8 +1487,7 @@ struct
14861487
let make_if cond ifso ifnot =
14871488
Cifthenelse (cond, Debuginfo.none, ifso, Debuginfo.none, ifnot,
14881489
Debuginfo.none)
1489-
let make_switch loc arg cases actions =
1490-
let dbg = Debuginfo.from_location loc in
1490+
let make_switch dbg arg cases actions =
14911491
let actions = Array.map (fun expr -> expr, dbg) actions in
14921492
make_switch arg cases actions dbg
14931493
let bind arg body = bind "switcher" arg body
@@ -1555,7 +1555,7 @@ module SwitcherBlocks = Switch.Make(SArgBlocks)
15551555
(* Int switcher, arg in [low..high],
15561556
cases is list of individual cases, and is sorted by first component *)
15571557

1558-
let transl_int_switch loc arg low high cases default = match cases with
1558+
let transl_int_switch dbg arg low high cases default = match cases with
15591559
| [] -> assert false
15601560
| _::_ ->
15611561
let store = StoreExp.mk_store () in
@@ -1595,7 +1595,7 @@ let transl_int_switch loc arg low high cases default = match cases with
15951595
bind "switcher" arg
15961596
(fun a ->
15971597
SwitcherBlocks.zyva
1598-
loc
1598+
dbg
15991599
(low,high)
16001600
a
16011601
(Array.of_list inters) store)

Diff for: asmcomp/cmm_helpers.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,12 @@ val make_switch :
529529

530530
(** [transl_int_switch loc arg low high cases default] *)
531531
val transl_int_switch :
532-
Location.t -> expression -> int -> int ->
532+
Debuginfo.t -> expression -> int -> int ->
533533
(int * expression) list -> expression -> expression
534534

535535
(** [transl_switch_clambda loc arg index cases] *)
536536
val transl_switch_clambda :
537-
Location.t -> expression -> int array -> expression array -> expression
537+
Debuginfo.t -> expression -> int array -> expression array -> expression
538538

539539
(** [strmatch_compile dbg arg default cases] *)
540540
val strmatch_compile :

Diff for: asmcomp/cmmgen.ml

+5-6
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ let rec transl env e =
562562

563563
(* Control structures *)
564564
| Uswitch(arg, s, dbg) ->
565-
let loc = Debuginfo.to_location dbg in
566565
(* As in the bytecode interpreter, only matching against constants
567566
can be checked *)
568567
if Array.length s.us_index_blocks = 0 then
@@ -573,17 +572,17 @@ let rec transl env e =
573572
dbg
574573
else if Array.length s.us_index_consts = 0 then
575574
bind "switch" (transl env arg) (fun arg ->
576-
transl_switch loc env (get_tag arg dbg)
575+
transl_switch dbg env (get_tag arg dbg)
577576
s.us_index_blocks s.us_actions_blocks)
578577
else
579578
bind "switch" (transl env arg) (fun arg ->
580579
Cifthenelse(
581580
Cop(Cand, [arg; Cconst_int (1, dbg)], dbg),
582581
dbg,
583-
transl_switch loc env
582+
transl_switch dbg env
584583
(untag_int arg dbg) s.us_index_consts s.us_actions_consts,
585584
dbg,
586-
transl_switch loc env
585+
transl_switch dbg env
587586
(get_tag arg dbg) s.us_index_blocks s.us_actions_blocks,
588587
dbg))
589588
| Ustringswitch(arg,sw,d) ->
@@ -1307,12 +1306,12 @@ and transl_sequor env (approx : then_else)
13071306
then_
13081307

13091308
(* This assumes that [arg] can be safely discarded if it is not used. *)
1310-
and transl_switch loc env arg index cases = match Array.length cases with
1309+
and transl_switch dbg env arg index cases = match Array.length cases with
13111310
| 0 -> fatal_error "Cmmgen.transl_switch"
13121311
| 1 -> transl env cases.(0)
13131312
| _ ->
13141313
let cases = Array.map (transl env) cases in
1315-
transl_switch_clambda loc arg index cases
1314+
transl_switch_clambda dbg arg index cases
13161315

13171316
and transl_letrec env bindings cont =
13181317
let dbg = Debuginfo.none in

Diff for: asmcomp/strmatch.ml

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module VP = Backend_var.With_provenance
2424
module type I = sig
2525
val string_block_length : Cmm.expression -> Cmm.expression
2626
val transl_switch :
27-
Location.t -> Cmm.expression -> int -> int ->
27+
Debuginfo.t -> Cmm.expression -> int -> int ->
2828
(int * Cmm.expression) list -> Cmm.expression ->
2929
Cmm.expression
3030
end
@@ -353,8 +353,7 @@ module Make(I:I) = struct
353353
(len,act))
354354
(by_size cases) in
355355
let id = gen_size_id () in
356-
let loc = Debuginfo.to_location dbg in
357-
let switch = I.transl_switch loc (Cvar id) 1 max_int size_cases default in
356+
let switch = I.transl_switch dbg (Cvar id) 1 max_int size_cases default in
358357
mk_let_size (VP.create id) str switch
359358

360359
(*

Diff for: asmcomp/strmatch.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
module type I = sig
1919
val string_block_length : Cmm.expression -> Cmm.expression
2020
val transl_switch :
21-
Location.t -> Cmm.expression -> int -> int ->
21+
Debuginfo.t -> Cmm.expression -> int -> int ->
2222
(int * Cmm.expression) list -> Cmm.expression ->
2323
Cmm.expression
2424
end

Diff for: bytecomp/bytegen.ml

+5-5
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ let rec comp_expr env exp sz cont =
584584
(getmethod :: Kapply nargs :: cont1)
585585
end
586586
| Lfunction{params; body; loc} -> (* assume kind = Curried *)
587-
let cont = add_pseudo_event loc !compunit_name cont in
587+
let cont = add_pseudo_event (raw_location loc) !compunit_name cont in
588588
let lbl = new_label() in
589589
let fv = Ident.Set.elements(free_variables exp) in
590590
let to_compile =
@@ -735,7 +735,7 @@ let rec comp_expr env exp sz cont =
735735
Kconst (Const_base (Const_int n))::
736736
Kaddint::cont)
737737
| Lprim(Pmakearray (kind, _), args, loc) ->
738-
let cont = add_pseudo_event loc !compunit_name cont in
738+
let cont = add_pseudo_event (raw_location loc) !compunit_name cont in
739739
begin match kind with
740740
Pintarray | Paddrarray ->
741741
comp_args env args sz (Kmakeblock(List.length args, 0) :: cont)
@@ -780,10 +780,10 @@ let rec comp_expr env exp sz cont =
780780
in
781781
comp_args env args sz cont
782782
| Lprim(Pmakeblock(tag, _mut, _), args, loc) ->
783-
let cont = add_pseudo_event loc !compunit_name cont in
783+
let cont = add_pseudo_event (raw_location loc) !compunit_name cont in
784784
comp_args env args sz (Kmakeblock(List.length args, tag) :: cont)
785785
| Lprim(Pfloatfield n, args, loc) ->
786-
let cont = add_pseudo_event loc !compunit_name cont in
786+
let cont = add_pseudo_event (raw_location loc) !compunit_name cont in
787787
comp_args env args sz (Kgetfloatfield n :: cont)
788788
| Lprim(p, args, _) ->
789789
comp_args env args sz (comp_primitive p args :: cont)
@@ -925,7 +925,7 @@ let rec comp_expr env exp sz cont =
925925
let event kind info =
926926
{ ev_pos = 0; (* patched in emitcode *)
927927
ev_module = !compunit_name;
928-
ev_loc = lev.lev_loc;
928+
ev_loc = raw_location lev.lev_loc;
929929
ev_kind = kind;
930930
ev_info = info;
931931
ev_typenv = Env.summary lev.lev_env;

Diff for: lambda/debuginfo.ml

+9-8
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ type item = {
104104
dinfo_start_bol: int;
105105
dinfo_end_bol: int;
106106
dinfo_end_line: int;
107+
dinfo_scopes: Scoped_location.scopes;
107108
}
108109

109110
type t = item list
@@ -132,7 +133,7 @@ let to_string dbg =
132133
in
133134
"{" ^ String.concat ";" items ^ "}"
134135

135-
let item_from_location loc =
136+
let item_from_location ~scopes loc =
136137
let valid_endpos =
137138
String.equal loc.loc_end.pos_fname loc.loc_start.pos_fname in
138139
{ dinfo_file = loc.loc_start.pos_fname;
@@ -149,10 +150,14 @@ let item_from_location loc =
149150
dinfo_end_line =
150151
if valid_endpos then loc.loc_end.pos_lnum
151152
else loc.loc_start.pos_lnum;
153+
dinfo_scopes = scopes
152154
}
153155

154-
let from_location loc =
155-
if loc == Location.none then [] else [item_from_location loc]
156+
let from_location = function
157+
| Scoped_location.Loc_unknown -> []
158+
| Scoped_location.Loc_known {scopes; loc} ->
159+
assert (not (Location.is_none loc));
160+
[item_from_location ~scopes loc]
156161

157162
let to_location = function
158163
| [] -> Location.none
@@ -171,11 +176,7 @@ let to_location = function
171176
} in
172177
{ loc_ghost = false; loc_start; loc_end; }
173178

174-
let inline loc t =
175-
if loc == Location.none then t
176-
else (item_from_location loc) :: t
177-
178-
let concat dbg1 dbg2 =
179+
let inline dbg1 dbg2 =
179180
dbg1 @ dbg2
180181

181182
(* CR-someday afrisch: FWIW, the current compare function does not seem very

Diff for: lambda/debuginfo.mli

+3-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type item = private {
5050
dinfo_start_bol: int;
5151
dinfo_end_bol: int;
5252
dinfo_end_line: int;
53+
dinfo_scopes: Scoped_location.scopes;
5354
}
5455

5556
type t = item list
@@ -71,13 +72,11 @@ val is_none : t -> bool
7172

7273
val to_string : t -> string
7374

74-
val from_location : Location.t -> t
75+
val from_location : Scoped_location.t -> t
7576

7677
val to_location : t -> Location.t
7778

78-
val concat: t -> t -> t
79-
80-
val inline: Location.t -> t -> t
79+
val inline : t -> t -> t
8180

8281
val compare : t -> t -> int
8382

0 commit comments

Comments
 (0)