Skip to content

Commit 3584e1a

Browse files
committed
change to have two explicit injectable args instead
1 parent 77ef6f4 commit 3584e1a

File tree

10 files changed

+63
-84
lines changed

10 files changed

+63
-84
lines changed

compiler/ml/lambda.ml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type loc_kind =
1717
| Loc_FILE
1818
| Loc_LINE
1919
| Loc_MODULE
20-
| Loc_MODULE_PATH
21-
| Loc_VALUE_PATH
20+
| Loc_SOURCE_LOC_VALUE_PATH
21+
| Loc_SOURCE_LOC_POS
2222
| Loc_LOC
2323
| Loc_POS
2424

@@ -707,7 +707,9 @@ let raise_kind = function
707707
let lam_of_loc ?(root_path : Path.t option)
708708
?(current_value_ident : Ident.t option) kind loc =
709709
let loc_start = loc.Location.loc_start in
710+
let loc_end = loc.loc_end in
710711
let file, lnum, cnum = Location.get_pos_info loc_start in
712+
let _, end_lnum, end_cnum = Location.get_pos_info loc_end in
711713
let file = Filename.basename file in
712714
let enum =
713715
loc.Location.loc_end.Lexing.pos_cnum - loc_start.Lexing.pos_cnum + cnum
@@ -724,11 +726,18 @@ let lam_of_loc ?(root_path : Path.t option)
724726
Const_base (Const_int enum);
725727
] ))
726728
| Loc_FILE -> Lconst (Const_immstring file)
727-
| Loc_MODULE_PATH -> (
728-
match root_path with
729-
| None -> Lconst (Const_immstring "<none>")
730-
| Some path -> Lconst (Const_immstring (Path.name path)))
731-
| Loc_VALUE_PATH -> (
729+
| Loc_SOURCE_LOC_POS ->
730+
Lconst
731+
(Const_immstring
732+
([
733+
file;
734+
string_of_int lnum;
735+
string_of_int cnum;
736+
string_of_int end_lnum;
737+
string_of_int end_cnum;
738+
]
739+
|> String.concat ";"))
740+
| Loc_SOURCE_LOC_VALUE_PATH -> (
732741
match root_path with
733742
| None -> Lconst (Const_immstring "<none>")
734743
| Some path ->

compiler/ml/lambda.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ type loc_kind =
2121
| Loc_FILE
2222
| Loc_LINE
2323
| Loc_MODULE
24-
| Loc_MODULE_PATH
25-
| Loc_VALUE_PATH
24+
| Loc_SOURCE_LOC_VALUE_PATH
25+
| Loc_SOURCE_LOC_POS
2626
| Loc_LOC
2727
| Loc_POS
2828

compiler/ml/predef.ml

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ and ident_result = ident_create "result"
5151

5252
and ident_dict = ident_create "dict"
5353

54-
and ident_source_loc = ident_create "sourceLoc"
54+
and ident_source_loc_pos = ident_create "sourceLocPos"
55+
56+
and ident_source_loc_value_path = ident_create "sourceLocValuePath"
5557

5658
and ident_bigint = ident_create "bigint"
5759

@@ -100,7 +102,9 @@ and path_result = Pident ident_result
100102

101103
and path_dict = Pident ident_dict
102104

103-
and path_source_loc = Pident ident_source_loc
105+
and path_source_loc_pos = Pident ident_source_loc_pos
106+
107+
and path_source_loc_value_path = Pident ident_source_loc_value_path
104108

105109
and path_bigint = Pident ident_bigint
106110

@@ -322,36 +326,6 @@ let common_initial_env add_type add_extension empty_env =
322326
],
323327
Record_regular );
324328
}
325-
and decl_source_loc =
326-
{
327-
decl_abstr with
328-
type_kind =
329-
(let mk_field name typ =
330-
{
331-
ld_id = ident_create name;
332-
ld_attributes = [];
333-
ld_loc = Location.none;
334-
ld_mutable = Immutable;
335-
ld_optional = false;
336-
ld_type = typ;
337-
}
338-
in
339-
Type_record
340-
( [
341-
(* __FILE__ *)
342-
mk_field "filename" type_string;
343-
(* __MODULE__ *)
344-
mk_field "module_" type_string;
345-
(* __POS__ *)
346-
mk_field "pos"
347-
(newgenty (Ttuple [type_string; type_int; type_int; type_int]));
348-
(* __MODULE_PATH__ *)
349-
mk_field "modulePath" type_string;
350-
(* __VALUE_PATH__ *)
351-
mk_field "valuePath" type_string;
352-
],
353-
Record_regular ));
354-
}
355329
and decl_uncurried =
356330
let tvar1 = newgenvar () in
357331
{
@@ -436,7 +410,8 @@ let common_initial_env add_type add_extension empty_env =
436410
|> add_type ident_array decl_array
437411
|> add_type ident_list decl_list
438412
|> add_type ident_dict decl_dict
439-
|> add_type ident_source_loc decl_source_loc
413+
|> add_type ident_source_loc_pos decl_abstr
414+
|> add_type ident_source_loc_value_path decl_abstr
440415
|> add_type ident_unknown decl_unknown
441416
|> add_exception ident_undefined_recursive_module
442417
[newgenty (Ttuple [type_string; type_int; type_int])]

compiler/ml/predef.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ val path_list : Path.t
4646
val path_option : Path.t
4747
val path_result : Path.t
4848
val path_dict : Path.t
49-
val path_source_loc : Path.t
49+
val path_source_loc_pos : Path.t
50+
val path_source_loc_value_path : Path.t
5051

5152
val path_bigint : Path.t
5253
val path_lazy_t : Path.t

compiler/ml/printlambda.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ let string_of_loc_kind = function
5555
| Loc_FILE -> "loc_FILE"
5656
| Loc_LINE -> "loc_LINE"
5757
| Loc_MODULE -> "loc_MODULE"
58-
| Loc_MODULE_PATH -> "loc_MODULE_PATH"
59-
| Loc_VALUE_PATH -> "loc_VALUE_PATH"
58+
| Loc_SOURCE_LOC_VALUE_PATH -> "loc_SOURCE_LOC_VALUE_PATH"
59+
| Loc_SOURCE_LOC_POS -> "loc_SOURCE_LOC_POS"
6060
| Loc_POS -> "loc_POS"
6161
| Loc_LOC -> "loc_LOC"
6262

compiler/ml/translcore.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ let primitives_table =
247247
("%loc_LINE", Ploc Loc_LINE);
248248
("%loc_POS", Ploc Loc_POS);
249249
("%loc_MODULE", Ploc Loc_MODULE);
250-
("%loc_MODULE_PATH", Ploc Loc_MODULE_PATH);
251-
("%loc_VALUE_PATH", Ploc Loc_VALUE_PATH);
250+
("%loc_SOURCE_LOC_VALUE_PATH", Ploc Loc_SOURCE_LOC_VALUE_PATH);
251+
("%loc_SOURCE_LOC_POS", Ploc Loc_SOURCE_LOC_POS);
252252
(* BEGIN Triples for ref data type *)
253253
("%makeref", Pmakeblock Lambda.ref_tag_info);
254254
("%refset", Psetfield (0, Lambda.ref_field_set_info));

compiler/ml/typecore.ml

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,42 +2223,36 @@ let not_function env ty =
22232223
let ls, tvar = list_labels env ty in
22242224
ls = [] && not tvar
22252225
2226-
let rec find_injectable_source_loc_arg t =
2227-
match t.desc with
2228-
| Tarrow (Labelled n, {desc = Tconstr (p, [], _)}, _, _, _)
2229-
when Path.same p Predef.path_source_loc ->
2230-
Some n
2231-
| Tarrow (_, _, t, _, _) -> find_injectable_source_loc_arg t
2232-
| _ -> None
2226+
type injectable_source_loc_arg = ValuePath | Pos
22332227
2234-
let mk_source_loc_field ~parent_loc field_name ident_name =
2235-
( Location.mknoloc (Longident.Lident field_name),
2236-
Ast_helper.Exp.ident
2237-
~loc:{parent_loc with loc_ghost = true}
2238-
(Location.mknoloc (Longident.Lident ident_name)),
2239-
false )
2228+
let rec find_injectable_source_loc_args ?(found = []) t =
2229+
match t.desc with
2230+
| Tarrow (Labelled n, {desc = Tconstr (p, [], _)}, next, _, _)
2231+
when Path.same p Predef.path_source_loc_pos ->
2232+
(Pos, n) :: find_injectable_source_loc_args ~found next
2233+
| Tarrow (Labelled n, {desc = Tconstr (p, [], _)}, next, _, _)
2234+
when Path.same p Predef.path_source_loc_value_path ->
2235+
(ValuePath, n) :: find_injectable_source_loc_args ~found next
2236+
| Tarrow (_, _, t, _, _) -> find_injectable_source_loc_args t
2237+
| _ -> found
22402238
22412239
let expand_injectable_args ~(apply_expr : Parsetree.expression) ~exp_type
22422240
(sargs : sargs) =
2243-
match find_injectable_source_loc_arg exp_type with
2244-
| None -> sargs
2245-
| Some injectable_source_loc_arg_label_name ->
2246-
let mk_source_loc_field =
2247-
mk_source_loc_field ~parent_loc:apply_expr.pexp_loc
2248-
in
2241+
match find_injectable_source_loc_args exp_type with
2242+
| [] -> sargs
2243+
| injectable_args ->
2244+
(* TODO: Error on args already being supplied *)
22492245
sargs
2250-
@ [
2251-
( Labelled (Location.mknoloc injectable_source_loc_arg_label_name),
2252-
Ast_helper.Exp.record
2253-
[
2254-
mk_source_loc_field "filename" "__FILE__";
2255-
mk_source_loc_field "module_" "__MODULE__";
2256-
mk_source_loc_field "pos" "__POS__";
2257-
mk_source_loc_field "modulePath" "__MODULE_PATH__";
2258-
mk_source_loc_field "valuePath" "__VALUE_PATH__";
2259-
]
2260-
None );
2261-
]
2246+
@ (injectable_args
2247+
|> List.map (fun (t, n) ->
2248+
( Labelled (Location.mknoloc n),
2249+
Ast_helper.Exp.ident
2250+
~loc:{apply_expr.pexp_loc with loc_ghost = true}
2251+
(Location.mknoloc
2252+
(Longident.Lident
2253+
(match t with
2254+
| ValuePath -> "__SOURCE_LOC_VALUE_PATH__"
2255+
| Pos -> "__SOURCE_LOC_POS__"))) )))
22622256
22632257
type lazy_args =
22642258
(Asttypes.Noloc.arg_label * (unit -> Typedtree.expression) option) list

runtime/Pervasives.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ external __LOC__: string = "%loc_LOC"
3434
external __FILE__: string = "%loc_FILE"
3535
external __LINE__: int = "%loc_LINE"
3636
external __MODULE__: string = "%loc_MODULE"
37-
external __MODULE_PATH__: string = "%loc_MODULE_PATH"
38-
external __VALUE_PATH__: string = "%loc_VALUE_PATH"
37+
external __SOURCE_LOC_VALUE_PATH__: sourceLocValuePath = "%loc_SOURCE_LOC_VALUE_PATH"
38+
external __SOURCE_LOC_POS__: sourceLocPos = "%loc_SOURCE_LOC_POS"
3939
external __POS__: (string, int, int, int) = "%loc_POS"
4040

4141
external __LOC_OF__: 'a => (string, 'a) = "%loc_LOC"

