summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAbdul-Rahman Sibahi <asibahi@users.noreply.github.com>2024-10-31 14:52:11 +0300
committerGitHub <noreply@github.com>2024-10-31 11:52:11 +0000
commitb969c01b282287b44c3e131f8c0c53dcbb304e30 (patch)
treefe58484bfa76e7fe7a35bf0bffdc339b24621693 /crates
parent644ed252dda1a0785d2bee577a89322416f4d950 (diff)
Replace `once_cell`'s `Lazy` as much as possible (#4617)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/typst-cli/Cargo.toml1
-rw-r--r--crates/typst-cli/src/main.rs4
-rw-r--r--crates/typst-cli/src/world.rs7
-rw-r--r--crates/typst-layout/Cargo.toml1
-rw-r--r--crates/typst-layout/src/flow/block.rs11
-rw-r--r--crates/typst-layout/src/flow/collect.rs5
-rw-r--r--crates/typst-layout/src/inline/box.rs7
-rw-r--r--crates/typst-layout/src/inline/linebreak.rs10
-rw-r--r--crates/typst-layout/src/transforms.rs5
-rw-r--r--crates/typst-library/Cargo.toml1
-rw-r--r--crates/typst-library/src/foundations/element.rs6
-rw-r--r--crates/typst-library/src/foundations/func.rs9
-rw-r--r--crates/typst-library/src/foundations/mod.rs1
-rw-r--r--crates/typst-library/src/foundations/ty.rs6
-rw-r--r--crates/typst-library/src/model/bibliography.rs7
-rw-r--r--crates/typst-library/src/text/mod.rs4
-rw-r--r--crates/typst-library/src/text/raw.rs13
-rw-r--r--crates/typst-library/src/visualize/color.rs11
-rw-r--r--crates/typst-macros/src/elem.rs8
-rw-r--r--crates/typst-macros/src/func.rs6
-rw-r--r--crates/typst-macros/src/ty.rs4
-rw-r--r--crates/typst-pdf/Cargo.toml1
-rw-r--r--crates/typst-pdf/src/color.rs11
-rw-r--r--crates/typst-realize/Cargo.toml1
-rw-r--r--crates/typst-realize/src/lib.rs6
-rw-r--r--crates/typst-syntax/Cargo.toml1
-rw-r--r--crates/typst-syntax/src/file.rs9
-rw-r--r--crates/typst-utils/src/macros.rs3
-rw-r--r--crates/typst-utils/src/pico.rs9
29 files changed, 79 insertions, 89 deletions
diff --git a/crates/typst-cli/Cargo.toml b/crates/typst-cli/Cargo.toml
index 855d7bee..2ecade54 100644
--- a/crates/typst-cli/Cargo.toml
+++ b/crates/typst-cli/Cargo.toml
@@ -36,7 +36,6 @@ ecow = { workspace = true }
fs_extra = { workspace = true }
native-tls = { workspace = true }
notify = { workspace = true }
-once_cell = { workspace = true }
open = { workspace = true }
parking_lot = { workspace = true }
pathdiff = { workspace = true }
diff --git a/crates/typst-cli/src/main.rs b/crates/typst-cli/src/main.rs
index 464ad624..631befe5 100644
--- a/crates/typst-cli/src/main.rs
+++ b/crates/typst-cli/src/main.rs
@@ -16,12 +16,12 @@ mod world;
use std::cell::Cell;
use std::io::{self, Write};
use std::process::ExitCode;
+use std::sync::LazyLock;
use clap::error::ErrorKind;
use clap::Parser;
use codespan_reporting::term;
use codespan_reporting::term::termcolor::WriteColor;
-use once_cell::sync::Lazy;
use typst::diag::HintedStrResult;
use crate::args::{CliArguments, Command};
@@ -33,7 +33,7 @@ thread_local! {
}
/// The parsed command line arguments.
-static ARGS: Lazy<CliArguments> = Lazy::new(|| {
+static ARGS: LazyLock<CliArguments> = LazyLock::new(|| {
CliArguments::try_parse().unwrap_or_else(|error| {
if error.kind() == ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand {
crate::greet::greet();
diff --git a/crates/typst-cli/src/world.rs b/crates/typst-cli/src/world.rs
index b790f41a..f3597544 100644
--- a/crates/typst-cli/src/world.rs
+++ b/crates/typst-cli/src/world.rs
@@ -1,12 +1,11 @@
use std::collections::HashMap;
use std::io::Read;
use std::path::{Path, PathBuf};
-use std::sync::OnceLock;
+use std::sync::{LazyLock, OnceLock};
use std::{fmt, fs, io, mem};
use chrono::{DateTime, Datelike, FixedOffset, Local, Utc};
use ecow::{eco_format, EcoString};
-use once_cell::sync::Lazy;
use parking_lot::Mutex;
use typst::diag::{FileError, FileResult};
use typst::foundations::{Bytes, Datetime, Dict, IntoValue};
@@ -25,8 +24,8 @@ use crate::package;
/// Static `FileId` allocated for stdin.
/// This is to ensure that a file is read in the correct way.
-static STDIN_ID: Lazy<FileId> =
- Lazy::new(|| FileId::new_fake(VirtualPath::new("<stdin>")));
+static STDIN_ID: LazyLock<FileId> =
+ LazyLock::new(|| FileId::new_fake(VirtualPath::new("<stdin>")));
/// A world that provides access to the operating system.
pub struct SystemWorld {
diff --git a/crates/typst-layout/Cargo.toml b/crates/typst-layout/Cargo.toml
index 4c133a4e..438e09e4 100644
--- a/crates/typst-layout/Cargo.toml
+++ b/crates/typst-layout/Cargo.toml
@@ -30,7 +30,6 @@ icu_provider_adapters = { workspace = true }
icu_provider_blob = { workspace = true }
icu_segmenter = { workspace = true }
kurbo = { workspace = true }
-once_cell = { workspace = true }
rustybuzz = { workspace = true }
smallvec = { workspace = true }
ttf-parser = { workspace = true }
diff --git a/crates/typst-layout/src/flow/block.rs b/crates/typst-layout/src/flow/block.rs
index 48ca1fba..71eacc1c 100644
--- a/crates/typst-layout/src/flow/block.rs
+++ b/crates/typst-layout/src/flow/block.rs
@@ -1,4 +1,5 @@
-use once_cell::unsync::Lazy;
+use std::cell::LazyCell;
+
use smallvec::SmallVec;
use typst_library::diag::SourceResult;
use typst_library::engine::Engine;
@@ -79,8 +80,8 @@ pub fn layout_single_block(
.map(|s| s.map(Stroke::unwrap_or_default));
// Only fetch these if necessary (for clipping or filling/stroking).
- let outset = Lazy::new(|| elem.outset(styles).unwrap_or_default());
- let radius = Lazy::new(|| elem.radius(styles).unwrap_or_default());
+ let outset = LazyCell::new(|| elem.outset(styles).unwrap_or_default());
+ let radius = LazyCell::new(|| elem.radius(styles).unwrap_or_default());
// Clip the contents, if requested.
if elem.clip(styles) {
@@ -194,8 +195,8 @@ pub fn layout_multi_block(
.map(|s| s.map(Stroke::unwrap_or_default));
// Only fetch these if necessary (for clipping or filling/stroking).
- let outset = Lazy::new(|| elem.outset(styles).unwrap_or_default());
- let radius = Lazy::new(|| elem.radius(styles).unwrap_or_default());
+ let outset = LazyCell::new(|| elem.outset(styles).unwrap_or_default());
+ let radius = LazyCell::new(|| elem.radius(styles).unwrap_or_default());
// Fetch/compute these outside of the loop.
let clip = elem.clip(styles);
diff --git a/crates/typst-layout/src/flow/collect.rs b/crates/typst-layout/src/flow/collect.rs
index aee5d508..d3974349 100644
--- a/crates/typst-layout/src/flow/collect.rs
+++ b/crates/typst-layout/src/flow/collect.rs
@@ -1,11 +1,10 @@
-use std::cell::RefCell;
+use std::cell::{LazyCell, RefCell};
use std::fmt::{self, Debug, Formatter};
use std::hash::Hash;
use bumpalo::boxed::Box as BumpBox;
use bumpalo::Bump;
use comemo::{Track, Tracked, TrackedMut};
-use once_cell::unsync::Lazy;
use typst_library::diag::{bail, SourceResult};
use typst_library::engine::{Engine, Route, Sink, Traced};
use typst_library::foundations::{Packed, Resolve, Smart, StyleChain};
@@ -182,7 +181,7 @@ impl<'a> Collector<'a, '_, '_> {
_ => None,
};
- let fallback = Lazy::new(|| ParElem::spacing_in(styles));
+ let fallback = LazyCell::new(|| ParElem::spacing_in(styles));
let spacing = |amount| match amount {
Smart::Auto => Child::Rel((*fallback).into(), 4),
Smart::Custom(Spacing::Rel(rel)) => Child::Rel(rel.resolve(styles), 3),
diff --git a/crates/typst-layout/src/inline/box.rs b/crates/typst-layout/src/inline/box.rs
index 62054bea..6dfbc969 100644
--- a/crates/typst-layout/src/inline/box.rs
+++ b/crates/typst-layout/src/inline/box.rs
@@ -1,4 +1,5 @@
-use once_cell::unsync::Lazy;
+use std::cell::LazyCell;
+
use typst_library::diag::SourceResult;
use typst_library::engine::Engine;
use typst_library::foundations::{Packed, StyleChain};
@@ -56,8 +57,8 @@ pub fn layout_box(
.map(|s| s.map(Stroke::unwrap_or_default));
// Only fetch these if necessary (for clipping or filling/stroking).
- let outset = Lazy::new(|| elem.outset(styles).unwrap_or_default());
- let radius = Lazy::new(|| elem.radius(styles).unwrap_or_default());
+ let outset = LazyCell::new(|| elem.outset(styles).unwrap_or_default());
+ let radius = LazyCell::new(|| elem.radius(styles).unwrap_or_default());
// Clip the contents, if requested.
if elem.clip(styles) {
diff --git a/crates/typst-layout/src/inline/linebreak.rs b/crates/typst-layout/src/inline/linebreak.rs
index 7fc8b368..26621cd7 100644
--- a/crates/typst-layout/src/inline/linebreak.rs
+++ b/crates/typst-layout/src/inline/linebreak.rs
@@ -1,4 +1,5 @@
use std::ops::{Add, Sub};
+use std::sync::LazyLock;
use az::SaturatingAs;
use icu_properties::maps::{CodePointMapData, CodePointMapDataBorrowed};
@@ -7,7 +8,6 @@ use icu_provider::AsDeserializingBufferProvider;
use icu_provider_adapters::fork::ForkByKeyProvider;
use icu_provider_blob::BlobDataProvider;
use icu_segmenter::LineSegmenter;
-use once_cell::sync::Lazy;
use typst_library::engine::Engine;
use typst_library::layout::{Abs, Em};
use typst_library::model::Linebreaks;
@@ -40,11 +40,11 @@ fn blob() -> BlobDataProvider {
}
/// The general line break segmenter.
-static SEGMENTER: Lazy<LineSegmenter> =
- Lazy::new(|| LineSegmenter::try_new_lstm_with_buffer_provider(&blob()).unwrap());
+static SEGMENTER: LazyLock<LineSegmenter> =
+ LazyLock::new(|| LineSegmenter::try_new_lstm_with_buffer_provider(&blob()).unwrap());
/// The line break segmenter for Chinese/Japanese text.
-static CJ_SEGMENTER: Lazy<LineSegmenter> = Lazy::new(|| {
+static CJ_SEGMENTER: LazyLock<LineSegmenter> = LazyLock::new(|| {
let cj_blob =
BlobDataProvider::try_new_from_static_blob(typst_assets::icu::ICU_CJ_SEGMENT)
.unwrap();
@@ -53,7 +53,7 @@ static CJ_SEGMENTER: Lazy<LineSegmenter> = Lazy::new(|| {
});
/// The Unicode line break properties for each code point.
-static LINEBREAK_DATA: Lazy<CodePointMapData<LineBreak>> = Lazy::new(|| {
+static LINEBREAK_DATA: LazyLock<CodePointMapData<LineBreak>> = LazyLock::new(|| {
icu_properties::maps::load_line_break(&blob().as_deserializing()).unwrap()
});
diff --git a/crates/typst-layout/src/transforms.rs b/crates/typst-layout/src/transforms.rs
index 5ac9f777..e0f29c4c 100644
--- a/crates/typst-layout/src/transforms.rs
+++ b/crates/typst-layout/src/transforms.rs
@@ -1,4 +1,5 @@
-use once_cell::unsync::Lazy;
+use std::cell::LazyCell;
+
use typst_library::diag::{bail, SourceResult};
use typst_library::engine::Engine;
use typst_library::foundations::{Content, Packed, Resolve, Smart, StyleChain};
@@ -113,7 +114,7 @@ fn resolve_scale(
})
}
- let size = Lazy::new(|| {
+ let size = LazyCell::new(|| {
let pod = Region::new(container, Axes::splat(false));
let frame = crate::layout_frame(engine, &elem.body, locator, styles, pod)?;
SourceResult::Ok(frame.size())
diff --git a/crates/typst-library/Cargo.toml b/crates/typst-library/Cargo.toml
index de28f001..a1fb1033 100644
--- a/crates/typst-library/Cargo.toml
+++ b/crates/typst-library/Cargo.toml
@@ -37,7 +37,6 @@ indexmap = { workspace = true }
kamadak-exif = { workspace = true }
kurbo = { workspace = true }
lipsum = { workspace = true }
-once_cell = { workspace = true }
palette = { workspace = true }
phf = { workspace = true }
png = { workspace = true }
diff --git a/crates/typst-library/src/foundations/element.rs b/crates/typst-library/src/foundations/element.rs
index 8da71965..7ff00b9d 100644
--- a/crates/typst-library/src/foundations/element.rs
+++ b/crates/typst-library/src/foundations/element.rs
@@ -3,9 +3,9 @@ use std::cmp::Ordering;
use std::fmt::{self, Debug};
use std::hash::Hash;
use std::ptr::NonNull;
+use std::sync::LazyLock;
use ecow::EcoString;
-use once_cell::sync::Lazy;
use smallvec::SmallVec;
#[doc(inline)]
pub use typst_macros::elem;
@@ -292,9 +292,9 @@ pub struct NativeElementData {
pub field_from_styles: fn(u8, StyleChain) -> Result<Value, FieldAccessError>,
/// Gets the localized name for this element (see [`LocalName`][crate::text::LocalName]).
pub local_name: Option<fn(Lang, Option<Region>) -> &'static str>,
- pub scope: Lazy<Scope>,
+ pub scope: LazyLock<Scope>,
/// A list of parameter information for each field.
- pub params: Lazy<Vec<ParamInfo>>,
+ pub params: LazyLock<Vec<ParamInfo>>,
}
impl From<&'static NativeElementData> for Element {
diff --git a/crates/typst-library/src/foundations/func.rs b/crates/typst-library/src/foundations/func.rs
index 1b40714b..e34f48a1 100644
--- a/crates/typst-library/src/foundations/func.rs
+++ b/crates/typst-library/src/foundations/func.rs
@@ -2,11 +2,10 @@
pub use typst_macros::func;
use std::fmt::{self, Debug, Formatter};
-use std::sync::Arc;
+use std::sync::{Arc, LazyLock};
use comemo::{Tracked, TrackedMut};
use ecow::{eco_format, EcoString};
-use once_cell::sync::Lazy;
use typst_syntax::{ast, Span, SyntaxNode};
use typst_utils::{singleton, LazyHash, Static};
@@ -463,11 +462,11 @@ pub struct NativeFuncData {
pub keywords: &'static [&'static str],
/// Whether this function makes use of context.
pub contextual: bool,
- pub scope: Lazy<Scope>,
+ pub scope: LazyLock<Scope>,
/// A list of parameter information for each parameter.
- pub params: Lazy<Vec<ParamInfo>>,
+ pub params: LazyLock<Vec<ParamInfo>>,
/// Information about the return value of this function.
- pub returns: Lazy<CastInfo>,
+ pub returns: LazyLock<CastInfo>,
}
impl From<&'static NativeFuncData> for Func {
diff --git a/crates/typst-library/src/foundations/mod.rs b/crates/typst-library/src/foundations/mod.rs
index a6d6c253..9259a7d1 100644
--- a/crates/typst-library/src/foundations/mod.rs
+++ b/crates/typst-library/src/foundations/mod.rs
@@ -71,7 +71,6 @@ pub use typst_macros::{scope, ty};
pub use {
ecow::{eco_format, eco_vec},
indexmap::IndexMap,
- once_cell::sync::Lazy,
};
use ecow::EcoString;
diff --git a/crates/typst-library/src/foundations/ty.rs b/crates/typst-library/src/foundations/ty.rs
index 70845dd2..680c4f6a 100644
--- a/crates/typst-library/src/foundations/ty.rs
+++ b/crates/typst-library/src/foundations/ty.rs
@@ -3,9 +3,9 @@ pub use typst_macros::{scope, ty};
use std::cmp::Ordering;
use std::fmt::{self, Debug, Display, Formatter};
+use std::sync::LazyLock;
use ecow::{eco_format, EcoString};
-use once_cell::sync::Lazy;
use typst_utils::Static;
use crate::diag::StrResult;
@@ -207,8 +207,8 @@ pub struct NativeTypeData {
/// A list of alternate search terms for this type.
pub keywords: &'static [&'static str],
/// The constructor for this type.
- pub constructor: Lazy<Option<&'static NativeFuncData>>,
- pub scope: Lazy<Scope>,
+ pub constructor: LazyLock<Option<&'static NativeFuncData>>,
+ pub scope: LazyLock<Scope>,
}
impl From<&'static NativeTypeData> for Type {
diff --git a/crates/typst-library/src/model/bibliography.rs b/crates/typst-library/src/model/bibliography.rs
index d11055b9..56916731 100644
--- a/crates/typst-library/src/model/bibliography.rs
+++ b/crates/typst-library/src/model/bibliography.rs
@@ -4,7 +4,7 @@ use std::fmt::{self, Debug, Formatter};
use std::hash::{Hash, Hasher};
use std::num::NonZeroUsize;
use std::path::Path;
-use std::sync::Arc;
+use std::sync::{Arc, LazyLock};
use comemo::Tracked;
use ecow::{eco_format, EcoString, EcoVec};
@@ -15,7 +15,6 @@ use hayagriva::{
SpecificLocator,
};
use indexmap::IndexMap;
-use once_cell::sync::Lazy;
use smallvec::{smallvec, SmallVec};
use typed_arena::Arena;
use typst_syntax::{Span, Spanned};
@@ -633,8 +632,8 @@ impl<'a> Generator<'a> {
/// Drives hayagriva's citation driver.
fn drive(&mut self) -> hayagriva::Rendered {
- static LOCALES: Lazy<Vec<citationberg::Locale>> =
- Lazy::new(hayagriva::archive::locales);
+ static LOCALES: LazyLock<Vec<citationberg::Locale>> =
+ LazyLock::new(hayagriva::archive::locales);
let database = self.bibliography.bibliography();
let bibliography_style = self.bibliography.style(StyleChain::default());
diff --git a/crates/typst-library/src/text/mod.rs b/crates/typst-library/src/text/mod.rs
index acf100b5..6aeebbba 100644
--- a/crates/typst-library/src/text/mod.rs
+++ b/crates/typst-library/src/text/mod.rs
@@ -29,12 +29,12 @@ pub use self::smartquote::*;
pub use self::space::*;
use std::fmt::{self, Debug, Formatter};
+use std::sync::LazyLock;
use ecow::{eco_format, EcoString};
use icu_properties::sets::CodePointSetData;
use icu_provider::AsDeserializingBufferProvider;
use icu_provider_blob::BlobDataProvider;
-use once_cell::sync::Lazy;
use rustybuzz::Feature;
use smallvec::SmallVec;
use ttf_parser::Tag;
@@ -1275,7 +1275,7 @@ cast! {
/// Whether a codepoint is Unicode `Default_Ignorable`.
pub fn is_default_ignorable(c: char) -> bool {
/// The set of Unicode default ignorables.
- static DEFAULT_IGNORABLE_DATA: Lazy<CodePointSetData> = Lazy::new(|| {
+ static DEFAULT_IGNORABLE_DATA: LazyLock<CodePointSetData> = LazyLock::new(|| {
icu_properties::sets::load_default_ignorable_code_point(
&BlobDataProvider::try_new_from_static_blob(typst_assets::icu::ICU)
.unwrap()
diff --git a/crates/typst-library/src/text/raw.rs b/crates/typst-library/src/text/raw.rs
index 5ce77348..8691afcb 100644
--- a/crates/typst-library/src/text/raw.rs
+++ b/crates/typst-library/src/text/raw.rs
@@ -1,10 +1,9 @@
+use std::cell::LazyCell;
use std::hash::Hash;
use std::ops::Range;
-use std::sync::Arc;
+use std::sync::{Arc, LazyLock};
use ecow::{eco_format, EcoString, EcoVec};
-use once_cell::sync::Lazy;
-use once_cell::unsync::Lazy as UnsyncLazy;
use syntect::highlighting::{self as synt, Theme};
use syntect::parsing::{SyntaxDefinition, SyntaxSet, SyntaxSetBuilder};
use typst_syntax::{split_newlines, LinkedNode, Span, Spanned};
@@ -325,7 +324,7 @@ impl Packed<RawElem> {
.map(|s| s.to_lowercase())
.or(Some("txt".into()));
- let extra_syntaxes = UnsyncLazy::new(|| {
+ let extra_syntaxes = LazyCell::new(|| {
load_syntaxes(&elem.syntaxes(styles), &elem.syntaxes_data(styles)).unwrap()
});
let non_highlighted_result = |lines: EcoVec<(EcoString, Span)>| {
@@ -838,11 +837,11 @@ fn parse_theme(
///
/// Syntax set is generated from the syntaxes from the `bat` project
/// <https://github.com/sharkdp/bat/tree/master/assets/syntaxes>
-pub static RAW_SYNTAXES: Lazy<syntect::parsing::SyntaxSet> =
- Lazy::new(two_face::syntax::extra_no_newlines);
+pub static RAW_SYNTAXES: LazyLock<syntect::parsing::SyntaxSet> =
+ LazyLock::new(two_face::syntax::extra_no_newlines);
/// The default theme used for syntax highlighting.
-pub static RAW_THEME: Lazy<synt::Theme> = Lazy::new(|| synt::Theme {
+pub static RAW_THEME: LazyLock<synt::Theme> = LazyLock::new(|| synt::Theme {
name: Some("Typst Light".into()),
author: Some("The Typst Project Developers".into()),
settings: synt::ThemeSettings::default(),
diff --git a/crates/typst-library/src/visualize/color.rs b/crates/typst-library/src/visualize/color.rs
index 1a279fbb..8ff8dbdb 100644
--- a/crates/typst-library/src/visualize/color.rs
+++ b/crates/typst-library/src/visualize/color.rs
@@ -1,9 +1,9 @@
use std::fmt::{self, Debug, Formatter};
use std::hash::{Hash, Hasher};
use std::str::FromStr;
+use std::sync::LazyLock;
use ecow::{eco_format, EcoString, EcoVec};
-use once_cell::sync::Lazy;
use palette::encoding::{self, Linear};
use palette::{
Alpha, Darken, Desaturate, FromColor, Lighten, OklabHue, RgbHue, Saturate, ShiftHue,
@@ -33,17 +33,18 @@ pub type Luma = palette::luma::Lumaa<encoding::Srgb, f32>;
/// to convert from CMYK to RGB. It is based on the CGATS TR 001-1995
/// specification. See
/// <https://github.com/saucecontrol/Compact-ICC-Profiles#cmyk>.
-static CMYK_TO_XYZ: Lazy<Box<Profile>> =
- Lazy::new(|| Profile::new_from_slice(typst_assets::icc::CMYK_TO_XYZ, false).unwrap());
+static CMYK_TO_XYZ: LazyLock<Box<Profile>> = LazyLock::new(|| {
+ Profile::new_from_slice(typst_assets::icc::CMYK_TO_XYZ, false).unwrap()
+});
/// The target sRGB profile.
-static SRGB_PROFILE: Lazy<Box<Profile>> = Lazy::new(|| {
+static SRGB_PROFILE: LazyLock<Box<Profile>> = LazyLock::new(|| {
let mut out = Profile::new_sRGB();
out.precache_output_transform();
out
});
-static TO_SRGB: Lazy<qcms::Transform> = Lazy::new(|| {
+static TO_SRGB: LazyLock<qcms::Transform> = LazyLock::new(|| {
qcms::Transform::new_to(
&CMYK_TO_XYZ,
&SRGB_PROFILE,
diff --git a/crates/typst-macros/src/elem.rs b/crates/typst-macros/src/elem.rs
index 3b968f76..78a3c180 100644
--- a/crates/typst-macros/src/elem.rs
+++ b/crates/typst-macros/src/elem.rs
@@ -432,8 +432,8 @@ fn create_default_static(field: &Field) -> TokenStream {
};
quote! {
- static #const_ident: ::once_cell::sync::Lazy<#ty> =
- ::once_cell::sync::Lazy::new(#init);
+ static #const_ident: ::std::sync::LazyLock<#ty> =
+ ::std::sync::LazyLock::new(#init);
}
}
@@ -660,8 +660,8 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
field_name: |id| id.try_into().ok().map(Fields::to_str),
field_from_styles: <#ident as #foundations::Fields>::field_from_styles,
local_name: #local_name,
- scope: #foundations::Lazy::new(|| #scope),
- params: #foundations::Lazy::new(|| ::std::vec![#(#params),*])
+ scope: ::std::sync::LazyLock::new(|| #scope),
+ params: ::std::sync::LazyLock::new(|| ::std::vec![#(#params),*])
}
};
diff --git a/crates/typst-macros/src/func.rs b/crates/typst-macros/src/func.rs
index d402efd9..b8ab7a36 100644
--- a/crates/typst-macros/src/func.rs
+++ b/crates/typst-macros/src/func.rs
@@ -321,9 +321,9 @@ fn create_func_data(func: &Func) -> TokenStream {
docs: #docs,
keywords: &[#(#keywords),*],
contextual: #contextual,
- scope: #foundations::Lazy::new(|| #scope),
- params: #foundations::Lazy::new(|| ::std::vec![#(#params),*]),
- returns: #foundations::Lazy::new(|| <#returns as #foundations::Reflect>::output()),
+ scope: ::std::sync::LazyLock::new(|| #scope),
+ params: ::std::sync::LazyLock::new(|| ::std::vec![#(#params),*]),
+ returns: ::std::sync::LazyLock::new(|| <#returns as #foundations::Reflect>::output()),
}
}
}
diff --git a/crates/typst-macros/src/ty.rs b/crates/typst-macros/src/ty.rs
index 200798af..66284904 100644
--- a/crates/typst-macros/src/ty.rs
+++ b/crates/typst-macros/src/ty.rs
@@ -102,8 +102,8 @@ fn create(ty: &Type, item: Option<&syn::Item>) -> TokenStream {
title: #title,
docs: #docs,
keywords: &[#(#keywords),*],
- constructor: #foundations::Lazy::new(|| #constructor),
- scope: #foundations::Lazy::new(|| #scope),
+ constructor: ::std::sync::LazyLock::new(|| #constructor),
+ scope: ::std::sync::LazyLock::new(|| #scope),
}
};
diff --git a/crates/typst-pdf/Cargo.toml b/crates/typst-pdf/Cargo.toml
index 4cef14bd..bc0da06c 100644
--- a/crates/typst-pdf/Cargo.toml
+++ b/crates/typst-pdf/Cargo.toml
@@ -27,7 +27,6 @@ ecow = { workspace = true }
image = { workspace = true }
indexmap = { workspace = true }
miniz_oxide = { workspace = true }
-once_cell = { workspace = true }
pdf-writer = { workspace = true }
serde = { workspace = true }
subsetter = { workspace = true }
diff --git a/crates/typst-pdf/src/color.rs b/crates/typst-pdf/src/color.rs
index 26f2044c..7097c14a 100644
--- a/crates/typst-pdf/src/color.rs
+++ b/crates/typst-pdf/src/color.rs
@@ -1,5 +1,6 @@
+use std::sync::LazyLock;
+
use arrayvec::ArrayVec;
-use once_cell::sync::Lazy;
use pdf_writer::{writers, Chunk, Dict, Filter, Name, Ref};
use typst_library::diag::{bail, SourceResult};
use typst_library::visualize::{Color, ColorSpace, Paint};
@@ -13,10 +14,10 @@ pub const D65_GRAY: Name<'static> = Name(b"d65gray");
pub const LINEAR_SRGB: Name<'static> = Name(b"linearrgb");
// The ICC profiles.
-static SRGB_ICC_DEFLATED: Lazy<Vec<u8>> =
- Lazy::new(|| deflate(typst_assets::icc::S_RGB_V4));
-static GRAY_ICC_DEFLATED: Lazy<Vec<u8>> =
- Lazy::new(|| deflate(typst_assets::icc::S_GREY_V4));
+static SRGB_ICC_DEFLATED: LazyLock<Vec<u8>> =
+ LazyLock::new(|| deflate(typst_assets::icc::S_RGB_V4));
+static GRAY_ICC_DEFLATED: LazyLock<Vec<u8>> =
+ LazyLock::new(|| deflate(typst_assets::icc::S_GREY_V4));
/// The color spaces present in the PDF document
#[derive(Default)]
diff --git a/crates/typst-realize/Cargo.toml b/crates/typst-realize/Cargo.toml
index 78bda259..cbf0cbca 100644
--- a/crates/typst-realize/Cargo.toml
+++ b/crates/typst-realize/Cargo.toml
@@ -22,7 +22,6 @@ arrayvec = { workspace = true }
bumpalo = { workspace = true }
comemo = { workspace = true }
ecow = { workspace = true }
-once_cell = { workspace = true }
regex = { workspace = true }
[lints]
diff --git a/crates/typst-realize/src/lib.rs b/crates/typst-realize/src/lib.rs
index 58668962..ec7ee0ae 100644
--- a/crates/typst-realize/src/lib.rs
+++ b/crates/typst-realize/src/lib.rs
@@ -5,12 +5,12 @@
//! further.
use std::borrow::Cow;
+use std::cell::LazyCell;
use arrayvec::ArrayVec;
use bumpalo::collections::{String as BumpString, Vec as BumpVec};
use comemo::Track;
use ecow::EcoString;
-use once_cell::unsync::Lazy;
use typst_library::diag::{bail, At, SourceResult};
use typst_library::engine::Engine;
use typst_library::foundations::{
@@ -420,7 +420,7 @@ fn verdict<'a>(
// it to determine whether a particular show rule was already applied to the
// `target` previously. For this purpose, show rules are indexed from the
// top of the chain as the chain might grow to the bottom.
- let depth = Lazy::new(|| styles.recipes().count());
+ let depth = LazyCell::new(|| styles.recipes().count());
for (r, recipe) in styles.recipes().enumerate() {
// We're not interested in recipes that don't match.
@@ -1032,7 +1032,7 @@ fn find_regex_match_in_str<'a>(
let mut revoked = SmallBitSet::new();
let mut leftmost: Option<(regex::Match, RecipeIndex, &Recipe)> = None;
- let depth = Lazy::new(|| styles.recipes().count());
+ let depth = LazyCell::new(|| styles.recipes().count());
for entry in styles.entries() {
let recipe = match &**entry {
diff --git a/crates/typst-syntax/Cargo.toml b/crates/typst-syntax/Cargo.toml
index 3dc983eb..263595bd 100644
--- a/crates/typst-syntax/Cargo.toml
+++ b/crates/typst-syntax/Cargo.toml
@@ -16,7 +16,6 @@ readme = { workspace = true }
typst-timing = { workspace = true }
typst-utils = { workspace = true }
ecow = { workspace = true }
-once_cell = { workspace = true }
serde = { workspace = true }
toml = { workspace = true }
unicode-ident = { workspace = true }
diff --git a/crates/typst-syntax/src/file.rs b/crates/typst-syntax/src/file.rs
index bc7dd314..e24fc8fb 100644
--- a/crates/typst-syntax/src/file.rs
+++ b/crates/typst-syntax/src/file.rs
@@ -2,16 +2,15 @@
use std::collections::HashMap;
use std::fmt::{self, Debug, Formatter};
-use std::sync::RwLock;
-
-use once_cell::sync::Lazy;
+use std::sync::{LazyLock, RwLock};
use crate::package::PackageSpec;
use crate::VirtualPath;
/// The global package-path interner.
-static INTERNER: Lazy<RwLock<Interner>> =
- Lazy::new(|| RwLock::new(Interner { to_id: HashMap::new(), from_id: Vec::new() }));
+static INTERNER: LazyLock<RwLock<Interner>> = LazyLock::new(|| {
+ RwLock::new(Interner { to_id: HashMap::new(), from_id: Vec::new() })
+});
/// A package-path interner.
struct Interner {
diff --git a/crates/typst-utils/src/macros.rs b/crates/typst-utils/src/macros.rs
index dd60a2e0..e286d05f 100644
--- a/crates/typst-utils/src/macros.rs
+++ b/crates/typst-utils/src/macros.rs
@@ -2,8 +2,7 @@
#[macro_export]
macro_rules! singleton {
($ty:ty, $value:expr) => {{
- static VALUE: $crate::once_cell::sync::Lazy<$ty> =
- $crate::once_cell::sync::Lazy::new(|| $value);
+ static VALUE: ::std::sync::LazyLock<$ty> = ::std::sync::LazyLock::new(|| $value);
&*VALUE
}};
}
diff --git a/crates/typst-utils/src/pico.rs b/crates/typst-utils/src/pico.rs
index d531f14a..dcab39b6 100644
--- a/crates/typst-utils/src/pico.rs
+++ b/crates/typst-utils/src/pico.rs
@@ -1,13 +1,12 @@
use std::cmp::Ordering;
use std::collections::HashMap;
use std::fmt::{self, Debug, Formatter};
-use std::sync::RwLock;
-
-use once_cell::sync::Lazy;
+use std::sync::{LazyLock, RwLock};
/// The global string interner.
-static INTERNER: Lazy<RwLock<Interner>> =
- Lazy::new(|| RwLock::new(Interner { to_id: HashMap::new(), from_id: Vec::new() }));
+static INTERNER: LazyLock<RwLock<Interner>> = LazyLock::new(|| {
+ RwLock::new(Interner { to_id: HashMap::new(), from_id: Vec::new() })
+});
/// A string interner.
struct Interner {