Skip to content

Commit 549a0ff

Browse files
Merge pull request #193 from oxcaml/make-short-paths-lazier
Stop forcing substitutions while constructing short-paths graph
2 parents 4ef46b9 + 5a56d6d commit 549a0ff

File tree

7 files changed

+73
-80
lines changed

7 files changed

+73
-80
lines changed

src/ocaml/typing/env.ml

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,11 @@ and cltype_data =
830830
and short_paths_addition =
831831
| Type of Ident.t * type_declaration
832832
| Class_type of Ident.t * class_type_declaration
833-
| Module_type of Ident.t * modtype_declaration
834-
| Module of Ident.t * module_declaration * module_components
833+
| Module_type of Ident.t * Subst.Lazy.modtype_declaration
834+
| Module of Ident.t * Subst.Lazy.module_declaration * module_components
835835
| Type_open of Path.t * type_data NameMap.t
836836
| Class_type_open of Path.t * class_type_declaration NameMap.t
837-
| Module_type_open of Path.t * modtype_declaration NameMap.t
837+
| Module_type_open of Path.t * Subst.Lazy.modtype_declaration NameMap.t
838838
| Module_open of Path.t * module_data NameMap.t
839839

840840
let clda_mode = Mode.Value.(
@@ -2226,20 +2226,15 @@ let short_paths_class_type_open path decls old =
22262226
else Class_type_open(path, decls) :: old
22272227

22282228
let short_paths_module_type id decl old =
2229-
let decl = Subst.Lazy.force_modtype_decl decl in
22302229
if !Clflags.real_paths then old
22312230
else Module_type(id, decl) :: old
22322231

22332232
let short_paths_module_type_open path decls old =
2234-
let decls = NameMap.map
2235-
(fun mtda -> Subst.Lazy.force_modtype_decl mtda.mtda_declaration)
2236-
decls
2237-
in
2233+
let decls = NameMap.map (fun mtda -> mtda.mtda_declaration) decls in
22382234
if !Clflags.real_paths then old
22392235
else Module_type_open(path, decls) :: old
22402236

22412237
let short_paths_module id decl comps old =
2242-
let decl = Subst.Lazy.force_module_decl decl in
22432238
if !Clflags.real_paths then old
22442239
else Module(id, decl, comps) :: old
22452240

@@ -5354,7 +5349,7 @@ let short_paths_class_type_desc clty =
53545349
| ns -> Subst(path, ns)
53555350
end
53565351

5357-
let short_paths_module_type_desc mty =
5352+
let short_paths_module_type_desc (mty : Subst.Lazy.module_type option) =
53585353
let open Short_paths.Desc.Module_type in
53595354
match mty with
53605355
| None | Some Mty_for_hole -> Fresh
@@ -5378,13 +5373,14 @@ let deprecated_of_alerts alerts =
53785373
let deprecated_of_attributes attrs =
53795374
deprecated_of_alerts (Builtin_attributes.alerts_of_attrs attrs)
53805375

5381-
let scrape =
5382-
(* to be filled with Mtype.scrape_alias *)
5383-
ref ((fun _env _mty -> assert false) : t -> module_type -> module_type)
5376+
let scrape_lazy =
5377+
(* to be filled with Mtype.scrape_lazy *)
5378+
ref ((fun (_env : t) (_mty : Subst.Lazy.module_type) : Subst.Lazy.module_type ->
5379+
assert false))
53845380

53855381
let rec short_paths_module_desc env mpath mty comp =
53865382
let open Short_paths.Desc.Module in
5387-
match !scrape env mty with
5383+
match !scrape_lazy env mty with
53885384
| Mty_alias path -> Alias path
53895385
| Mty_ident _ -> Fresh (Signature (lazy []))
53905386
| Mty_signature _ ->
@@ -5423,19 +5419,17 @@ and short_paths_module_components_desc env mpath comp =
54235419
in
54245420
let comps =
54255421
String.Map.fold (fun name mtda acc ->
5426-
let mtd = Subst.Lazy.force_modtype_decl mtda.mtda_declaration in
5427-
let desc = short_paths_module_type_desc mtd.mtd_type in
5428-
let depr = deprecated_of_attributes mtd.mtd_attributes in
5422+
let desc = short_paths_module_type_desc mtda.mtda_declaration.mtd_type in
5423+
let depr = deprecated_of_attributes mtda.mtda_declaration.mtd_attributes in
54295424
let item = Short_paths.Desc.Module.Module_type(name, desc, depr) in
54305425
item :: acc
54315426
) c.comp_modtypes comps
54325427
in
54335428
let comps =
54345429
String.Map.fold (fun name { mda_declaration; mda_components; _ } acc ->
5435-
let mty = Subst.Lazy.force_module_decl mda_declaration in
54365430
let mpath = Pdot(mpath, name) in
54375431
let desc =
5438-
short_paths_module_desc env mpath mty.md_type mda_components
5432+
short_paths_module_desc env mpath mda_declaration.md_type mda_components
54395433
in
54405434
let depr = deprecated_of_alerts mda_components.alerts in
54415435
let item = Short_paths.Desc.Module.Module(name, desc, depr) in
@@ -5465,6 +5459,7 @@ and short_paths_functor_components_desc env mpath comp path =
54655459
stamped_path_add f.fcomp_subst_cache path mty;
54665460
mty
54675461
in
5462+
let mty = Subst.Lazy.of_modtype mty in
54685463
let loc = Location.(in_file !input_name) in
54695464
let comps =
54705465
components_of_functor_appl ~loc ~f_comp:f env ~f_path:mpath ~arg:path
@@ -5492,9 +5487,7 @@ let short_paths_additions_desc env additions =
54925487
let depr = deprecated_of_attributes mtd.mtd_attributes in
54935488
Short_paths.Desc.Module_type(id, desc, source, depr) :: acc
54945489
| Module(id, md, comps) ->
5495-
let desc =
5496-
short_paths_module_desc env (Pident id) md.md_type comps
5497-
in
5490+
let desc = short_paths_module_desc env (Pident id) md.md_type comps in
54985491
let source = Short_paths.Desc.Local in
54995492
let depr = deprecated_of_alerts comps.alerts in
55005493
Short_paths.Desc.Module(id, desc, source, depr) :: acc
@@ -5520,7 +5513,7 @@ let short_paths_additions_desc env additions =
55205513
decls acc
55215514
| Module_type_open(root, decls) ->
55225515
String.Map.fold
5523-
(fun name mtd acc ->
5516+
(fun name (mtd : Subst.Lazy.modtype_declaration) acc ->
55245517
let id = Ident.create_local name in
55255518
let path = Pdot(root, name) in
55265519
let desc = Short_paths.Desc.Module_type.Alias path in

src/ocaml/typing/env.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ val with_cmis : (unit -> 'a) -> 'a
754754

755755
val add_merlin_extension_module: Ident.t -> module_type -> t -> t
756756
val cleanup_functor_caches : stamp:int -> unit
757-
val scrape: (t -> module_type -> module_type) ref
757+
val scrape_lazy: (t -> Subst.Lazy.module_type -> Subst.Lazy.module_type) ref
758758
val cleanup_usage_tables : stamp:int -> unit
759759

760760
(** This value should be filled in with [Msupport.raise_error]. [Env] cannot use this

src/ocaml/typing/mtype.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ let scrape env mty =
422422
let () =
423423
Printtyp.expand_module_type := expand ;
424424
Env.scrape_alias := scrape_alias_lazy ;
425-
Env.scrape := scrape
425+
Env.scrape_lazy := scrape_lazy
426426

427427
let find_type_of_module ~strengthen ~aliasable env path =
428428
if strengthen then

tests/test-dirs/function-recovery.t

Lines changed: 12 additions & 12 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
13-
ERROR_locate_from_inside_function_literal_used_as_non_function/284
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/282\"
22+
Tpat_var \"problem/275\"
2323
sort value
2424
value_mode meet(local,once,nonportable,unforkable,yielding,stateful)(modevar#4[global,many,portable,forkable,unyielding,stateless .. global,once,nonportable,unforkable,yielding,stateful]);imply(unique,uncontended,read_write)(modevar#5[aliased,contended,immutable .. unique,uncontended,read_write])
2525
expression (test.ml[2,79+16]..test.ml[2,79+24])
@@ -49,7 +49,7 @@
4949
expression (_none_[0,0+-1]..[0,0+-1]) ghost
5050
Pexp_constant PConst_int (1,None)
5151
]
52-
Texp_ident \"*type-error*/283\"
52+
Texp_ident \"*type-error*/276\"
5353
]
5454
]
5555
]
@@ -69,7 +69,7 @@
6969
[
7070
<def>
7171
pattern (type.ml[1,0+4]..type.ml[1,0+5])
72-
Tpat_var \"f/282\"
72+
Tpat_var \"f/275\"
7373
sort value
7474
value_mode meet(local,once,nonportable,unforkable,yielding,stateful)(modevar#2[global,many,portable,forkable,unyielding,stateless .. global,once,nonportable,unforkable,yielding,stateful]);imply(unique,uncontended,read_write)(modevar#3[aliased,contended,immutable .. unique,uncontended,read_write])
7575
expression (type.ml[1,0+8]..type.ml[1,0+61])
@@ -87,10 +87,10 @@
8787
Ttyp_constr \"list/11!\"
8888
[
8989
core_type (type.ml[1,0+28]..type.ml[1,0+29])
90-
Ttyp_constr \"t/284\"
90+
Ttyp_constr \"t/277\"
9191
[]
9292
]
93-
Tpat_var \"foo/285\"
93+
Tpat_var \"foo/278\"
9494
sort value
9595
value_mode map_comonadic(local_to_regional)(modevar#6[global,many,portable,forkable,unyielding,stateless .. local,once,nonportable,unforkable,yielding,stateful]);imply(unique,uncontended,read_write)(modevar#7[aliased,contended,immutable .. unique,uncontended,read_write])
9696
]
@@ -103,7 +103,7 @@
103103
extra
104104
Tpat_extra_constraint
105105
core_type (type.ml[1,0+48]..type.ml[1,0+49])
106-
Ttyp_constr \"t/284\"
106+
Ttyp_constr \"t/277\"
107107
[]
108108
Tpat_any
109109
expression (type.ml[1,0+53]..type.ml[1,0+55])
@@ -116,7 +116,7 @@
116116
expression (_none_[0,0+-1]..[0,0+-1]) ghost
117117
Pexp_constant PConst_int (1,None)
118118
]
119-
Texp_ident \"*type-error*/286\"
119+
Texp_ident \"*type-error*/279\"
120120
]
121121
expression (type.ml[1,0+59]..type.ml[1,0+61])
122122
attribute \"merlin.loc\"
@@ -195,7 +195,7 @@
195195
"ghost": false,
196196
"attrs": [],
197197
"kind": "pattern (test.ml[1,0+4]..test.ml[1,0+5])
198-
Tpat_var \"f/282\"
198+
Tpat_var \"f/275\"
199199
sort value
200200
value_mode meet(local,once,nonportable,unforkable,yielding,stateful)(modevar#2[global,many,portable,forkable,unyielding,stateless .. global,once,nonportable,unforkable,yielding,stateful]);imply(unique,uncontended,read_write)(modevar#3[aliased,contended,immutable .. unique,uncontended,read_write])
201201
",
@@ -228,7 +228,7 @@
228228
"ghost": false,
229229
"attrs": [],
230230
"kind": "pattern (test.ml[1,0+6]..test.ml[1,0+9])
231-
Tpat_var \"x/284\"
231+
Tpat_var \"x/277\"
232232
sort '_representable_layout_1
233233
value_mode map_comonadic(local_to_regional)(modevar#6[global,many,portable,forkable,unyielding,stateless .. local,once,nonportable,unforkable,yielding,stateful]);imply(unique,uncontended,read_write)(modevar#7[aliased,contended,immutable .. unique,uncontended,read_write])
234234
",
@@ -460,7 +460,7 @@
460460
Tpat_construct \"Some\"
461461
[
462462
pattern (test.ml[4,57+9]..test.ml[4,57+12])
463-
Tpat_var \"_aa/285\"
463+
Tpat_var \"_aa/278\"
464464
sort value
465465
value_mode global,many,portable,forkable,unyielding,stateless;unique,uncontended,read_write
466466
]
@@ -480,7 +480,7 @@
480480
"ghost": false,
481481
"attrs": [],
482482
"kind": "pattern (test.ml[4,57+9]..test.ml[4,57+12])
483-
Tpat_var \"_aa/285\"
483+
Tpat_var \"_aa/278\"
484484
sort value
485485
value_mode global,many,portable,forkable,unyielding,stateless;unique,uncontended,read_write
486486
",

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/282\"
12-
Tpat_var \"x/284\"
11+
Tpat_var \"f/275\"
12+
Tpat_var \"x/277\"
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/285\"
18-
Tpat_var \"x/287\"
17+
Tpat_var \"f/278\"
18+
Tpat_var \"x/280\"
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/282\"
24-
Tpat_var \"x/284\"
23+
Tpat_var \"f/275\"
24+
Tpat_var \"x/277\"
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/285\"
30-
Tpat_var \"x/287\"
29+
Tpat_var \"f/278\"
30+
Tpat_var \"x/280\"
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/288\"
36-
Tpat_var \"x/290\"
35+
Tpat_var \"f/281\"
36+
Tpat_var \"x/283\"
3737
3838
$ $MERLIN server stop-server

tests/test-dirs/type-enclosing/underscore-ids.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ We try several places in the identifier to check the result stability
443443
[
444444
<def>
445445
pattern (under.ml[1,0+4]..under.ml[1,0+6])
446-
Tpat_var \"aa/282\"
446+
Tpat_var \"aa/275\"
447447
sort value
448448
value_mode meet(local,once,nonportable,unforkable,yielding,stateful)(modevar#2[global,many,portable,forkable,unyielding,stateless .. global,once,nonportable,unforkable,yielding,stateful]);imply(unique,uncontended,read_write)(modevar#3[aliased,contended,immutable .. unique,uncontended,read_write])
449449
expression (under.ml[1,0+9]..under.ml[1,0+12])
@@ -454,7 +454,7 @@ We try several places in the identifier to check the result stability
454454
[
455455
<def>
456456
pattern (under.ml[2,13+4]..under.ml[2,13+5])
457-
Tpat_var \"f/283\"
457+
Tpat_var \"f/276\"
458458
sort value
459459
value_mode meet(local,once,nonportable,unforkable,yielding,stateful)(modevar#9[global,many,portable,forkable,unyielding,stateless .. global,once,nonportable,unforkable,yielding,stateful]);imply(unique,uncontended,read_write)(modevar#a[aliased,contended,immutable .. unique,uncontended,read_write])
460460
expression (under.ml[2,13+6]..under.ml[5,70+17]) ghost
@@ -464,7 +464,7 @@ We try several places in the identifier to check the result stability
464464
Nolabel
465465
Param_pat
466466
pattern (under.ml[2,13+6]..under.ml[2,13+9])
467-
Tpat_var \"x/285\"
467+
Tpat_var \"x/278\"
468468
sort '_representable_layout_1
469469
value_mode map_comonadic(local_to_regional)(modevar#d[global,many,portable,forkable,unyielding,stateless .. local,once,nonportable,unforkable,yielding,stateful]);imply(unique,uncontended,read_write)(modevar#e[aliased,contended,immutable .. unique,uncontended,read_write])
470470
]
@@ -479,7 +479,7 @@ We try several places in the identifier to check the result stability
479479
expression (_none_[0,0+-1]..[0,0+-1]) ghost
480480
Pexp_constant PConst_int (1,None)
481481
]
482-
Texp_ident \"*type-error*/288\"
482+
Texp_ident \"*type-error*/281\"
483483
]
484484
]
485485

0 commit comments

Comments
 (0)