Skip to content

Commit de1dc70

Browse files
committed
quick lazy
1 parent ac36283 commit de1dc70

File tree

7 files changed

+25
-140
lines changed

7 files changed

+25
-140
lines changed

compiler/ml/predef.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ and ident_dict = ident_create "dict"
5353

5454
and ident_bigint = ident_create "bigint"
5555

56-
and ident_lazy_t = ident_create "lazy_t"
56+
and ident_lazy_t = ident_create "lazy_t_to_remove"
5757

5858
and ident_string = ident_create "string"
5959

runtime/Primitive_lazy.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
@@config({flags: ["-bs-no-cross-module-opt"]})
2626

27+
type lazy_t<+'a>
28+
2729
/* Internals of forcing lazy values. */
2830
type t<'a> = {
2931
@as("LAZY_DONE") mutable tag: bool,

runtime/Primitive_lazy.resi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
exception Undefined
22

3+
type lazy_t<+'a>
4+
35
/** [force x] forces the suspension [x] and returns its result.
46
If [x] has already been forced, [Lazy.force x] returns the
57
same value again without recomputing it. If it raised an exception,

runtime/Stdlib_Lazy.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type t<'a> = lazy_t<'a>
1+
type t<+'a> = Primitive_lazy.lazy_t<'a>
22

33
exception Undefined = Primitive_lazy.Undefined
44

runtime/Stdlib_Lazy.resi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
subsequent accesses. If the computation raises an exception,
1313
the same exception is raised again on subsequent accesses.
1414
*/
15-
type t<'a> = lazy_t<'a>
15+
@notUndefined
16+
type t<+'a>
1617

1718
/**
1819
`Lazy.make(f)` creates a lazy value from `f` which is the

tests/tests/src/recursive_module.mjs

Lines changed: 17 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -41,139 +41,40 @@ Primitive_module.update({
4141
]]
4242
}, Int3, Int3);
4343

44-
let Inta = Primitive_module.init([
45-
"recursive_module.res",
46-
29,
47-
4
48-
], {
49-
TAG: "Module",
50-
_0: [[
51-
"Lazy",
52-
"a"
53-
]]
54-
});
55-
56-
let Intb = Primitive_module.init([
57-
"recursive_module.res",
58-
34,
59-
4
60-
], {
61-
TAG: "Module",
62-
_0: [[
63-
"Lazy",
64-
"a"
65-
]]
66-
});
67-
68-
let a = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Intb.a));
44+
let a = Stdlib_Lazy.make(() => 2);
6945

70-
Primitive_module.update({
71-
TAG: "Module",
72-
_0: [[
73-
"Lazy",
74-
"a"
75-
]]
76-
}, Inta, {
46+
let Intb = {
7747
a: a
78-
});
48+
};
7949

80-
let a$1 = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Inta.a) + 1 | 0);
50+
let a$1 = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Intb.a) + 1 | 0);
8151

82-
Primitive_module.update({
83-
TAG: "Module",
84-
_0: [[
85-
"Lazy",
86-
"a"
87-
]]
88-
}, Intb, {
52+
let Inta = {
8953
a: a$1
90-
});
91-
92-
let tmp;
93-
94-
try {
95-
tmp = Stdlib_Lazy.get(Intb.a);
96-
} catch (raw_exn) {
97-
let exn = Primitive_exceptions.internalToException(raw_exn);
98-
if (exn.RE_EXN_ID === Stdlib_Lazy.Undefined) {
99-
tmp = -1;
100-
} else {
101-
throw exn;
102-
}
103-
}
104-
105-
eq("File \"recursive_module.res\", line 39, characters 2-9", -1, tmp);
106-
107-
let Inta$1 = Primitive_module.init([
108-
"recursive_module.res",
109-
49,
110-
6
111-
], {
112-
TAG: "Module",
113-
_0: [[
114-
"Lazy",
115-
"a"
116-
]]
117-
});
118-
119-
let Intb$1 = Primitive_module.init([
120-
"recursive_module.res",
121-
54,
122-
6
123-
], {
124-
TAG: "Module",
125-
_0: [[
126-
"Lazy",
127-
"a"
128-
]]
129-
});
130-
131-
let a$2 = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Intb$1.a) + 1 | 0);
132-
133-
Primitive_module.update({
134-
TAG: "Module",
135-
_0: [[
136-
"Lazy",
137-
"a"
138-
]]
139-
}, Inta$1, {
140-
a: a$2
141-
});
142-
143-
let a$3 = Stdlib_Lazy.make(() => 2);
144-
145-
Primitive_module.update({
146-
TAG: "Module",
147-
_0: [[
148-
"Lazy",
149-
"a"
150-
]]
151-
}, Intb$1, {
152-
a: a$3
153-
});
54+
};
15455

15556
let A = {
156-
Inta: Inta$1,
157-
Intb: Intb$1
57+
Inta: Inta,
58+
Intb: Intb
15859
};
15960

160-
eq("File \"recursive_module.res\", line 59, characters 3-10", Stdlib_Lazy.get(Inta$1.a), 3);
61+
eq("File \"recursive_module.res\", line 40, characters 3-10", Stdlib_Lazy.get(a$1), 3);
16162

162-
let tmp$1;
63+
let tmp;
16364

16465
try {
16566
Int3.u(3);
166-
tmp$1 = 3;
167-
} catch (raw_exn$1) {
168-
let exn$1 = Primitive_exceptions.internalToException(raw_exn$1);
169-
if (exn$1.RE_EXN_ID === "Undefined_recursive_module") {
170-
tmp$1 = 4;
67+
tmp = 3;
68+
} catch (raw_exn) {
69+
let exn = Primitive_exceptions.internalToException(raw_exn);
70+
if (exn.RE_EXN_ID === "Undefined_recursive_module") {
71+
tmp = 4;
17172
} else {
172-
throw exn$1;
73+
throw exn;
17374
}
17475
}
17576

176-
eq("File \"recursive_module.res\", line 62, characters 2-9", 4, tmp$1);
77+
eq("File \"recursive_module.res\", line 43, characters 2-9", 4, tmp);
17778

17879
Mt.from_pair_suites("Recursive_module", suites.contents);
17980

@@ -189,8 +90,6 @@ export {
18990
Xx,
19091
uuu,
19192
Int3,
192-
Inta,
193-
Intb,
19493
A,
19594
}
19695
/* Int3 Not a pure module */

tests/tests/src/recursive_module.res

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,6 @@ module rec Int3: {
2424
let u: int => int
2525
} = Int3
2626

27-
module rec Inta: {
28-
let a: Lazy.t<int>
29-
} = {
30-
let a = Lazy.make(() => Lazy.get(Intb.a))
31-
}
32-
and Intb: {
33-
let a: Lazy.t<int>
34-
} = {
35-
let a = Lazy.make(() => Lazy.get(Inta.a) + 1)
36-
}
37-
38-
eq(
39-
__LOC__,
40-
-1,
41-
try Lazy.get(Intb.a) catch {
42-
| Lazy.Undefined => -1
43-
},
44-
)
45-
4627
module A = {
4728
module rec Inta: {
4829
let a: Lazy.t<int>

0 commit comments

Comments
 (0)