Skip to content

Commit 23a8ce8

Browse files
authored
Merge 5.2.0minus 3 (#119)
* Update import scripts * Import ocaml sources for oxcaml/oxcaml@e1efceb89a5 * Automatic merges * Commit conflicts * Remove files that were deleted in flambda * Apply old diff to language_extension * Resolve conflicts * Resolve errors outside of merlin-specific code * Resolve more issues * Fix more issues * Update magic number script * Bump magic numbers * Promote tests * Add comments about subdirectory * Use Ast_helper.Sg.mk
1 parent 51aee26 commit 23a8ce8

File tree

177 files changed

+24401
-53394
lines changed

Some content is hidden

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

177 files changed

+24401
-53394
lines changed

import-added-ocaml-source-files.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,28 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
77
# Script arguments with their default values
88
commitish=main
99
repository=https://github.com/ocaml-flambda/flambda-backend
10-
subdirectory=ocaml
10+
subdirectory=.
11+
old_subdirectory=.
1112

1213
function usage () {
1314
cat <<USAGE
14-
Usage: $0 [COMMITISH [REPO [SUBDIRECTORY]]]
15+
Usage: $0 [COMMITISH [REPO [SUBDIRECTORY [OLD_SUBDIRECTORY]]]]
1516
1617
Fetches any new files that previously hadn't been imported. This ignores
1718
files outside of *directories* that were previously imported,
1819
so if a whole new directory is added, you may need to manually
1920
add the new file.
21+
22+
See usage information for ./import-ocaml-source.sh for more info about
23+
the subdirectory arguments.
2024
USAGE
2125
}
2226

23-
if [[ $# -le 3 ]]; then
27+
if [[ $# -le 4 ]]; then
2428
commitish="${1-$commitish}"
2529
repository="${2-$repository}"
2630
subdirectory="${3-$subdirectory}"
31+
old_subdirectory="${4-$old_subdirectory}"
2732
else
2833
usage >&2
2934
exit 1
@@ -39,7 +44,7 @@ esac
3944
# First, fetch the new flambda-backend sources (which include ocaml-jst).
4045

4146
function sorted_files_at_committish() {
42-
git ls-tree -r --name-only "$1" | sort
47+
git ls-tree -r --name-only "$1" "$2" | sed "s#^$2/##" | sort
4348
}
4449

4550
git fetch "$repository" "$(cat upstream/ocaml_flambda/base-rev.txt)"
@@ -48,15 +53,15 @@ rev=$(git rev-parse FETCH_HEAD)
4853

4954
function files_new_at_fetch_head() {
5055
comm -13 \
51-
<(sorted_files_at_committish "$(cat upstream/ocaml_flambda/base-rev.txt)") \
52-
<(sorted_files_at_committish FETCH_HEAD)
56+
<(sorted_files_at_committish "$(cat upstream/ocaml_flambda/base-rev.txt)" "$old_subdirectory") \
57+
<(sorted_files_at_committish FETCH_HEAD "$subdirectory")
5358
}
5459

5560
function directories_from_previous_import() {
5661
comm -12 \
5762
<(cd src/ocaml; ls -d */) \
5863
<(cd upstream/ocaml_flambda; ls -d */) \
59-
| xargs -n 1 printf "^$subdirectory/%s\n"
64+
| xargs -n 1 printf "^%s\n"
6065
}
6166

6267
files=$(files_new_at_fetch_head | grep -f <(directories_from_previous_import))
@@ -69,9 +74,9 @@ for file in $files; do
6974
case ${answer} in
7075
y|Y|"" )
7176
echo "Importing $file"
72-
ocaml_flambda_file=upstream/ocaml_flambda/"${file#$subdirectory/}"
77+
ocaml_flambda_file=upstream/ocaml_flambda/"${file}"
7378
git show "FETCH_HEAD:$file" > "$ocaml_flambda_file"
74-
cp "$ocaml_flambda_file" src/$file
79+
cp "$ocaml_flambda_file" src/ocaml/$file
7580
;;
7681
* )
7782
echo "Skipping $file; run '$0' again in order to make a different decision"

import-ocaml-source.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
44

55
# Script arguments with their default values
66
repository=https://github.com/ocaml-flambda/flambda-backend
7-
subdirectory=ocaml
7+
subdirectory=.
8+
old_subdirectory=.
89

910
function usage () {
1011
cat <<USAGE
11-
Usage: $0 COMMITISH [REPO [SUBDIRECTORY]]
12+
Usage: $0 COMMITISH [REPO [SUBDIRECTORY [OLD_SUBDIRECTORY]]]
1213
1314
Fetch the new compiler sources and patch Merlin to keep Merlin's local copies of
1415
things in sync. By default, this will pull the COMMITISH branch from
@@ -22,6 +23,12 @@ This attempts to import new files from the compiler by running the
2223
try making matched pairs of files in this repository with the right names: one
2324
in "upstream/ocaml_flambda/", and one in "src/ocaml". Then running the script
2425
will pull in the named file(s).
26+
27+
The SUBDIRECTORY argument is useful when importing from a repository that buries
28+
the relevant compiler files inside a subdirectory. This used to be the case for
29+
flambda (files were under an "ocaml/" direcotry), although it is no longer the
30+
case. The OLD_SUBDIRECTORY argument is useful for when the directory structure
31+
has changed since the last import.
2532
USAGE
2633
}
2734

@@ -47,9 +54,12 @@ else
4754
exit 1
4855
fi
4956

50-
if [[ $# -le 3 ]]; then
57+
if [[ $# -le 4 ]]; then
5158
repository="${2-$repository}"
59+
# Although the subdirectory arguments are probably no longer useful, it doesn't hurt
60+
# to keep them around in case they ever are of use.
5261
subdirectory="${3-$subdirectory}"
62+
old_subdirectory="${4-$old_subdirectory}"
5363
else
5464
usage >&2
5565
exit 1
@@ -68,7 +78,7 @@ old_base_rev="$(cat upstream/ocaml_flambda/base-rev.txt)"
6878
current_head="$(git symbolic-ref --short HEAD)"
6979

7080
# First, add any files that have been added since the last import.
71-
./import-added-ocaml-source-files.sh "$commitish" "$repository" "$subdirectory"
81+
./import-added-ocaml-source-files.sh "$commitish" "$repository" "$subdirectory" "$old_subdirectory"
7282

7383
# Then, fetch the new flambda-backend sources (which include ocaml-jst) and
7484
# copy into upstream/ocaml_flambda
@@ -77,7 +87,12 @@ rev=$(git rev-parse FETCH_HEAD)
7787
cd upstream/ocaml_flambda
7888
echo $rev > base-rev.txt
7989
for file in $(git ls-tree --name-only -r HEAD | grep -v base-rev.txt); do
80-
git show "FETCH_HEAD:$subdirectory/$file" > "$file";
90+
if [[ "$subdirectory" = "." ]]; then
91+
git_file="$file"
92+
else
93+
git_file="$subdirectory/$file"
94+
fi
95+
git show "FETCH_HEAD:$git_file" > "$file"
8196
done
8297
git add -u .
8398
cd ../..

src/analysis/construct.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module Util = struct
5151
(Predef.path_bool, construct "false");
5252
(Predef.path_unit, construct "()");
5353
(Predef.path_exn, ident "exn");
54-
(Predef.path_array, Ast_helper.Exp.array []);
54+
(Predef.path_array, Ast_helper.Exp.array Mutable []);
5555
(Predef.path_nativeint, constant (Pconst_integer ("0", Some 'n')));
5656
(Predef.path_int32, constant (Pconst_integer ("0", Some 'l')));
5757
(Predef.path_int64, constant (Pconst_integer ("0", Some 'L')));

src/analysis/destruct.ml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -575,13 +575,7 @@ module Conv = struct
575575
(* PR#7330 *)
576576
mkpat (Ppat_var nm)
577577
| Tpat_any | Tpat_var _ -> mkpat Ppat_any
578-
| Tpat_constant c -> begin
579-
match Untypeast.constant c with
580-
| `Jane_syntax c ->
581-
Jane_syntax.Layouts.pat_of (Lpat_constant c)
582-
~loc:!Ast_helper.default_loc
583-
| `Parsetree c -> mkpat (Ppat_constant c)
584-
end
578+
| Tpat_constant c -> mkpat (Ppat_constant (Untypeast.constant c))
585579
| Tpat_alias (p, _, _, _, _) -> loop p
586580
| Tpat_tuple lst ->
587581
let lst = List.map ~f:(fun (lbl, p) -> (lbl, loop p)) lst in
@@ -617,17 +611,16 @@ module Conv = struct
617611
mkpat (Ppat_record (fields, Open))
618612
| Tpat_array (mut, _, lst) ->
619613
let lst = List.map ~f:loop lst in
620-
begin
614+
let mut : Asttypes.mutable_flag =
621615
match mut with
622616
| Mutable mode ->
623617
assert (
624618
Mode.Alloc.Comonadic.Const.eq mode
625619
Mode.Alloc.Comonadic.Const.legacy);
626-
mkpat (Ppat_array lst)
627-
| Immutable ->
628-
Jane_syntax.Immutable_arrays.pat_of ~loc:pat.pat_loc
629-
(Iapat_immutable_array lst)
630-
end
620+
Mutable
621+
| Immutable -> Immutable
622+
in
623+
mkpat (Ppat_array (mut, lst))
631624
| Tpat_lazy p -> mkpat (Ppat_lazy (loop p))
632625
in
633626
let ps = loop typed in

src/analysis/ppx_expand.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ let get_ppxed_source ~ppxed_parsetree ~pos ppx_kind_with_attr :
142142
}
143143
| Sig_item _, attr_loc ->
144144
let exp =
145-
Pprintast.signature Format.str_formatter (List.rev !signature);
145+
Pprintast.signature Format.str_formatter
146+
(Ast_helper.Sg.mk (List.rev !signature));
146147
Format.flush_str_formatter ()
147148
in
148149
{ code = exp; attr_start = attr_loc.loc_start; attr_end = attr_loc.loc_end }

src/analysis/ptyp_of_type.ml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@ let rec module_type =
2828
let out = module_type type_out in
2929
Mty.functor_ param out
3030
| Mty_strengthen (mty, path, _aliasability) ->
31-
Jane_syntax.Strengthen.mty_of ~loc:Location.none
32-
{ mty = module_type mty;
33-
mod_id = Location.mknoloc (Untypeast.lident_of_path path)
34-
}
31+
Mty.strengthen ~loc:Location.none (module_type mty)
32+
(Location.mknoloc (Untypeast.lident_of_path path))
3533

3634
and core_type type_expr =
3735
let open Ast_helper in
3836
match Types.get_desc type_expr with
39-
| Tvar { name = None; _ } | Tunivar { name = None; _ } -> Typ.any ()
40-
| Tvar { name = Some s; _ } | Tunivar { name = Some s; _ } -> Typ.var s
37+
| Tvar { name = None; jkind = _ } | Tunivar { name = None; jkind = _ } ->
38+
(* CR modes: do something better here with the jkind *)
39+
Typ.any None
40+
| Tvar { name = Some s; jkind = _ } | Tunivar { name = Some s; jkind = _ } ->
41+
(* CR modes: do something better here with the jkind *)
42+
Typ.var s None
4143
| Tarrow
4244
( (label, arg_alloc_mode, ret_alloc_mode),
4345
type_expr,
@@ -121,8 +123,10 @@ and core_type type_expr =
121123
List.map
122124
~f:(fun v ->
123125
match get_desc v with
124-
| Tunivar { name = Some name; _ } | Tvar { name = Some name; _ } ->
125-
mknoloc name
126+
| Tunivar { name = Some name; jkind = _ }
127+
| Tvar { name = Some name; jkind = _ } ->
128+
(* CR modes: do something *)
129+
(mknoloc name, None)
126130
| _ -> failwith "poly: not a var")
127131
type_exprs
128132
in
@@ -272,10 +276,11 @@ and signature_item (str_item : Types.signature_item) =
272276
in
273277
Sig.text [ Docstrings.docstring str Location.none ] |> List.hd
274278

275-
and signature (items : Types.signature_item list) =
276-
List.map (group_items items) ~f:(function
277-
| Item item -> signature_item item
278-
| Type (rec_flag, type_decls) -> Ast_helper.Sig.type_ rec_flag type_decls)
279+
and signature (items : Types.signature) =
280+
Ast_helper.Sg.mk
281+
(List.map (group_items items) ~f:(function
282+
| Item item -> signature_item item
283+
| Type (rec_flag, type_decls) -> Ast_helper.Sig.type_ rec_flag type_decls))
279284

280285
and group_items (items : Types.signature_item list) =
281286
let rec read_type type_acc items =

src/analysis/stack_or_heap_enclosing.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ let from_nodes ~lsp_compat ~pos ~path =
105105
| None, Record_unboxed -> ret_no_alloc "unboxed record"
106106
| None, (Record_boxed _ | Record_float | Record_ufloat | Record_mixed _)
107107
-> ret Unexpected_no_alloc)
108-
| Texp_field (_, _, _, boxed_or_unboxed) -> (
108+
| Texp_field (_, _, _, boxed_or_unboxed, _) -> (
109109
match boxed_or_unboxed with
110110
| Boxing (alloc_mode, _) -> ret_alloc alloc_mode.mode
111111
| Non_boxing _ -> None)

src/frontend/query_commands.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,9 @@ let dispatch pipeline (type a) : a Query_protocol.t -> a = function
609609
let ppxed_parsetree = Mpipeline.ppx_parsetree pipeline in
610610
let ppx_kind_with_attr = Ppx_expand.check_extension ~parsetree ~pos in
611611
match ppx_kind_with_attr with
612-
| Some _ ->
612+
| Some ppx_kind_with_attr ->
613613
`Found
614-
(Ppx_expand.get_ppxed_source ~ppxed_parsetree ~pos
615-
(Option.get ppx_kind_with_attr))
614+
(Ppx_expand.get_ppxed_source ~ppxed_parsetree ~pos ppx_kind_with_attr)
616615
| None -> `No_ppx)
617616
| Locate (patho, ml_or_mli, pos, context) ->
618617
let typer = Mpipeline.typer_result pipeline in

src/kernel/extension.ml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,32 @@ let add_hidden_signature env sign =
142142
List.fold_left ~f:add_item ~init:env sign
143143
*)
144144

145+
(* Combine a list of signatures together into one by turning [s1; s2; ...] into:
146+
sig
147+
include s1
148+
include s2
149+
...
150+
end *)
151+
let combine_sigs sigs : Parsetree.signature =
152+
let items =
153+
List.map sigs ~f:(fun sig_ : Parsetree.signature_item ->
154+
{ psig_desc =
155+
Psig_include
156+
( { pincl_kind = Structure;
157+
pincl_mod =
158+
{ pmty_desc = Pmty_signature sig_;
159+
pmty_loc = Location.none;
160+
pmty_attributes = []
161+
};
162+
pincl_loc = Location.none;
163+
pincl_attributes = []
164+
},
165+
[] );
166+
psig_loc = Location.none
167+
})
168+
in
169+
Ast_helper.Sg.mk items
170+
145171
let register exts env =
146172
(* Log errors ? *)
147173
let try_type sg' = try type_sig env sg' with _exn -> [] in
@@ -155,8 +181,8 @@ let register exts env =
155181
exts
156182
in
157183
let process_ext e =
158-
let prv = List.concat_map ~f:parse_sig e.private_def in
159-
let pub = List.concat_map ~f:parse_sig e.public_def in
184+
let prv = List.map ~f:parse_sig e.private_def |> combine_sigs in
185+
let pub = List.map ~f:parse_sig e.public_def |> combine_sigs in
160186
(try_type prv, try_type pub)
161187
in
162188
let fakes, tops = List.split (List.map ~f:process_ext exts) in

0 commit comments

Comments
 (0)