Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OCaml 5.2 #1727

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d997acb
upstream: fetch latest changes from 5.2 branch.
voodoos Feb 5, 2024
74b377b
fix auto-patcher
voodoos Feb 5, 2024
903470f
typer: merge upstream changes into vendored typer
voodoos Feb 5, 2024
77087e0
upgrade: adapt to small changes in the typer
voodoos Feb 5, 2024
16e8b3d
upgrade: support for hidden dependencies
voodoos Feb 5, 2024
6b9143f
Use new iterator to perform locate and occurrences
voodoos Feb 7, 2024
f721769
Build with new Texp_function nodes
voodoos Feb 7, 2024
a9a35c4
config: bump magic number
voodoos Feb 7, 2024
90c1977
shape_reduce: fix late usage of local_store
voodoos Feb 7, 2024
fc6bff8
tests: promote improved tests
voodoos Feb 7, 2024
5b79590
opam: bump required ocaml version
voodoos Feb 7, 2024
64bf748
construct: handle function arity better
voodoos Feb 8, 2024
0bcc770
tests: new function recovery test with 5.1 output
voodoos Feb 8, 2024
1b3d09b
tests: more expected function recovery
voodoos Feb 9, 2024
db98a34
functions: add uid to [Texp_newtype'] nodes
voodoos Feb 9, 2024
0f8e1a9
env_lookup: log in all cases
voodoos Feb 12, 2024
b292417
destruct: add test for fun. param. case analysis
voodoos Feb 12, 2024
e3a1803
tests: more updates
voodoos Feb 14, 2024
7599d3c
tests: test for fun recovery saved parts
voodoos Feb 14, 2024
b5a5297
squash: commit change to handle newtype'
voodoos Feb 14, 2024
c6c5186
parser: remove old lwt extension
voodoos Feb 14, 2024
1ed2652
Try to restore function recovery
voodoos Feb 14, 2024
ef9b1cb
tests: promote changes
voodoos Feb 14, 2024
df79a74
printtyped: expose expression printing
voodoos Feb 16, 2024
123a40e
tests: push test changes with remaining FIXMEs
voodoos Feb 16, 2024
fee9181
destruct: wip: stop raising when called on function parameters
voodoos Feb 16, 2024
74191f1
Prepare for preview release
voodoos Feb 16, 2024
f372f46
recovery: fix issue with function recovery
voodoos Feb 19, 2024
c6df10f
tests: more function recovery test
voodoos Feb 19, 2024
bfe31e5
recovery: fix erroneous type repr
voodoos Feb 19, 2024
13d7c14
test: promote improvements in testsuite
voodoos Feb 19, 2024
2ad9d01
occurrences: refactor and remove code related to project-wide occurre…
voodoos Feb 19, 2024
1f9c44c
occurrences: introduce a cache for the index
voodoos Feb 20, 2024
b0d13d5
index: remove unused index_format
voodoos Feb 22, 2024
96a95bd
index: re-add missing function
voodoos Feb 22, 2024
278872f
occurrences: use the cache, Luke !
voodoos Feb 29, 2024
04adde9
shapes: don't read_back entire modules in alias case
voodoos Mar 1, 2024
f37f72a
Test case and changelog for #1739
xvw Apr 8, 2024
07adfdc
Refactor `destruct`
xvw Apr 8, 2024
9f38a32
Fix #1739: destruct in function arguments
xvw Apr 8, 2024
615014e
Additional tests using 1-elt sum/record
xvw Apr 9, 2024
86e76b3
Add more bunch of test and remove old FIXME
xvw Apr 10, 2024
df12650
Externalize `included_in` for location overlapping
xvw Apr 12, 2024
3af2514
Add labeled argument for `Location_aux.included`
xvw Apr 15, 2024
5e50cc6
upstream: pull changes from ocaml/ocaml
voodoos Apr 15, 2024
ec74925
Merge changes in vendored typer and update analysis
voodoos Apr 16, 2024
884c078
Merge pull request #10 from xvw/handle-destruct-in-function-arg
voodoos Apr 16, 2024
8eedc4d
Fix a typo in lexer_raw
voodoos Apr 26, 2024
7ab04c8
hidden_path: use distinct source and build paths
voodoos Apr 26, 2024
2336424
Attempt to please ocaml-ci
voodoos Apr 30, 2024
e66212f
hidden path: change H -> BH and SH in dot_merlin_reader
voodoos Apr 30, 2024
4f342e8
Small refactors, added documentation and tests update
voodoos May 2, 2024
13e7f94
context: improve detection of cursor position
voodoos May 2, 2024
1687121
occurrences: do not attempt to shrink the selection of idents that ne…
voodoos May 2, 2024
be60076
hidden_deps: test showing multiple issues
voodoos May 2, 2024
3b22496
hidden_deps: fix new load_path init function
voodoos May 2, 2024
3c36928
hidden_deps: add hidden paths to source and cmt paths
voodoos May 2, 2024
4bc3cf6
hidden_deps: show that the dep is hidden in the test
voodoos May 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: CI
# events but only for the master branch
on:
push:
branches: [ '501' ]
branches: [ '502-preview' ]
paths-ignore:
- '**.md'
- '**.txt'
Expand All @@ -16,7 +16,7 @@ on:
- 'vim/**'
- '**/emacs-lint.yml'
pull_request:
branches: [ '501' ]
branches: [ '502-preview' ]
paths-ignore:
- '**.md'
- '**.txt'
Expand All @@ -40,7 +40,7 @@ jobs:
- ubuntu-latest
# - windows-latest
ocaml-compiler:
- "5.1.1"
- "5.2"
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}

