From e42e497ae8a9d525a46da55fa3eba798fc575360 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 24 Jul 2025 10:45:19 +0200 Subject: [PATCH] Prescient --- Cargo.lock | 5 +++-- Cargo.toml | 2 +- crates/typst-cli/Cargo.toml | 1 + crates/typst-cli/src/main.rs | 13 +++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7d12aa699..d16880724 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -451,7 +451,7 @@ checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "comemo" version = "0.4.0" -source = "git+https://github.com/typst/comemo?rev=70c0307#70c03075453deda2b2cc592ee8676edfe7962804" +source = "git+https://github.com/typst/comemo?rev=499bce5#499bce59ae44af9e61dc106b6b1663a45669b87e" dependencies = [ "bumpalo", "comemo-macros", @@ -463,7 +463,7 @@ dependencies = [ [[package]] name = "comemo-macros" version = "0.4.0" -source = "git+https://github.com/typst/comemo?rev=70c0307#70c03075453deda2b2cc592ee8676edfe7962804" +source = "git+https://github.com/typst/comemo?rev=499bce5#499bce59ae44af9e61dc106b6b1663a45669b87e" dependencies = [ "proc-macro2", "quote", @@ -2935,6 +2935,7 @@ dependencies = [ "dirs", "ecow", "fs_extra", + "memmap2", "notify", "open", "parking_lot", diff --git a/Cargo.toml b/Cargo.toml index 6c99b2131..fe26d3d90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -165,4 +165,4 @@ uninlined_format_args = "warn" wildcard_in_or_patterns = "allow" [patch.crates-io] -comemo = { git = "https://github.com/typst/comemo", rev = "70c0307" } +comemo = { git = "https://github.com/typst/comemo", rev = "499bce5" } diff --git a/crates/typst-cli/Cargo.toml b/crates/typst-cli/Cargo.toml index 792cabae1..e1c4924c7 100644 --- a/crates/typst-cli/Cargo.toml +++ b/crates/typst-cli/Cargo.toml @@ -56,6 +56,7 @@ toml = { workspace = true } ureq = { workspace = true } xz2 = { workspace = true, optional = true } zip = { workspace = true, optional = true } +memmap2 = "*" [build-dependencies] chrono = { workspace = true } diff --git a/crates/typst-cli/src/main.rs b/crates/typst-cli/src/main.rs index 4774dd43b..7ad45d257 100644 --- a/crates/typst-cli/src/main.rs +++ b/crates/typst-cli/src/main.rs @@ -47,6 +47,13 @@ static ARGS: LazyLock = LazyLock::new(|| { /// Entry point. fn main() -> ExitCode { + let mut prescient = false; + if let Ok(file) = std::fs::File::open("comemo-sink") { + let mmap = Box::leak(Box::new(unsafe { memmap2::Mmap::map(&file).unwrap() })); + comemo::put_prescience(&*mmap); + prescient = true; + } + // Handle SIGPIPE // https://stackoverflow.com/questions/65755853/simple-word-count-rust-program-outputs-valid-stdout-but-panicks-when-piped-to-he/65760807 sigpipe::reset(); @@ -58,6 +65,12 @@ fn main() -> ExitCode { print_error(msg.message()).expect("failed to print error"); } + if !prescient { + let file = std::fs::File::create("comemo-sink").unwrap(); + let sink = std::io::BufWriter::new(file); + comemo::write_prescience(sink); + } + EXIT.with(|cell| cell.get()) }