Skip to content

Commit 6c0f9f0

Browse files
committed
Merge branch 'master' into compiler-error-variant-tag-constructor-field
2 parents ae25762 + 6d9eedf commit 6c0f9f0

File tree

431 files changed

+15261
-30486
lines changed

Some content is hidden

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

431 files changed

+15261
-30486
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,8 @@ jobs:
674674
shell: bash
675675

676676
publish:
677+
permissions:
678+
id-token: write
677679
needs:
678680
- test-installation-npm
679681
- test-installation-pnpm
@@ -701,11 +703,9 @@ jobs:
701703
shell: bash
702704

703705
- name: Publish packages on npm with tag "ci"
704-
env:
705-
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
706706
run: |
707707
yarn workspaces foreach -W --no-private \
708-
npm publish --tolerate-republish --tag ci
708+
npm publish --provenance --tolerate-republish --tag ci
709709
710710
- name: Update Website Playground
711711
run: curl -X POST "${{ secrets.CLOUDFLARE_PAGES_DEPLOYMENT_HOOK }}"

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,30 @@
1414

1515
#### :boom: Breaking Change
1616

17+
- Fix return type of `String.charCodeAt`. https://github.com/rescript-lang/rescript/pull/7864
18+
1719
#### :eyeglasses: Spec Compliance
1820

1921
#### :rocket: New Feature
2022

2123
#### :bug: Bug fix
2224

2325
- Fix code generation for emojis in polyvars and labels. https://github.com/rescript-lang/rescript/pull/7853
26+
- Add `reset` to `experimental_features` to correctly reset playground. https://github.com/rescript-lang/rescript/pull/7868
27+
- Fix crash with `@get` on external of type `unit => 'a`. https://github.com/rescript-lang/rescript/pull/7866
28+
- Fix record type spreads in inline records. https://github.com/rescript-lang/rescript/pull/7859
2429

2530
#### :memo: Documentation
2631

2732
#### :nail_care: Polish
2833

34+
- Reactivate optimization for length of array literals. https://github.com/rescript-lang/rescript/pull/7872
35+
2936
#### :house: Internal
3037

38+
- Playground: Add config options for experimental features and jsx preserve mode. https://github.com/rescript-lang/rescript/pull/7865
39+
- Clean up tests. https://github.com/rescript-lang/rescript/pull/7861 https://github.com/rescript-lang/rescript/pull/7871
40+
3141
# 12.0.0-beta.10
3242

3343
#### :rocket: New Feature

CONTRIBUTING.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,23 @@ Below we will discuss on how to write, build and run these test files.
227227
- Inside the file, add a mocha test suite. The mocha bindings are defined in `tests/tests/src/mt.res`. To get you started, here is a simple scaffold for a test suite with multiple test cases:
228228

229229
```rescript
230-
let suites: Mt.pair_suites = list{
231-
("hey", _ => Eq(true, 3 > 2)),
232-
("hi", _ => Neq(2, 3)),
233-
("hello", _ => Approx(3.0, 3.0)),
234-
("throw", _ => ThrowAny(_ => raise(SomeException))),
235-
}
236-
237-
Mt.from_pair_suites(__MODULE__, suites)
230+
open Mocha
231+
open Test_utils
232+
233+
describe(__MODULE__, () => {
234+
test("hey", () => {
235+
ok(__LOC__, 3 > 2)
236+
})
237+
238+
test("hi", () => {
239+
eq(__LOC__, 2, 2)
240+
eq(__LOC__, 3, 3)
241+
})
242+
243+
test("throw", () => {
244+
throws(__LOC__, () => throw(SomeException))
245+
})
246+
})
238247
```
239248

240249
- Build the test files and run the tests: `node scripts/test.js -mocha`.

biome.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"rewatch/**",
6666
"lib/es6/**",
6767
"lib/js/**",
68+
"lib/bs/**",
6869
"ninja/**",
6970
"playground/**",
7071
"*.bs.js",

