Skip to content

Commit f0b2f17

Browse files
trefislet-def
andauthored
Support for OCaml 4.10 (#1117)
* import upstream ocaml-4.10+beta1 code * create ocaml 4.10 folders * remove envaux from upstream * remove envaux from upstream * WIP Support OCaml 4.10 * WIP Fixing 4.10 definitions * WIP Typemod * RESET ME * Add Type_immediacy module * build and run... until failwith "TODO" * don't be to eager TODO * implement env caching * add test-current target * catch errors in structure item * catch initialization errors * locate: use find_by_name, not lookup * type_utils: use find_by_name, not lookup * Env.sign_of_cmi: make locs ghost * typemod: port omitted patch (should be upstreamed!) * typemod: comment out some fatal errors * rebuild 4.10 parser with latest menhir * update upstream/ocaml_410 to 4.10.0 * port changes from 4.10.0 * FIX ME: disable short-paths for now * REMOVE ME: release for OCaml 4.10 only * update dune-release.sh script (allow explicit specification of package-version) * Update CHANGES.md * list 4.10 to magic_numbers * same menhir as on other backends * tests: -short-paths disabled on 4.10 * 408: env plumbing * functor parameters and optional module names * Env.fold_type_decls * Result on 4.02 * WIP: first 409 * WIP: first 407 * WIP: first 406 * WIP: first 405 * WIP: first 404 * WIP: first 403 * WIP: first 402 * WIP: 407_0 * WIP: third (all backends) * 4.10 in dune-workspace files * Revert "FIX ME: disable short-paths for now" This reverts commit 35cb490. * rebased -short-paths * tests: reenable short-paths for 4.10 * typeclass: pardon? * 410: short-paths fixes and cleanup * 410: finish fixing env * update tests * fix cons test * fix errors in constrained env test * Update opam constraints * non_shadowed_pervasives: lookup was removed in our 4.09, remove from our 4.10 * typemod: recover from inclusion error on 4.10 * fix tests pre 4.10 * disable broken test on 4.10 * add 4.10 version of the test Co-authored-by: Frédéric Bour <[email protected]>
1 parent 37e38e4 commit f0b2f17

File tree

384 files changed

+179743
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

384 files changed

+179743
-121
lines changed

CHANGES.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
merlin 3.3.4~4.10preview1
2+
=========================
3+
Mon Mar 2 14:26:32 CET 2020
4+
5+
This is a preview release that adds support for OCaml 4.10.
6+
Short-path is disabled. Other versions of OCaml are not supported.
7+
18
merlin 3.3.3
29
============
310
Fri Nov 29 17:35:58 CET 2019

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ test:
1616
dune build --always-show-command-line --workspace=dune-workspace.test
1717
dune runtest --workspace=dune-workspace.test
1818

19+
test-current:
20+
dune build --always-show-command-line
21+
dune runtest
22+
1923
preprocess:
2024
dune build --always-show-command-line @preprocess
2125

dune-release.sh

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
#!/bin/sh
22

33
TAG="$1"
4+
VER="$2"
45

56
if [ -z "$TAG" ]; then
6-
printf "Usage: ./dune-release.sh <tag-name>\n"
7+
printf "Usage: ./dune-release.sh <tag-name> [<pkg-version>]\n"
78
printf "Please make sure that dune-release is available.\n"
89
exit 1
910
fi
1011

12+
FLAGS="-t $TAG"
13+
14+
if [ -n "$VER" ]; then
15+
FLAGS="$FLAGS --pkg-version=$VER"
16+
fi
17+
1118
step()
1219
{
1320
printf "Continue? [Yn] "
@@ -16,10 +23,10 @@ step()
1623
if [ "x$action" == "xN" ]; then exit 2; fi
1724
}
1825

19-
dune-release distrib -p merlin -n merlin -t "$TAG" --skip-tests #--skip-lint
26+
dune-release distrib -p merlin -n merlin $FLAGS --skip-tests #--skip-lint
2027
step
21-
dune-release publish distrib -p merlin -n merlin -t "$TAG"
28+
dune-release publish distrib -p merlin -n merlin $FLAGS
2229
step
23-
dune-release opam pkg -p merlin -n merlin -t "$TAG"
30+
dune-release opam pkg -p merlin -n merlin $FLAGS
2431
step
25-
dune-release opam submit -p merlin -n merlin -t "$TAG"
32+
dune-release opam submit -p merlin -n merlin $FLAGS

dune-workspace.template

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
(context (opam (switch 4.05.0)))
66
(context (opam (switch 4.06.1)))
77
(context (opam (switch 4.07.1)))
8-
(context (opam (switch 4.08.1) (merlin)))
8+
(context (opam (switch 4.08.1)))
99
(context (opam (switch 4.09.0)))
10+
(context (opam (switch 4.10.0) (merlin)))

dune-workspace.test

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
(context (opam (switch 4.07.1)))
77
(context (opam (switch 4.08.1)))
88
(context (opam (switch 4.09.0)))
9+
(context (opam (switch 4.10.0) (merlin)))

merlin.opam

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build: [
1010
["dune" "runtest" "-p" name "-j" jobs] {with-test}
1111
]
1212
depends: [
13-
"ocaml" {>= "4.02.1" & < "4.10"}
13+
"ocaml" {>= "4.02.3"}
1414
"dune" {>= "1.8.0"}
1515
"ocamlfind" {>= "1.5.2"}
1616
"yojson" {>= "1.6.0"}

src/analysis/completion.ml

+1-4
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ let make_candidate ~get_doc ~attrs ~exact ~prefix_path name ?loc ?path ty =
240240
let item_for_global_module name =
241241
{name; kind = `Module; desc = `None; info = `None; deprecated = false}
242242

243-
let fold_types f id env acc =
244-
Env.fold_types (fun s p (decl,_) acc -> f s p decl acc) id env acc
245-
246243
let fold_constructors f id env acc =
247244
Env.fold_constructors
248245
(fun constr acc -> f constr.Types.cstr_name constr acc)
@@ -397,7 +394,7 @@ let get_candidates ?get_doc ?target_type ?prefix_path ~prefix kind ~validate env
397394
) prefix_path env []
398395

399396
| `Types ->
400-
fold_types (fun name path decl candidates ->
397+
Env.fold_type_decls (fun name path decl candidates ->
401398
if not @@ validate `Lident `Typ name then candidates else
402399
make_weighted_candidate ~exact:(name = prefix) name ~path (`Typ decl)
403400
~loc:decl.Types.type_loc ~attrs:(type_attributes decl)

src/analysis/destruct.ml

+1-2
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,8 @@ let node config source node parents =
404404
let pexp = filter_expr_attr (Untypeast.untype_expression expr) in
405405
let needs_parentheses, result =
406406
if is_package ty then (
407-
let name = Location.mknoloc "M" in
408407
let mode = Ast_helper.Mod.unpack pexp in
409-
false, Ast_helper.Exp.letmodule name mode placeholder
408+
false, Ast_helper.Exp.letmodule_no_opt "M" mode placeholder
410409
) else (
411410
let ps = gen_patterns expr.Typedtree.exp_env ty in
412411
let cases =

src/analysis/locate.ml

+6-8
Original file line numberDiff line numberDiff line change
@@ -628,27 +628,25 @@ end = struct
628628
raise (Found (path, Namespaced_path.of_path ~namespace:`Type path, loc))
629629
| `Constr ->
630630
log ~title:"lookup" "lookup in constructor namespace" ;
631-
let cd = Env.lookup_constructor ident env in
631+
let cd = Env.find_constructor_by_name ident env in
632632
let path, loc = path_and_loc_of_cstr cd env in
633633
(* TODO: Use [`Constr] here instead of [`Type] *)
634634
raise (Found (path, Namespaced_path.of_path ~namespace:`Type path, loc))
635635
| `Mod ->
636636
log ~title:"lookup" "lookup in module namespace" ;
637-
let path = Env.lookup_module ~load:true ident env in
638-
let md = Env.find_module path env in
637+
let path, md = Env.find_module_by_name ident env in
639638
raise (Found (path, Namespaced_path.of_path ~namespace:`Mod path, md.Types.md_loc))
640639
| `Modtype ->
641640
log ~title:"lookup" "lookup in module type namespace" ;
642-
let path, mtd = Env.lookup_modtype ident env in
641+
let path, mtd = Env.find_modtype_by_name ident env in
643642
raise (Found (path, Namespaced_path.of_path ~namespace:`Modtype path, mtd.Types.mtd_loc))
644643
| `Type ->
645644
log ~title:"lookup" "lookup in type namespace" ;
646-
let path = Env.lookup_type ident env in
647-
let typ_decl = Env.find_type path env in
645+
let path, typ_decl = Env.find_type_by_name ident env in
648646
raise (Found (path, Namespaced_path.of_path ~namespace:`Type path, typ_decl.Types.type_loc))
649647
| `Vals ->
650648
log ~title:"lookup" "lookup in value namespace" ;
651-
let path, val_desc = Env.lookup_value ident env in
649+
let path, val_desc = Env.find_value_by_name ident env in
652650
raise (Found (path, Namespaced_path.of_path ~namespace:`Vals path, val_desc.Types.val_loc))
653651
| `This_label lbl ->
654652
log ~title:"lookup"
@@ -658,7 +656,7 @@ end = struct
658656
raise (Found (path, Namespaced_path.of_path ~namespace:`Type path, loc))
659657
| `Labels ->
660658
log ~title:"lookup" "lookup in label namespace" ;
661-
let lbl = Env.lookup_label ident env in
659+
let lbl = Env.find_label_by_name ident env in
662660
let path, loc = path_and_loc_from_label lbl env in
663661
(* TODO: Use [`Labels] here instead of [`Type] *)
664662
raise (Found (path, Namespaced_path.of_path ~namespace:`Type path, loc))

