diff --git a/Cargo.lock b/Cargo.lock index 1c01622ea..21a5eb4ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -195,6 +195,25 @@ version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +[[package]] +name = "bincode" +version = "2.0.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f11ea1a0346b94ef188834a65c068a03aec181c94896d481d7a0a40d85b0ce95" +dependencies = [ + "bincode_derive", + "serde", +] + +[[package]] +name = "bincode_derive" +version = "2.0.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e30759b3b99a1b802a7a3aa21c85c3ded5c28e1c83170d82d70f08bbf7f3e4c" +dependencies = [ + "virtue", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -228,28 +247,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bytecheck" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b6372023ac861f6e6dc89c8344a8f398fb42aaba2b5dbc649ca0c0e9dbcb627" -dependencies = [ - "bytecheck_derive", - "ptr_meta", - "simdutf8", -] - -[[package]] -name = "bytecheck_derive" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7ec4c6f261935ad534c0c22dbef2201b45918860eb1c574b972bd213a76af61" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "byteorder" version = "1.4.3" @@ -965,8 +962,8 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" name = "lsp-positions" version = "0.3.2" dependencies = [ + "bincode", "memchr", - "rkyv", "serde", "tree-sitter", "unicode-segmentation", @@ -1164,26 +1161,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "ptr_meta" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" -dependencies = [ - "ptr_meta_derive", -] - -[[package]] -name = "ptr_meta_derive" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "quote" version = "1.0.32" @@ -1257,43 +1234,6 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" -[[package]] -name = "rend" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581008d2099240d37fb08d77ad713bcaec2c4d89d50b5b21a8bb1996bbab68ab" -dependencies = [ - "bytecheck", -] - -[[package]] -name = "rkyv" -version = "0.7.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0200c8230b013893c0b2d6213d6ec64ed2b9be2e0e016682b7224ff82cff5c58" -dependencies = [ - "bitvec", - "bytecheck", - "hashbrown 0.12.3", - "ptr_meta", - "rend", - "rkyv_derive", - "seahash", - "tinyvec", - "uuid", -] - -[[package]] -name = "rkyv_derive" -version = "0.7.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2e06b915b5c230a17d7a736d1e2e63ee753c256a8614ef3f5147b13a4f5541d" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "rusqlite" version = "0.28.0" @@ -1358,12 +1298,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "seahash" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" - [[package]] name = "serde" version = "1.0.177" @@ -1424,12 +1358,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" -[[package]] -name = "simdutf8" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" - [[package]] name = "slab" version = "0.4.8" @@ -1450,6 +1378,7 @@ name = "stack-graphs" version = "0.12.0" dependencies = [ "assert-json-diff", + "bincode", "bitvec", "controlled-option", "either", @@ -1460,7 +1389,6 @@ dependencies = [ "lsp-positions", "maplit", "pretty_assertions", - "rkyv", "rusqlite", "serde", "serde_json", @@ -1947,12 +1875,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" -[[package]] -name = "uuid" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" - [[package]] name = "vcpkg" version = "0.2.15" @@ -1965,6 +1887,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "virtue" +version = "0.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dcc60c0624df774c82a0ef104151231d37da4962957d691c011c852b2473314" + [[package]] name = "walkdir" version = "2.3.3" diff --git a/lsp-positions/Cargo.toml b/lsp-positions/Cargo.toml index 80da24636..2b2d496b3 100644 --- a/lsp-positions/Cargo.toml +++ b/lsp-positions/Cargo.toml @@ -18,11 +18,11 @@ test = false [features] default = ["tree-sitter"] -rkyv = ["dep:rkyv"] +bincode = ["dep:bincode"] [dependencies] memchr = "2.4" tree-sitter = { version=">= 0.19", optional=true } unicode-segmentation = { version="1.8" } serde = { version="1", optional=true, features=["derive"] } -rkyv = { version="0.7.42", optional=true } +bincode = { version="2.0.0-rc.3", optional=true } diff --git a/lsp-positions/src/lib.rs b/lsp-positions/src/lib.rs index 035a1d3d1..f948c47d4 100644 --- a/lsp-positions/src/lib.rs +++ b/lsp-positions/src/lib.rs @@ -46,8 +46,8 @@ fn utf16_len(string: &str) -> usize { #[derive(Clone, Debug, Default, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct Position { /// The 0-indexed line number containing the character @@ -113,8 +113,8 @@ impl PartialOrd for Position { #[derive(Clone, Debug, Default, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct Span { pub start: Position, @@ -153,8 +153,8 @@ impl PartialOrd for Span { #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct Offset { /// The number of UTF-8-encoded bytes appearing before this character in the string diff --git a/stack-graphs/Cargo.toml b/stack-graphs/Cargo.toml index 5696dcb2c..a5aa0621c 100644 --- a/stack-graphs/Cargo.toml +++ b/stack-graphs/Cargo.toml @@ -15,8 +15,8 @@ edition = "2018" [features] copious-debugging = [] serde = ["dep:serde", "lsp-positions/serde"] -rkyv = ["dep:rkyv", "lsp-positions/rkyv"] -storage = ["rkyv", "rusqlite", "serde"] +bincode = ["dep:bincode", "lsp-positions/bincode"] +storage = ["bincode", "rusqlite", "serde"] visualization = ["serde", "serde_json"] [lib] @@ -32,7 +32,7 @@ fxhash = "0.2" itertools = "0.10" libc = "0.2" lsp-positions = { version = "0.3", path = "../lsp-positions" } -rkyv = { version = "0.7.42", optional = true } +bincode = { version = "2.0.0-rc.3", optional = true } rusqlite = { version = "0.28", optional = true, features = ["bundled", "functions"] } serde = { version = "1.0", optional = true, features = ["derive"] } serde_json = { version = "1.0", optional = true } diff --git a/stack-graphs/src/serde/graph.rs b/stack-graphs/src/serde/graph.rs index 54966252d..935aa557f 100644 --- a/stack-graphs/src/serde/graph.rs +++ b/stack-graphs/src/serde/graph.rs @@ -17,8 +17,8 @@ use super::NoFilter; #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct StackGraph { pub files: Files, @@ -208,8 +208,8 @@ impl StackGraph { #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] #[serde(transparent)] pub struct Files { @@ -218,8 +218,8 @@ pub struct Files { #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] #[serde(transparent)] pub struct Nodes { @@ -229,8 +229,8 @@ pub struct Nodes { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[serde(tag = "type", rename_all = "snake_case")] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub enum Node { DropScopes { @@ -340,8 +340,8 @@ impl Node { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct SourceInfo { pub span: lsp_positions::Span, @@ -352,8 +352,8 @@ pub struct SourceInfo { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[serde(transparent)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct DebugInfo { pub data: Vec, @@ -361,8 +361,8 @@ pub struct DebugInfo { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct DebugEntry { pub key: String, @@ -371,8 +371,8 @@ pub struct DebugEntry { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct NodeID { #[serde(skip_serializing_if = "Option::is_none")] @@ -433,8 +433,8 @@ impl std::fmt::Display for NodeID { #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] #[serde(transparent)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct Edges { pub data: Vec, @@ -442,8 +442,8 @@ pub struct Edges { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct Edge { pub source: NodeID, diff --git a/stack-graphs/src/serde/partial.rs b/stack-graphs/src/serde/partial.rs index f4b81d00e..f7960816e 100644 --- a/stack-graphs/src/serde/partial.rs +++ b/stack-graphs/src/serde/partial.rs @@ -15,8 +15,8 @@ use super::NodeID; #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct PartialPath { pub(crate) start_node: NodeID, @@ -88,8 +88,8 @@ impl PartialPath { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct PartialScopeStack { pub(crate) scopes: Vec, @@ -137,8 +137,8 @@ impl PartialScopeStack { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] #[serde(transparent)] pub struct ScopeStackVariable(u32); @@ -156,8 +156,8 @@ impl ScopeStackVariable { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct PartialSymbolStack { pub(crate) symbols: Vec, @@ -207,8 +207,8 @@ impl PartialSymbolStack { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] #[serde(transparent)] pub struct SymbolStackVariable(u32); @@ -226,8 +226,8 @@ impl SymbolStackVariable { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct PartialScopedSymbol { symbol: String, @@ -268,8 +268,8 @@ impl PartialScopedSymbol { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] #[serde(transparent)] pub struct PartialPathEdgeList { @@ -308,8 +308,8 @@ impl PartialPathEdgeList { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + feature = "bincode", + derive(bincode::Encode, bincode::Decode) )] pub struct PartialPathEdge { pub(crate) source: NodeID, diff --git a/stack-graphs/src/storage.rs b/stack-graphs/src/storage.rs index 56fec593c..3b3c0b24d 100644 --- a/stack-graphs/src/storage.rs +++ b/stack-graphs/src/storage.rs @@ -5,7 +5,9 @@ // Please see the LICENSE-APACHE or LICENSE-MIT files in this distribution for license details. // ------------------------------------------------------------------------------------------------ -use rkyv::Deserialize; +use bincode::config; +use bincode::error::DecodeError; +use bincode::error::EncodeError; use rusqlite::functions::FunctionFlags; use rusqlite::types::ValueRef; use rusqlite::Connection; @@ -75,10 +77,10 @@ pub enum StorageError { Rusqlite(#[from] rusqlite::Error), #[error(transparent)] Serde(#[from] serde::Error), - #[error("rkyv serialization error")] - RkyvSerialize(Box), - #[error("rkyv deserialization error")] - RkyvDeserialize(Box), + #[error(transparent)] + SerializeFail(#[from] EncodeError), + #[error(transparent)] + DeserializeFail(#[from] DecodeError), } pub type Result = std::result::Result; @@ -280,10 +282,8 @@ impl SQLiteWriter { let mut stmt = conn .prepare_cached("INSERT INTO graphs (file, tag, error, value) VALUES (?, ?, ?, ?)")?; let graph = crate::serde::StackGraph::default(); - let serialized = rkyv::to_bytes::<_, 256>(&graph) - .map_err(|e| StorageError::RkyvSerialize(Box::new(e)))?; - // TODO: determine if this doesn't do a copy - stmt.execute((&file.to_string_lossy(), tag, error, &serialized.as_slice()))?; + let serialized = bincode::encode_to_vec(&graph, config::standard())?; + stmt.execute((&file.to_string_lossy(), tag, error, serialized))?; Ok(()) } @@ -322,10 +322,8 @@ impl SQLiteWriter { let mut stmt = conn.prepare_cached("INSERT INTO graphs (file, tag, value) VALUES (?, ?, ?)")?; let graph = serde::StackGraph::from_graph_filter(graph, &FileFilter(file)); - let serialized = rkyv::to_bytes::<_, 256>(&graph) - .map_err(|e| StorageError::RkyvSerialize(Box::new(e)))?; - // TODO: determine if this doesn't do a copy - stmt.execute((file_str, tag, &serialized.as_slice()))?; + let serialized = bincode::encode_to_vec(&graph, config::standard())?; + stmt.execute((file_str, tag, &serialized))?; Ok(()) } @@ -366,10 +364,8 @@ impl SQLiteWriter { ); let symbol_stack = path.symbol_stack_precondition.storage_key(graph, partials); let path = serde::PartialPath::from_partial_path(graph, partials, path); - let serialized = rkyv::to_bytes::<_, 256>(&path) - .map_err(|e| StorageError::RkyvSerialize(Box::new(e)))?; - // TODO: determine if this doesn't do a copy - root_stmt.execute((file_str, symbol_stack, &serialized.as_slice()))?; + let serialized = bincode::encode_to_vec(&path, config::standard())?; + root_stmt.execute((file_str, symbol_stack, serialized))?; root_path_count += 1; } else if start_node.is_in_file(file) { copious_debugging!( @@ -377,10 +373,8 @@ impl SQLiteWriter { path.start_node.display(graph), ); let path = serde::PartialPath::from_partial_path(graph, partials, path); - let serialized = rkyv::to_bytes::<_, 256>(&path) - .map_err(|e| StorageError::RkyvSerialize(Box::new(e)))?; - // TODO: determine if this doesn't do a copy - node_stmt.execute((file_str, path.start_node.local_id, serialized.as_slice()))?; + let serialized = bincode::encode_to_vec(&path, config::standard())?; + node_stmt.execute((file_str, path.start_node.local_id, serialized))?; node_path_count += 1; } else { panic!( @@ -529,9 +523,8 @@ impl SQLiteReader { copious_debugging!(" * Load from database"); let mut stmt = conn.prepare_cached("SELECT value FROM graphs WHERE file = ?")?; let value = stmt.query_row([file], |row| row.get::<_, Vec>(0))?; - // database only contains serialized rkyv values, so this should be safe - let file_graph: serde::StackGraph = unsafe { rkyv::from_bytes_unchecked(&value) } - .map_err(|e| StorageError::RkyvDeserialize(Box::new(e)))?; + let (file_graph, _): (serde::StackGraph, usize) = + bincode::decode_from_slice(&value, config::standard())?; file_graph.load_into(graph)?; Ok(graph.get_file(file).expect("loaded file to exist")) } @@ -587,8 +580,8 @@ impl SQLiteReader { &mut self.loaded_graphs, &self.conn, )?; - let path: serde::PartialPath = unsafe { rkyv::from_bytes_unchecked(&value) } - .map_err(|e| StorageError::RkyvDeserialize(Box::new(e)))?; + let (path, _): (serde::PartialPath, usize) = + bincode::decode_from_slice(&value, config::standard())?; let path = path.to_partial_path(&mut self.graph, &mut self.partials)?; copious_debugging!( " > Loaded {}", @@ -642,9 +635,8 @@ impl SQLiteReader { &mut self.loaded_graphs, &self.conn, )?; - // database only contains serialized rkyv values, so this should be safe - let path: serde::PartialPath = unsafe { rkyv::from_bytes_unchecked(&value) } - .map_err(|e| StorageError::RkyvDeserialize(Box::new(e)))?; + let (path, _): (serde::PartialPath, usize) = + bincode::decode_from_slice(&value, config::standard())?; let path = path.to_partial_path(&mut self.graph, &mut self.partials)?; copious_debugging!( " > Loaded {}",