Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit ee490e9

Browse files
author
Hendrik van Antwerpen
authored
Merge pull request #302 from bluskript/work/blusk/rkyv-storage
move DB to bincode
2 parents aaec4ec + a4feae4 commit ee490e9

File tree

8 files changed

+149
-80
lines changed

8 files changed

+149
-80
lines changed

lsp-positions/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ test = false
1818

1919
[features]
2020
default = ["tree-sitter"]
21+
bincode = ["dep:bincode"]
2122

2223
[dependencies]
2324
memchr = "2.4"
2425
tree-sitter = { version=">= 0.19", optional=true }
2526
unicode-segmentation = { version="1.8" }
2627
serde = { version="1", optional=true, features=["derive"] }
28+
bincode = { version="2.0.0-rc.3", optional=true }

lsp-positions/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ fn utf16_len(string: &str) -> usize {
4545
#[repr(C)]
4646
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
4747
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
48+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
4849
pub struct Position {
4950
/// The 0-indexed line number containing the character
5051
pub line: usize,
@@ -108,6 +109,7 @@ impl PartialOrd<tree_sitter::Point> for Position {
108109
#[repr(C)]
109110
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
110111
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
112+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
111113
pub struct Span {
112114
pub start: Position,
113115
pub end: Position,
@@ -144,6 +146,7 @@ impl PartialOrd for Span {
144146
/// All offsets are 0-indexed.
145147
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
146148
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
149+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
147150
pub struct Offset {
148151
/// The number of UTF-8-encoded bytes appearing before this character in the string
149152
pub utf8_offset: usize,

stack-graphs/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ authors = [
1313
edition = "2018"
1414

1515
[features]
16+
bincode = ["dep:bincode", "lsp-positions/bincode"]
1617
copious-debugging = []
17-
serde = ["dep:serde", "lsp-positions/serde"]
18-
storage = ["postcard", "rusqlite", "serde"]
18+
serde = ["dep:serde", "serde_with", "lsp-positions/serde"]
19+
storage = ["bincode", "rusqlite"]
1920
visualization = ["serde", "serde_json"]
2021

2122
[lib]
2223
# All of our tests are in the tests/it "integration" test executable.
2324
test = false
2425

2526
[dependencies]
27+
bincode = { version = "2.0.0-rc.3", optional = true }
2628
bitvec = "1.0"
2729
controlled-option = "0.4"
2830
either = "1.6"
@@ -31,10 +33,10 @@ fxhash = "0.2"
3133
itertools = "0.10"
3234
libc = "0.2"
3335
lsp-positions = { version = "0.3", path = "../lsp-positions" }
34-
postcard = { version = "1", optional = true, features = ["use-std"] }
3536
rusqlite = { version = "0.28", optional = true, features = ["bundled", "functions"] }
3637
serde = { version = "1.0", optional = true, features = ["derive"] }
3738
serde_json = { version = "1.0", optional = true }
39+
serde_with = { version = "3.1", optional = true }
3840
smallvec = { version = "1.6", features = ["union"] }
3941
thiserror = { version = "1.0" }
4042

stack-graphs/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ mod debugging;
6868
pub mod graph;
6969
pub mod partial;
7070
pub mod paths;
71-
#[cfg(feature = "serde")]
7271
pub mod serde;
7372
pub mod stitching;
7473
#[cfg(feature = "storage")]

stack-graphs/src/serde/graph.rs

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// Please see the LICENSE-APACHE or LICENSE-MIT files in this distribution for license details.
66
// ------------------------------------------------------------------------------------------------
77

8-
use serde::Deserialize;
9-
use serde::Serialize;
108
use thiserror::Error;
119

1210
use crate::arena::Handle;
@@ -15,7 +13,9 @@ use super::Filter;
1513
use super::ImplicationFilter;
1614
use super::NoFilter;
1715

18-
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
16+
#[derive(Clone, Debug, Default, Eq, PartialEq)]
17+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
18+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
1919
pub struct StackGraph {
2020
pub files: Files,
2121
pub nodes: Nodes,
@@ -202,54 +202,62 @@ impl StackGraph {
202202
}
203203
}
204204

205-
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
206-
#[serde(transparent)]
205+
#[derive(Clone, Debug, Default, Eq, PartialEq)]
206+
#[cfg_attr(
207+
feature = "serde",
208+
derive(serde::Deserialize, serde::Serialize),
209+
serde(transparent)
210+
)]
211+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
207212
pub struct Files {
208213
pub data: Vec<String>,
209214
}
210215

211-
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
212-
#[serde(transparent)]
216+
#[derive(Clone, Debug, Default, Eq, PartialEq)]
217+
#[cfg_attr(
218+
feature = "serde",
219+
derive(serde::Deserialize, serde::Serialize),
220+
serde(transparent)
221+
)]
222+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
213223
pub struct Nodes {
214224
pub data: Vec<Node>,
215225
}
216226

217-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
218-
#[serde(tag = "type", rename_all = "snake_case")]
227+
#[derive(Clone, Debug, Eq, PartialEq)]
228+
#[cfg_attr(
229+
feature = "serde",
230+
serde_with::skip_serializing_none, // must come before derive
231+
derive(serde::Deserialize, serde::Serialize),
232+
serde(tag = "type", rename_all = "snake_case"),
233+
)]
234+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
219235
pub enum Node {
220236
DropScopes {
221237
id: NodeID,
222-
#[serde(skip_serializing_if = "Option::is_none")]
223238
source_info: Option<SourceInfo>,
224-
#[serde(skip_serializing_if = "Option::is_none")]
225239
debug_info: Option<DebugInfo>,
226240
},
227241

228242
JumpToScope {
229243
id: NodeID,
230-
#[serde(skip_serializing_if = "Option::is_none")]
231244
source_info: Option<SourceInfo>,
232-
#[serde(skip_serializing_if = "Option::is_none")]
233245
debug_info: Option<DebugInfo>,
234246
},
235247

236248
PopScopedSymbol {
237249
id: NodeID,
238250
symbol: String,
239251
is_definition: bool,
240-
#[serde(skip_serializing_if = "Option::is_none")]
241252
source_info: Option<SourceInfo>,
242-
#[serde(skip_serializing_if = "Option::is_none")]
243253
debug_info: Option<DebugInfo>,
244254
},
245255

246256
PopSymbol {
247257
id: NodeID,
248258
symbol: String,
249259
is_definition: bool,
250-
#[serde(skip_serializing_if = "Option::is_none")]
251260
source_info: Option<SourceInfo>,
252-
#[serde(skip_serializing_if = "Option::is_none")]
253261
debug_info: Option<DebugInfo>,
254262
},
255263

@@ -258,36 +266,28 @@ pub enum Node {
258266
symbol: String,
259267
scope: NodeID,
260268
is_reference: bool,
261-
#[serde(skip_serializing_if = "Option::is_none")]
262269
source_info: Option<SourceInfo>,
263-
#[serde(skip_serializing_if = "Option::is_none")]
264270
debug_info: Option<DebugInfo>,
265271
},
266272

267273
PushSymbol {
268274
id: NodeID,
269275
symbol: String,
270276
is_reference: bool,
271-
#[serde(skip_serializing_if = "Option::is_none")]
272277
source_info: Option<SourceInfo>,
273-
#[serde(skip_serializing_if = "Option::is_none")]
274278
debug_info: Option<DebugInfo>,
275279
},
276280

277281
Root {
278282
id: NodeID,
279-
#[serde(skip_serializing_if = "Option::is_none")]
280283
source_info: Option<SourceInfo>,
281-
#[serde(skip_serializing_if = "Option::is_none")]
282284
debug_info: Option<DebugInfo>,
283285
},
284286

285287
Scope {
286288
id: NodeID,
287289
is_exported: bool,
288-
#[serde(skip_serializing_if = "Option::is_none")]
289290
source_info: Option<SourceInfo>,
290-
#[serde(skip_serializing_if = "Option::is_none")]
291291
debug_info: Option<DebugInfo>,
292292
},
293293
}
@@ -322,28 +322,45 @@ impl Node {
322322
}
323323
}
324324

