Skip to content

Commit d8a1145

Browse files
authored
Merge pull request #4399 from BuckleScript/internal_cleanup
remove magics in belt_List to prepare new data representations
2 parents ad446ae + d18f49d commit d8a1145

File tree

8 files changed

+107
-100
lines changed

8 files changed

+107
-100
lines changed

jscomp/core/lam_convert.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,6 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
561561
| "#apply8" -> Pjs_apply
562562
| "#makemutablelist" ->
563563
Pmakeblock(0, Blk_constructor{name = "::"; num_nonconst = 1},Mutable)
564-
| "#setfield1" ->
565-
Psetfield(1, Fld_set_na)
566564
| "#undefined_to_opt" -> Pundefined_to_opt
567565
| "#nullable_to_opt" -> Pnull_undefined_to_opt
568566
| "#null_to_opt" -> Pnull_to_opt

jscomp/main/builtin_cmj_datasets.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(* b78370ca593fdb4c6753dbd463241f61 *)
1+
(* 47d03a239582821b3c61b7f1d81133b6 *)
22
let module_names : string array = Obj.magic (
33
"Gc" (* 220 *),
44
"Js" (* 23 *),
@@ -202,7 +202,7 @@ let module_data : string array = Obj.magic (
202202
(* Js_types *)"\132\149\166\190\000\000\000!\000\000\000\012\000\000\000%\000\000\000#\160\160\176$test\144\160\160B@@@\176(classify\144\160\160A@@@A",
203203
(* Printexc *)"\132\149\166\190\000\000\001\249\000\000\000h\000\000\001\127\000\000\001V\160\b\000\000L\000\176$Slot\145\192\160\160A@@\160\160A@@\160\160A@@\160\160B@@@\176%catch\144\160\160B@@@\176%print\144\160\160B@@@\176)to_string\144\160\160A@@@\176-get_backtrace\144\160\160A@@@\176-get_callstack\144\160\160A@@@\176/backtrace_slots\144\160\160A@@@\176/print_backtrace\144\160\160A@@@\1760backtrace_status\144\160\160A@@@\1760record_backtrace\144\160\160A@@@\1760register_printer\144\160\160A@@@\1761get_raw_backtrace\144\160\160A@@@\1763print_raw_backtrace\144\160\160B@@@\1764raw_backtrace_length\144\160\160A@@@\1766get_raw_backtrace_slot\144\160\160B@@@\1767raw_backtrace_to_string\144\160\160A@@@\176:convert_raw_backtrace_slot\144\160\160A@A@\176;get_raw_backtrace_next_slot\144\160\160A@@@\176>set_uncaught_exception_handler\144\160\160A@@@A",
204204
(* Std_exit *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128@",
205-
(* Belt_List *)"\132\149\166\190\000\000\006\011\000\000\001\201\000\000\005\230\000\000\005\132\160\b\000\001`\000\176\"eq\144\160\160C@@@\176#add\144\160\160B@@\144\180B\160\176\001\004\n\"xs@\160\176\001\004\011!x@@\151\176\176@\160\"::A@\160\144\004\t\160\144\004\014@\176\1923others/belt_List.ml\000g\001\0110\001\011@\192\004\002\000g\001\0110\001\011G@\176#cmp\144\160\160C@@@\176#eqU\144\160\160C@@@\176#get\144\160\160B@@@\176#has\144\160\160C@@@\176#map\144\160\160B@@@\176#zip\144\160\160B@@@\176$cmpU\144\160\160C@@@\176$drop\144\160\160B@@@\176$hasU\144\160\160C@@@\176$head\144\160\160A@@@\176$keep\144\160\160B@@@\176$make\144\160\160B@@@\176$mapU\144\160\160B@@@\176$size\144\160\160A@@@\176$some\144\160\160B@@@\176$sort\144\160\160B@@@\176$tail\144\160\160A@@@\176$take\144\160\160B@@@\176%every\144\160\160B@@@\176%getBy\144\160\160B@@@\176%keepU\144\160\160B@@@\176%some2\144\160\160C@@@\176%someU\144\160\160B@@@\176%sortU\144\160\160B@@@\176%unzip\144\160\160A@@@\176%zipBy\144\160\160C@@@\176&concat\144\160\160B@@@\176&every2\144\160\160C@@@\176&everyU\144\160\160B@@@\176&filter\144\004_@\176&getByU\144\160\160B@@@\176&getExn\144\160\160B@@@\176&length\144\004]@\176&makeBy\144\160\160B@@@\176&reduce\144\160\160C@@@\176&some2U\144\160\160C@@@\176&zipByU\144\160\160C@@@\176'every2U\144\160\160C@@@\176'flatten\144\160\160A@@@\176'forEach\144\160\160B@@@\176'headExn\144\160\160A@@@\176'keepMap\144\160\160B@@@\176'makeByU\144\160\160B@@@\176'reduce2\144\160\160D@@@\176'reduceU\144\160\160C@@@\176'reverse\144\160\160A@@@\176'shuffle\144\160\160A@@@\176'splitAt\144\160\160B@@@\176'tailExn\144\160\160A@@@\176'toArray\144\160\160A@@@\176(forEach2\144\160\160C@@@\176(forEachU\144\160\160B@@@\176(getAssoc\144\160\160C@@@\176(hasAssoc\144\160\160C@@@\176(keepMapU\144\160\160B@@@\176(reduce2U\144\160\160D@@@\176(setAssoc\144\160\160D@@@\176)forEach2U\144\160\160C@@@\176)fromArray\144\160\160A@@@\176)getAssocU\144\160\160C@@@\176)hasAssocU\144\160\160C@@@\176)partition\144\160\160B@@@\176)setAssocU\144\160\160D@@@\176*concatMany\144\160\160A@@@\176*mapReverse\144\160\160B@@@\176*partitionU\144\160\160B@@@\176+cmpByLength\144\160\160B@@@\176+mapReverse2\144\160\160C@@@\176+mapReverseU\144\160\160B@@@\176+removeAssoc\144\160\160C@@@\176,mapReverse2U\144\160\160C@@@\176,mapWithIndex\144\160\160B@@@\176,removeAssocU\144\160\160C@@@\176-keepWithIndex\144\160\160B@@@\176-mapWithIndexU\144\160\160B@@@\176-reduceReverse\144\160\160C@@@\176-reverseConcat\144\160\160B@@@\176.keepWithIndexU\144\160\160B@@@\176.reduceReverse2\144\160\160D@@@\176.reduceReverseU\144\160\160C@@@\176/filterWithIndex\144\004#@\176/reduceReverse2U\144\160\160D@@@\176/reduceWithIndex\144\160\160C@@@\1760forEachWithIndex\144\160\160B@@@\1760reduceWithIndexU\144\160\160C@@@\1761forEachWithIndexU\144\160\160B@@@A",
205+
(* Belt_List *)"\132\149\166\190\000\000\006\011\000\000\001\201\000\000\005\230\000\000\005\132\160\b\000\001`\000\176\"eq\144\160\160C@@@\176#add\144\160\160B@@\144\180B\160\176\001\004\018\"xs@\160\176\001\004\019!x@@\151\176\176@\160\"::A@\160\144\004\t\160\144\004\014@\176\1923others/belt_List.ml\000p\001\011\191\001\011\207\192\004\002\000p\001\011\191\001\011\214@\176#cmp\144\160\160C@@@\176#eqU\144\160\160C@@@\176#get\144\160\160B@@@\176#has\144\160\160C@@@\176#map\144\160\160B@@@\176#zip\144\160\160B@@@\176$cmpU\144\160\160C@@@\176$drop\144\160\160B@@@\176$hasU\144\160\160C@@@\176$head\144\160\160A@@@\176$keep\144\160\160B@@@\176$make\144\160\160B@@@\176$mapU\144\160\160B@@@\176$size\144\160\160A@@@\176$some\144\160\160B@@@\176$sort\144\160\160B@@@\176$tail\144\160\160A@@@\176$take\144\160\160B@@@\176%every\144\160\160B@@@\176%getBy\144\160\160B@@@\176%keepU\144\160\160B@@@\176%some2\144\160\160C@@@\176%someU\144\160\160B@@@\176%sortU\144\160\160B@@@\176%unzip\144\160\160A@@@\176%zipBy\144\160\160C@@@\176&concat\144\160\160B@@@\176&every2\144\160\160C@@@\176&everyU\144\160\160B@@@\176&filter\144\004_@\176&getByU\144\160\160B@@@\176&getExn\144\160\160B@@@\176&length\144\004]@\176&makeBy\144\160\160B@@@\176&reduce\144\160\160C@@@\176&some2U\144\160\160C@@@\176&zipByU\144\160\160C@@@\176'every2U\144\160\160C@@@\176'flatten\144\160\160A@@@\176'forEach\144\160\160B@@@\176'headExn\144\160\160A@@@\176'keepMap\144\160\160B@@@\176'makeByU\144\160\160B@@@\176'reduce2\144\160\160D@@@\176'reduceU\144\160\160C@@@\176'reverse\144\160\160A@@@\176'shuffle\144\160\160A@@@\176'splitAt\144\160\160B@@@\176'tailExn\144\160\160A@@@\176'toArray\144\160\160A@@@\176(forEach2\144\160\160C@@@\176(forEachU\144\160\160B@@@\176(getAssoc\144\160\160C@@@\176(hasAssoc\144\160\160C@@@\176(keepMapU\144\160\160B@@@\176(reduce2U\144\160\160D@@@\176(setAssoc\144\160\160D@@@\176)forEach2U\144\160\160C@@@\176)fromArray\144\160\160A@@@\176)getAssocU\144\160\160C@@@\176)hasAssocU\144\160\160C@@@\176)partition\144\160\160B@@@\176)setAssocU\144\160\160D@@@\176*concatMany\144\160\160A@@@\176*mapReverse\144\160\160B@@@\176*partitionU\144\160\160B@@@\176+cmpByLength\144\160\160B@@@\176+mapReverse2\144\160\160C@@@\176+mapReverseU\144\160\160B@@@\176+removeAssoc\144\160\160C@@@\176,mapReverse2U\144\160\160C@@@\176,mapWithIndex\144\160\160B@@@\176,removeAssocU\144\160\160C@@@\176-keepWithIndex\144\160\160B@@@\176-mapWithIndexU\144\160\160B@@@\176-reduceReverse\144\160\160C@@@\176-reverseConcat\144\160\160B@@@\176.keepWithIndexU\144\160\160B@@@\176.reduceReverse2\144\160\160D@@@\176.reduceReverseU\144\160\160C@@@\176/filterWithIndex\144\004#@\176/reduceReverse2U\144\160\160D@@@\176/reduceWithIndex\144\160\160C@@@\1760forEachWithIndex\144\160\160B@@@\1760reduceWithIndexU\144\160\160C@@@\1761forEachWithIndexU\144\160\160B@@@A",
206206
(* Ephemeron *)"\132\149\166\190\000\000\001>\000\000\000|\000\000\001\162\000\000\001\160\160\192\176\"K1\145\b\000\000<\000\160\160A@@\160\160A@@\160\160A@@\160\160B@@\160\160A@@\160\160A@@\160\160B@@\160\160A@@\160\160A@@\160\160B@@\160\160A@@\160\160A@@\160\160B@@\160\160A@@\160\160A@@@\176\"K2\145\b\000\000X\000\160\160A@@\160\160A@@\160\160A@@\160\160B@@\160\160A@@\160\160A@@\160\160A@@\160\160A@@\160\160B@@\160\160A@@\160\160A@@\160\160B@@\160\160B@@\160\160B@@\160\160A@@\160\160A@@\160\160B@@\160\160A@@\160\160A@@\160\160B@@\160\160B@@\160\160B@@@\176\"Kn\145\b\000\000<\000\160\160A@@\160\160B@@\160\160B@@\160\160C@@\160\160B@@\160\160B@@\160\160E@@\160\160A@@\160\160A@@\160\160B@@\160\160A@@\160\160A@@\160\160B@@\160\160A@@\160\160A@@@\176,GenHashTable\145\144\160\160A@@@A",
207207
(* Js_array2 *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",
208208
(* Js_global *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",

jscomp/others/belt_List.ml

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,23 @@ module A = Belt_Array
6767

6868
external mutableCell :
6969
'a -> 'a t -> 'a t = "#makemutablelist"
70+
71+
72+
type poly = { unsafeMutateTail : 'a . 'a t -> 'a t -> unit } [@@unboxed]
73+
74+
7075
(*
7176
[mutableCell x []] == [x]
7277
but tell the compiler that is a mutable cell, so it wont
7378
be mis-inlined in the future
7479
dont inline a binding to mutable cell, it is mutable
7580
*)
76-
external unsafeMutateTail :
77-
'a t -> 'a t -> unit = "#setfield1"
81+
(* relies on list internal representation *)
82+
let m : poly = {unsafeMutateTail = [%raw{|function(xs,ys){
83+
xs[1] = ys
84+
}|}]}
85+
86+
7887

7988
(*
8089
- the cell is not empty
@@ -128,12 +137,12 @@ let rec partitionAux p cell precX precY =
128137
let next = mutableCell h [] in
129138
if p h [@bs] then
130139
begin
131-
unsafeMutateTail precX next ;
140+
m.unsafeMutateTail precX next ;
132141
partitionAux p t next precY
133142
end
134143
else
135144
begin
136-
unsafeMutateTail precY next ;
145+
m.unsafeMutateTail precY next ;
137146
partitionAux p t precX next
138147
end
139148

@@ -143,8 +152,8 @@ let rec splitAux cell precX precY =
143152
| (a,b)::t ->
144153
let nextA = mutableCell a [] in
145154
let nextB = mutableCell b [] in
146-
unsafeMutateTail precX nextA;
147-
unsafeMutateTail precY nextB;
155+
m.unsafeMutateTail precX nextA;
156+
m.unsafeMutateTail precY nextB;
148157
splitAux t nextA nextB
149158

150159
(* return the tail pointer so it can continue copy other
@@ -155,7 +164,7 @@ let rec copyAuxCont cellX prec =
155164
| [] -> prec
156165
| h::t ->
157166
let next = mutableCell h [] in
158-
unsafeMutateTail prec next ;
167+
m.unsafeMutateTail prec next ;
159168
copyAuxCont t next
160169

161170
let rec copyAuxWitFilter f cellX prec =
@@ -166,7 +175,7 @@ let rec copyAuxWitFilter f cellX prec =
166175
if f h [@bs] then
167176
begin
168177
let next = mutableCell h [] in
169-
unsafeMutateTail prec next ;
178+
m.unsafeMutateTail prec next ;
170179
copyAuxWitFilter f t next
171180
end
172181
else copyAuxWitFilter f t prec
@@ -179,7 +188,7 @@ let rec copyAuxWithFilterIndex f cellX prec i =
179188
if f h i [@bs] then
180189
begin
181190
let next = mutableCell h [] in
182-
unsafeMutateTail prec next ;
191+
m.unsafeMutateTail prec next ;
183192
copyAuxWithFilterIndex f t next (i + 1)
184193
end
185194
else copyAuxWithFilterIndex f t prec (i + 1)
@@ -193,7 +202,7 @@ let rec copyAuxWitFilterMap f cellX prec =
193202
| Some h ->
194203
begin
195204
let next = mutableCell h [] in
196-
unsafeMutateTail prec next ;
205+
m.unsafeMutateTail prec next ;
197206
copyAuxWitFilterMap f t next
198207
end
199208
| None -> copyAuxWitFilterMap f t prec
@@ -203,21 +212,21 @@ let rec removeAssocAuxWithMap cellX x prec f =
203212
| [] -> false
204213
| ((a,_) as h):: t ->
205214
if f a x [@bs] then
206-
(unsafeMutateTail prec t ; true)
215+
(m.unsafeMutateTail prec t ; true)
207216
else
208217
let next = mutableCell h [] in
209-
unsafeMutateTail prec next ;
218+
m.unsafeMutateTail prec next ;
210219
removeAssocAuxWithMap t x next f
211220

212221
let rec setAssocAuxWithMap cellX x k prec eq =
213222
match cellX with
214223
| [] -> false
215224
| ((a,_) as h) :: t ->
216225
if eq a x [@bs] then
217-
(unsafeMutateTail prec ( (x,k)::t); true)
226+
(m.unsafeMutateTail prec ( (x,k)::t); true)
218227
else
219228
let next = mutableCell h [] in
220-
unsafeMutateTail prec next ;
229+
m.unsafeMutateTail prec next ;
221230
setAssocAuxWithMap t x k next eq
222231

223232

@@ -227,15 +236,15 @@ let rec copyAuxWithMap cellX prec f =
227236
()
228237
| h::t ->
229238
let next = mutableCell (f h [@bs]) [] in
230-
unsafeMutateTail prec next ;
239+
m.unsafeMutateTail prec next ;
231240
copyAuxWithMap t next f
232241

233242

234243
let rec zipAux cellX cellY prec =
235244
match cellX, cellY with
236245
| h1::t1, h2::t2 ->
237246
let next = mutableCell ( h1, h2) [] in
238-
unsafeMutateTail prec next ;
247+
m.unsafeMutateTail prec next ;
239248
zipAux t1 t2 next
240249
| [],_ | _,[] ->
241250
()
@@ -244,7 +253,7 @@ let rec copyAuxWithMap2 f cellX cellY prec =
244253
match cellX, cellY with
245254
| h1::t1, h2::t2 ->
246255
let next = mutableCell (f h1 h2 [@bs]) [] in
247-
unsafeMutateTail prec next ;
256+
m.unsafeMutateTail prec next ;
248257
copyAuxWithMap2 f t1 t2 next
249258
| [],_ | _,[] ->
250259
()
@@ -253,7 +262,7 @@ let rec copyAuxWithMapI f i cellX prec =
253262
match cellX with
254263
| h::t ->
255264
let next = mutableCell (f i h [@bs]) [] in
256-
unsafeMutateTail prec next ;
265+
m.unsafeMutateTail prec next ;
257266
copyAuxWithMapI f (i + 1) t next
258267
| [] ->
259268
()
@@ -265,7 +274,7 @@ let rec takeAux n cell prec =
265274
| [] -> false
266275
| x::xs ->
267276
let cell = mutableCell x [] in
268-
unsafeMutateTail prec cell;
277+
m.unsafeMutateTail prec cell;
269278
takeAux (n - 1) xs cell
270279

271280
let rec splitAtAux n cell prec =
@@ -275,7 +284,7 @@ let rec splitAtAux n cell prec =
275284
| [] -> None
276285
| x::xs ->
277286
let cell = mutableCell x [] in
278-
unsafeMutateTail prec cell;
287+
m.unsafeMutateTail prec cell;
279288
splitAtAux (n - 1) xs cell
280289

281290
(* invarint [n >= 0] *)
@@ -323,7 +332,7 @@ let concat xs ys =
323332
| [] -> ys
324333
| h::t ->
325334
let cell = mutableCell h [] in
326-
unsafeMutateTail (copyAuxCont t cell) ys;
335+
m.unsafeMutateTail (copyAuxCont t cell) ys;
327336
cell
328337

329338
let mapU xs f =
@@ -365,7 +374,7 @@ let makeByU n f =
365374
let i = ref 1 in
366375
while i.contents < n do
367376
let v = mutableCell (f i.contents [@bs]) [] in
368-
unsafeMutateTail cur.contents v ;
377+
m.unsafeMutateTail cur.contents v ;
369378
cur.contents<- v ;
370379
i.contents <- i.contents + 1 ;
371380
done
@@ -374,15 +383,15 @@ let makeByU n f =
374383

375384
let makeBy n f = makeByU n (fun[@bs] x -> f x)
376385

377-
let make n v =
386+
let make (type a) n (v : a) : a list =
378387
if n <= 0 then []
379388
else
380389
let headX = mutableCell v [] in
381390
let cur = ref headX in
382391
let i = ref 1 in
383392
while i.contents < n do
384393
let v = mutableCell v [] in
385-
unsafeMutateTail cur.contents v ;
394+
m.unsafeMutateTail cur.contents v ;
386395
cur.contents<- v ;
387396
i.contents <- i.contents + 1 ;
388397
done
@@ -452,7 +461,7 @@ let shuffle xs =
452461
(* let cell = ref head in *)
453462
(* for i = 1 to len - 1 do *)
454463
(* let next = mutableCell (f (A.getUnsafe arr i) [@bs]) [] in *)
455-
(* unsafeMutateTail !cell next ; *)
464+
(* unsafeMutateTail.unsafeMutateTail !cell next ; *)
456465
(* cell .contents<- next *)
457466
(* done ; *)
458467
(* head *)
@@ -468,7 +477,7 @@ let reverse l = reverseConcat l []
468477

469478
let rec flattenAux prec xs =
470479
match xs with
471-
| [] -> unsafeMutateTail prec []
480+
| [] -> m.unsafeMutateTail prec []
472481
| h::r -> flattenAux (copyAuxCont h prec) r
473482

474483

0 commit comments

Comments
 (0)