Skip to content

Commit 10314cb

Browse files
authored
Merge branch 'master' into componentWithProps-directive
2 parents 1f9c8f1 + 2f38459 commit 10314cb

File tree

318 files changed

+3432
-2359
lines changed

Some content is hidden

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

318 files changed

+3432
-2359
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
# matrix.ocaml_compiler may contain commas
154154
- name: Get OPAM cache key
155155
shell: bash
156-
run: echo "opam_cache_key=opam-env-v6-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('dune-project') }}" | sed 's/,/-/g' >> $GITHUB_ENV
156+
run: echo "opam_cache_key=opam-env-v7-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('dune-project') }}" | sed 's/,/-/g' >> $GITHUB_ENV
157157

158158
- name: Restore OPAM environment
159159
id: cache-opam-env
@@ -191,6 +191,10 @@ jobs:
191191
if: steps.cache-opam-env.outputs.cache-hit != 'true'
192192
run: opam install . --deps-only --with-test
193193

194+
- name: "Install reanalyze"
195+
if: steps.cache-opam-env.outputs.cache-hit != 'true' && matrix.run_reanalyze
196+
run: opam install reanalyze
197+
194198
- name: Cache OPAM environment
195199
if: steps.cache-opam-env.outputs.cache-hit != 'true'
196200
uses: actions/cache/save@v4
@@ -303,9 +307,7 @@ jobs:
303307

304308
- name: "Syntax: Run reanalyze"
305309
if: matrix.run_reanalyze
306-
run: |
307-
opam install reanalyze
308-
opam exec -- make reanalyze
310+
run: opam exec -- make reanalyze
309311

310312
- name: Build runtime/stdlib
311313
run: ./scripts/buildRuntime.sh
@@ -324,7 +326,7 @@ jobs:
324326
run: git diff --ignore-cr-at-eol --exit-code tests
325327

326328
- name: Run analysis / tools tests
327-
if: runner.os != 'Windows' && matrix.os != 'ubuntu-24.04-arm'
329+
if: runner.os != 'Windows' && runner.os != 'Linux'
328330
run: opam exec -- make -C tests/analysis_tests test && make -C tests/tools_tests test
329331

330332
- name: Run gentype tests

CHANGELOG.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
1313
# 12.0.0-alpha.9 (Unreleased)
1414

15+
#### :boom: Breaking Change
16+
17+
- Clean list API. https://github.com/rescript-lang/rescript/pull/7290
18+
1519
#### :nail_care: Polish
1620

1721
- Allow single newline in JSX. https://github.com/rescript-lang/rescript/pull/7269
1822
- Editor: Always complete from Core first. Use actual native regex syntax in code snippets for regexps. https://github.com/rescript-lang/rescript/pull/7295
23+
- Add `type t` to Stdlib modules. https://github.com/rescript-lang/rescript/pull/7302
24+
- Gentype: handle null/nullable/undefined from Stdlib. https://github.com/rescript-lang/rescript/pull/7132
1925

2026
#### :bug: Bug fix
2127

@@ -25,14 +31,19 @@
2531
- Fix completion for application with tagged template. https://github.com/rescript-lang/rescript/pull/7278
2632
- Fix error message for arity in the presence of optional arguments. https://github.com/rescript-lang/rescript/pull/7284
2733
- Fix issue in functors with more than one argument (which are curried): emit nested function always. https://github.com/rescript-lang/rescript/pull/7273
28-
- Fix dot completion issue with React primitives. https://github.com/rescript-lang/rescript/pull/7292
34+
- Fix dot completion issue with React primitives. https://github.com/rescript-lang/rescript/pull/7292
35+
- Stdlib namespace for Core modules (fixes name clashes with user modules). https://github.com/rescript-lang/rescript/pull/7285
36+
- Fix runtime type check for Object in untagged variants when one variant case is `null`. https://github.com/rescript-lang/rescript/pull/7303
37+
- Fix files that were being truncated when sent to the CDN over FTP. https://github.com/rescript-lang/rescript/pull/7306
38+
- Fix better editor completion for applications. https://github.com/rescript-lang/rescript/pull/7291
2939
- Fix @react.componentWithProps no longer works with @directive("'use memo'"). https://github.com/rescript-lang/rescript/pull/7300
3040

