Skip to content

Commit 2b218d1

Browse files
committed
CP-49140: [prep]: database: drop unused of_sexp conversions
sexp_of is used when saving the schema, but of_sexp is unused. This enables a future commit to store the deserialized value as a pair value, and deserialization (unmarshaling) requires knowing the schema, whereas serialization (marshaling) does not. Thus we couldn't implement a generic `t_of_sexp` function, but with this change we won't have to. No functional change. Signed-off-by: Edwin Török <[email protected]>
1 parent bb17702 commit 2b218d1

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

ocaml/database/schema.ml

+9-22
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ open Sexplib0.Sexp_conv
1616

1717
module Type = struct
1818
type t = String | Set (** of strings *) | Pairs (** of strings *)
19-
[@@deriving sexp]
19+
[@@deriving sexp_of]
2020

2121
exception Error of t * t
2222

@@ -38,7 +38,7 @@ module Value = struct
3838
| String of string
3939
| Set of string list
4040
| Pairs of (string * string) list
41-
[@@deriving sexp]
41+
[@@deriving sexp_of]
4242

4343
let marshal = function
4444
| String x ->
@@ -95,7 +95,7 @@ module Column = struct
9595
; issetref: bool
9696
(** only so we can special case set refs in the interface *)
9797
}
98-
[@@deriving sexp]
98+
[@@deriving sexp_of]
9999

100100
let name_of t = t.name
101101
end
@@ -109,7 +109,7 @@ let values_of_table tbl = Hashtbl.fold (fun _ v vs -> v :: vs) tbl []
109109

110110
module Table = struct
111111
type t' = {name: string; columns: Column.t list; persistent: bool}
112-
[@@deriving sexp]
112+
[@@deriving sexp_of]
113113

114114
type t = {
115115
name: string
@@ -133,11 +133,6 @@ module Table = struct
133133
let t' = t'_of_t t in
134134
sexp_of_t' t'
135135

136-
let t_of_sexp s =
137-
let ({name; columns; persistent} : t') = t'_of_sexp s in
138-
let columns = tabulate columns ~key_fn:Column.name_of in
139-
({name; columns; persistent} : t)
140-
141136
let find name (t : t) =
142137
match Hashtbl.find_opt t.columns name with
143138
| Some c ->
@@ -157,10 +152,10 @@ module Table = struct
157152
end
158153

159154
type relationship = OneToMany of string * string * string * string
160-
[@@deriving sexp]
155+
[@@deriving sexp_of]
161156

162157
module Database = struct
163-
type t' = {tables: Table.t list} [@@deriving sexp]
158+
type t' = {tables: Table.t list} [@@deriving sexp_of]
164159

165160
type t = {tables: (string, Table.t) Hashtbl.t}
166161

@@ -180,10 +175,6 @@ module Database = struct
180175
let t' = t'_of_t t in
181176
sexp_of_t' t'
182177

183-
let t_of_sexp s =
184-
let t' = t'_of_sexp s in
185-
t_of_t' t'
186-
187178
let find name t =
188179
match Hashtbl.find_opt t.tables name with
189180
| Some tbl ->
@@ -197,7 +188,7 @@ module Database = struct
197188
end
198189

199190
(** indexed by table name, a list of (this field, foreign table, foreign field) *)
200-
type foreign = (string * string * string) list [@@deriving sexp]
191+
type foreign = (string * string * string) list [@@deriving sexp_of]
201192

202193
module ForeignMap = struct
203194
include Map.Make (struct
@@ -206,17 +197,13 @@ module ForeignMap = struct
206197
let compare = Stdlib.compare
207198
end)
208199

209-
type t' = (string * foreign) list [@@deriving sexp]
200+
type t' = (string * foreign) list [@@deriving sexp_of]
210201

211202
type m = foreign t
212203

213204
let sexp_of_m t : Sexp.t =
214205
let t' = fold (fun key foreign acc -> (key, foreign) :: acc) t [] in
215206
sexp_of_t' t'
216-
217-
let m_of_sexp sexp : m =
218-
let t' = t'_of_sexp sexp in
219-
List.fold_left (fun acc (key, foreign) -> add key foreign acc) empty t'
220207
end
221208

222209
type t = {
@@ -227,7 +214,7 @@ type t = {
227214
; one_to_many: ForeignMap.m
228215
; many_to_many: ForeignMap.m
229216
}
230-
[@@deriving sexp]
217+
[@@deriving sexp_of]
231218

232219
let database x = x.database
233220

0 commit comments

Comments
 (0)