src/analysis/outline.ml

+10-3
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,17 @@ let rec summarize node =
6969

7070
| Module_declaration md ->
7171
let children = get_mod_children node in
72-
Some (mk ~children ~location `Module None md.md_id)
73-
| Module_binding mb ->
72+
begin match Raw_compat.md_id md with
73+
| None -> None
74+
| Some id -> Some (mk ~children ~location `Module None id)
75+
end
76+
77+
| Module_binding mb ->
7478
let children = get_mod_children node in
75-
Some (mk ~children ~location `Module None mb.mb_id)
79+
begin match Raw_compat.mb_id mb with
80+
| None -> None
81+
| Some id -> Some (mk ~children ~location `Module None id)
82+
end
7683

7784
| Module_type_declaration mtd ->
7885
let children = get_mod_children node in

src/analysis/polarity_search.ml

+4-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ let match_query env query t =
8080
let build_query ~positive ~negative env =
8181
let prepare r l =
8282
if l = Longident.Lident "fun" then (incr r; None) else
83-
Some (normalize_path env (Env.lookup_type l env))
83+
let set, _ = Env.find_type_by_name l env in
84+
Some (normalize_path env set)
8485
in
8586
let pos_fun = ref 0 and neg_fun = ref 0 in
8687
let positive = List.filter_map positive ~f:(prepare pos_fun) in
@@ -104,7 +105,7 @@ let directories ~global_modules env =
104105
in
105106
List.fold_left ~f:(fun l name ->
106107
let lident = Longident.Lident name in
107-
match Env.lookup_module ~load:true lident env with
108+
match Env.find_module_by_name lident env with
108109
| exception _ -> l
109110
| _ -> Trie (name, lident, lazy (explore lident env)) :: l
110111
) ~init:[] global_modules
@@ -124,7 +125,7 @@ let execute_query query env dirs =
124125
in
125126
let rec recurse acc (Trie (_, dir, children)) =
126127
match
127-
ignore (Env.lookup_module ~load:true dir env);
128+
ignore (Env.find_module_by_name dir env);
128129
Lazy.force children
129130
with
130131
| children ->

