Skip to content

Commit df1a633

Browse files
committed
remove lazy keyword
1 parent ae871c5 commit df1a633

Some content is hidden

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

64 files changed

+234
-791
lines changed

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

jscomp/syntax/src/res_grammar.ml

Lines changed: 9 additions & 9 deletions
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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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/parenthesized.res

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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/lazy.res

Lines changed: 0 additions & 49 deletions
This file was deleted.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@ switch x {
55
| (Blue as c1) | (Red as c2) => ()
66
| exception Exit | exception Continue => ()
77
| exception (Exit | exception Continue) => ()
8-
| lazy x | lazy y => ()
9-
| lazy (x | lazy y) => ()
108
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ let cmp = (selectedChoice, value) =>
9494
| #...a as x => true
9595
| # ...a | # ... b => true
9696
| (#...a : typ) => true
97-
| lazy #...a => true
9897
| exception #...a => true
9998
| _ => false
10099
}

0 commit comments

Comments
 (0)