Expand Down
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
merlin 4.14-preview
===================
Fri Feb 16 17:31:42 CET 2024

+ merlin binary
- Preliminary support for OCaml 5.2

merlin 4.13.1
=============
Fri Dec 1 15:00:42 CET 2023
Expand Down
2 changes: 1 addition & 1 deletion dot-merlin-reader.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build: [
["dune" "build" "-p" name "-j" jobs]
]
depends: [
"ocaml" {>= "5.1" & < "5.2" }
"ocaml" {>= "5.2" }
"dune" {>= "2.9.0"}
"merlin-lib" {>= "4.9"}
"ocamlfind" {>= "1.6.0"}
Expand Down
2 changes: 1 addition & 1 deletion merlin-lib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build: [
["dune" "build" "-p" name "-j" jobs]
]
depends: [
"ocaml" {>= "5.1.1" & < "5.2"}
"ocaml" {>= "5.2" & < "5.3"}
"dune" {>= "2.9.0"}
"csexp" {>= "1.5.1"}
"menhir" {dev & >= "20201216"}
Expand Down
2 changes: 1 addition & 1 deletion merlin.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build: [
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
depends: [
"ocaml" {>= "5.1" & < "5.2"}
"ocaml" {>= "5.2" & < "5.3"}
voodoos marked this conversation as resolved.
Show resolved Hide resolved
"dune" {>= "2.9.0"}
"merlin-lib" {= version}
"dot-merlin-reader" {>= "4.9"}
Expand Down
51 changes: 51 additions & 0 deletions src/analysis/ast_iterators.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
open Std
open Typedtree

let {Logger. log} = Logger.for_section "iterators"

(* The compiler contains an iterator that aims to gather definitions but
ignores local values like let-in expressions and local type definition. To
provide occurrences in the active buffer we extend the compiler's iterator with
these cases. *)
let iter_on_defs ~uid_to_locs_tbl =
let log = log ~title:"iter_on_defs" in
let register_uid uid fragment =
let loc = Misc_utils.loc_of_decl ~uid fragment in
Option.iter loc ~f:(fun loc ->
Types.Uid.Tbl.add uid_to_locs_tbl uid loc)
in
let iter_decl = Cmt_format.iter_on_declarations ~f:register_uid in
let register_uid uid loc =
Types.Uid.Tbl.add uid_to_locs_tbl uid loc
in
{ iter_decl with
expr = (fun sub ({ exp_extra; _ } as expr) ->
List.iter exp_extra ~f:(fun (exp_extra, _loc, _attr) ->
match exp_extra with
| Texp_newtype' (typ_id, typ_name, uid) ->
log "Found newtype %s wit id %a (%a)\n%!" typ_name.txt
Logger.fmt (Fun.flip Ident.print_with_scope typ_id)
Logger.fmt (fun fmt -> Location.print_loc fmt typ_name.loc);
register_uid uid typ_name;
()
| _ -> ());
iter_decl.expr sub expr);
}

let build_uid_to_locs_tbl ~(local_defs : Mtyper.typedtree) () =
let uid_to_locs_tbl : string Location.loc Types.Uid.Tbl.t =
Types.Uid.Tbl.create 64
in
let iter = iter_on_defs ~uid_to_locs_tbl in
begin match local_defs with
| `Interface sign ->
iter.signature iter sign
| `Implementation str ->
iter.structure iter str end;
uid_to_locs_tbl

let iter_on_usages ~f (local_defs : Mtyper.typedtree) =
let iter = Cmt_format.iter_on_occurrences ~f in
begin match local_defs with
| `Interface signature -> iter.signature iter signature
| `Implementation structure -> iter.structure iter structure end
10 changes: 6 additions & 4 deletions src/analysis/completion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ let make_candidate ~get_doc ~attrs ~exact ~prefix_path name ?loc ?path ty =
| Some p, Some loc ->
let namespace = (* FIXME: that's just terrible *)
match kind with
| `Value -> `Vals
| `Type -> `Type
| `Value -> Shape.Sig_component_kind.Value
| `Type -> Type
| _ -> assert false
in
begin match get_doc (`Completion_entry (namespace, p, loc)) with
Expand Down Expand Up @@ -280,7 +280,7 @@ let fold_sumtype_constructors ~env ~init ~f t =
(Path.name path);
begin match Env.find_type_descrs path env with
| exception Not_found -> init
| Type_record _ | Type_abstract | Type_open -> init
| Type_record _ | Type_abstract _ | Type_open -> init
| Type_variant (constrs, _) ->
List.fold_right constrs ~init ~f
end
Expand Down Expand Up @@ -650,7 +650,9 @@ let branch_complete buffer ?get_doc ?target_type ?kinds ~keywords prefix =
let lbls = Datarepr.labels_of_type p decl in
let labels = List.map lbls ~f:(fun (_,lbl) ->
try
let _, lbl_arg, lbl_res = Ctype.instance_label false lbl in
let _, lbl_arg, lbl_res =
Ctype.instance_label ~fixed:false lbl
in
begin try
Ctype.unify_var env ty lbl_res;
with _ -> ()
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/completion.mli
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ val map_entry : ('a -> 'b) ->

val branch_complete
: Mconfig.t
-> ?get_doc:([> `Completion_entry of Namespace.t
-> ?get_doc:([> `Completion_entry of Env_lookup.Namespace.t
* Path.t * Location.t ] -> [> `Found of string ])
-> ?target_type:Types.type_expr
-> ?kinds:Compl.kind list
Expand Down
56 changes: 37 additions & 19 deletions src/analysis/construct.ml
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,23 @@ module Gen = struct
in
fun env label ty ->
let open Asttypes in
let make_param arg_label pat =
{
Parsetree.pparam_loc = Location.none;
pparam_desc = Pparam_val (arg_label, None, pat)

}
in

match label with
| Labelled s | Optional s ->
(* Pun for labelled arguments *)
Ast_helper.Pat.var ( Location.mknoloc s), s
make_param label (Ast_helper.Pat.var (Location.mknoloc s)), s
| Nolabel -> begin match get_desc ty with
| Tconstr (path, _, _) ->
let name = uniq_name env (Path.last path) in
Ast_helper.Pat.var (Location.mknoloc name), name
| _ -> Ast_helper.Pat.any (), "_" end
make_param label (Ast_helper.Pat.var (Location.mknoloc name)), name
| _ -> make_param label (Ast_helper.Pat.any ()), "_" end
in

let constructor env type_expr path constrs =
Expand Down Expand Up @@ -425,7 +433,7 @@ module Gen = struct
(List.map labels ~f:(fun l -> l.Types.lbl_name)));

let labels = List.map labels ~f:(fun ({ lbl_name; _ } as lbl) ->
let _, arg, res = Ctype.instance_label true lbl in
let _, arg, res = Ctype.instance_label ~fixed:true lbl in
Ctype.unify env res typ ;
let lid =
Util.maybe_prefix env
Expand Down Expand Up @@ -477,21 +485,31 @@ module Gen = struct
match def with
| Type_variant (constrs, _) -> constructor env rtyp path constrs
| Type_record (labels, _) -> record env rtyp path labels
| Type_abstract | Type_open -> []
| Type_abstract _ | Type_open -> []
end
| Tarrow (label, tyleft, tyright, _) ->
let argument, name = make_arg env label tyleft in
let value_description = {
val_type = tyleft;
val_kind = Val_reg;
val_loc = Location.none;
val_attributes = [];
val_uid = Uid.mk ~current_unit:(Env.get_unit_name ());
}
in
let env = Env.add_value (Ident.create_local name) value_description env in
let exps = arrow_rhs env tyright in
List.map exps ~f:(Ast_helper.Exp.fun_ label None argument)
| Tarrow _ ->
let rec left_types acc env ty =
match get_desc ty with
| Tarrow (label, tyleft, tyright, _) ->
let arg, name = make_arg env label tyleft in
let value_description = {
val_type = tyleft;
val_kind = Val_reg;
val_loc = Location.none;
val_attributes = [];
val_uid = Uid.mk ~current_unit:(Env.get_unit_name ());
}
in
let env =
Env.add_value (Ident.create_local name) value_description env
in
left_types (arg :: acc) env tyright
| _ -> List.rev acc, ty, env
in
let arguments, body_type, env = left_types [] env rtyp in
let exps = arrow_rhs env body_type in
List.map exps ~f:(fun e ->
Ast_helper.Exp.function_ arguments None (Pfunction_body e))
| Ttuple types ->
let choices = List.map types ~f:(exp_or_hole env)
|> Util.combinations
Expand Down Expand Up @@ -548,7 +566,7 @@ module Gen = struct
end

let needs_parentheses e = match e.Parsetree.pexp_desc with
| Pexp_fun _
| Pexp_function _
| Pexp_lazy _
| Pexp_apply _
| Pexp_variant (_, Some _)
Expand Down
17 changes: 13 additions & 4 deletions src/analysis/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ let cursor_on_longident_end
match lid with
| Longident.Lident _ -> true
| _ ->
let end_offset = loc.loc_end.pos_cnum in
let cstr_name_size = String.length name in
let end_offset =
loc.loc_end.pos_cnum in
let cstr_name_size =
(* FIXME: this is britle, but lids don't have precise enough location
information to handle these cases correctly. *)
let name_lenght = String.length name in
if Pprintast.needs_parens name then
name_lenght + 2
else name_lenght
in
let constr_pos =
{ loc.loc_end
with pos_cnum = end_offset - cstr_name_size }
Expand All @@ -78,9 +86,9 @@ let inspect_pattern (type a) ~cursor ~lid (p : a Typedtree.general_pattern) =
(Printtyped.pattern 0) p);
match p.pat_desc with
| Tpat_any when Longident.last lid = "_" -> None
| Tpat_var (_, str_loc) when (Longident.last lid) = str_loc.txt ->
| Tpat_var (_, str_loc, _) when (Longident.last lid) = str_loc.txt ->
None
| Tpat_alias (_, _, str_loc)
| Tpat_alias (_, _, str_loc, _)
when (Longident.last lid) = str_loc.txt ->
(* Assumption: if [Browse.enclosing] stopped on this node and not on the
subpattern, then it must mean that the cursor is on the alias. *)
Expand All @@ -107,6 +115,7 @@ let inspect_expression ~cursor ~lid e : t =
else Module_path
| Texp_ident (p, lid_loc, _) ->
let name = Path.last p in
log ~title:"inspect_context" "name is: [%s]" name;
if name = "*type-error*" then
(* For type_enclosing: it is enough to return Module_path here.
- If the cursor was on the end of the lid typing should fail anyway
Expand Down
Loading