Skip to content

Commit

Permalink
Merge pull request #302 from bluskript/work/blusk/rkyv-storage
Browse files Browse the repository at this point in the history
move DB to bincode
  • Loading branch information
hendrikvanantwerpen authored Aug 2, 2023
2 parents aaec4ec + a4feae4 commit ee490e9
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 80 deletions.
2 changes: 2 additions & 0 deletions lsp-positions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ test = false

[features]
default = ["tree-sitter"]
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"] }
bincode = { version="2.0.0-rc.3", optional=true }
3 changes: 3 additions & 0 deletions lsp-positions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fn utf16_len(string: &str) -> usize {
#[repr(C)]
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct Position {
/// The 0-indexed line number containing the character
pub line: usize,
Expand Down Expand Up @@ -108,6 +109,7 @@ impl PartialOrd<tree_sitter::Point> for Position {
#[repr(C)]
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct Span {
pub start: Position,
pub end: Position,
Expand Down Expand Up @@ -144,6 +146,7 @@ impl PartialOrd for Span {
/// All offsets are 0-indexed.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct Offset {
/// The number of UTF-8-encoded bytes appearing before this character in the string
pub utf8_offset: usize,
Expand Down
8 changes: 5 additions & 3 deletions stack-graphs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ authors = [
edition = "2018"

[features]
bincode = ["dep:bincode", "lsp-positions/bincode"]
copious-debugging = []
serde = ["dep:serde", "lsp-positions/serde"]
storage = ["postcard", "rusqlite", "serde"]
serde = ["dep:serde", "serde_with", "lsp-positions/serde"]
storage = ["bincode", "rusqlite"]
visualization = ["serde", "serde_json"]

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

[dependencies]
bincode = { version = "2.0.0-rc.3", optional = true }
bitvec = "1.0"
controlled-option = "0.4"
either = "1.6"
Expand All @@ -31,10 +33,10 @@ fxhash = "0.2"
itertools = "0.10"
libc = "0.2"
lsp-positions = { version = "0.3", path = "../lsp-positions" }
postcard = { version = "1", optional = true, features = ["use-std"] }
rusqlite = { version = "0.28", optional = true, features = ["bundled", "functions"] }
serde = { version = "1.0", optional = true, features = ["derive"] }
serde_json = { version = "1.0", optional = true }
serde_with = { version = "3.1", optional = true }
smallvec = { version = "1.6", features = ["union"] }
thiserror = { version = "1.0" }

Expand Down
1 change: 0 additions & 1 deletion stack-graphs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ mod debugging;
pub mod graph;
pub mod partial;
pub mod paths;
#[cfg(feature = "serde")]
pub mod serde;
pub mod stitching;
#[cfg(feature = "storage")]
Expand Down
99 changes: 63 additions & 36 deletions stack-graphs/src/serde/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Please see the LICENSE-APACHE or LICENSE-MIT files in this distribution for license details.
// ------------------------------------------------------------------------------------------------

use serde::Deserialize;
use serde::Serialize;
use thiserror::Error;

use crate::arena::Handle;
Expand All @@ -15,7 +13,9 @@ use super::Filter;
use super::ImplicationFilter;
use super::NoFilter;

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct StackGraph {
pub files: Files,
pub nodes: Nodes,
Expand Down Expand Up @@ -202,54 +202,62 @@ impl StackGraph {
}
}

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(transparent)]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(transparent)
)]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct Files {
pub data: Vec<String>,
}

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(transparent)]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(transparent)
)]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct Nodes {
pub data: Vec<Node>,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
serde_with::skip_serializing_none, // must come before derive
derive(serde::Deserialize, serde::Serialize),
serde(tag = "type", rename_all = "snake_case"),
)]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub enum Node {
DropScopes {
id: NodeID,
#[serde(skip_serializing_if = "Option::is_none")]
source_info: Option<SourceInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
debug_info: Option<DebugInfo>,
},

JumpToScope {
id: NodeID,
#[serde(skip_serializing_if = "Option::is_none")]
source_info: Option<SourceInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
debug_info: Option<DebugInfo>,
},

PopScopedSymbol {
id: NodeID,
symbol: String,
is_definition: bool,
#[serde(skip_serializing_if = "Option::is_none")]
source_info: Option<SourceInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
debug_info: Option<DebugInfo>,
},

PopSymbol {
id: NodeID,
symbol: String,
is_definition: bool,
#[serde(skip_serializing_if = "Option::is_none")]
source_info: Option<SourceInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
debug_info: Option<DebugInfo>,
},

Expand All @@ -258,36 +266,28 @@ pub enum Node {
symbol: String,
scope: NodeID,
is_reference: bool,
#[serde(skip_serializing_if = "Option::is_none")]
source_info: Option<SourceInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
debug_info: Option<DebugInfo>,
},

PushSymbol {
id: NodeID,
symbol: String,
is_reference: bool,
#[serde(skip_serializing_if = "Option::is_none")]
source_info: Option<SourceInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
debug_info: Option<DebugInfo>,
},

Root {
id: NodeID,
#[serde(skip_serializing_if = "Option::is_none")]
source_info: Option<SourceInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
debug_info: Option<DebugInfo>,
},

Scope {
id: NodeID,
is_exported: bool,
#[serde(skip_serializing_if = "Option::is_none")]
source_info: Option<SourceInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
debug_info: Option<DebugInfo>,
},
}
Expand Down Expand Up @@ -322,28 +322,45 @@ impl Node {
}
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
serde_with::skip_serializing_none, // must come before derive
derive(serde::Deserialize, serde::Serialize),
)]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct SourceInfo {
pub span: lsp_positions::Span,
#[serde(skip_serializing_if = "Option::is_none")]
pub syntax_type: Option<String>,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(transparent)
)]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct DebugInfo {
pub data: Vec<DebugEntry>,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct DebugEntry {
pub key: String,
pub value: String,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
serde_with::skip_serializing_none, // must come before derive
derive(serde::Deserialize, serde::Serialize),
)]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct NodeID {
#[serde(skip_serializing_if = "Option::is_none")]
pub file: Option<String>,
pub local_id: u32,
}
Expand Down Expand Up @@ -398,18 +415,28 @@ impl std::fmt::Display for NodeID {
}
}

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(transparent)]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(transparent)
)]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct Edges {
pub data: Vec<Edge>,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
serde_with::skip_serializing_none, // must come before derive
derive(serde::Deserialize, serde::Serialize),
)]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct Edge {
pub source: NodeID,
pub sink: NodeID,
pub precedence: i32,
#[serde(skip_serializing_if = "Option::is_none")]
pub debug_info: Option<DebugInfo>,
}

Expand Down
Loading

0 comments on commit ee490e9

Please sign in to comment.