Skip to content

Commit 96ef1be

Browse files
committed
1. use dict to make module pass consistent
2. inline camlinternalOO into camlinternalMod to avoid unnecessary deps
1 parent f49a5d9 commit 96ef1be

11 files changed

+335
-324
lines changed

jscomp/bsb/bsb_templates.ml

+235-235
Large diffs are not rendered by default.

jscomp/others/bs_Set.ml

+30-30
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type ('elt, 'id)enumeration =
99
| More of 'elt * ('elt, 'id) t0 * ('elt, 'id) enumeration
1010

1111
type ('elt, 'id) t = {
12-
cmp : ('elt,'id) Bs_Cmp.t ;
12+
dict : ('elt,'id) Bs_Cmp.t ;
1313
data : ('elt,'id) t0
1414
}
1515

@@ -190,74 +190,74 @@ let ofArray0 ~cmp (xs : _ array) : _ t0 =
190190
done ;
191191
!result
192192

193-
let empty cmp = {
194-
cmp ;
193+
let empty dict = {
194+
dict ;
195195
data = empty0
196196
}
197-
let ofArray (type elt) (type id) (cmp : (elt,id) Bs_Cmp.t) data =
198-
let module M = (val cmp ) in
197+
let ofArray (type elt) (type id) (dict : (elt,id) Bs_Cmp.t) data =
198+
let module M = (val dict ) in
199199
{
200-
cmp ;
200+
dict ;
201201
data = ofArray0 ~cmp:M.cmp data
202202
}
203203

204204
let isEmpty m = isEmpty0 m.data
205205

206206

207207
let mem (type elt) (type id) e (m : (elt,id) t) =
208-
let module M = (val m.cmp) in
208+
let module M = (val m.dict) in
209209
mem0 ~cmp:(M.cmp) e m.data
210210

211211
let add (type elt) (type id) e (m : (elt,id) t) =
212-
let m_cmp = m.cmp in
212+
let m_cmp = m.dict in
213213
let module M = (val m_cmp) in
214-
{data = add0 ~cmp:(M.cmp) e m.data ; cmp = m_cmp}
214+
{data = add0 ~cmp:(M.cmp) e m.data ; dict = m_cmp}
215215

216-
let singleton cmp e =
217-
{ cmp;
216+
let singleton dict e =
217+
{ dict;
218218
data = singleton0 e
219219
}
220220

221221
let remove (type elt) (type id) e (m : (elt,id) t) =
222-
let m_cmp = m.cmp in
222+
let m_cmp = m.dict in
223223
let module M = (val m_cmp) in
224224
{ data = remove0 ~cmp:M.cmp e m.data ;
225-
cmp = m_cmp
225+
dict = m_cmp
226226
}
227227

228228
let union (type elt) (type id) (m : (elt,id) t) (n : (elt,id) t) =
229-
let m_cmp = m.cmp in
229+
let m_cmp = m.dict in
230230
let module M = (val m_cmp) in
231231
{ data = union0 ~cmp:M.cmp m.data n.data ;
232-
cmp = m_cmp
232+
dict = m_cmp
233233
}
234234

235235
let inter (type elt) (type id) (m : (elt,id) t) (n : (elt,id) t) =
236-
let m_cmp = m.cmp in
236+
let m_cmp = m.dict in
237237
let module M = (val m_cmp) in
238238
{ data = inter0 ~cmp:M.cmp m.data n.data ;
239-
cmp = m_cmp
239+
dict = m_cmp
240240
}
241241

242242
let diff (type elt) (type id) (m : (elt,id) t) (n : (elt,id) t) =
243-
let m_cmp = m.cmp in
243+
let m_cmp = m.dict in
244244
let module M = (val m_cmp) in
245245
{ data = diff0 ~cmp:M.cmp m.data n.data ;
246-
cmp = m_cmp
246+
dict = m_cmp
247247
}
248248

249249
let cmp (type elt) (type id) (m : (elt,id) t) (n : (elt,id) t) =
250-
let m_cmp = m.cmp in
250+
let m_cmp = m.dict in
251251
let module M = (val m_cmp) in
252252
cmp0 ~cmp:M.cmp m.data n.data
253253

254254
let eq (type elt) (type id) (m : (elt,id) t) (n : (elt,id) t) =
255-
let m_cmp = m.cmp in
255+
let m_cmp = m.dict in
256256
let module M = (val m_cmp) in
257257
eq0 ~cmp:M.cmp m.data n.data
258258

259259
let subset (type elt) (type id) (m : (elt,id) t) (n : (elt,id) t) =
260-
let m_cmp = m.cmp in
260+
let m_cmp = m.dict in
261261
let module M = (val m_cmp) in
262262
subset0 ~cmp:M.cmp m.data n.data
263263

@@ -273,8 +273,8 @@ let filter f m = {m with data = filter0 f m.data}
273273

274274
let partition f m =
275275
let l,r = partition0 f m.data in
276-
let cmp = m.cmp in
277-
{data = l; cmp}, {data = r; cmp}
276+
let dict = m.dict in
277+
{data = l; dict }, {data = r; dict }
278278

279279
let cardinal m = cardinal0 m.data
280280

@@ -285,20 +285,20 @@ let min m = min0 m.data
285285
let max m = max0 m.data
286286

287287
let split (type elt) (type id) e (m : (elt,id) t) =
288-
let m_cmp = m.cmp in
289-
let module M = (val m_cmp) in
288+
let dict = m.dict in
289+
let module M = (val dict) in
290290
let l, b, r = split0 ~cmp:M.cmp e m.data in
291-
{cmp = m_cmp; data = l},
291+
{dict; data = l},
292292
b,
293-
{cmp = m_cmp ; data = r}
293+
{dict; data = r}
294294

295295
let findOpt (type elt) (type id) e (m : (elt,id) t) =
296-
let m_cmp = m.cmp in
296+
let m_cmp = m.dict in
297297
let module M = (val m_cmp) in
298298
findOpt0 ~cmp:M.cmp e m.data
299299

300300
let findAssert (type elt) (type id) e (m : (elt,id) t) =
301-
let m_cmp = m.cmp in
301+
let m_cmp = m.dict in
302302
let module M = (val m_cmp) in
303303
findAssert0 ~cmp:M.cmp e m.data
304304

jscomp/others/bs_Set.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
type ('elt, 'id) t0
55

66
type ('elt, 'id) t = {
7-
cmp : ('elt,'id) Bs_Cmp.t ;
7+
dict : ('elt,'id) Bs_Cmp.t ;
88
data : ('elt,'id) t0
99
}
1010
(** The type of sets. *)

jscomp/stdlib/camlinternalMod.ml

+11-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ type shape =
6868
(* update_mod comps.(i) (Obj.field o i) (Obj.field n i) *)
6969
(* done *)
7070
(* | Value v -> () (\* the value is already there *\) *)
71-
72-
71+
#if BS then
72+
let dummy_class loc =
73+
let undef = fun _ -> raise (Undefined_recursive_module loc) in
74+
(Obj.magic undef, undef, undef, Obj.repr 0)
75+
#end
7376
(** Note that we have to provide a drop in replacement, since compiler internally will
7477
spit out ("CamlinternalMod".[init_mod|update_mod] unless we intercept it
7578
in the lambda layer
@@ -80,7 +83,12 @@ let init_mod (loc : string * int * int) (shape : shape) =
8083
match shape with
8184
| Function -> struct_.(idx)<-(Obj.magic undef_module)
8285
| Lazy -> struct_.(idx)<- (Obj.magic (lazy undef_module))
83-
| Class -> struct_.(idx)<- (Obj.magic (CamlinternalOO.dummy_class loc))
86+
| Class -> struct_.(idx)<-
87+
#if BS then
88+
(Obj.magic (dummy_class loc))
89+
#else
90+
(Obj.magic (CamlinternalOO.dummy_class loc))
91+
#end
8492
| Module comps
8593
->
8694
let v = (Obj.magic [||]) in

jscomp/stdlib/camlinternalOO.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,11 @@ let make_class_store pub_meths class_init init_table =
382382
init_table.class_init <- class_init;
383383
init_table.env_init <- env_init
384384

385+
#if undefined BS then
385386
let dummy_class loc =
386387
let undef = fun _ -> raise (Undefined_recursive_module loc) in
387388
(Obj.magic undef, undef, undef, Obj.repr 0)
388-
389+
#end
389390
(**** Objects ****)
390391

391392
let create_object table =

jscomp/stdlib/camlinternalOO.mli

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ val make_class :
5151
type init_table
5252
val make_class_store :
5353
string array -> (table -> t) -> init_table -> unit
54+
#if undefined BS then
5455
val dummy_class :
5556
string * int * int ->
5657
(t * (table -> Obj.t -> t) * (Obj.t -> t) * Obj.t)
57-
58+
#end
5859
(** {6 Objects} *)
5960

6061
val copy : (< .. > as 'a) -> 'a

lib/bsb.ml

+10-7
Original file line numberDiff line numberDiff line change
@@ -13100,7 +13100,7 @@ let root = OCamlRes.Res.([
1310013100
\ }\n\
1310113101
}") ;
1310213102
Dir ("src", [
13103-
File ("demo.re",
13103+
File ("Demo.re",
1310413104
"Js.log(\"Hello, BuckleScript and Reason!\");\n\
1310513105
")]) ;
1310613106
File ("README.md",
@@ -13396,15 +13396,15 @@ let root = OCamlRes.Res.([
1339613396
"const path = require('path');\n\
1339713397
\n\
1339813398
module.exports = {\n\
13399-
\ entry: './src/index.bs.js',\n\
13399+
\ entry: './src/Index.bs.js',\n\
1340013400
\ output: {\n\
1340113401
\ path: path.join(__dirname, \"build\"),\n\
13402-
\ filename: 'index.js',\n\
13402+
\ filename: 'Index.js',\n\
1340313403
\ },\n\
1340413404
};\n\
1340513405
") ;
1340613406
Dir ("src", [
13407-
File ("page.re",
13407+
File ("Page.re",
1340813408
"/* This is the basic component. */\n\
1340913409
let component = ReasonReact.statelessComponent(\"Page\");\n\
1341013410
\n\
@@ -13427,7 +13427,7 @@ let root = OCamlRes.Res.([
1342713427
\ <div onClick=(self.handle(handleClick))> (ReasonReact.stringToElement(message)) </div>\n\
1342813428
};\n\
1342913429
") ;
13430-
File ("index.re",
13430+
File ("Index.re",
1343113431
"ReactDOMRe.renderToElementWithId(<Page message=\"Hello!\" />, \"index\");\n\
1343213432
") ;
1343313433
File ("index.html",
@@ -13439,7 +13439,7 @@ let root = OCamlRes.Res.([
1343913439
</head>\n\
1344013440
<body>\n\
1344113441
\ <div id=\"index\"></div>\n\
13442-
\ <script src=\"../build/index.js\"></script>\n\
13442+
\ <script src=\"../build/Index.js\"></script>\n\
1344313443
</body>\n\
1344413444
</html>\n\
1344513445
")]) ;
@@ -13506,7 +13506,10 @@ let root = OCamlRes.Res.([
1350613506
\ \"bs-dependencies\": [\n\
1350713507
\ \"reason-react\"\n\
1350813508
\ ],\n\
13509-
\ \"refmt\": 3\n\
13509+
\ \"refmt\": 3,\n\
13510+
\ \"warnings\": {\n\
13511+
\ \"error\": \"+5\"\n\
13512+
\ }\n\
1351013513
}\n\
1351113514
") ;
1351213515
File (".gitignore",

lib/js/bs_Set.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,17 @@ function ofArray0(cmp, xs) {
195195
return result;
196196
}
197197

198-
function empty(cmp) {
198+
function empty(dict) {
199199
return /* record */[
200-
/* cmp */cmp,
200+
/* dict */dict,
201201
/* data */Bs_internalAVLset.empty0
202202
];
203203
}
204204

205-
function ofArray(cmp, data) {
205+
function ofArray(dict, data) {
206206
return /* record */[
207-
/* cmp */cmp,
208-
/* data */ofArray0(cmp[/* cmp */0], data)
207+
/* dict */dict,
208+
/* data */ofArray0(dict[/* cmp */0], data)
209209
];
210210
}
211211

@@ -214,48 +214,48 @@ function isEmpty(m) {
214214
}
215215

216216
function mem(e, m) {
217-
var M = m[/* cmp */0];
217+
var M = m[/* dict */0];
218218
return mem0(M[/* cmp */0], e, m[/* data */1]);
219219
}
220220

221221
function add(e, m) {
222-
var m_cmp = m[/* cmp */0];
222+
var m_cmp = m[/* dict */0];
223223
return /* record */[
224-
/* cmp */m_cmp,
224+
/* dict */m_cmp,
225225
/* data */add0(m_cmp[/* cmp */0], e, m[/* data */1])
226226
];
227227
}
228228

229-
function singleton(cmp, e) {
229+
function singleton(dict, e) {
230230
return /* record */[
231-
/* cmp */cmp,
231+
/* dict */dict,
232232
/* data */Bs_internalAVLset.singleton0(e)
233233
];
234234
}
235235

236236
function remove(e, m) {
237-
var m_cmp = m[/* cmp */0];
237+
var m_cmp = m[/* dict */0];
238238
return /* record */[
239-
/* cmp */m_cmp,
239+
/* dict */m_cmp,
240240
/* data */remove0(m_cmp[/* cmp */0], e, m[/* data */1])
241241
];
242242
}
243243

244244
function union(m, n) {
245-
var m_cmp = m[/* cmp */0];
245+
var m_cmp = m[/* dict */0];
246246
return /* record */[
247-
/* cmp */m_cmp,
247+
/* dict */m_cmp,
248248
/* data */union0(m_cmp[/* cmp */0], m[/* data */1], n[/* data */1])
249249
];
250250
}
251251

252252
function cmp(m, n) {
253-
var m_cmp = m[/* cmp */0];
253+
var m_cmp = m[/* dict */0];
254254
return cmp0(m_cmp[/* cmp */0], m[/* data */1], n[/* data */1]);
255255
}
256256

257257
function eq(m, n) {
258-
var m_cmp = m[/* cmp */0];
258+
var m_cmp = m[/* dict */0];
259259
return eq0(m_cmp[/* cmp */0], m[/* data */1], n[/* data */1]);
260260
}
261261

@@ -277,21 +277,21 @@ function exists(f, m) {
277277

278278
function filter(f, m) {
279279
return /* record */[
280-
/* cmp */m[/* cmp */0],
280+
/* dict */m[/* dict */0],
281281
/* data */Bs_internalAVLset.filter0(f, m[/* data */1])
282282
];
283283
}
284284

285285
function partition(f, m) {
286286
var match = Bs_internalAVLset.partition0(f, m[/* data */1]);
287-
var cmp = m[/* cmp */0];
287+
var dict = m[/* dict */0];
288288
return /* tuple */[
289289
/* record */[
290-
/* cmp */cmp,
290+
/* dict */dict,
291291
/* data */match[0]
292292
],
293293
/* record */[
294-
/* cmp */cmp,
294+
/* dict */dict,
295295
/* data */match[1]
296296
]
297297
];
@@ -314,16 +314,16 @@ function max(m) {
314314
}
315315

316316
function split(e, m) {
317-
var m_cmp = m[/* cmp */0];
318-
var match = split0(m_cmp[/* cmp */0], e, m[/* data */1]);
317+
var dict = m[/* dict */0];
318+
var match = split0(dict[/* cmp */0], e, m[/* data */1]);
319319
return /* tuple */[
320320
/* record */[
321-
/* cmp */m_cmp,
321+
/* dict */dict,
322322
/* data */match[0]
323323
],
324324
match[1],
325325
/* record */[
326-
/* cmp */m_cmp,
326+
/* dict */dict,
327327
/* data */match[2]
328328
]
329329
];

0 commit comments

Comments
 (0)