Skip to content

Commit 9c1a499

Browse files
authored
Merge pull request #4273 from BuckleScript/no_deriving_abstract
deriving abstract free in belt
2 parents 996dd6c + 177d83c commit 9c1a499

File tree

113 files changed

+2895
-2978
lines changed

Some content is hidden

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

113 files changed

+2895
-2978
lines changed

jscomp/main/builtin_cmj_datasets.ml

Lines changed: 31 additions & 31 deletions
Large diffs are not rendered by default.

jscomp/others/belt_HashMap.ml

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type ('a,'b,'id) t =
2626

2727

2828
let clear = C.clear
29-
let size = C.sizeGet
29+
let size h = h.C.size
3030
let forEach = N.forEach
3131
let forEachU = N.forEachU
3232
let reduce = N.reduce
@@ -46,162 +46,162 @@ let rec copyBucketReHash ~hash ~h_buckets ~ndata_tail old_bucket =
4646
match C.toOpt old_bucket with
4747
| None -> ()
4848
| Some cell ->
49-
let nidx = hash (N.keyGet cell) [@bs] land (A.length h_buckets - 1) in
49+
let nidx = hash cell.N.key [@bs] land (A.length h_buckets - 1) in
5050
let v = C.return cell in
5151
begin match C.toOpt (A.getUnsafe ndata_tail nidx) with
5252
| None ->
5353
A.setUnsafe h_buckets nidx v
5454
| Some tail ->
55-
N.nextSet tail v (* cell put at the end *)
55+
tail.N.next <- v (* cell put at the end *)
5656
end;
5757
A.setUnsafe ndata_tail nidx v;
58-
copyBucketReHash ~hash ~h_buckets ~ndata_tail (N.nextGet cell)
58+
copyBucketReHash ~hash ~h_buckets ~ndata_tail cell.N.next
5959

6060

6161
let resize ~hash h =
62-
let odata = C.bucketsGet h in
62+
let odata = h.C.buckets in
6363
let osize = A.length odata in
6464
let nsize = osize * 2 in
6565
if nsize >= osize then begin (* no overflow *)
6666
let h_buckets = A.makeUninitialized nsize in
6767
let ndata_tail = A.makeUninitialized nsize in (* keep track of tail *)
68-
C.bucketsSet h h_buckets; (* so that indexfun sees the new bucket count *)
68+
h.C.buckets <- h_buckets; (* so that indexfun sees the new bucket count *)
6969
for i = 0 to osize - 1 do
7070
copyBucketReHash ~hash ~h_buckets ~ndata_tail (A.getUnsafe odata i)
7171
done;
7272
for i = 0 to nsize - 1 do
7373
match C.toOpt (A.getUnsafe ndata_tail i) with
7474
| None -> ()
75-
| Some tail -> N.nextSet tail C.emptyOpt
75+
| Some tail -> tail.N.next <- C.emptyOpt
7676
done
7777
end
7878

7979
let rec replaceInBucket ~eq key info cell =
80-
if eq (N.keyGet cell) key [@bs]
80+
if eq cell.N.key key [@bs]
8181
then
8282
begin
83-
N.valueSet cell info;
83+
cell.N.value <- info;
8484
false
8585
end
8686
else
87-
match C.toOpt (N.nextGet cell) with
87+
match C.toOpt cell.N.next with
8888
| None -> true
8989
| Some cell ->
9090
replaceInBucket ~eq key info cell
9191

9292
let set0 h key value ~eq ~hash =
93-
let h_buckets = C.bucketsGet h in
93+
let h_buckets = h.C.buckets in
9494
let buckets_len = A.length h_buckets in
9595
let i = hash key [@bs] land (buckets_len - 1) in
9696
let l = A.getUnsafe h_buckets i in
9797
(match C.toOpt l with
9898
| None ->
99-
A.setUnsafe h_buckets i (C.return (N.bucket ~key ~value ~next:C.emptyOpt));
100-
C.sizeSet h (C.sizeGet h + 1);
99+
A.setUnsafe h_buckets i (C.return {N.key; value; next = C.emptyOpt});
100+
h.C.size <- (h.C.size + 1);
101101
| Some bucket ->
102102
if replaceInBucket ~eq key value bucket then begin
103-
A.setUnsafe h_buckets i (C.return (N.bucket ~key ~value ~next:l));
104-
C.sizeSet h (C.sizeGet h + 1);
103+
A.setUnsafe h_buckets i (C.return {N.key; value; next = l});
104+
h.C.size <- (h.C.size + 1);
105105
end
106106
);
107-
if C.sizeGet h > buckets_len lsl 1 then resize ~hash h
107+
if h.C.size > buckets_len lsl 1 then resize ~hash h
108108

109109
(* if [key] already exists, replace it, otherwise add it
110110
Here we add it to the head, it could be tail
111111
*)
112112
let set h key value =
113113
set0 h key value
114-
~eq:(Belt_Id.getEqInternal (C.eqGet h))
115-
~hash:(Belt_Id.getHashInternal (C.hashGet h))
114+
~eq:(Belt_Id.getEqInternal h.C.eq)
115+
~hash:(Belt_Id.getHashInternal h.C.hash)
116116

117117
let rec removeInBucket h h_buckets i key prec bucket ~eq =
118118
match C.toOpt bucket with
119119
| None -> ()
120120
| Some cell ->
121-
let cell_next = N.nextGet cell in
122-
if eq (N.keyGet cell) key [@bs]
121+
let cell_next = cell.N.next in
122+
if eq cell.N.key key [@bs]
123123
then
124124
begin
125-
N.nextSet prec cell_next ;
126-
C.sizeSet h (C.sizeGet h - 1);
125+
prec.N.next <- cell_next ;
126+
h.C.size <- (h.C.size - 1);
127127
end
128128
else removeInBucket ~eq h h_buckets i key cell cell_next
129129

130130

131131
let remove h key =
132-
let h_buckets = C.bucketsGet h in
133-
let i = (Belt_Id.getHashInternal (C.hashGet h)) key [@bs] land (A.length h_buckets - 1) in
132+
let h_buckets = h.C.buckets in
133+
let i = (Belt_Id.getHashInternal h.C.hash) key [@bs] land (A.length h_buckets - 1) in
134134
let bucket = A.getUnsafe h_buckets i in
135135
match C.toOpt bucket with
136136
| None -> ()
137137
| Some cell ->
138-
let eq = (Belt_Id.getEqInternal (C.eqGet h)) in
139-
if eq (N.keyGet cell ) key [@bs] then
138+
let eq = (Belt_Id.getEqInternal h.C.eq) in
139+
if eq cell.N.key key [@bs] then
140140
begin
141-
A.setUnsafe h_buckets i (N.nextGet cell);
142-
C.sizeSet h (C.sizeGet h - 1)
141+
A.setUnsafe h_buckets i cell.N.next;
142+
h.C.size <- (h.C.size - 1)
143143
end
144144
else
145-
removeInBucket ~eq h h_buckets i key cell (N.nextGet cell)
145+
removeInBucket ~eq h h_buckets i key cell cell.N.next
146146

147147

148148
let rec getAux ~eq key buckets =
149149
match C.toOpt buckets with
150150
| None ->
151151
None
152152
| Some cell ->
153-
if eq key (N.keyGet cell) [@bs] then Some (N.valueGet cell)
154-
else getAux ~eq key (N.nextGet cell)
153+
if eq key cell.N.key [@bs] then Some cell.N.value
154+
else getAux ~eq key cell.N.next
155155

156156
let get h key =
157-
let h_buckets = C.bucketsGet h in
158-
let nid = (Belt_Id.getHashInternal (C.hashGet h)) key [@bs] land (A.length h_buckets - 1) in
157+
let h_buckets = h.C.buckets in
158+
let nid = (Belt_Id.getHashInternal h.C.hash) key [@bs] land (A.length h_buckets - 1) in
159159
match C.toOpt @@ A.getUnsafe h_buckets nid with
160160
| None -> None
161-
| Some cell1 ->
162-
let eq = Belt_Id.getEqInternal (C.eqGet h) in
163-
if eq key (N.keyGet cell1) [@bs] then
164-
Some (N.valueGet cell1)
161+
| Some (cell1 : _ N.bucket) ->
162+
let eq = Belt_Id.getEqInternal h.C.eq in
163+
if eq key cell1.key [@bs] then
164+
Some cell1.value
165165
else
166-
match C.toOpt (N.nextGet cell1) with
166+
match C.toOpt cell1.N.next with
167167
| None -> None
168168
| Some cell2 ->
169-
if eq key (N.keyGet cell2) [@bs] then
170-
Some (N.valueGet cell2) else
171-
match C.toOpt (N.nextGet cell2) with
169+
if eq key cell2.key [@bs] then
170+
Some cell2.value else
171+
match C.toOpt cell2.next with
172172
| None -> None
173173
| Some cell3 ->
174-
if eq key (N.keyGet cell3) [@bs] then
175-
Some (N.valueGet cell3)
174+
if eq key cell3.key [@bs] then
175+
Some cell3.value
176176
else
177-
getAux ~eq key (N.nextGet cell3)
177+
getAux ~eq key cell3.next
178178

179179

180180
let rec memInBucket key cell ~eq =
181-
eq (N.keyGet cell) key [@bs] ||
182-
(match C.toOpt (N.nextGet cell) with
181+
eq cell.N.key key [@bs] ||
182+
(match C.toOpt cell.N.next with
183183
| None -> false
184184
| Some nextCell ->
185185
memInBucket ~eq key nextCell)
186186

187187
let has h key =
188-
let h_buckets = C.bucketsGet h in
189-
let nid = (Belt_Id.getHashInternal (C.hashGet h)) key [@bs] land (A.length h_buckets - 1) in
188+
let h_buckets = h.C.buckets in
189+
let nid = (Belt_Id.getHashInternal h.C.hash) key [@bs] land (A.length h_buckets - 1) in
190190
let bucket = A.getUnsafe h_buckets nid in
191191
match C.toOpt bucket with
192192
| None -> false
193193
| Some bucket ->
194-
memInBucket ~eq:(Belt_Id.getEqInternal (C.eqGet h)) key bucket
194+
memInBucket ~eq:(Belt_Id.getEqInternal h.C.eq) key bucket
195195

196196

197197

198198

199-
let make (type key) (type identity) ~hintSize ~(id : (key,identity) id) =
199+
let make (type key identity) ~hintSize ~(id : (key,identity) id) =
200200
let module M = (val id) in
201201
C.make ~hash:M.hash ~eq:M.eq ~hintSize
202202

203203

204-
let fromArray (type a) (type identity) arr ~id:(id:(a,identity) id) =
204+
let fromArray (type a identity) arr ~id:(id:(a,identity) id) =
205205
let module M = (val id) in
206206
let hash, eq = M.hash, M.eq in
207207
let len = A.length arr in
@@ -214,7 +214,7 @@ let fromArray (type a) (type identity) arr ~id:(id:(a,identity) id) =
214214
v
215215

216216
let mergeMany h arr =
217-
let hash, eq = Belt_Id.getHashInternal ( C.hashGet h) , Belt_Id.getEqInternal (C.eqGet h) in
217+
let hash, eq = Belt_Id.getHashInternal h.C.hash , Belt_Id.getEqInternal h.C.eq in
218218
let len = A.length arr in
219219
for i = 0 to len - 1 do
220220
let key,value = (A.getUnsafe arr i) in

0 commit comments

Comments
 (0)