compiler/core/lam_compile_external_call.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,11 @@ let translate_ffi ?(transformed_jsx = false) (cxt : Lam_compile_context.t)
421421
| [obj] ->
422422
let obj = translate_scoped_access scopes obj in
423423
E.dot obj name
424-
| _ -> assert false
424+
| _ ->
425+
(* This should have been caught in the frontend validation. *)
426+
invalid_arg
427+
"Internal compiler error: @get external called with wrong number of \
428+
arguments. Expected exactly one object argument."
425429
(* Note these assertion happens in call site *))
426430
| Js_set {js_set_name = name; js_set_scopes = scopes} -> (
427431
(* assert (js_splice = false) ; *)

compiler/frontend/ast_external_process.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,12 @@ let external_desc_of_non_obj (loc : Location.t) (st : external_desc)
899899
tagged_template = _;
900900
} ->
901901
if arg_type_specs_length = 1 then
902-
Js_get {js_get_name = name; js_get_scopes = scopes}
902+
(* Check if the first argument is unit, which is invalid for @get *)
903+
match arg_type_specs with
904+
| [{arg_type = Extern_unit}] ->
905+
Location.raise_errorf ~loc
906+
"Ill defined attribute %@get (unit argument is not allowed)"
907+
| _ -> Js_get {js_get_name = name; js_get_scopes = scopes}
903908
else
904909
Location.raise_errorf ~loc
905910
"Ill defined attribute %@get (only one argument)"

compiler/jsoo/jsoo_playground_main.ml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@
4949
`config.uncurried` to the BundleConfig.
5050
* v4: Added `config.open_modules` to the BundleConfig to enable implicitly opened
5151
* modules in the playground.
52+
* v5: Removed .ml support.
53+
* v6: Added `config.experimental_features` and `config.jsx_preserve_mode` to the BundleConfig.
5254
* *)
53-
let api_version = "5"
55+
let api_version = "6"
5456

5557
module Js = Js_of_ocaml.Js
5658

@@ -73,6 +75,8 @@ module BundleConfig = struct
7375
mutable filename: string option;
7476
mutable warn_flags: string;
7577
mutable open_modules: string list;
78+
mutable experimental_features: string list;
79+
mutable jsx_preserve_mode: bool;
7680
}
7781

7882
let make () =
@@ -81,6 +85,8 @@ module BundleConfig = struct
8185
filename = None;
8286
warn_flags = Bsc_warnings.defaults_w;
8387
open_modules = [];
88+
experimental_features = [];
89+
jsx_preserve_mode = false;
8490
}
8591

8692
let default_filename (lang : Lang.t) = "playground." ^ Lang.to_string lang
@@ -372,6 +378,7 @@ module Compile = struct
372378
(* Responsible for resetting all compiler state as if it were a new instance *)
373379
let reset_compiler () =
374380
warning_infos := [||];
381+
Experimental_features.reset ();
375382
flush_warning_buffer () |> ignore;
376383
Warnings.reset_fatal ();
377384
Env.reset_cache_toplevel ()
@@ -467,7 +474,15 @@ module Compile = struct
467474
Js.array (!acc |> Array.of_list)
468475

