[sourcefiles] use custom serializer

Summary: Given the brittleness of DB-indexing over marshalled values (one example exposed in D23191601), the serializer "for comparison" must be removed.  Its only use is for source files, and these have an obvious, trivial (and possibly faster and less space hungry) protocol.

Reviewed By: jberdine

Differential Revision: D23499481

fbshipit-source-id: 57ad0ced6
master
Nikos Gorogiannis 4 years ago committed by Facebook GitHub Bot
parent a2c1aa79c8
commit db9828809e

@ -139,24 +139,33 @@ let changed_sources_from_changed_files changed_files =
module SQLite = struct module SQLite = struct
module T = struct type nonrec t = t
type nonrec t = t
end
module Serializer = SqliteUtils.MarshalledDataForComparison (T) let invalid_tag = 'I'
include T
let serialize = function let absolute_tag = 'A'
| RelativeProjectRoot path ->
(* show the most common paths as text (for debugging, possibly perf) *)
Sqlite3.Data.TEXT path
| _ as x ->
Serializer.serialize x
let relative_tag = 'R'
let deserialize = function let serialize sourcefile =
| Sqlite3.Data.TEXT rel_path -> let tag_text tag str = Sqlite3.Data.TEXT (Printf.sprintf "%c%s" tag str) in
RelativeProjectRoot rel_path match sourcefile with
| blob -> | Invalid {ml_source_file} ->
Serializer.deserialize blob tag_text invalid_tag ml_source_file
| Absolute abs_path ->
tag_text absolute_tag abs_path
| RelativeProjectRoot rel_path ->
tag_text relative_tag rel_path
let deserialize serialized_sourcefile =
let[@warning "-8"] (Sqlite3.Data.TEXT text) = serialized_sourcefile in
if String.is_empty text then
L.die InternalError "Could not deserialize sourcefile with empty representation@." ;
let tag = text.[0] in
let str = String.sub ~pos:1 ~len:(String.length text - 1) text in
if Char.equal tag invalid_tag then Invalid {ml_source_file= str}
else if Char.equal tag absolute_tag then Absolute str
else if Char.equal tag relative_tag then RelativeProjectRoot str
else L.die InternalError "Could not deserialize sourcefile with tag=%c, str= %s@." tag str
end end

@ -101,20 +101,6 @@ module type T = sig
type t type t
end end
module MarshalledDataForComparison (D : T) = struct
type t = D.t
let deserialize = function[@warning "-8"] Sqlite3.Data.BLOB b -> Marshal.from_string b 0
(*
If the serialized data is used for comparison (e.g. used in WHERE clause), we need to normalize it.
Marshalling is brittle as it depends on sharing.
For now let's suppose that marshalling with no sharing is normalizing.
*)
let serialize x = Sqlite3.Data.BLOB (Marshal.to_string x [Marshal.No_sharing])
end
module MarshalledDataNOTForComparison (D : T) = struct module MarshalledDataNOTForComparison (D : T) = struct
type t = D.t type t = D.t

@ -69,12 +69,6 @@ module type Data = sig
val deserialize : Sqlite3.Data.t -> t val deserialize : Sqlite3.Data.t -> t
end end
(** A default implementation of the Data API that encodes every objects as marshalled blobs with no
sharing *)
module MarshalledDataForComparison (D : sig
type t
end) : Data with type t = D.t
(** A default implementation of the Data API that encodes every objects as marshalled blobs *) (** A default implementation of the Data API that encodes every objects as marshalled blobs *)
module MarshalledDataNOTForComparison (D : sig module MarshalledDataNOTForComparison (D : sig
type t type t

Loading…
Cancel
Save