Skip to content

Commit 470d034

Browse files
authored
Remove lazy keyword (#6342)
* remove lazy keyword * fix contributing doc stating old ocaml ver * sync test output * change CHANGELOG
1 parent ae871c5 commit 470d034

Some content is hidden

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

88 files changed

+241
-842
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
- Build with OCaml 5.1.1. https://github.com/rescript-lang/rescript-compiler/pull/6641
1818

19+
#### :boom: Breaking Change
20+
21+
- `lazy` syntax is no longer supported. If you're using it, use `Lazy` module or `React.lazy_` instead. https://github.com/rescript-lang/rescript-compiler/pull/6342
22+
1923
# 11.1.0-rc.2
2024

2125
#### :rocket: New Feature

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Make sure you have [opam](https://opam.ocaml.org/doc/Install.html) installed on
4141
opam init
4242

4343
# Any recent OCaml version works as a development compiler
44-
opam switch create 4.14.1 # can also create local switch with opam switch create . 4.14.1
44+
opam switch create 5.1.1 # can also create local switch with opam switch create
4545

4646
# Install dev dependencies from OPAM
4747
opam install . --deps-only

jscomp/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(dirs bsb bsb_exe bsb_helper bsb_helper_exe bsc cmij common core depends ext
2-
frontend gentype jsoo js_parser ml napkin ounit_tests syntax)
2+
frontend gentype jsoo js_parser ml ounit_tests syntax)
33

44
(env
55
(dev

jscomp/runtime/caml_module.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let init_mod = (loc: (string, int, int), shape: shape) => {
5353
let rec loop = (shape: shape, struct_: Obj.t, idx) =>
5454
switch shape {
5555
| Function => set_field(struct_, idx, Obj.magic(undef_module))
56-
| Lazy => set_field(struct_, idx, Obj.magic(lazy undef_module))
56+
| Lazy => set_field(struct_, idx, Obj.magic(undef_module))
5757
| Class =>
5858
set_field(
5959
struct_,

jscomp/stdlib-406/camlinternalLazy.res

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type t<'a> = {
3535
%%private(external fnToVal: ((. unit) => 'a) => 'a = "%identity")
3636
%%private(external valToFn: 'a => (. unit) => 'a = "%identity")
3737
%%private(external castToConcrete: lazy_t<'a> => t<'a> = "%identity")
38+
%%private(external castFromConcrete: t<'a> => lazy_t<'a> = "%identity")
3839

3940
let is_val = (type a, l: lazy_t<a>): bool => castToConcrete(l).tag
4041

@@ -90,3 +91,19 @@ let force_val = (type a, lzv: lazy_t<a>): a => {
9091
force_val_lazy_block(lzv)
9192
}
9293
}
94+
95+
let from_fun = (type a, closure: (. unit) => a): lazy_t<a> => {
96+
let blk = {
97+
tag: false,
98+
value: fnToVal(closure),
99+
}
100+
castFromConcrete(blk)
101+
}
102+
103+
let from_val = (type a, value: a): lazy_t<a> => {
104+
let blk = {
105+
tag: true,
106+
value: value,
107+
}
108+
castFromConcrete(blk)
109+
}

jscomp/stdlib-406/camlinternalLazy.resi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ let force: lazy_t<'a> => 'a
2525
let force_val: lazy_t<'a> => 'a
2626

2727
let is_val: lazy_t<'a> => bool
28+
29+
let from_fun: ((. unit) => 'a) => lazy_t<'a>
30+
31+
let from_val: 'a => lazy_t<'a>

jscomp/stdlib-406/hashtbl.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let randomized = ref(randomized_default)
5656
let randomize = () => randomized := true
5757
let is_randomized = () => randomized.contents
5858

59-
let prng = lazy Random.State.make_self_init()
59+
let prng = Lazy.from_fun(() => Random.State.make_self_init())
6060

6161
/* Creating a fresh, empty table */
6262

jscomp/stdlib-406/lazy.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ external force: t<'a> => 'a = "%lazy_force"
5555

5656
let force_val = CamlinternalLazy.force_val
5757

58-
let from_fun = f => lazy f()
58+
let from_fun = f => CamlinternalLazy.from_fun((. ) => f())
5959

60-
let from_val = v => lazy v
60+
let from_val = v => CamlinternalLazy.from_val(v)
6161

6262
let is_val = CamlinternalLazy.is_val
6363

jscomp/stdlib-406/stream.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,13 @@ let iapp = (i, s) => Some({count: 0, data: Sapp(data(i), data(s))})
218218
let icons = (i, s) => Some({count: 0, data: Scons(i, data(s))})
219219
let ising = i => Some({count: 0, data: Scons(i, Sempty)})
220220

221-
let lapp = (f, s) => Some({count: 0, data: Slazy(lazy Sapp(data(f()), data(s)))})
221+
let lapp = (f, s) => Some({count: 0, data: Slazy(Lazy.from_fun(() => Sapp(data(f()), data(s))))})
222222

223-
let lcons = (f, s) => Some({count: 0, data: Slazy(lazy Scons(f(), data(s)))})
224-
let lsing = f => Some({count: 0, data: Slazy(lazy Scons(f(), Sempty))})
223+
let lcons = (f, s) => Some({count: 0, data: Slazy(Lazy.from_fun(() => Scons(f(), data(s))))})
224+
let lsing = f => Some({count: 0, data: Slazy(Lazy.from_fun(() => Scons(f(), Sempty)))})
225225

226226
let sempty = None
227-
let slazy = f => Some({count: 0, data: Slazy(lazy data(f()))})
227+
let slazy = f => Some({count: 0, data: Slazy(Lazy.from_fun(() => data(f())))})
228228

229229
/* For debugging use */
230230

jscomp/syntax/src/res_core.ml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,11 +1108,6 @@ let rec parsePattern ?(alias = true) ?(or_ = true) p =
11081108
let pat = parsePattern ~alias:false ~or_:false p in
11091109
let loc = mkLoc startPos p.prevEndPos in
11101110
Ast_helper.Pat.exception_ ~loc ~attrs pat
1111-
| Lazy ->
1112-
Parser.next p;
1113-
let pat = parsePattern ~alias:false ~or_:false p in
1114-
let loc = mkLoc startPos p.prevEndPos in
1115-
Ast_helper.Pat.lazy_ ~loc ~attrs pat
11161111
| List ->
11171112
Parser.next p;
11181113
parseListPattern ~startPos ~attrs p
@@ -2128,11 +2123,6 @@ and parseOperandExpr ~context p =
21282123
let () = attrs := [] in
21292124
parseAsyncArrowExpression ~arrowAttrs p
21302125
| Await -> parseAwaitExpression p
2131-
| Lazy ->
2132-
Parser.next p;
2133-
let expr = parseUnaryExpr p in
2134-
let loc = mkLoc startPos p.prevEndPos in
2135-
Ast_helper.Exp.lazy_ ~loc expr
21362126
| Try -> parseTryExpression p
21372127
| If -> parseIfOrIfLetExpression p
21382128
| For -> parseForExpression p

0 commit comments

Comments
 (0)