runtime/Pervasives_mini.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ external __LOC__: string = "%loc_LOC"
77
external __FILE__: string = "%loc_FILE"
88
external __LINE__: int = "%loc_LINE"
99
external __MODULE__: string = "%loc_MODULE"
10-
external __MODULE_PATH__: string = "%loc_MODULE_PATH"
11-
external __VALUE_PATH__: string = "%loc_VALUE_PATH"
10+
external __SOURCE_LOC_VALUE_PATH__: sourceLocValuePath = "%loc_SOURCE_LOC_VALUE_PATH"
11+
external __SOURCE_LOC_POS__: sourceLocPos = "%loc_SOURCE_LOC_POS"
1212
external __POS__: (string, int, int, int) = "%loc_POS"
1313

1414
external __LOC_OF__: 'a => (string, 'a) = "%loc_LOC"

tests/tests/src/test_per.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ external __LOC__: string = "%loc_LOC"
1919
external __MODULE__: string = "%loc_FILE"
2020
external __LINE__: int = "%loc_LINE"
2121
external __MODULE__: string = "%loc_MODULE"
22-
external __MODULE_PATH__: string = "%loc_MODULE_PATH"
23-
external __VALUE_PATH__: string = "%loc_VALUE_PATH"
22+
external __SOURCE_LOC_VALUE_PATH__: sourceLocValuePath = "%loc_SOURCE_LOC_VALUE_PATH"
23+
external __SOURCE_LOC_POS__: sourceLocPos = "%loc_SOURCE_LOC_POS"
2424
external __POS__: (string, int, int, int) = "%loc_POS"
2525

2626
external __LOC_OF__: 'a => (string, 'a) = "%loc_LOC"

0 commit comments

Comments
 (0)