From 41c0dae2097ae4368c259bd1b1b10ef6667bb850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20d=27Herbais=20de=20Thun?= Date: Fri, 15 Dec 2023 12:25:54 +0100 Subject: [PATCH] Switch to parallel comemo using Git dependency (#2973) --- Cargo.lock | 18 ++++++++++++++---- Cargo.toml | 2 +- crates/typst/src/foundations/plugin.rs | 2 +- crates/typst/src/model/bibliography.rs | 6 +++--- crates/typst/src/visualize/image/mod.rs | 4 ++-- crates/typst/src/visualize/image/raster.rs | 2 +- crates/typst/src/visualize/image/svg.rs | 4 ++-- 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 262d89727..f20c52706 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -393,18 +393,18 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "comemo" version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5705468fa80602ee6a5f9318306e6c428bffd53e43209a78bc05e6e667c6f4" +source = "git+https://github.com/typst/comemo?rev=ddb3773#ddb3773d062369e120d09c9a0a7909faf29d8fe1" dependencies = [ "comemo-macros", + "once_cell", + "parking_lot", "siphasher 1.0.0", ] [[package]] name = "comemo-macros" version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54af6ac68ada2d161fa9cc1ab52676228e340866d094d6542107e74b82acc095" +source = "git+https://github.com/typst/comemo?rev=ddb3773#ddb3773d062369e120d09c9a0a7909faf29d8fe1" dependencies = [ "proc-macro2", "quote", @@ -1566,6 +1566,16 @@ dependencies = [ "syn 2.0.39", ] +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + [[package]] name = "parking_lot_core" version = "0.9.9" diff --git a/Cargo.toml b/Cargo.toml index 1ddd504fe..2163d7c0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ clap = { version = "4.4", features = ["derive", "env"] } clap_complete = "4.2.1" clap_mangen = "0.2.10" codespan-reporting = "0.11" -comemo = "0.3.1" +comemo = { git = "https://github.com/typst/comemo", rev = "ddb3773" } csv = "1" dirs = "5" ecow = { version = "0.2", features = ["serde"] } diff --git a/crates/typst/src/foundations/plugin.rs b/crates/typst/src/foundations/plugin.rs index 89237f940..b7e52e72e 100644 --- a/crates/typst/src/foundations/plugin.rs +++ b/crates/typst/src/foundations/plugin.rs @@ -167,7 +167,7 @@ impl Plugin { impl Plugin { /// Create a new plugin from raw WebAssembly bytes. #[comemo::memoize] - pub fn new(bytes: Bytes) -> StrResult { + pub fn new(bytes: Bytes) -> StrResult { let engine = wasmi::Engine::default(); let module = wasmi::Module::new(&engine, bytes.as_slice()) .map_err(|err| format!("failed to load WebAssembly module ({err})"))?; diff --git a/crates/typst/src/model/bibliography.rs b/crates/typst/src/model/bibliography.rs index cd1b19f5a..94e6aafa2 100644 --- a/crates/typst/src/model/bibliography.rs +++ b/crates/typst/src/model/bibliography.rs @@ -489,7 +489,7 @@ impl CslStyle { /// Load a built-in CSL style. #[comemo::memoize] - pub fn from_name(name: &str) -> StrResult { + pub fn from_name(name: &str) -> StrResult { match hayagriva::archive::ArchivedStyle::by_name(name).map(ArchivedStyle::get) { Some(citationberg::Style::Independent(style)) => Ok(Self { name: Some(name.into()), @@ -501,7 +501,7 @@ impl CslStyle { /// Load a CSL style from file contents. #[comemo::memoize] - pub fn from_data(data: &Bytes) -> StrResult { + pub fn from_data(data: &Bytes) -> StrResult { let text = std::str::from_utf8(data.as_slice()).map_err(FileError::from)?; citationberg::IndependentStyle::from_xml(text) .map(|style| Self { name: None, style: Arc::new(Prehashed::new(style)) }) @@ -589,7 +589,7 @@ impl Works { pub fn generate( world: Tracked, introspector: Tracked, - ) -> StrResult> { + ) -> StrResult> { let mut generator = Generator::new(world, introspector)?; let rendered = generator.drive(); let works = generator.display(&rendered)?; diff --git a/crates/typst/src/visualize/image/mod.rs b/crates/typst/src/visualize/image/mod.rs index d883dab90..a10f7e7b5 100644 --- a/crates/typst/src/visualize/image/mod.rs +++ b/crates/typst/src/visualize/image/mod.rs @@ -325,7 +325,7 @@ impl Image { data: Bytes, format: ImageFormat, alt: Option, - ) -> StrResult { + ) -> StrResult { let kind = match format { ImageFormat::Raster(format) => { ImageKind::Raster(RasterImage::new(data, format)?) @@ -346,7 +346,7 @@ impl Image { alt: Option, world: Tracked, families: &[String], - ) -> StrResult { + ) -> StrResult { let kind = match format { ImageFormat::Raster(format) => { ImageKind::Raster(RasterImage::new(data, format)?) diff --git a/crates/typst/src/visualize/image/raster.rs b/crates/typst/src/visualize/image/raster.rs index 5bd1ad108..98ba8fc05 100644 --- a/crates/typst/src/visualize/image/raster.rs +++ b/crates/typst/src/visualize/image/raster.rs @@ -27,7 +27,7 @@ struct Repr { impl RasterImage { /// Decode a raster image. #[comemo::memoize] - pub fn new(data: Bytes, format: RasterFormat) -> StrResult { + pub fn new(data: Bytes, format: RasterFormat) -> StrResult { fn decode_with<'a, T: ImageDecoder<'a>>( decoder: ImageResult, ) -> ImageResult<(image::DynamicImage, Option>)> { diff --git a/crates/typst/src/visualize/image/svg.rs b/crates/typst/src/visualize/image/svg.rs index d72893673..a4cf3807c 100644 --- a/crates/typst/src/visualize/image/svg.rs +++ b/crates/typst/src/visualize/image/svg.rs @@ -28,7 +28,7 @@ struct Repr { impl SvgImage { /// Decode an SVG image without fonts. #[comemo::memoize] - pub fn new(data: Bytes) -> StrResult { + pub fn new(data: Bytes) -> StrResult { let opts = usvg::Options::default(); let tree = usvg::Tree::from_data(&data, &opts).map_err(format_usvg_error)?; Ok(Self(Arc::new(Repr { @@ -46,7 +46,7 @@ impl SvgImage { data: Bytes, world: Tracked, families: &[String], - ) -> StrResult { + ) -> StrResult { // Disable usvg's default to "Times New Roman". Instead, we default to // the empty family and later, when we traverse the SVG, we check for // empty and non-existing family names and replace them with the true