Use rpds rather than im for persistent data types

rpds is actively maintained and it's even a significant performance
win in my testing (40% time reduction on slow_before.rs).
pull/297/head
Wilfred Hughes 2022-03-04 21:47:05 +07:00
parent efc59360cc
commit 4b674d4b8e
3 changed files with 33 additions and 75 deletions

80
Cargo.lock generated

@ -20,6 +20,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "archery"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a8da9bc4c4053ee067669762bcaeea6e241841295a2b6c948312dad6ef4cc02"
dependencies = [
"static_assertions",
]
[[package]]
name = "atty"
version = "0.2.14"
@ -43,15 +52,6 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitmaps"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2"
dependencies = [
"typenum",
]
[[package]]
name = "cc"
version = "1.0.72"
@ -169,7 +169,6 @@ dependencies = [
"clap",
"const_format",
"diff",
"im-rc",
"itertools",
"lazy_static",
"libc",
@ -181,6 +180,7 @@ dependencies = [
"radix-heap",
"rayon",
"regex",
"rpds",
"rustc-hash",
"strsim",
"term_size",
@ -232,20 +232,6 @@ dependencies = [
"quick-error",
]
[[package]]
name = "im-rc"
version = "15.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ca8957e71f04a205cb162508f9326aea04676c8dfd0711220190d6b83664f3f"
dependencies = [
"bitmaps",
"rand_core",
"rand_xoshiro",
"sized-chunks",
"typenum",
"version_check",
]
[[package]]
name = "indexmap"
version = "1.8.0"
@ -405,21 +391,6 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bde9110b6926b8aaf55623dd7a0e2545b83b9b01cd9f47d36275fc2bc69a0bda"
[[package]]
name = "rand_core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
[[package]]
name = "rand_xoshiro"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9fcdd2e881d02f1d9390ae47ad8e5696a9e4be7b547a1da2afbc61973217004"
dependencies = [
"rand_core",
]
[[package]]
name = "rayon"
version = "1.5.1"
@ -462,6 +433,15 @@ version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "rpds"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ef5140bcb576bfd6d56cd2de709a7d17851ac1f3805e67fe9d99e42a11821f"
dependencies = [
"archery",
]
[[package]]
name = "rustc-hash"
version = "1.1.0"
@ -484,14 +464,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "sized-chunks"
version = "0.6.5"
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16d69225bde7a69b235da73377861095455d298f2b970996eec25ddbb42b3d1e"
dependencies = [
"bitmaps",
"typenum",
]
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "strsim"
@ -551,24 +527,12 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae"
[[package]]
name = "typenum"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "walkdir"
version = "2.3.2"

@ -40,7 +40,7 @@ walkdir = "2.3.2"
term_size = "0.3.2"
const_format = "0.2.22"
owo-colors = "3.2.0"
im-rc = "15.0.0"
rpds = "0.11.0"
[dev-dependencies]
pretty_assertions = "1.0.0"

@ -41,7 +41,7 @@ pub struct Vertex<'a> {
pub rhs_syntax: Option<&'a Syntax<'a>>,
// Instead, store parent pointers for both sides and a hashset of
// novel delimiter parent IDs.
parents: im_rc::Vector<(Option<&'a Syntax<'a>>, Option<&'a Syntax<'a>>)>,
parents: rpds::Stack<(Option<&'a Syntax<'a>>, Option<&'a Syntax<'a>>)>,
parents_hash: u64,
}
@ -64,7 +64,7 @@ impl<'a> Hash for Vertex<'a> {
}
}
fn hash_parents(parents: &im_rc::Vector<(Option<&Syntax>, Option<&Syntax>)>) -> u64 {
fn hash_parents(parents: &rpds::Stack<(Option<&Syntax>, Option<&Syntax>)>) -> u64 {
let mut hasher = FxHasher::default();
for (parent_id, _) in parents.iter() {
@ -122,7 +122,7 @@ impl<'a> Vertex<'a> {
}
pub fn new(lhs_syntax: Option<&'a Syntax<'a>>, rhs_syntax: Option<&'a Syntax<'a>>) -> Self {
let parents = im_rc::Vector::new();
let parents = rpds::Stack::new();
let parents_hash = hash_parents(&parents);
Vertex {
lhs_syntax,
@ -210,15 +210,14 @@ pub fn neighbours<'a>(v: &Vertex<'a>, buf: &mut [Option<(Edge, Vertex<'a>)>]) {
let mut i = 0;
if let Some((lhs_parent, rhs_parent)) = v.parents.back() {
if let Some((lhs_parent, rhs_parent)) = v.parents.peek() {
match (lhs_parent, rhs_parent) {
(Some(lhs_parent), Some(rhs_parent))
if v.lhs_syntax.is_none() && v.rhs_syntax.is_none() =>
{
// We have exhausted all the nodes on both lists, so we can
// move up to the parent node.
let mut next_parents = v.parents.clone();
next_parents.pop_back();
let next_parents = v.parents.pop().unwrap();
let parents_hash = hash_parents(&next_parents);
// Continue from sibling of parent.
@ -235,8 +234,7 @@ pub fn neighbours<'a>(v: &Vertex<'a>, buf: &mut [Option<(Edge, Vertex<'a>)>]) {
}
(Some(lhs_parent), None) if v.lhs_syntax.is_none() => {
// Move to next after LHS parent.
let mut next_parents = v.parents.clone();
next_parents.pop_back();
let next_parents = v.parents.pop().unwrap();
let parents_hash = hash_parents(&next_parents);
// Continue from sibling of parent.
@ -253,8 +251,7 @@ pub fn neighbours<'a>(v: &Vertex<'a>, buf: &mut [Option<(Edge, Vertex<'a>)>]) {
}
(None, Some(rhs_parent)) if v.rhs_syntax.is_none() => {
// Move to next after RHS parent.
let mut next_parents = v.parents.clone();
next_parents.pop_back();
let next_parents = v.parents.pop().unwrap();
let parents_hash = hash_parents(&next_parents);
// Continue from sibling of parent.
@ -309,8 +306,7 @@ pub fn neighbours<'a>(v: &Vertex<'a>, buf: &mut [Option<(Edge, Vertex<'a>)>]) {
let rhs_next = rhs_children.get(0).copied();
// TODO: be consistent between parents_next and next_parents.
let mut parents_next = v.parents.clone();
parents_next.push_back((Some(lhs_syntax), Some(rhs_syntax)));
let parents_next = v.parents.push((Some(lhs_syntax), Some(rhs_syntax)));
let parents_hash = hash_parents(&parents_next);
buf[i] = Some((
@ -385,8 +381,7 @@ pub fn neighbours<'a>(v: &Vertex<'a>, buf: &mut [Option<(Edge, Vertex<'a>)>]) {
} => {
let lhs_next = children.get(0).copied();
let mut parents_next = v.parents.clone();
parents_next.push_back((Some(lhs_syntax), None));
let parents_next = v.parents.push((Some(lhs_syntax), None));
let parents_hash = hash_parents(&parents_next);
buf[i] = Some((
@ -445,8 +440,7 @@ pub fn neighbours<'a>(v: &Vertex<'a>, buf: &mut [Option<(Edge, Vertex<'a>)>]) {
} => {
let rhs_next = children.get(0).copied();
let mut parents_next = v.parents.clone();
parents_next.push_back((None, Some(rhs_syntax)));
let parents_next = v.parents.push((None, Some(rhs_syntax)));
let parents_hash = hash_parents(&parents_next);
buf[i] = Some((