3141
#### :house: Internal
3242

3343
- Remove ignore in res_scanner.ml . https://github.com/rescript-lang/rescript/pull/7280
3444
- Use the new stdlib modules in the analysis tests. https://github.com/rescript-lang/rescript/pull/7295
35-
- Build with OCaml 5.3.0. https://github.com/rescript-lang/rescript-compiler/pull/7294
45+
- Build with OCaml 5.3.0. https://github.com/rescript-lang/rescript/pull/7294
46+
- Simplify JSON.Decode implementation. https://github.com/rescript-lang/rescript/pull/7304
3647

3748
# 12.0.0-alpha.8
3849

analysis/src/CompletionBackEnd.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,8 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
965965
| [], [(Nolabel | Labelled _ | Optional _)] ->
966966
(* should not happen, but just ignore extra arguments *) []
967967
in
968-
match TypeUtils.extractFunctionType ~env ~package typ with
968+
969+
match TypeUtils.extractFunctionType ~env ~package ~digInto:false typ with
969970
| args, tRet when args <> [] ->
970971
let args = processApply args labels in
971972
let retType = reconstructFunctionType args tRet in
@@ -1452,6 +1453,7 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
14521453
let completionItems =
14531454
match path with
14541455
| Pdot (Pdot (Pident {name = "Js"}, "Re", _), "t", _)
1456+
| Pdot (Pdot (Pident {name = "Stdlib"}, "RegExp", _), "t", _)
14551457
| Pdot (Pident {name = "RegExp"}, "t", _) ->
14561458
(* regexps *)
14571459
create "/<regexp>/g" ~insertText:"/$0/g" ~includesSnippets:true

analysis/src/Packages.ml

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,35 @@ let newBsPackage ~rootPath =
115115
let path = [FindFiles.nameSpaceToName namespace] in
116116
[path]
117117
in
118+
let bind f x = Option.bind x f in
119+
let bsc_flags =
120+
Json.get "bsc-flags" config
121+
|> bind Json.array |> Option.value ~default:[]
122+
in
123+
let no_pervasives =
124+
bsc_flags
125+
|> List.exists (fun s -> Json.string s = Some "-nopervasives")
126+
in
118127
let opens_from_bsc_flags =
119-
let bind f x = Option.bind x f in
120-
match Json.get "bsc-flags" config |> bind Json.array with
121-
| Some l ->
122-
List.fold_left
123-
(fun opens item ->
124-
match item |> Json.string with
125-
| None -> opens
126-
| Some s -> (
127-
let parts = String.split_on_char ' ' s in
128-
match parts with
129-
| "-open" :: name :: _ ->
130-
let path = name |> String.split_on_char '.' in
131-
path :: opens
132-
| _ -> opens))
133-
[] l
134-
| None -> []
128+
List.fold_left
129+
(fun opens item ->
130+
match item |> Json.string with
131+
| None -> opens
132+
| Some s -> (
133+
let parts = String.split_on_char ' ' s in
134+
match parts with
135+
| "-open" :: name :: _ ->
136+
let path = name |> String.split_on_char '.' in
137+
path :: opens
138+
| _ -> opens))
139+
[] bsc_flags
140+
in
141+
let opens_from_pervasives =
142+
if no_pervasives then []
143+
else [["Stdlib"]; ["Pervasives"; "JsxModules"]]
135144
in
136145
let opens =
137-
["Pervasives"; "JsxModules"] :: opens_from_namespace
146+
opens_from_pervasives @ opens_from_namespace
138147
|> List.rev_append opens_from_bsc_flags
139148
|> List.map (fun path -> path @ ["place holder"])
140149
in

analysis/src/TypeUtils.ml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,12 @@ let rec extractObjectType ~env ~package (t : Types.type_expr) =
243243
| _ -> None)
244244
| _ -> None
245245

