Skip to content

Commit 8057833

Browse files
vouillonhhugo
authored andcommitted
No longer keep track of the location of identifiers
1 parent d09ce4d commit 8057833

File tree

8 files changed

+8
-87
lines changed

8 files changed

+8
-87
lines changed

compiler/lib/code.ml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ module Var : sig
7575

7676
val compare : t -> t -> int
7777

78-
val get_loc : t -> Parse_info.t option
79-
80-
val loc : t -> Parse_info.t -> unit
81-
8278
val name : t -> string -> unit
8379

8480
val get_name : t -> string option
@@ -157,13 +153,10 @@ end = struct
157153

158154
let printer = Var_printer.create Var_printer.Alphabet.javascript
159155

160-
let locations = Hashtbl.create 17
161-
162156
let last_var = ref 0
163157

164158
let reset () =
165159
last_var := 0;
166-
Hashtbl.clear locations;
167160
Var_printer.reset printer
168161

169162
let to_string ?origin i = Var_printer.to_string printer ?origin i
@@ -174,14 +167,6 @@ end = struct
174167

175168
let name i nm = Var_printer.name printer i nm
176169

177-
let loc i pi = Hashtbl.add locations i pi
178-
179-
(*;
180-
Format.eprintf "loc for %d : %d-%d\n%!"
181-
i pi.Parse_info.line pi.Parse_info.col
182-
*)
183-
let get_loc i = try Some (Hashtbl.find locations i) with Not_found -> None
184-
185170
let fresh () =
186171
incr last_var;
187172
!last_var
@@ -199,11 +184,7 @@ end = struct
199184

200185
let get_name i = Var_printer.get_name printer i
201186

202-
let propagate_name i j =
203-
Var_printer.propagate_name printer i j;
204-
match get_loc i with
205-
| None -> ()
206-
| Some l -> loc j l
187+
let propagate_name i j = Var_printer.propagate_name printer i j
207188

208189
let set_pretty b = Var_printer.set_pretty printer b
209190

compiler/lib/code.mli

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ module Var : sig
6868

6969
val compare : t -> t -> int
7070

71-
val loc : t -> Parse_info.t -> unit
72-
73-
val get_loc : t -> Parse_info.t option
74-
7571
val get_name : t -> string option
7672

7773
val name : t -> string -> unit

compiler/lib/js_output.ml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,14 @@ struct
194194
current_loc := loc;
195195
on_ident := false
196196

