From 8351a4c1dece2a135b699b3f45254dbebfcecea4 Mon Sep 17 00:00:00 2001 From: xxchan Date: Tue, 13 Jun 2023 19:53:22 +0200 Subject: [PATCH] fix: replace ouroboros with self_cell https://github.com/joshua-maros/ouroboros/issues/88 --- Cargo.lock | 43 ++++---------------- src/expr/Cargo.toml | 2 +- src/expr/src/expr/expr_to_char_const_tmpl.rs | 4 +- src/expr/src/vector_op/to_char.rs | 27 ++++++------ src/expr/src/vector_op/to_timestamp.rs | 2 +- 5 files changed, 24 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ac0d23280ddc6..a502b0abb6d46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "Inflector" -version = "0.11.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" - [[package]] name = "addr2line" version = "0.19.0" @@ -62,12 +56,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "aliasable" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" - [[package]] name = "android_system_properties" version = "0.1.5" @@ -4340,29 +4328,6 @@ version = "6.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" -[[package]] -name = "ouroboros" -version = "0.15.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1358bd1558bd2a083fed428ffeda486fbfb323e698cdda7794259d592ca72db" -dependencies = [ - "aliasable", - "ouroboros_macro", -] - -[[package]] -name = "ouroboros_macro" -version = "0.15.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f7d21ccd03305a674437ee1248f3ab5d4b1db095cf1caf49f1713ddf61956b7" -dependencies = [ - "Inflector", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "output_vt100" version = "0.1.3" @@ -6072,7 +6037,6 @@ dependencies = [ "madsim-tokio", "md5", "num-traits", - "ouroboros", "parse-display", "paste", "regex", @@ -6081,6 +6045,7 @@ dependencies = [ "risingwave_pb", "risingwave_udf", "rust_decimal", + "self_cell", "serde_json", "sha1", "sha2", @@ -7008,6 +6973,12 @@ dependencies = [ "libc", ] +[[package]] +name = "self_cell" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c309e515543e67811222dbc9e3dd7e1056279b782e1dacffe4242b718734fb6" + [[package]] name = "semver" version = "1.0.17" diff --git a/src/expr/Cargo.toml b/src/expr/Cargo.toml index 9bd5fa2ecaf6f..5dbe7d3d77ea8 100644 --- a/src/expr/Cargo.toml +++ b/src/expr/Cargo.toml @@ -34,7 +34,6 @@ hex = "0.4.3" itertools = "0.10" md5 = "0.7.0" num-traits = "0.2" -ouroboros = "0.15" parse-display = "0.6" paste = "1" regex = "1" @@ -43,6 +42,7 @@ risingwave_expr_macro = { path = "macro" } risingwave_pb = { path = "../prost" } risingwave_udf = { path = "../udf" } rust_decimal = { version = "1", features = ["db-postgres", "maths"] } +self_cell = "1.0.0" serde_json = "1" sha1 = "0.10.5" sha2 = "0.10.6" diff --git a/src/expr/src/expr/expr_to_char_const_tmpl.rs b/src/expr/src/expr/expr_to_char_const_tmpl.rs index 5b4165ff84b6b..4164dfed44053 100644 --- a/src/expr/src/expr/expr_to_char_const_tmpl.rs +++ b/src/expr/src/expr/expr_to_char_const_tmpl.rs @@ -56,7 +56,7 @@ impl Expression for ExprToCharConstTmpl { let mut writer = output.writer().begin(); let fmt = data .0 - .format_with_items(self.ctx.chrono_pattern.borrow_items().iter()); + .format_with_items(self.ctx.chrono_pattern.borrow_dependent().iter()); write!(writer, "{fmt}").unwrap(); writer.finish(); } else { @@ -72,7 +72,7 @@ impl Expression for ExprToCharConstTmpl { Ok(if let Some(ScalarImpl::Timestamp(data)) = data { Some( data.0 - .format_with_items(self.ctx.chrono_pattern.borrow_items().iter()) + .format_with_items(self.ctx.chrono_pattern.borrow_dependent().iter()) .to_string() .into(), ) diff --git a/src/expr/src/vector_op/to_char.rs b/src/expr/src/vector_op/to_char.rs index d6dccec509457..fd332cc7a7675 100644 --- a/src/expr/src/vector_op/to_char.rs +++ b/src/expr/src/vector_op/to_char.rs @@ -17,22 +17,23 @@ use std::sync::LazyLock; use aho_corasick::{AhoCorasick, AhoCorasickBuilder}; use chrono::format::StrftimeItems; -use ouroboros::self_referencing; use risingwave_common::types::Timestamp; use static_assertions::const_assert_eq; -#[self_referencing] -pub struct ChronoPattern { - pub(crate) tmpl: String, - #[borrows(tmpl)] - #[covariant] - pub(crate) items: Vec>, +type Pattern<'a> = Vec>; + +self_cell::self_cell! { + pub struct ChronoPattern { + owner: String, + #[covariant] + dependent: Pattern, + } } impl Debug for ChronoPattern { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("ChronoPattern") - .field("tmpl", self.borrow_tmpl()) + .field("tmpl", self.borrow_owner()) .finish() } } @@ -67,16 +68,14 @@ pub fn compile_pattern_to_chrono(tmpl: &str) -> ChronoPattern { true }); tracing::debug!(tmpl, chrono_tmpl, "compile_pattern_to_chrono"); - ChronoPatternBuilder { - tmpl: chrono_tmpl, - items_builder: |tmpl| StrftimeItems::new(tmpl).collect::>(), - } - .build() + ChronoPattern::new(chrono_tmpl, |tmpl| { + StrftimeItems::new(tmpl).collect::>() + }) } // #[function("to_char(timestamp, varchar) -> varchar")] pub fn to_char_timestamp(data: Timestamp, tmpl: &str, writer: &mut dyn Write) { let pattern = compile_pattern_to_chrono(tmpl); - let format = data.0.format_with_items(pattern.borrow_items().iter()); + let format = data.0.format_with_items(pattern.borrow_dependent().iter()); write!(writer, "{}", format).unwrap(); } diff --git a/src/expr/src/vector_op/to_timestamp.rs b/src/expr/src/vector_op/to_timestamp.rs index 732d28ce5a7fd..c9a9f0a4a30b5 100644 --- a/src/expr/src/vector_op/to_timestamp.rs +++ b/src/expr/src/vector_op/to_timestamp.rs @@ -22,7 +22,7 @@ use crate::Result; #[inline(always)] pub fn to_timestamp_const_tmpl(s: &str, tmpl: &ChronoPattern) -> Result { let mut parsed = Parsed::new(); - chrono::format::parse(&mut parsed, s, tmpl.borrow_items().iter())?; + chrono::format::parse(&mut parsed, s, tmpl.borrow_dependent().iter())?; // chrono will only assign the default value for seconds/nanoseconds fields, and raise an error // for other ones. We should specify the default value manually.