246-
let extractFunctionType ~env ~package typ =
246+
let extractFunctionType ~env ~package ?(digInto = true) typ =
247247
let rec loop ~env acc (t : Types.type_expr) =
248248
match t.desc with
249249
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> loop ~env acc t1
250250
| Tarrow (label, tArg, tRet, _, _) -> loop ~env ((label, tArg) :: acc) tRet
251-
| Tconstr (path, typeArgs, _) -> (
251+
| Tconstr (path, typeArgs, _) when digInto -> (
252252
match References.digConstructor ~env ~package path with
253253
| Some
254254
( env,
@@ -1255,14 +1255,14 @@ let pathToBuiltin path =
12551255

12561256
let completionPathFromMaybeBuiltin path =
12571257
match pathToBuiltin path with
1258-
| Some ("array", _) -> Some ["Array"]
1259-
| Some ("option", _) -> Some ["Option"]
1260-
| Some ("string", _) -> Some ["String"]
1261-
| Some ("int", _) -> Some ["Int"]
1262-
| Some ("float", _) -> Some ["Float"]
1263-
| Some ("promise", _) -> Some ["Promise"]
1264-
| Some ("list", _) -> Some ["List"]
1265-
| Some ("result", _) -> Some ["Result"]
1266-
| Some ("dict", _) -> Some ["Dict"]
1267-
| Some ("char", _) -> Some ["Char"]
1258+
| Some ("array", _) -> Some ["Stdlib"; "Array"]
1259+
| Some ("option", _) -> Some ["Stdlib"; "Option"]
1260+
| Some ("string", _) -> Some ["Stdlib"; "String"]
1261+
| Some ("int", _) -> Some ["Stdlib"; "Int"]
1262+
| Some ("float", _) -> Some ["Stdlib"; "Float"]
1263+
| Some ("promise", _) -> Some ["Stdlib"; "Promise"]
1264+
| Some ("list", _) -> Some ["Stdlib"; "List"]
1265+
| Some ("result", _) -> Some ["Stdlib"; "Result"]
1266+
| Some ("dict", _) -> Some ["Stdlib"; "Dict"]
1267+
| Some ("char", _) -> Some ["Stdlib"; "Char"]
12681268
| _ -> None

compiler/core/lam_compile.ml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -638,14 +638,14 @@ let compile output_prefix =
638638
Some ((String name, lam) :: string_table)
639639
| _, _ -> None)
640640
table (Some [])
641-
and compile_cases ?(untagged = false) ~cxt ~(switch_exp : E.t)
642-
?(default = NonComplete) ?(get_tag = fun _ -> None) ?(block_cases = [])
643-
cases : initialization =
641+
and compile_cases ?(untagged = false) ?(has_null_case = false) ~cxt
642+
~(switch_exp : E.t) ?(default = NonComplete) ?(get_tag = fun _ -> None)
643+
?(block_cases = []) cases : initialization =
644644
match use_compile_literal_cases cases ~get_tag with
645645
| Some string_cases ->
646646
if untagged then
647647
compile_untagged_cases ~cxt ~switch_exp ~block_cases ~default
648-
string_cases
648+
~has_null_case string_cases
649649
else compile_string_cases ~cxt ~switch_exp ~default string_cases
650650
| None ->
651651
cases
@@ -718,7 +718,7 @@ let compile output_prefix =
718718
else
719719
(* [e] will be used twice *)
720720
let dispatch e =
721-
let is_a_literal_case =
721+
let is_a_literal_case () =
722722
if untagged then
723723
E.is_a_literal_case
724724
~literal_cases:(get_literal_cases sw_names)
@@ -740,13 +740,17 @@ let compile output_prefix =
740740
&& List.length sw_consts = 0
741741
&& eq_default sw_num_default sw_blocks_default
742742
then
743+
let literal_cases = get_literal_cases sw_names in
744+
let has_null_case =
745+
List.mem Ast_untagged_variants.Null literal_cases
746+
in
743747
compile_cases ~untagged ~cxt
744748
~switch_exp:(if untagged then e else E.tag ~name:tag_name e)
745-
~block_cases ~default:sw_blocks_default ~get_tag:get_block_tag
746-
sw_blocks
749+
~block_cases ~has_null_case ~default:sw_blocks_default
750+
~get_tag:get_block_tag sw_blocks
747751
else
748752
[
749-
S.if_ is_a_literal_case
753+
S.if_ (is_a_literal_case ())
750754
(compile_cases ~cxt ~switch_exp:e ~block_cases
751755
~default:sw_num_default ~get_tag:get_const_tag sw_consts)
752756
~else_:
@@ -789,16 +793,17 @@ let compile output_prefix =
789793
~switch:(fun ?default ?declaration e clauses ->
790794
S.string_switch ?default ?declaration e clauses)
791795
~switch_exp ~default
792-
and compile_untagged_cases ~cxt ~switch_exp ~default ~block_cases cases =
796+
and compile_untagged_cases ~cxt ~switch_exp ~default ~block_cases
797+
~has_null_case cases =
793798
let mk_eq (i : Ast_untagged_variants.tag_type option) x j y =
794799
let check =
795800
match (i, j) with
796801
| Some tag_type, _ ->
797802
Ast_untagged_variants.DynamicChecks.add_runtime_type_check ~tag_type
798-
~block_cases (Expr x) (Expr y)
803+
~has_null_case ~block_cases (Expr x) (Expr y)
799804
| _, Some tag_type ->
800805
Ast_untagged_variants.DynamicChecks.add_runtime_type_check ~tag_type
801-
~block_cases (Expr y) (Expr x)
806+
~has_null_case ~block_cases (Expr y) (Expr x)
802807
| _ -> Ast_untagged_variants.DynamicChecks.( == ) (Expr x) (Expr y)
803808
in
804809
E.emit_check check

compiler/core/res_compmisc.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ let initial_env ?modulename () =
5454
let initial = Env.initial_safe_string in
5555
let env =
5656
if !Clflags.nopervasives then initial
57-
else open_implicit_module "Pervasives" initial
57+
else
58+
initial
59+
|> open_implicit_module "Pervasives"
60+
|> open_implicit_module "Stdlib"
5861
in
5962
List.fold_left
6063
(fun env m -> open_implicit_module m env)

compiler/gentype/TranslateTypeExprFromTypes.ml

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,36 +81,42 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
8181
| ( ( ["FB"; "string"]
8282
| ["string"]
8383
| ["String"; "t"]
84+
| ["Stdlib"; "String"; "t"]
8485
| ["Js"; ("String" | "String2"); "t"] ),
8586
[] ) ->
8687
{dependencies = []; type_ = string_t}
87-
| (["Js"; "Types"; "bigint_val"] | ["BigInt"; "t"]), [] ->
88+
| ( ( ["Js"; "Types"; "bigint_val"]
89+
| ["BigInt"; "t"]
90+
| ["Stdlib"; "BigInt"; "t"] ),
91+
[] ) ->
8892
{dependencies = []; type_ = bigint_t}
89-
| (["Js"; "Date"; "t"] | ["Date"; "t"]), [] ->
93+
| (["Js"; "Date"; "t"] | ["Date"; "t"] | ["Stdlib"; "Date"; "t"]), [] ->
9094
{dependencies = []; type_ = date_t}
91-
| ["Map"; "t"], [param_translation1; param_translation2] ->
95+
| ( (["Map"; "t"] | ["Stdlib"; "Map"; "t"]),
96+
[param_translation1; param_translation2] ) ->
9297
{
9398
dependencies =
9499
param_translation1.dependencies @ param_translation2.dependencies;
95100
type_ = map_t (param_translation1.type_, param_translation2.type_);
96101
}
97-
| ["WeakMap"; "t"], [param_translation1; param_translation2] ->
102+
| ( (["WeakMap"; "t"] | ["Stdlib"; "WeakMap"; "t"]),
103+
[param_translation1; param_translation2] ) ->
98104
{
99105
dependencies =
100106
param_translation1.dependencies @ param_translation2.dependencies;
101107
type_ = weakmap_t (param_translation1.type_, param_translation2.type_);
102108
}
103-
| ["Set"; "t"], [param_translation] ->
109+
| (["Set"; "t"] | ["Stdlib"; "Set"; "t"]), [param_translation] ->
104110
{
105111
dependencies = param_translation.dependencies;
106112
type_ = set_t param_translation.type_;
107113
}
108-
| ["WeakSet"; "t"], [param_translation] ->
114+
| (["WeakSet"; "t"] | ["Stdlib"; "WeakSet"; "t"]), [param_translation] ->
109115
{
110116
dependencies = param_translation.dependencies;
111117
type_ = weakset_t param_translation.type_;
112118
}
113-
| (["Js"; "Re"; "t"] | ["RegExp"; "t"]), [] ->
119+
| (["Js"; "Re"; "t"] | ["RegExp"; "t"] | ["Stdlib"; "RegExp"; "t"]), [] ->
114120
{dependencies = []; type_ = regexp_t}
115121
| (["FB"; "unit"] | ["unit"]), [] -> {dependencies = []; type_ = unit_t}
116122
| ( (["FB"; "array"] | ["array"] | ["Js"; ("Array" | "Array2"); "t"]),
@@ -134,7 +140,10 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
134140
};
135141
] );
136142
}
137-
| ( (["Pervasives"; "result"] | ["Belt"; "Result"; "t"] | ["result"]),
143+
| ( ( ["Pervasives"; "result"]
144+
| ["Belt"; "Result"; "t"]
145+
| ["result"]
146+
| ["Stdlib"; "Result"; "t"] ),
138147
[param_translation1; param_translation2] ) ->
139148
let case name type_ = {case = {label_js = StringLabel name}; t = type_} in
140149
let variant =
@@ -213,23 +222,36 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
213222
{dependencies = []; type_ = EmitType.type_react_element}
214223
| (["FB"; "option"] | ["option"]), [param_translation] ->
215224
{param_translation with type_ = Option param_translation.type_}
216-
| ( (["Js"; "Undefined"; "t"] | ["Undefined"; "t"] | ["Js"; "undefined"]),
225+
| ( ( ["Js"; "Undefined"; "t"]
226+
| ["Undefined"; "t"]
227+
| ["Js"; "undefined"]
228+
| ["Stdlib"; "undefined"] ),
217229
[param_translation] ) ->
218230
{param_translation with type_ = Option param_translation.type_}
219-
| (["Js"; "Null"; "t"] | ["Null"; "t"] | ["Js"; "null"]), [param_translation]
220-
->
231+
| ( ( ["Js"; "Null"; "t"]
232+
| ["Null"; "t"]
233+
| ["Js"; "null"]
234+
| ["Stdlib"; "Null"; "t"]
235+
| ["Stdlib"; "null"] ),
236+
[param_translation] ) ->
221237
{param_translation with type_ = Null param_translation.type_}
222238
| ( ( ["Js"; "Nullable"; "t"]
223239
| ["Nullable"; "t"]
224240
| ["Js"; "nullable"]
225241
| ["Js"; "Null_undefined"; "t"]
226-
| ["Js"; "null_undefined"] ),
242+
| ["Js"; "null_undefined"]
243+
| ["Stdlib"; "Nullable"; "t"]
244+
| ["Stdlib"; "nullable"] ),
227245
[param_translation] ) ->
228246
{param_translation with type_ = Nullable param_translation.type_}
229-
| ( (["Js"; "Promise"; "t"] | ["Promise"; "t"] | ["promise"]),
247+
| ( ( ["Js"; "Promise"; "t"]
248+
| ["Promise"; "t"]
249+
| ["promise"]
250+
| ["Stdlib"; "Promise"; "t"] ),
230251
[param_translation] ) ->
231252
{param_translation with type_ = Promise param_translation.type_}
232-
| (["Js"; "Dict"; "t"] | ["Dict"; "t"] | ["dict"]), [param_translation] ->
253+
| ( (["Js"; "Dict"; "t"] | ["Dict"; "t"] | ["dict"] | ["Stdlib"; "Dict"; "t"]),
254+
[param_translation] ) ->
233255
{param_translation with type_ = Dict param_translation.type_}
234256
| _ -> default_case ()
235257

0 commit comments

Comments
 (0)