325-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
325+
#[derive(Clone, Debug, Eq, PartialEq)]
326+
#[cfg_attr(
327+
feature = "serde",
328+
serde_with::skip_serializing_none, // must come before derive
329+
derive(serde::Deserialize, serde::Serialize),
330+
)]
331+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
326332
pub struct SourceInfo {
327333
pub span: lsp_positions::Span,
328-
#[serde(skip_serializing_if = "Option::is_none")]
329334
pub syntax_type: Option<String>,
330335
}
331336

332-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
333-
#[serde(transparent)]
337+
#[derive(Clone, Debug, Eq, PartialEq)]
338+
#[cfg_attr(
339+
feature = "serde",
340+
derive(serde::Deserialize, serde::Serialize),
341+
serde(transparent)
342+
)]
343+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
334344
pub struct DebugInfo {
335345
pub data: Vec<DebugEntry>,
336346
}
337347

338-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
348+
#[derive(Clone, Debug, Eq, PartialEq)]
349+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
350+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
339351
pub struct DebugEntry {
340352
pub key: String,
341353
pub value: String,
342354
}
343355

344-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
356+
#[derive(Clone, Debug, Eq, PartialEq)]
357+
#[cfg_attr(
358+
feature = "serde",
359+
serde_with::skip_serializing_none, // must come before derive
360+
derive(serde::Deserialize, serde::Serialize),
361+
)]
362+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
345363
pub struct NodeID {
346-
#[serde(skip_serializing_if = "Option::is_none")]
347364
pub file: Option<String>,
348365
pub local_id: u32,
349366
}
@@ -398,18 +415,28 @@ impl std::fmt::Display for NodeID {
398415
}
399416
}
400417

401-
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
402-
#[serde(transparent)]
418+
#[derive(Clone, Debug, Default, Eq, PartialEq)]
419+
#[cfg_attr(
420+
feature = "serde",
421+
derive(serde::Deserialize, serde::Serialize),
422+
serde(transparent)
423+
)]
424+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
403425
pub struct Edges {
404426
pub data: Vec<Edge>,
405427
}
406428

407-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
429+
#[derive(Clone, Debug, Eq, PartialEq)]
430+
#[cfg_attr(
431+
feature = "serde",
432+
serde_with::skip_serializing_none, // must come before derive
433+
derive(serde::Deserialize, serde::Serialize),
434+
)]
435+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
408436
pub struct Edge {
409437
pub source: NodeID,
410438
pub sink: NodeID,
411439
pub precedence: i32,
412-
#[serde(skip_serializing_if = "Option::is_none")]
413440
pub debug_info: Option<DebugInfo>,
414441
}
415442

0 commit comments

Comments
 (0)