469476
let implementation ~(config : BundleConfig.t) ~lang str =
470-
let {BundleConfig.module_system; warn_flags; open_modules} = config in
477+
let {
478+
BundleConfig.module_system;
479+
warn_flags;
480+
open_modules;
481+
experimental_features;
482+
jsx_preserve_mode;
483+
} =
484+
config
485+
in
471486
try
472487
reset_compiler ();
473488
Warnings.parse_options false warn_flags;
@@ -485,6 +500,9 @@ module Compile = struct
485500
(* let finalenv = ref Env.empty in *)
486501
let types_signature = ref [] in
487502
Js_config.jsx_version := Some Js_config.Jsx_v4;
503+
Js_config.jsx_preserve := jsx_preserve_mode;
504+
experimental_features
505+
|> List.iter Experimental_features.enable_from_string;
488506
(* default *)
489507
let ast = impl str in
490508
let ast = Ppx_entry.rewrite_implementation ast in
@@ -606,6 +624,14 @@ module Export = struct
606624
config.open_modules <- value;
607625
true
608626
in
627+
let set_experimental_features value =
628+
config.experimental_features <- value;
629+
true
630+
in
631+
let set_jsx_preserve_mode value =
632+
config.jsx_preserve_mode <- value;
633+
true
634+
in
609635
let convert_syntax ~(from_lang : string) ~(to_lang : string) (src : string)
610636
=
611637
let open Lang in
@@ -653,6 +679,17 @@ module Export = struct
653679
(set_open_modules
654680
(value |> Js.to_array |> Array.map Js.to_string
655681
|> Array.to_list))) );
682+
( "setExperimentalFeatures",
683+
inject
684+
@@ Js.wrap_meth_callback (fun _ value ->
685+
Js.bool
686+
(set_experimental_features
687+
(value |> Js.to_array |> Array.map Js.to_string
688+
|> Array.to_list))) );
689+
( "setJsxPreserveMode",
690+
inject
691+
@@ Js.wrap_meth_callback (fun _ value ->
692+
Js.bool (set_jsx_preserve_mode (Js.to_bool value))) );
656693
( "getConfig",
657694
inject
658695
@@ Js.wrap_meth_callback (fun _ ->
@@ -665,6 +702,12 @@ module Export = struct
665702
|> BundleConfig.string_of_module_system
666703
|> Js.string) );
667704
("warn_flags", inject @@ Js.string config.warn_flags);
705+
( "jsx_preserve_mode",
706+
inject @@ (config.jsx_preserve_mode |> Js.bool) );
707+
( "experimental_features",
708+
inject
709+
@@ (config.experimental_features |> Array.of_list
710+
|> Js.array) );
668711
( "open_modules",
669712
inject
670713
@@ (config.open_modules |> Array.of_list |> Js.array)

compiler/ml/experimental_features.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ let enable_from_string (s : string) =
2020
| Some f -> enabled_features := FeatureSet.add f !enabled_features
2121
| None -> ()
2222

23+
let reset () = enabled_features := FeatureSet.empty
24+
2325
let is_enabled (f : feature) = FeatureSet.mem f !enabled_features

compiler/ml/experimental_features.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ type feature = LetUnwrap
33
val enable_from_string : string -> unit
44
val is_enabled : feature -> bool
55
val to_string : feature -> string
6+
val reset : unit -> unit

compiler/ml/record_type_spread.ml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,52 @@ let extract_type_vars (type_params : Types.type_expr list)
8989
| Tvar (Some tname) -> Some (tname, applied_tvar)
9090
| _ -> None)
9191
else []
92+
93+
let expand_labels_with_type_spreads (env : Env.t)
94+
(lbls : Typedtree.label_declaration list)
95+
(lbls' : Types.label_declaration list) =
96+
match has_type_spread lbls with
97+
| false -> Some (lbls, lbls')
98+
| true ->
99+
let rec extract (t : Types.type_expr) =
100+
match t.desc with
101+
| Tpoly (t, []) -> extract t
102+
| _ -> Ctype.repr t
103+
in
104+
let mk_lbl (l : Types.label_declaration) (ld_type : Typedtree.core_type)
105+
(type_vars : (string * Types.type_expr) list) :
106+
Typedtree.label_declaration =
107+
{
108+
ld_id = l.ld_id;
109+
ld_name = {txt = Ident.name l.ld_id; loc = l.ld_loc};
110+
ld_mutable = l.ld_mutable;
111+
ld_optional = l.ld_optional;
112+
ld_type =
113+
{ld_type with ctyp_type = substitute_type_vars type_vars l.ld_type};
114+
ld_loc = l.ld_loc;
115+
ld_attributes = l.ld_attributes;
116+
}
117+
in
118+
let rec process_lbls acc (lbls : Typedtree.label_declaration list)
119+
(lbls' : Types.label_declaration list) =
120+
match (lbls, lbls') with
121+
| {ld_name = {txt = "..."}; ld_type} :: rest, _ :: rest' -> (
122+
match
123+
Ctype.extract_concrete_typedecl env (extract ld_type.ctyp_type)
124+
with
125+
| _p0, _p, {type_kind = Type_record (fields, _repr); type_params} ->
126+
let type_vars = extract_type_vars type_params ld_type.ctyp_type in
127+
process_lbls
128+
( fst acc @ Ext_list.map fields (fun l -> mk_lbl l ld_type type_vars),
129+
snd acc
130+
@ Ext_list.map fields (fun l ->
131+
{l with ld_type = substitute_type_vars type_vars l.ld_type})
132+
)
133+
rest rest'
134+
| _ -> None
135+
| exception _ -> None)
136+
| lbl :: rest, lbl' :: rest' ->
137+
process_lbls (fst acc @ [lbl], snd acc @ [lbl']) rest rest'
138+
| _ -> Some acc
139+
in
140+
process_lbls ([], []) lbls lbls'

0 commit comments

Comments
 (0)