Skip to content

Commit 9265b64

Browse files
committed
Refine reactive_file_collection representation
Simplify the reactive_file_collection implementation by making 'v t be the concrete record type used at runtime, removing the unused phantom fields and internal wrapper type. This eliminates warning 69 about unused record fields and relies directly on a single record with its process function stored as an Obj.t-based callback.
1 parent 7f482bf commit 9265b64

File tree

2 files changed

+25
-43
lines changed

2 files changed

+25
-43
lines changed

analysis/vendor/skip-lite/reactive_file_collection/reactive_file_collection.ml

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,32 @@ type event =
55
| Removed of string
66
| Modified of string
77

8-
type 'v t = {
9-
data : (string, 'v) Hashtbl.t;
10-
process : 'a. 'a -> 'v;
11-
}
12-
13-
(* We need to use Obj.magic to make the polymorphic process function work
14-
with Marshal_cache which returns 'a. This is safe because the user
8+
(* We need to use Obj.t to make the polymorphic process function work
9+
with Marshal_cache which returns ['a]. This is safe because the user
1510
guarantees the file contains data of the expected type. *)
1611
type 'v process_fn = Obj.t -> 'v
1712

18-
type 'v t_internal = {
19-
data_internal : (string, 'v) Hashtbl.t;
20-
process_internal : 'v process_fn;
13+
type 'v t = {
14+
data : (string, 'v) Hashtbl.t;
15+
process : 'v process_fn;
2116
}
2217

2318
let create (type a v) ~(process : a -> v) : v t =
24-
let process_internal : v process_fn = fun obj -> process (Obj.obj obj) in
25-
let t = {
26-
data_internal = Hashtbl.create 256;
27-
process_internal;
28-
} in
29-
(* Safe cast - same representation *)
30-
Obj.magic t
31-
32-
let to_internal (t : 'v t) : 'v t_internal = Obj.magic t
19+
let process_fn : v process_fn = fun obj -> process (Obj.obj obj) in
20+
{
21+
data = Hashtbl.create 256;
22+
process = process_fn;
23+
}
3324

3425
let add t path =
35-
let t = to_internal t in
3626
let value = Marshal_cache.with_unmarshalled_file path (fun data ->
37-
t.process_internal (Obj.repr data)
27+
t.process (Obj.repr data)
3828
) in
39-
Hashtbl.replace t.data_internal path value
29+
Hashtbl.replace t.data path value
4030
[@@alert "-unsafe"]
4131

4232
let remove t path =
43-
let t = to_internal t in
44-
Hashtbl.remove t.data_internal path
33+
Hashtbl.remove t.data path
4534

4635
let update t path =
4736
(* Just reload - Marshal_cache handles the file reading efficiently *)
@@ -53,33 +42,26 @@ let apply t events =
5342
| Removed path -> remove t path
5443
| Modified path -> update t path
5544
) events
56-
5745
let get t path =
58-
let t = to_internal t in
59-
Hashtbl.find_opt t.data_internal path
46+
Hashtbl.find_opt t.data path
6047

6148
let find t path =
62-
let t = to_internal t in
63-
Hashtbl.find t.data_internal path
49+
Hashtbl.find t.data path
6450

6551
let mem t path =
66-
let t = to_internal t in
67-
Hashtbl.mem t.data_internal path
52+
Hashtbl.mem t.data path
6853

6954
let length t =
70-
let t = to_internal t in
71-
Hashtbl.length t.data_internal
55+
Hashtbl.length t.data
7256

7357
let is_empty t =
7458
length t = 0
7559

7660
let iter f t =
77-
let t = to_internal t in
78-
Hashtbl.iter f t.data_internal
61+
Hashtbl.iter f t.data
7962

8063
let fold f t init =
81-
let t = to_internal t in
82-
Hashtbl.fold f t.data_internal init
64+
Hashtbl.fold f t.data init
8365

8466
let to_list t =
8567
fold (fun k v acc -> (k, v) :: acc) t []

yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ __metadata:
452452
languageName: node
453453
linkType: hard
454454

455+
"@rescript/react@workspace:tests/dependencies/rescript-react":
456+
version: 0.0.0-use.local
457+
resolution: "@rescript/react@workspace:tests/dependencies/rescript-react"
458+
languageName: unknown
459+
linkType: soft
460+
455461
"@rescript/runtime@workspace:packages/@rescript/runtime":
456462
version: 0.0.0-use.local
457463
resolution: "@rescript/runtime@workspace:packages/@rescript/runtime"
@@ -724,12 +730,6 @@ __metadata:
724730
languageName: unknown
725731
linkType: soft
726732

727-
"@tests/rescript-react@workspace:tests/dependencies/rescript-react":
728-
version: 0.0.0-use.local
729-
resolution: "@tests/rescript-react@workspace:tests/dependencies/rescript-react"
730-
languageName: unknown
731-
linkType: soft
732-
733733
"@tests/tools@workspace:tests/tools_tests":
734734
version: 0.0.0-use.local
735735
resolution: "@tests/tools@workspace:tests/tools_tests"

0 commit comments

Comments
 (0)