Skip to content

Commit 6b21f0b

Browse files
namenuJonoPrest
authored andcommitted
Remove lazy keyword (rescript-lang#6342)
* remove lazy keyword * fix contributing doc stating old ocaml ver * sync test output * change CHANGELOG
1 parent 86bcb02 commit 6b21f0b

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

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141

4242
- Fix compiler crash when reexporting tagged template literal externals. https://github.com/rescript-lang/rescript-compiler/pull/6645
4343

44+
#### :boom: Breaking Change
45+
46+
- `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
47+
4448
# 11.1.0-rc.2
4549

4650
#### :rocket: New Feature

CONTRIBUTING.md

+1-1
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

+1-1
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

+1-1
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

+17
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

+4
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

+1-1
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

+2-2
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

+4-4
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

-10
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
@@ -2127,11 +2122,6 @@ and parseOperandExpr ~context p =
21272122
let () = attrs := [] in
21282123
parseAsyncArrowExpression ~arrowAttrs p
21292124
| Await -> parseAwaitExpression p
2130-
| Lazy ->
2131-
Parser.next p;
2132-
let expr = parseUnaryExpr p in
2133-
let loc = mkLoc startPos p.prevEndPos in
2134-
Ast_helper.Exp.lazy_ ~loc expr
21352125
| Try -> parseTryExpression p
21362126
| If -> parseIfOrIfLetExpression p
21372127
| For -> parseForExpression p

jscomp/syntax/src/res_grammar.ml

+9-9
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ let isSignatureItemStart = function
129129

130130
let isAtomicPatternStart = function
131131
| Token.Int _ | String _ | Codepoint _ | Backtick | Lparen | Lbracket | Lbrace
132-
| Underscore | Lident _ | Uident _ | List | Exception | Lazy | Percent ->
132+
| Underscore | Lident _ | Uident _ | List | Exception | Percent ->
133133
true
134134
| _ -> false
135135

@@ -148,9 +148,9 @@ let isAtomicTypExprStart = function
148148

149149
let isExprStart = function
150150
| Token.Assert | At | Await | Backtick | Bang | Codepoint _ | False | Float _
151-
| For | Hash | If | Int _ | Lazy | Lbrace | Lbracket | LessThan | Lident _
152-
| List | Lparen | Minus | MinusDot | Module | Percent | Plus | PlusDot
153-
| String _ | Switch | True | Try | Uident _ | Underscore (* _ => doThings() *)
151+
| For | Hash | If | Int _ | Lbrace | Lbracket | LessThan | Lident _ | List
152+
| Lparen | Minus | MinusDot | Module | Percent | Plus | PlusDot | String _
153+
| Switch | True | Try | Uident _ | Underscore (* _ => doThings() *)
154154
| While ->
155155
true
156156
| _ -> false
@@ -169,7 +169,7 @@ let isStructureItemStart = function
169169
let isPatternStart = function
170170
| Token.Int _ | Float _ | String _ | Codepoint _ | Backtick | True | False
171171
| Minus | Plus | Lparen | Lbracket | Lbrace | List | Underscore | Lident _
172-
| Uident _ | Hash | Exception | Lazy | Percent | Module | At ->
172+
| Uident _ | Hash | Exception | Percent | Module | At ->
173173
true
174174
| _ -> false
175175

@@ -257,10 +257,10 @@ let isJsxChildStart = isAtomicExprStart
257257

258258
let isBlockExprStart = function
259259
| Token.Assert | At | Await | Backtick | Bang | Codepoint _ | Exception
260-
| False | Float _ | For | Forwardslash | Hash | If | Int _ | Lazy | Lbrace
261-
| Lbracket | LessThan | Let | Lident _ | List | Lparen | Minus | MinusDot
262-
| Module | Open | Percent | Plus | PlusDot | String _ | Switch | True | Try
263-
| Uident _ | Underscore | While ->
260+
| False | Float _ | For | Forwardslash | Hash | If | Int _ | Lbrace | Lbracket
261+
| LessThan | Let | Lident _ | List | Lparen | Minus | MinusDot | Module | Open
262+
| Percent | Plus | PlusDot | String _ | Switch | True | Try | Uident _
263+
| Underscore | While ->
264264
true
265265
| _ -> false
266266

jscomp/syntax/src/res_token.ml

+2-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ type t =
5555
| Hash
5656
| HashEqual
5757
| Assert
58-
| Lazy
5958
| Tilde
6059
| Question
6160
| If
@@ -166,7 +165,6 @@ let toString = function
166165
| AsteriskDot -> "*."
167166
| Exponentiation -> "**"
168167
| Assert -> "assert"
169-
| Lazy -> "lazy"
170168
| Tilde -> "tilde"
171169
| Question -> "?"
172170
| If -> "if"
@@ -222,7 +220,6 @@ let keywordTable = function
222220
| "if" -> If
223221
| "in" -> In
224222
| "include" -> Include
225-
| "lazy" -> Lazy
226223
| "let" -> Let
227224
| "list{" -> List
228225
| "module" -> Module
@@ -242,8 +239,8 @@ let keywordTable = function
242239

243240
let isKeyword = function
244241
| Await | And | As | Assert | Constraint | Else | Exception | External | False
245-
| For | If | In | Include | Land | Lazy | Let | List | Lor | Module | Mutable
246-
| Of | Open | Private | Rec | Switch | True | Try | Typ | When | While ->
242+
| For | If | In | Include | Land | Let | List | Lor | Module | Mutable | Of
243+
| Open | Private | Rec | Switch | True | Try | Typ | When | While ->
247244
true
248245
| _ -> false
249246

jscomp/syntax/tests/idempotency/covid-19charts.com/src/Data.res

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type value =
5757
let dataWithGrowth =
5858
Map.entries(data)
5959
|> Js.Array.map(((countryId, dataPoints)) => {
60-
let data = lazy {
60+
let data = Lazy.from_fun(() => {
6161
let countryDataWithGrowth = Map.empty()
6262
let _ = Js.Array.reduce((prevRecord, day) => {
6363
let record = Map.get(dataPoints, day)
@@ -72,7 +72,7 @@ let dataWithGrowth =
7272
Some(record)
7373
}, None, days)
7474
countryDataWithGrowth
75-
}
75+
})
7676
(countryId, data)
7777
})
7878
|> Belt.Map.String.fromArray
@@ -92,7 +92,7 @@ let calendar: t = Js.Array.mapi((day, index) => {
9292
Belt.HashMap.String.set(
9393
values,
9494
Map.get(locations, countryId).name,
95-
lazy Map.get(Belt.Map.String.getExn(dataWithGrowth, countryId) |> Lazy.force, day),
95+
Lazy.from_fun(() => Map.get(Belt.Map.String.getExn(dataWithGrowth, countryId) |> Lazy.force, day)),
9696
),
9797
countryIds,
9898
)
@@ -140,7 +140,7 @@ let getValue = (dataType, dataItem) => getValueFromRecord(dataType, getRecord(da
140140

141141
let alignToDay0 = (dataType, threshold) => {
142142
let data = Belt.Map.String.mapU(dataWithGrowth, (. dataPoints) =>
143-
lazy {
143+
Lazy.from_fun(() => {
144144
let dataPoints = Lazy.force(dataPoints)
145145
Map.entries(dataPoints)
146146
|> Js.Array.map(((date, value)) => (Map.get(dayToIndex, date), value))
@@ -149,7 +149,7 @@ let alignToDay0 = (dataType, threshold) => {
149149
|> Js.Array.filter(value => getValue(dataType, value) >= threshold)
150150
|> Js.Array.mapi((value, index) => (index, value))
151151
|> Belt.Map.Int.fromArray
152-
}
152+
})
153153
)
154154

155155
Array.init(Js.Array.length(days), day => {

jscomp/syntax/tests/idempotency/genType/src/Arnold.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ let traverseAst = (~valueBindingsTable) => {
13591359
valueBindings |> List.iter((vb: Typedtree.value_binding) =>
13601360
switch vb.vb_pat.pat_desc {
13611361
| Tpat_var(id, {loc: {loc_start: pos}}) =>
1362-
let callees = lazy FindFunctionsCalled.findCallees(vb.vb_expr)
1362+
let callees = Lazy.from_fun(() => FindFunctionsCalled.findCallees(vb.vb_expr))
13631363
Hashtbl.replace(valueBindingsTable, Ident.name(id), (pos, vb.vb_expr, callees))
13641364
| _ => ()
13651365
}

jscomp/syntax/tests/idempotency/genType/src/DeadValue.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ let whiteListSideEffects = list{
1212
"Int64.one",
1313
"String.length",
1414
}
15-
let whiteTableSideEffects = lazy {
15+
let whiteTableSideEffects = Lazy.from_fun(() => {
1616
let tbl = Hashtbl.create(11)
1717

1818
whiteListSideEffects |> List.iter(s => Hashtbl.add(tbl, s, ()))
1919
tbl
20-
}
20+
})
2121

2222
let pathIsWhitelistedForSideEffects = path =>
2323
switch path |> Path.flatten {

jscomp/syntax/tests/idempotency/genType/src/Log_.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Color = {
2-
let color_enabled = lazy Unix.isatty(Unix.stdout)
2+
let color_enabled = Lazy.from_fun(() => Unix.isatty(Unix.stdout))
33
let forceColor = ref(false)
44

55
let get_color_enabled = () => forceColor.contents || Lazy.force(color_enabled)

jscomp/syntax/tests/idempotency/genType/src/ModuleResolver.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ type resolver = {
189189
}
190190

191191
let createLazyResolver = (~config, ~extensions, ~excludeFile) => {
192-
lazyFind: lazy {
192+
lazyFind: Lazy.from_fun(() => {
193193
let (moduleNameMap, bsDependenciesFileMap) = sourcedirsJsonToMap(
194194
~config,
195195
~extensions,
@@ -210,7 +210,7 @@ let createLazyResolver = (~config, ~extensions, ~excludeFile) => {
210210
moduleName |> find(~bsDependencies=true, ~map=bsDependenciesFileMap)
211211
| res => res
212212
}
213-
},
213+
}),
214214
}
215215

216216
let apply = (~resolver, ~useBsDependencies, moduleName) =>

jscomp/syntax/tests/parsing/grammar/expressions/arrow.res

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ let f = ((a, b)) => a + b
2222
let f = ((a, b), (c, d)) => a + b + c + d
2323
let f = (exception Terminate) => ()
2424
let f = (exception Terminate, exception Exit) => ()
25-
let f = (lazy x) => ()
26-
let f = (lazy x, lazy y) => ()
2725
let f = (list{}) => ()
2826
let f = (list{x, ...xs}) => x + xs->Belt.List.length
2927

jscomp/syntax/tests/parsing/grammar/expressions/binary.res

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ let x = z |> switch z {| _ => false}
1818
let x = z |> @attr switch z {| _ => false}
1919
let x = z |> assert(z)
2020
let x = z |> @attr assert(z)
21-
let x = z |> lazy z
22-
let x = z |> @attr lazy z
2321
let x = z |> try sideEffect() catch { | _ => f() }
2422
let x = z |> @attr try sideEffect() catch { | _ => f() }
2523
let x = z |> for i in 0 to 10 { () }

jscomp/syntax/tests/parsing/grammar/expressions/expected/arrow.res.txt

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ let f (a, b) = a + b
1717
let f (a, b) (c, d) = ((a + b) + c) + d
1818
let f exception Terminate = ()
1919
let f exception Terminate exception Exit = ()
20-
let f (lazy x) = ()
21-
let f (lazy x) (lazy y) = ()
2220
let f [] = ()
2321
let f (x::xs) = x + (xs |. Belt.List.length)
2422
let f (x : int) (y : int) = x + y

jscomp/syntax/tests/parsing/grammar/expressions/expected/binary.res.txt

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ let x = z |> (match z with | _ -> false)
55
let x = z |> ((match z with | _ -> false)[@attr ])
66
let x = z |> (assert z)
77
let x = z |> ((assert z)[@attr ])
8-
let x = z |> (lazy z)
9-
let x = z |> ((lazy z)[@attr ])
108
let x = z |> (try sideEffect () with | _ -> f ())
119
let x = z |> ((try sideEffect () with | _ -> f ())[@attr ])
1210
let x = z |> for i = 0 to 10 do () done

jscomp/syntax/tests/parsing/grammar/expressions/expected/parenthesized.res.txt

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ let aTuple = (1, 2)
1616
let aRecord = { name = {js|steve|js}; age = 30 }
1717
let blockExpression = ((let a = 1 in let b = 2 in a + b)[@res.braces ])
1818
let assertSmthing = assert true
19-
let lazyThing = lazy true
2019
let jsx =
2120
((div ~className:(({js|cx|js})[@res.namedArgLoc ]) ~children:[foo] ())
2221
[@JSX ])

jscomp/syntax/tests/parsing/grammar/expressions/parenthesized.res

-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ let blockExpression = ({
3030

3131
let assertSmthing = (assert(true))
3232

33-
let lazyThing = (lazy true)
34-
3533
let jsx = (<div className="cx"> foo </div>)
3634

3735
let ifExpr = (if true {

jscomp/syntax/tests/parsing/grammar/pattern/constant.res

-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ switch science {
8383
| -4.15 as x => true
8484
| -4.15 | +4.15 => true
8585
| (-3.14 : float) => true
86-
| lazy 5.678 => true
8786
| exception 19.34 => true
8887
| _ => false
8988
}
@@ -99,7 +98,6 @@ switch literal {
9998
| `literal` as x => true
10099
| `literal` | `literal` => true
101100
| (`literal` : string) => true
102-
| lazy `literal` => true
103101
| exception `literal` => true
104102
| _ => false
105103
}

jscomp/syntax/tests/parsing/grammar/pattern/expected/constant.res.txt

-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ let (-1)..(-1.) = x
6666
| (-4.15) as x -> true
6767
| (-4.15)|4.15 -> true
6868
| ((-3.14) : float) -> true
69-
| (lazy 5.678) -> true
7069
| exception 19.34 -> true
7170
| _ -> false
7271
;;match literal with
@@ -92,7 +91,6 @@ let (-1)..(-1.) = x
9291
| (({js|literal|js})[@res.template ])|(({js|literal|js})[@res.template ])
9392
-> true
9493
| ((({js|literal|js})[@res.template ]) : string) -> true
95-
| (lazy (({js|literal|js})[@res.template ])) -> true
9694
| exception (({js|literal|js})[@res.template ]) -> true
9795
| _ -> false
9896
let (({js|literal constant|js})[@res.template ]) = x

0 commit comments

Comments
 (0)