src/analysis/type_utils.ml

+11-14
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@ let parse_expr ?(keywords=Lexer_raw.keywords []) expr =
4040
Parser_raw.parse_expression lexer lexbuf
4141

4242
let lookup_module name env =
43-
let path = Env.lookup_module ~load:true name env in
44-
let md = Env.find_module path env in
43+
let path, md = Env.find_module_by_name name env in
4544
path, md.Types.md_type, md.Types.md_attributes
4645

4746
let lookup_modtype name env =
48-
let path, mdtype = Env.lookup_modtype name env in
47+
let path, mdtype = Env.find_modtype_by_name name env in
4948
path, mdtype.Types.mtd_type
5049

5150
let lookup_module_or_modtype name env =
@@ -155,15 +154,14 @@ let rec mod_smallerthan n m =
155154
| Some n', _ -> Some (succ n')
156155
end
157156
end
158-
| Mty_functor (_,m1,m2) ->
157+
| Mty_functor _ ->
158+
let (m1,m2) = unpack_functor m in
159159
begin
160-
match m1 with
161-
| None -> None
162-
| Some m1 ->
163-
match mod_smallerthan n m1 with
164-
| None -> None
165-
| Some n1 ->
166-
match mod_smallerthan (n - n1) m2 with
160+
match mod_smallerthan n m2, m1 with
161+
| None, _ -> None
162+
| result, Unit -> result
163+
| Some n1, Named (_, mt) ->
164+
match mod_smallerthan (n - n1) mt with
167165
| None -> None
168166
| Some n2 -> Some (n1 + n2)
169167
end
@@ -243,8 +241,7 @@ let type_in_env ?(verbosity=0) ?keywords env ppf expr =
243241
true
244242
with exn ->
245243
try
246-
let p = Env.lookup_type longident.Asttypes.txt env in
247-
let t = Env.find_type p env in
244+
let p, t = Env.find_type_by_name longident.Asttypes.txt env in
248245
Printtyp.type_declaration env
249246
(Ident.create_persistent (* Incorrect, but doesn't matter. *)
250247
(Path.last p))
@@ -275,7 +272,7 @@ let type_in_env ?(verbosity=0) ?keywords env ppf expr =
275272
with _ ->
276273
try
277274
let cstr_desc =
278-
Env.lookup_constructor longident.Asttypes.txt env
275+
Env.find_constructor_by_name longident.Asttypes.txt env
279276
in
280277
(*
281278
Format.pp_print_string ppf name;

0 commit comments

Comments
 (0)