Skip to content

Commit 7b375c0

Browse files
authored
Ocaml 5.3 (#7294)
* OCaml 5.3 + some dependency upgrades * "effect" is a reserved word now * no 4.13 * ocamlformat 0.27.0 * Use OCaml 5.3.0 * Run reanalyze on OCaml 5.2.1
1 parent 0f84ac1 commit 7b375c0

Some content is hidden

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

67 files changed

+374
-316
lines changed

.devcontainer/postCreate.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Install dev dependencies from OPAM
44
opam init -y --bare --disable-sandboxing
5-
opam switch create 5.2.1 --packages ocaml-option-static
5+
opam switch create 5.3.0 --packages ocaml-option-static
66
opam install . --deps-only -y
77

88
# For IDE support, install the OCaml language server

.github/workflows/ci.yml

+15-7
Original file line numberDiff line numberDiff line change
@@ -87,32 +87,34 @@ jobs:
8787
matrix:
8888
include:
8989
- os: ubuntu-24.04 # x64
90-
ocaml_compiler: ocaml-variants.5.2.1+options,ocaml-option-static
90+
ocaml_compiler: ocaml-variants.5.3.0+options,ocaml-option-static
9191
upload_binaries: true
9292
upload_libs: true
9393
- os: ubuntu-24.04-arm # ARM
94-
ocaml_compiler: ocaml-variants.5.2.1+options,ocaml-option-static
94+
ocaml_compiler: ocaml-variants.5.3.0+options,ocaml-option-static
9595
upload_binaries: true
9696
# Build the playground compiler and run the benchmarks on the fastest runner
9797
build_playground: true
9898
benchmarks: true
9999
- os: macos-13 # x64
100-
ocaml_compiler: 5.2.1
100+
ocaml_compiler: 5.3.0
101101
upload_binaries: true
102102
- os: macos-14 # ARM
103-
ocaml_compiler: 5.2.1
103+
ocaml_compiler: 5.3.0
104104
upload_binaries: true
105105
- os: windows-latest
106-
ocaml_compiler: 5.2.1
106+
ocaml_compiler: 5.3.0
107107
upload_binaries: true
108108

109109
# Verify that the compiler still builds with older OCaml versions
110+
- os: ubuntu-24.04
111+
ocaml_compiler: ocaml-variants.5.2.1+options,ocaml-option-static
112+
# Reanalyze does not work on OCaml 5.3.0 anymore, therefore run it on 5.2.1
113+
run_reanalyze: true
110114
- os: ubuntu-24.04
111115
ocaml_compiler: ocaml-variants.5.0.0+options,ocaml-option-static
112116
- os: ubuntu-24.04
113117
ocaml_compiler: ocaml-variants.4.14.2+options,ocaml-option-static
114-
- os: ubuntu-24.04
115-
ocaml_compiler: ocaml-variants.4.13.0+options,ocaml-option-static
116118

117119
runs-on: ${{matrix.os}}
118120

@@ -299,6 +301,12 @@ jobs:
299301
if: ${{ runner.os == 'Windows' }}
300302
run: opam exec -- make test-syntax
301303

304+
- name: "Syntax: Run reanalyze"
305+
if: matrix.run_reanalyze
306+
run: |
307+
opam install reanalyze
308+
opam exec -- make reanalyze
309+
302310
- name: Build runtime/stdlib
303311
run: ./scripts/buildRuntime.sh
304312
shell: bash

.ocamlformat

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
profile = default
2-
version = 0.26.2
2+
version = 0.27.0
33

44
field-space = tight-decl
55
break-cases = toplevel
@@ -9,3 +9,4 @@ space-around-arrays = false
99
space-around-lists = false
1010
space-around-records = false
1111
space-around-variants = false
12+
parse-docstrings = false

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Make sure you have [opam](https://opam.ocaml.org/doc/Install.html) installed on
4747
opam init
4848

4949
# Any recent OCaml version works as a development compiler
50-
opam switch create 5.2.1 # can also create local switch with opam switch create
50+
opam switch create 5.3.0 # can also create local switch with opam switch create
5151

5252
# Install dev dependencies from OPAM
5353
opam install . --deps-only --with-test --with-dev-setup -y

Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ test-tools:
4040

4141
test-syntax:
4242
bash ./scripts/test_syntax.sh
43-
make reanalyze
4443
bash ./scripts/testok.sh
4544

4645
test-syntax-roundtrip:
4746
ROUNDTRIP_TEST=1 bash ./scripts/test_syntax.sh
48-
make reanalyze
4947
bash ./scripts/testok.sh
5048

5149
test-gentype:

analysis.opam

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ license: "LGPL-3.0-or-later"
77
homepage: "https://github.com/rescript-lang/rescript-compiler"
88
bug-reports: "https://github.com/rescript-lang/rescript-compiler/issues"
99
depends: [
10-
"ocaml" {>= "4.10"}
11-
"cppo" {= "1.6.9"}
10+
"ocaml" {>= "4.14"}
11+
"cppo" {= "1.8.0"}
1212
"dune"
1313
]
1414
build: [

analysis/reanalyze/src/DeadCommon.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ module Decl = struct
555555
let refIsBelow (pos : Lexing.position) =
556556
decl.pos.pos_fname <> pos.pos_fname
557557
|| decl.pos.pos_cnum < pos.pos_cnum
558-
&& (* not a function defined inside a function, e.g. not a callback *)
558+
&&
559+
(* not a function defined inside a function, e.g. not a callback *)
559560
decl.posEnd.pos_cnum < pos.pos_cnum
560561
in
561562
refs |> PosSet.exists refIsBelow

analysis/src/SignatureHelp.ml

+31-31
Original file line numberDiff line numberDiff line change
@@ -553,44 +553,44 @@ let signatureHelp ~path ~pos ~currentFile ~debug ~allowForConstructorPayloads =
553553
let offset = ref 0 in
554554
Some
555555
(`InlineRecord
556-
(fields
557-
|> List.map (fun (field : field) ->
558-
let startOffset = !offset in
559-
let argText =
560-
Printf.sprintf "%s%s: %s" field.fname.txt
561-
(if field.optional then "?" else "")
562-
(Shared.typeToString
563-
(if field.optional then
564-
Utils.unwrapIfOption field.typ
565-
else field.typ))
566-
in
567-
let endOffset =
568-
startOffset + String.length argText
569-
in
570-
offset := endOffset + String.length ", ";
571-
(argText, field, (startOffset, endOffset)))))
556+
(fields
557+
|> List.map (fun (field : field) ->
558+
let startOffset = !offset in
559+
let argText =
560+
Printf.sprintf "%s%s: %s" field.fname.txt
561+
(if field.optional then "?" else "")
562+
(Shared.typeToString
563+
(if field.optional then
564+
Utils.unwrapIfOption field.typ
565+
else field.typ))
566+
in
567+
let endOffset =
568+
startOffset + String.length argText
569+
in
570+
offset := endOffset + String.length ", ";
571+
(argText, field, (startOffset, endOffset)))))
572572
| Args [(typ, _)] ->
573573
Some
574574
(`SingleArg
575-
( typ |> Shared.typeToString,
576-
docsForLabel ~file:full.file ~package:full.package
577-
~supportsMarkdownLinks typ ))
575+
( typ |> Shared.typeToString,
576+
docsForLabel ~file:full.file ~package:full.package
577+
~supportsMarkdownLinks typ ))
578578
| Args args ->
579579
let offset = ref 0 in
580580
Some
581581
(`TupleArg
582-
(args
583-
|> List.map (fun (typ, _) ->
584-
let startOffset = !offset in
585-
let argText = typ |> Shared.typeToString in
586-
let endOffset =
587-
startOffset + String.length argText
588-
in
589-
offset := endOffset + String.length ", ";
590-
( argText,
591-
docsForLabel ~file:full.file ~package:full.package
592-
~supportsMarkdownLinks typ,
593-
(startOffset, endOffset) ))))
582+
(args
583+
|> List.map (fun (typ, _) ->
584+
let startOffset = !offset in
585+
let argText = typ |> Shared.typeToString in
586+
let endOffset =
587+
startOffset + String.length argText
588+
in
589+
offset := endOffset + String.length ", ";
590+
( argText,
591+
docsForLabel ~file:full.file ~package:full.package
592+
~supportsMarkdownLinks typ,
593+
(startOffset, endOffset) ))))
594594
in
595595
let label =
596596
constructor.name ^ "("

compiler/bsb/bsb_exception.ml

+6-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ let print (fmt : Format.formatter) (x : error) =
4040
| Conflict_module (modname, dir1, dir2) ->
4141
Format.fprintf fmt
4242
"@{<error>Error:@} %s found in two directories: (%s, %s)\n\
43-
File names must be unique per project" modname dir1 dir2
43+
File names must be unique per project"
44+
modname dir1 dir2
4445
| No_implementation modname ->
4546
Format.fprintf fmt "@{<error>Error:@} %s does not have implementation file"
4647
modname
@@ -51,12 +52,14 @@ let print (fmt : Format.formatter) (x : error) =
5152
"File \"bsconfig.json\", line 1\n\
5253
@{<error>Error:@} package @{<error>%s@} is not found\n\
5354
It's the basic, required package. If you have it installed globally,\n\
54-
Please run `npm link rescript` to make it available" name
55+
Please run `npm link rescript` to make it available"
56+
name
5557
else
5658
Format.fprintf fmt
5759
"File \"bsconfig.json\", line 1\n\
5860
@{<error>Error:@} package @{<error>%s@} not found or built\n\
59-
- Did you install it?" name
61+
- Did you install it?"
62+
name
6063
| Json_config (pos, s) ->
6164
Format.fprintf fmt
6265
"File %S, line %d:\n\

compiler/bsb/bsb_ninja_check.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ let record ~(package_kind : Bsb_package_kind.t) ~per_proj_dir ~file
114114
record_global_atime buf Sys.executable_name;
115115
Ext_list.iter config.ppx_files (fun {name; args = _} ->
116116
try record_global_atime buf name
117-
with _ -> (* record the ppx files as a best effort *)
118-
());
117+
with _ ->
118+
(* record the ppx files as a best effort *)
119+
());
119120
let oc = open_out_bin file in
120121
Ext_buffer.output_buffer oc buf;
121122
close_out oc

compiler/bsb/bsb_ninja_gen.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ let emit_bsc_lib_includes (bs_dependencies : Bsb_config_types.dependencies)
4040
let all_includes source_dirs =
4141
source_dirs
4242
@ Ext_list.map bs_dependencies (fun x -> x.package_install_path)
43-
@ (* for external includes, if it is absolute path, leave it as is
43+
@
44+
(* for external includes, if it is absolute path, leave it as is
4445
for relative path './xx', we need '../.././x' since we are in
4546
[lib/bs], [build] is different from merlin though
4647
*)

compiler/bsb/bsb_parse_sources.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,9 @@ and parse_sources (cxt : cxt) (sources : Ext_json_types.t) =
322322
| Arr file_groups -> parsing_arr_sources cxt file_groups.content
323323
| _ -> parsing_single_source cxt sources
324324

325-
let scan ~package_kind ~root ~cut_generators ~(* ~namespace *)
326-
ignored_dirs x : t =
325+
let scan ~package_kind ~root ~cut_generators
326+
~(* ~namespace *)
327+
ignored_dirs x : t =
327328
parse_sources
328329
{
329330
ignored_dirs;

compiler/bsb_helper/bsb_db_decode.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ and decode_single (x : string) (offset : cursor) : group =
5151
let modules = decode_modules x offset module_number in
5252
let dir_info_offset = !offset in
5353
let module_info_offset = String.index_from x dir_info_offset '\n' + 1 in
54-
let dir_length = Char.code x.[module_info_offset] - 48 (* Char.code '0'*) in
54+
let dir_length =
55+
Char.code x.[module_info_offset] - 48
56+
(* Char.code '0'*)
57+
in
5558
offset := module_info_offset + 1 + (dir_length * module_number) + 1;
5659
Group {modules; dir_info_offset; module_info_offset; dir_length})
5760
else Dummy

compiler/core/js_analyzer.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ let free_variables (stats : idents_stats) =
5858
| Fun {env}
5959
(* a optimization to avoid walking into function again
6060
if it's already comuted
61-
*) ->
61+
*)
62+
->
6263
stats.used_idents <-
6364
Set_ident.union (Js_fun_env.get_unbounded env) stats.used_idents
6465
| _ -> super.expression self exp);

compiler/core/js_cmj_format.ml

+8-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type cmj_value = {
3333
(** Either constant or closed functor *)
3434
}
3535

36-
type effect = string option
36+
type effect_ = string option
3737

3838
let single_na = Single Lam_arity.na
3939

@@ -52,7 +52,7 @@ type t = {
5252
case: Ext_js_file_kind.case;
5353
}
5454

55-
let make ~(values : cmj_value Map_string.t) ~effect ~package_spec ~case : t =
55+
let make ~(values : cmj_value Map_string.t) ~effect_ ~package_spec ~case : t =
5656
{
5757
values =
5858
Map_string.to_sorted_array_with_f values (fun k v ->
@@ -61,7 +61,7 @@ let make ~(values : cmj_value Map_string.t) ~effect ~package_spec ~case : t =
6161
arity = v.arity;
6262
persistent_closed_lambda = v.persistent_closed_lambda;
6363
});
64-
pure = effect = None;
64+
pure = effect_ = None;
6565
package_spec;
6666
case;
6767
}
@@ -113,7 +113,7 @@ let get_result mid_val =
113113
match mid_val.persistent_closed_lambda with
114114
| Some
115115
(Lconst
116-
(Const_js_null | Const_js_undefined _ | Const_js_true | Const_js_false))
116+
(Const_js_null | Const_js_undefined _ | Const_js_true | Const_js_false))
117117
| None ->
118118
mid_val
119119
| Some _ ->
@@ -131,8 +131,10 @@ let rec binary_search_aux arr lo hi (key : string) =
131131
let lo_val = Array.unsafe_get arr lo in
132132
if lo_val.name = key then get_result lo_val else not_found key
133133
else binary_search_aux arr lo mid key
134-
else if (* a[lo] =< a[mid] < key <= a[hi] *)
135-
lo = mid then
134+
else if
135+
(* a[lo] =< a[mid] < key <= a[hi] *)
136+
lo = mid
137+
then
136138
let hi_val = Array.unsafe_get arr hi in
137139
if hi_val.name = key then get_result hi_val else not_found key
138140
else binary_search_aux arr mid hi key

compiler/core/js_cmj_format.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type cmj_value = {
5252
persistent_closed_lambda: Lam.t option; (* Either constant or closed functor *)
5353
}
5454

55-
type effect = string option
55+
type effect_ = string option
5656

5757
type keyed_cmj_value = {
5858
name: string;
@@ -69,7 +69,7 @@ type t = {
6969

7070
val make :
7171
values:cmj_value Map_string.t ->
72-
effect:effect ->
72+
effect_:effect_ ->
7373
package_spec:Js_packages_info.t ->
7474
case:Ext_js_file_kind.case ->
7575
t

compiler/core/js_dump.ml

+6-5
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ and pp_function ~return_unit ~async ~is_method ?directive cxt (f : P.t)
436436
since it can be either [int] or [string]
437437
*)
438438
and pp_one_case_clause :
439-
'a. _ -> P.t -> (P.t -> 'a -> unit) -> 'a * J.case_clause -> _ =
439+
'a. _ -> P.t -> (P.t -> 'a -> unit) -> 'a * J.case_clause -> _ =
440440
fun cxt f pp_cond
441441
(switch_case, ({switch_body; should_break; comment} : J.case_clause)) ->
442442
P.newline f;
@@ -467,8 +467,7 @@ and pp_one_case_clause :
467467
cxt
468468

469469
and loop_case_clauses :
470-
'a. cxt -> P.t -> (P.t -> 'a -> unit) -> ('a * J.case_clause) list -> cxt
471-
=
470+
'a. cxt -> P.t -> (P.t -> 'a -> unit) -> ('a * J.case_clause) list -> cxt =
472471
fun cxt f pp_cond cases ->
473472
Ext_list.fold_left cases cxt (fun acc x -> pp_one_case_clause acc f pp_cond x)
474473

@@ -693,7 +692,8 @@ and expression_desc cxt ~(level : int) f x : cxt =
693692
{[ 0. - x ]}
694693
{[ 0.00 - x ]}
695694
{[ 0.000 - x ]}
696-
*) ->
695+
*)
696+
->
697697
P.cond_paren_group f (level > 13) (fun _ ->
698698
P.string f
699699
(match desc with
@@ -1214,7 +1214,8 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
12141214
semi f;
12151215
cxt)
12161216
(* There MUST be a space between the return and its
1217-
argument. A line return will not work *))
1217+
argument. A line return will not work *)
1218+
)
12181219
| Int_switch (e, cc, def) ->
12191220
P.string f L.switch;
12201221
P.space f;

0 commit comments

Comments
 (0)