197-
let output_debug_info_ident f nm loc =
197+
let output_debug_info_ident f nm =
198198
if source_map_enabled
199199
then (
200-
let loc =
201-
(* Keep the current location if possible, since we don't care
202-
about the actual identifier's location *)
203-
match !current_loc, loc with
204-
| (N | U | Pi { Parse_info.src = Some "" | None; _ }), Some _ -> loc
205-
| Pi ({ Parse_info.src = Some _; _ } as loc), _ -> Some loc
206-
| _, None -> None
207-
in
208200
on_ident := true;
209201
push_mapping
210202
(PP.pos f)
211-
(match loc with
212-
| None | Some { Parse_info.src = Some "" | None; _ } ->
203+
(match !current_loc with
204+
| N | U | Pi { Parse_info.src = Some "" | None; _ } ->
213205
(* Use a dummy location. It is going to be ignored anyway *)
214206
let ori_source =
215207
match hidden_location with
@@ -224,7 +216,7 @@ struct
224216
; ori_col = 0
225217
; ori_name = get_name_index nm
226218
}
227-
| Some { Parse_info.src = Some file; line; col; _ } ->
219+
| Pi { Parse_info.src = Some file; line; col; _ } ->
228220
Source_map.Gen_Ori_Name
229221
{ gen_line = -1
230222
; gen_col = -1
@@ -237,7 +229,7 @@ struct
237229
let ident f ~kind = function
238230
| S { name = Utf8 name; var = Some v; _ } ->
239231
(match kind, Code.Var.get_name v with
240-
| `Binding, Some nm -> output_debug_info_ident f nm (Code.Var.get_loc v)
232+
| `Binding, Some nm -> output_debug_info_ident f nm
241233
| `Reference, _ | `Binding, None -> ());
242234
if false then PP.string f (Printf.sprintf "/* %d */" (Code.Var.idx v));
243235
PP.string f name

compiler/lib/ocaml_compiler.ml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,6 @@ let rec constant_of_const c : Code.constant =
4646
let l = Array.of_list (List.map l ~f:constant_of_const) in
4747
Tuple (tag, l, Unknown)
4848

49-
let rec find_loc_in_summary ident' = function
50-
| Env.Env_empty -> None
51-
| Env.Env_value (_summary, ident, description) when Poly.(ident = ident') ->
52-
Some description.Types.val_loc
53-
| Env.Env_module (_summary, ident, _, description) when Ident.same ident ident' ->
54-
Some description.Types.md_loc
55-
| Env.Env_extension (_summary, ident, description) when Ident.same ident ident' ->
56-
Some description.Types.ext_loc
57-
| Env.Env_value (summary, _, _)
58-
| Env.Env_type (summary, _, _)
59-
| Env.Env_extension (summary, _, _)
60-
| Env.Env_module (summary, _, _, _)
61-
| Env.Env_modtype (summary, _, _)
62-
| Env.Env_class (summary, _, _)
63-
| Env.Env_cltype (summary, _, _)
64-
| Env.Env_open (summary, _)
65-
| Env.Env_functor_arg (summary, _)
66-
| Env.Env_constraints (summary, _)
67-
| ((Env.Env_copy_types (summary, _)) [@if ocaml_version < (4, 10, 0)])
68-
| ((Env.Env_copy_types summary) [@if ocaml_version >= (4, 10, 0)])
69-
| Env.Env_persistent (summary, _)
70-
| ((Env.Env_value_unbound (summary, _, _)) [@if ocaml_version >= (4, 10, 0)])
71-
| ((Env.Env_module_unbound (summary, _, _)) [@if ocaml_version >= (4, 10, 0)]) ->
72-
find_loc_in_summary ident' summary
73-
7449
module Symtable = struct
7550
(* Copied from ocaml/bytecomp/symtable.ml *)
7651
module Num_tbl (M : Map.S) = struct

compiler/lib/ocaml_compiler.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
val constant_of_const : Lambda.structured_constant -> Code.constant
2020

21-
val find_loc_in_summary : Ident.t -> Env.summary -> Location.t option
22-
2321
module Symtable : sig
2422
module Global : sig
2523
type t =

compiler/lib/parse_bytecode.ml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ module Debug : sig
6767
-> event:Instruct.debug_event
6868
-> Parse_info.t
6969

70-
val find_source : t -> string -> string option
71-
7270
val read_event :
7371
paths:string list
7472
-> crcs:(string, string option) Hashtbl.t
@@ -234,15 +232,6 @@ end = struct
234232
let paths = read_paths ic @ includes in
235233
List.iter evl ~f:(read_event ~paths ~crcs ~orig debug)
236234

237-
let find_source { pos_fname_to_source; _ } pos_fname =
238-
match pos_fname with
239-
| "_none_" -> None
240-
| _ -> (
241-
match String_table.find_all pos_fname_to_source pos_fname with
242-
| [ x ] -> Some x
243-
| _ :: _ :: _ -> None
244-
| [] -> None)
245-
246235
let read t ~crcs ~includes ic =
247236
let len = input_binary_int ic in
248237
for _i = 0 to len - 1 do
@@ -696,18 +685,10 @@ module State = struct
696685
print_env
697686
st.env
698687

699-
let pi_of_loc debug location =
700-
let pos = location.Location.loc_start in
701-
let src = Debug.find_source debug pos.Lexing.pos_fname in
702-
Parse_info.t_of_position ~src pos
703-
704688
let rec name_rec debug i l s summary =
705689
match l, s with
706690
| [], _ -> ()
707691
| (j, ident) :: lrem, Var v :: srem when i = j ->
708-
(match Ocaml_compiler.find_loc_in_summary ident summary with
709-
| None -> ()
710-
| Some loc -> Var.loc v (pi_of_loc debug loc));
711692
Var.name v (Ident.name ident);
712693
name_rec debug (i + 1) lrem srem summary
713694
| (j, _) :: _, _ :: srem when i < j -> name_rec debug (i + 1) l srem summary

compiler/tests-compiler/sourcemap.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ let%expect_test _ =
8686
/builtin/blackbox.ml:1:0 -> 5:7
8787
/builtin/blackbox.ml:1:0 -> 5:17
8888
/builtin/blackbox.ml:1:0 -> 6:0
89-
/dune-root/test.ml:1:4 -> 6:12
90-
/dune-root/test.ml:1:7 -> 6:15
89+
/builtin/blackbox.ml:1:0 -> 6:12
90+
/builtin/blackbox.ml:1:0 -> 6:15
9191
/dune-root/test.ml:1:11 -> 6:18
9292
/dune-root/test.ml:1:12 -> 6:27
9393
/dune-root/test.ml:1:12 -> 7:0

compiler/tests-sourcemap/dump.reference

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
sourcemap for test.bc.js
2-
/my/sourceRoot#b.ml:1:4 -> 12: function <>f(x){return x - 1 | 0;}
3-
/my/sourceRoot#b.ml:1:6 -> 14: function f(<>x){return x - 1 | 0;}
42
/my/sourceRoot#b.ml:1:10 -> 17: function f(x){<>return x - 1 | 0;}
53
/my/sourceRoot#b.ml:1:15 -> 34: function f(x){return x - 1 | 0;<>}
64
/my/sourceRoot#b.ml:1:15 -> 0:<> var Testlib_B = [0, f];

0 commit comments

Comments
 (0)