From 780f756450b2aeb95a051cd67a9421bcffc4107b Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Mon, 21 Nov 2022 20:30:20 +0800 Subject: [PATCH] fix: remove unknown type on content --- Cargo.lock | 7 +++++++ crates/loro-core/Cargo.toml | 1 + crates/loro-core/src/container/list/list_container.rs | 2 -- crates/loro-core/src/container/text/text_container.rs | 11 ++++++----- crates/loro-core/src/container/text/tracker.rs | 1 + crates/loro-core/src/log_store/encoding.rs | 1 - crates/loro-core/src/op/content.rs | 10 ---------- 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae6e0de3..17a134a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -474,6 +474,12 @@ dependencies = [ "syn 1.0.103", ] +[[package]] +name = "debug-log" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd2cce8e65a25b144661b7c661eefd89d06c5329ed9a30da8ec98c4f3fefc60b" + [[package]] name = "derive_arbitrary" version = "1.2.0" @@ -756,6 +762,7 @@ dependencies = [ "crdt-list", "criterion", "ctor", + "debug-log", "dhat", "enum-as-inner", "flate2", diff --git a/crates/loro-core/Cargo.toml b/crates/loro-core/Cargo.toml index 0a850cd3..4935674d 100644 --- a/crates/loro-core/Cargo.toml +++ b/crates/loro-core/Cargo.toml @@ -44,6 +44,7 @@ ctor = "0.1.23" criterion = "0.4.0" flate2 = "1.0.24" arbtest = "0.2.0" +debug-log = "0.1.1" # See https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html diff --git a/crates/loro-core/src/container/list/list_container.rs b/crates/loro-core/src/container/list/list_container.rs index d5c28639..0c5e50e9 100644 --- a/crates/loro-core/src/container/list/list_container.rs +++ b/crates/loro-core/src/container/list/list_container.rs @@ -188,7 +188,6 @@ impl Container for ListContainer { } }, InnerContent::Map(_) => unreachable!(), - InnerContent::Unknown(u) => smallvec::smallvec![RemoteContent::Unknown(u)], } } @@ -205,7 +204,6 @@ impl Container for ListContainer { }, ListOp::Delete(del) => InnerContent::List(InnerListOp::Delete(del)), }, - RemoteContent::Unknown(u) => InnerContent::Unknown(u), _ => unreachable!(), } } diff --git a/crates/loro-core/src/container/text/text_container.rs b/crates/loro-core/src/container/text/text_container.rs index 54df2de0..6f0f7852 100644 --- a/crates/loro-core/src/container/text/text_container.rs +++ b/crates/loro-core/src/container/text/text_container.rs @@ -145,7 +145,6 @@ impl Container for TextContainer { let mut ans = SmallVec::new(); match content { - InnerContent::Unknown(u) => ans.push(RemoteContent::Unknown(u)), InnerContent::List(list) => match list { InnerListOp::Insert { slice, pos } => { let r = slice; @@ -204,14 +203,16 @@ impl Container for TextContainer { let slice: SliceRange = range.into(); return InnerContent::List(InnerListOp::Insert { slice, pos }); } - ListSlice::Unknown(u) => return InnerContent::Unknown(u), + ListSlice::Unknown(u) => { + return InnerContent::List(InnerListOp::Insert { + slice: SliceRange::new_unknown(u as u32), + pos, + }) + } _ => unreachable!(), }, ListOp::Delete(del) => return InnerContent::List(InnerListOp::Delete(del)), }, - RemoteContent::Unknown(u) => { - return InnerContent::Unknown(u); - } _ => unreachable!(), } } diff --git a/crates/loro-core/src/container/text/tracker.rs b/crates/loro-core/src/container/text/tracker.rs index fce55aa2..27bcd2d4 100644 --- a/crates/loro-core/src/container/text/tracker.rs +++ b/crates/loro-core/src/container/text/tracker.rs @@ -312,6 +312,7 @@ impl Tracker { self.cached_fake_current_vv .set_end(id.inc(content.content_len() as i32)); self.all_vv.set_end(id.inc(content.content_len() as i32)); + dbg!(content); let text_content = content.as_list().expect("Content is not for list"); match text_content { InnerListOp::Insert { slice, pos } => { diff --git a/crates/loro-core/src/log_store/encoding.rs b/crates/loro-core/src/log_store/encoding.rs index 0f91e7f3..76f3850e 100644 --- a/crates/loro-core/src/log_store/encoding.rs +++ b/crates/loro-core/src/log_store/encoding.rs @@ -152,7 +152,6 @@ fn encode_changes(store: &LogStore) -> Encoded { } }, crate::op::RemoteContent::Dyn(_) => unreachable!(), - RemoteContent::Unknown(u) => (0, u, LoroValue::Null), }; op_len += 1; ops.push(OpEncoding { diff --git a/crates/loro-core/src/op/content.rs b/crates/loro-core/src/op/content.rs index 1dc17427..0c09a554 100644 --- a/crates/loro-core/src/op/content.rs +++ b/crates/loro-core/src/op/content.rs @@ -20,7 +20,6 @@ pub enum ContentType { #[derive(EnumAsInner, Debug, Clone)] pub enum InnerContent { - Unknown(usize), List(InnerListOp), Map(InnerMapSet), } @@ -29,7 +28,6 @@ pub enum InnerContent { pub enum RemoteContent { Map(MapSet), List(ListOp), - Unknown(usize), Dyn(Box), } @@ -39,7 +37,6 @@ impl Clone for RemoteContent { Self::Map(arg0) => Self::Map(arg0.clone()), Self::List(arg0) => Self::List(arg0.clone()), Self::Dyn(arg0) => Self::Dyn(arg0.clone_content()), - RemoteContent::Unknown(u) => RemoteContent::Unknown(*u), } } } @@ -98,7 +95,6 @@ impl HasLength for RemoteContent { RemoteContent::Map(x) => x.content_len(), RemoteContent::Dyn(x) => x.content_len(), RemoteContent::List(x) => x.content_len(), - RemoteContent::Unknown(x) => *x, } } } @@ -109,7 +105,6 @@ impl Sliceable for RemoteContent { RemoteContent::Map(x) => RemoteContent::Map(x.slice(from, to)), RemoteContent::Dyn(x) => RemoteContent::Dyn(x.slice_content(from, to)), RemoteContent::List(x) => RemoteContent::List(x.slice(from, to)), - RemoteContent::Unknown(_) => RemoteContent::Unknown(to - from), } } } @@ -141,7 +136,6 @@ impl Mergable for RemoteContent { _ => unreachable!(), }, RemoteContent::Dyn(x) => x.merge_content(&**_other.as_dyn().unwrap()), - RemoteContent::Unknown(x) => *x += _other.content_len(), } } } @@ -149,7 +143,6 @@ impl Mergable for RemoteContent { impl HasLength for InnerContent { fn content_len(&self) -> usize { match self { - InnerContent::Unknown(u) => *u, InnerContent::List(list) => list.atom_len(), InnerContent::Map(_) => 1, } @@ -161,7 +154,6 @@ impl Sliceable for InnerContent { match self { a @ InnerContent::Map(_) => a.clone(), InnerContent::List(x) => InnerContent::List(x.slice(from, to)), - InnerContent::Unknown(_) => InnerContent::Unknown(to - from), } } } @@ -173,7 +165,6 @@ impl Mergable for InnerContent { { match (self, other) { (InnerContent::List(x), InnerContent::List(y)) => x.is_mergable(y, &()), - (InnerContent::Unknown(_), InnerContent::Unknown(_)) => true, _ => false, } } @@ -187,7 +178,6 @@ impl Mergable for InnerContent { InnerContent::List(y) => x.merge(y, &()), _ => unreachable!(), }, - InnerContent::Unknown(x) => *x += _other.content_len(), InnerContent::Map(_) => unreachable!(), } }