Skip to content

Commit 5623f6f

Browse files
authored
Merge pull request #1988 from liam923/make-short-paths-lazier
Make short paths lazier
2 parents c1d4ae7 + 87875fc commit 5623f6f

File tree

5 files changed

+79
-85
lines changed

5 files changed

+79
-85
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ unreleased
44
+ merlin library
55
- Fix completion not working for inlined records labels (#1978, fixes #1977)
66
- Perform buffer indexing only if the query requires it (#1990 and #1991)
7+
- Stop unnecessarily forcing substitutions when initializing short-paths graph (#1988)
8+
79

810
merlin 5.6
911
==========

src/ocaml/typing/env.ml

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -662,11 +662,11 @@ and cltype_data =
662662
and short_paths_addition =
663663
| Type of Ident.t * type_declaration
664664
| Class_type of Ident.t * class_type_declaration
665-
| Module_type of Ident.t * modtype_declaration
666-
| Module of Ident.t * module_declaration * module_components
665+
| Module_type of Ident.t * Subst.Lazy.modtype_declaration
666+
| Module of Ident.t * Subst.Lazy.module_decl * module_components
667667
| Type_open of Path.t * type_data NameMap.t
668668
| Class_type_open of Path.t * class_type_declaration NameMap.t
669-
| Module_type_open of Path.t * modtype_declaration NameMap.t
669+
| Module_type_open of Path.t * Subst.Lazy.modtype_declaration NameMap.t
670670
| Module_open of Path.t * module_data NameMap.t
671671

672672
let empty_structure =
@@ -1771,20 +1771,15 @@ let short_paths_class_type_open path decls old =
17711771
else Class_type_open(path, decls) :: old
17721772

17731773
let short_paths_module_type id decl old =
1774-
let decl = Subst.Lazy.force_modtype_decl decl in
17751774
if !Clflags.real_paths then old
17761775
else Module_type(id, decl) :: old
17771776

17781777
let short_paths_module_type_open path decls old =
1779-
let decls = NameMap.map
1780-
(fun mtda -> Subst.Lazy.force_modtype_decl mtda.mtda_declaration)
1781-
decls
1782-
in
1778+
let decls = NameMap.map (fun mtda -> mtda.mtda_declaration) decls in
17831779
if !Clflags.real_paths then old
17841780
else Module_type_open(path, decls) :: old
17851781

17861782
let short_paths_module id decl comps old =
1787-
let decl = Subst.Lazy.force_module_decl decl in
17881783
if !Clflags.real_paths then old
17891784
else Module(id, decl, comps) :: old
17901785

@@ -4036,13 +4031,13 @@ let short_paths_class_type_desc clty =
40364031
| ns -> Subst(path, ns)
40374032
end
40384033

4039-
let short_paths_module_type_desc mty =
4034+
let short_paths_module_type_desc (mty : Subst.Lazy.modtype option) =
40404035
let open Short_paths.Desc.Module_type in
40414036
match mty with
4042-
| None | Some Mty_for_hole -> Fresh
4043-
| Some (Mty_ident path) -> Alias path
4044-
| Some (Mty_signature _ | Mty_functor _) -> Fresh
4045-
| Some (Mty_alias _) -> assert false
4037+
| None | Some MtyL_for_hole -> Fresh
4038+
| Some (MtyL_ident path) -> Alias path
4039+
| Some (MtyL_signature _ | MtyL_functor _) -> Fresh
4040+
| Some (MtyL_alias _) -> assert false
40464041

40474042
let deprecated_of_alerts alerts =
40484043
if
@@ -4059,26 +4054,26 @@ let deprecated_of_alerts alerts =
40594054
let deprecated_of_attributes attrs =
40604055
deprecated_of_alerts (Builtin_attributes.alerts_of_attrs attrs)
40614056

4062-
let rec short_paths_module_desc env mpath mty comp =
4057+
let rec short_paths_module_desc env mpath (mty : Subst.Lazy.modtype) comp =
40634058
let open Short_paths.Desc.Module in
40644059
match mty with
4065-
| Mty_alias path -> Alias path
4066-
| Mty_ident path -> begin
4067-
match find_modtype_expansion path env with
4060+
| MtyL_alias path -> Alias path
4061+
| MtyL_ident path -> begin
4062+
match find_modtype_expansion_lazy path env with
40684063
| exception Not_found -> Fresh (Signature (lazy []))
40694064
| mty -> short_paths_module_desc env mpath mty comp
40704065
end
4071-
| Mty_signature _ ->
4066+
| MtyL_signature _ ->
40724067
let components =
40734068
lazy (short_paths_module_components_desc env mpath comp)
40744069
in
40754070
Fresh (Signature components)
4076-
| Mty_functor _ ->
4071+
| MtyL_functor _ ->
40774072
let apply path =
40784073
short_paths_functor_components_desc env mpath comp path
40794074
in
40804075
Fresh (Functor apply)
4081-
| Mty_for_hole -> Fresh (Signature (lazy []))
4076+
| MtyL_for_hole -> Fresh (Signature (lazy []))
40824077

40834078
and short_paths_module_components_desc env mpath comp =
40844079
match get_components comp with
@@ -4103,19 +4098,17 @@ and short_paths_module_components_desc env mpath comp =
41034098
in
41044099
let comps =
41054100
String.Map.fold (fun name mtda acc ->
4106-
let mtd = Subst.Lazy.force_modtype_decl mtda.mtda_declaration in
4107-
let desc = short_paths_module_type_desc mtd.mtd_type in
4108-
let depr = deprecated_of_attributes mtd.mtd_attributes in
4101+
let desc = short_paths_module_type_desc mtda.mtda_declaration.mtdl_type in
4102+
let depr = deprecated_of_attributes mtda.mtda_declaration.mtdl_attributes in
41094103
let item = Short_paths.Desc.Module.Module_type(name, desc, depr) in
41104104
item :: acc
41114105
) c.comp_modtypes comps
41124106
in
41134107
let comps =
41144108
String.Map.fold (fun name { mda_declaration; mda_components; _ } acc ->
4115-
let mty = Subst.Lazy.force_module_decl mda_declaration in
41164109
let mpath = Pdot(mpath, name) in
41174110
let desc =
4118-
short_paths_module_desc env mpath mty.md_type mda_components
4111+
short_paths_module_desc env mpath mda_declaration.mdl_type mda_components
41194112
in
41204113
let depr = deprecated_of_alerts mda_components.alerts in
41214114
let item = Short_paths.Desc.Module.Module(name, desc, depr) in
@@ -4145,6 +4138,7 @@ and short_paths_functor_components_desc env mpath comp path =
41454138
stamped_path_add f.fcomp_subst_cache path mty;
41464139
mty
41474140
in
4141+
let mty = Subst.Lazy.of_modtype mty in
41484142
let loc = Location.(in_file !input_name) in
41494143
let comps =
41504144
components_of_functor_appl ~loc ~f_comp:f env ~f_path:mpath ~arg:path
@@ -4167,14 +4161,12 @@ let short_paths_additions_desc env additions =
41674161
let depr = deprecated_of_attributes clty.clty_attributes in
41684162
Short_paths.Desc.Class_type(id, desc, source, depr) :: acc
41694163
| Module_type(id, mtd) ->
4170-
let desc = short_paths_module_type_desc mtd.mtd_type in
4164+
let desc = short_paths_module_type_desc mtd.mtdl_type in
41714165
let source = Short_paths.Desc.Local in
4172-
let depr = deprecated_of_attributes mtd.mtd_attributes in
4166+
let depr = deprecated_of_attributes mtd.mtdl_attributes in
41734167
Short_paths.Desc.Module_type(id, desc, source, depr) :: acc
41744168
| Module(id, md, comps) ->
4175-
let desc =
4176-
short_paths_module_desc env (Pident id) md.md_type comps
4177-
in
4169+
let desc = short_paths_module_desc env (Pident id) md.mdl_type comps in
41784170
let source = Short_paths.Desc.Local in
41794171
let depr = deprecated_of_alerts comps.alerts in
41804172
Short_paths.Desc.Module(id, desc, source, depr) :: acc
@@ -4200,12 +4192,12 @@ let short_paths_additions_desc env additions =
42004192
decls acc
42014193
| Module_type_open(root, decls) ->
42024194
String.Map.fold
4203-
(fun name mtd acc ->
4195+
(fun name (mtd : Subst.Lazy.modtype_declaration) acc ->
42044196
let id = Ident.create_local name in
42054197
let path = Pdot(root, name) in
42064198
let desc = Short_paths.Desc.Module_type.Alias path in
42074199
let source = Short_paths.Desc.Open in
4208-
let depr = deprecated_of_attributes mtd.mtd_attributes in
4200+
let depr = deprecated_of_attributes mtd.mtdl_attributes in
42094201
Short_paths.Desc.Module_type(id, desc, source, depr) :: acc)
42104202
decls acc
42114203
| Module_open(root, decls) ->

tests/test-dirs/function-recovery.t

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"value": "[
1111
structure_item (test.ml[1,0+0]..test.ml[3,104+28])
1212
Tstr_module (Present)
13-
ERROR_locate_from_inside_function_literal_used_as_non_function/283
13+
ERROR_locate_from_inside_function_literal_used_as_non_function/277
1414
module_expr (test.ml[1,0+72]..test.ml[3,104+28])
1515
Tmod_structure
1616
[
@@ -19,7 +19,7 @@
1919
[
2020
<def>
2121
pattern (test.ml[2,79+6]..test.ml[2,79+13])
22-
Tpat_var \"problem/280\"
22+
Tpat_var \"problem/274\"
2323
expression (test.ml[2,79+16]..test.ml[2,79+24])
2424
Texp_variant \"Problem\"
2525
None
@@ -55,7 +55,7 @@
5555
constant (_none_[0,0+-1]..[0,0+-1]) ghost
5656
PConst_int (1,None)
5757
]
58-
Texp_ident \"*type-error*/281\"
58+
Texp_ident \"*type-error*/275\"
5959
]
6060
]
6161
]
@@ -76,10 +76,10 @@
7676
[
7777
<def>
7878
pattern (type.ml[1,0+4]..type.ml[1,0+5])
79-
Tpat_var \"f/280\"
79+
Tpat_var \"f/274\"
8080
expression (type.ml[1,0+8]..type.ml[1,0+61])
8181
extra (type.ml[1,0+18]..type.ml[1,0+19])
82-
Texp_newtype' \"t/282\"
82+
Texp_newtype' \"t/276\"
8383
Texp_function
8484
[
8585
Nolabel
@@ -91,10 +91,10 @@
9191
Ttyp_constr \"list/11!\"
9292
[
9393
core_type (type.ml[1,0+28]..type.ml[1,0+29])
94-
Ttyp_constr \"t/282\"
94+
Ttyp_constr \"t/276\"
9595
[]
9696
]
97-
Tpat_alias \"foo/283\"
97+
Tpat_alias \"foo/277\"
9898
pattern (type.ml[1,0+22]..type.ml[1,0+25]) ghost
9999
attribute \"merlin.hide\"
100100
[]
@@ -109,7 +109,7 @@
109109
extra (type.ml[1,0+43]..type.ml[1,0+50])
110110
Tpat_extra_constraint
111111
core_type (type.ml[1,0+48]..type.ml[1,0+49])
112-
Ttyp_constr \"t/282\"
112+
Ttyp_constr \"t/276\"
113113
[]
114114
Tpat_any
115115
expression (type.ml[1,0+53]..type.ml[1,0+55])
@@ -124,7 +124,7 @@
124124
constant (_none_[0,0+-1]..[0,0+-1]) ghost
125125
PConst_int (1,None)
126126
]
127-
Texp_ident \"*type-error*/284\"
127+
Texp_ident \"*type-error*/278\"
128128
]
129129
expression (type.ml[1,0+59]..type.ml[1,0+61])
130130
attribute \"merlin.loc\"
@@ -203,7 +203,7 @@
203203
"ghost": false,
204204
"attrs": [],
205205
"kind": "pattern (test.ml[1,0+4]..test.ml[1,0+5])
206-
Tpat_var \"f/280\"
206+
Tpat_var \"f/274\"
207207
",
208208
"children": []
209209
},
@@ -234,7 +234,7 @@
234234
"ghost": false,
235235
"attrs": [],
236236
"kind": "pattern (test.ml[1,0+6]..test.ml[1,0+9])
237-
Tpat_var \"x/282\"
237+
Tpat_var \"x/276\"
238238
",
239239
"children": []
240240
},
@@ -413,7 +413,7 @@
413413
Tpat_construct \"Some\"
414414
[
415415
pattern (test.ml[4,57+9]..test.ml[4,57+12])
416-
Tpat_var \"_aa/283\"
416+
Tpat_var \"_aa/277\"
417417
]
418418
None
419419
",
@@ -431,7 +431,7 @@
431431
"ghost": false,
432432
"attrs": [],
433433
"kind": "pattern (test.ml[4,57+9]..test.ml[4,57+12])
434-
Tpat_var \"_aa/283\"
434+
Tpat_var \"_aa/277\"
435435
",
436436
"children": []
437437
}

tests/test-dirs/server-tests/typer-cache/stamps.t/run.t

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@ buffers, and different runs for the same buffer:
88
$ echo "let f x = x" | \
99
> $MERLIN server dump -what browse -filename test.ml | \
1010
> sed 's:\\n:\n:g' | grep Tpat_var
11-
Tpat_var \"f/280\"
12-
Tpat_var \"x/282\"
11+
Tpat_var \"f/274\"
12+
Tpat_var \"x/276\"
1313
1414
$ echo "let f x = let () = () in x" | \
1515
> $MERLIN server dump -what browse -filename test.ml | \
1616
> sed 's:\\n:\n:g' | grep Tpat_var
17-
Tpat_var \"f/283\"
18-
Tpat_var \"x/285\"
17+
Tpat_var \"f/277\"
18+
Tpat_var \"x/279\"
1919
2020
$ echo "let f x = x" | \
2121
> $MERLIN server dump -what browse -filename other_test.ml | \
2222
> sed 's:\\n:\n:g' | grep Tpat_var
23-
Tpat_var \"f/280\"
24-
Tpat_var \"x/282\"
23+
Tpat_var \"f/274\"
24+
Tpat_var \"x/276\"
2525
2626
$ echo "let f x = let () = () in x" | \
2727
> $MERLIN server dump -what browse -filename test.ml | \
2828
> sed 's:\\n:\n:g' | grep Tpat_var
29-
Tpat_var \"f/283\"
30-
Tpat_var \"x/285\"
29+
Tpat_var \"f/277\"
30+
Tpat_var \"x/279\"
3131
3232
$ echo "let f x = x" | \
3333
> $MERLIN server dump -what browse -filename test.ml | \
3434
> sed 's:\\n:\n:g' | grep Tpat_var
35-
Tpat_var \"f/286\"
36-
Tpat_var \"x/288\"
35+
Tpat_var \"f/280\"
36+
Tpat_var \"x/282\"
3737
3838
$ $MERLIN server stop-server

0 commit comments

Comments
 (0)