Compare commits

..

5 Commits

Author SHA1 Message Date
Erik
c1d55f053a
Merge 47df51c6f1137cef2c64772239c7b86858542912 into 78355421ad73fdcbe93b4acca890b439c4b6f98d 2025-07-22 21:23:12 +09:00
tinger
47df51c6f1 Bundle deprecation message and version in DeprecationInfo
Because the increase in size of `Binding` seemed to create a performance
regression we'll try to reduce the size by putting the rarely used
deprecation on the heap. In fact, the struct is even smaller than before
now, because `deprecation` was previously a wide pointer.
2025-07-21 19:44:38 +02:00
tinger
9eb2cafcc3 Add 0.15.0 as removal version to deprecated bindings
Note that `path` was left out because it may not be removed, but
replaced by a path type constructor right away.
2025-07-21 19:34:43 +02:00
tinger
44c573d1a0 Add support for until to the deprecated macro
This allows easily annotating the `until` version in impl blocks
using the `#[scope]` macro.
2025-07-21 19:33:26 +02:00
tinger
e6ac31e92c Add version to Binding deprecation warnings
This allows displaying a hint in which the version a binding may be
removed in. It helps to signal how urgent a package update may be to
package authors. The version is also sent to the proprietary doc
generator.
2025-07-21 19:30:12 +02:00
9 changed files with 56 additions and 54 deletions

View File

@ -254,7 +254,7 @@ pub struct Binding {
/// The category of the binding. /// The category of the binding.
category: Option<Category>, category: Option<Category>,
/// The deprecation information if this item is deprecated. /// The deprecation information if this item is deprecated.
deprecation: Option<Box<Deprecation>>, deprecation: Option<Box<DeprecationInfo>>,
} }
/// The different kinds of slots. /// The different kinds of slots.
@ -284,8 +284,20 @@ impl Binding {
} }
/// Marks this binding as deprecated, with the given `message`. /// Marks this binding as deprecated, with the given `message`.
pub fn deprecated(&mut self, deprecation: Deprecation) -> &mut Self { pub fn deprecated(&mut self, message: &'static str) -> &mut Self {
self.deprecation = Some(Box::new(deprecation)); self.deprecation
.get_or_insert_with(|| Box::new(DeprecationInfo::new()))
.deprecated_message(message);
self
}
/// Set the version in which the binding is planned to be removed.
///
/// This is ignored if [`Binding::deprecated`] isn't also set.
pub fn deprecated_until(&mut self, version: &'static str) -> &mut Self {
self.deprecation
.get_or_insert_with(|| Box::new(DeprecationInfo::new()))
.deprecated_until(version);
self self
} }
@ -337,7 +349,7 @@ impl Binding {
} }
/// A deprecation message for the value, if any. /// A deprecation message for the value, if any.
pub fn deprecation(&self) -> Option<&Deprecation> { pub fn deprecation(&self) -> Option<&DeprecationInfo> {
self.deprecation.as_deref() self.deprecation.as_deref()
} }
@ -358,14 +370,14 @@ pub enum Capturer {
/// Information about a deprecated binding. /// Information about a deprecated binding.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct Deprecation { pub struct DeprecationInfo {
/// A deprecation message for the definition. /// A deprecation message for the definition.
message: &'static str, message: &'static str,
/// A version in which the deprecated binding is planned to be removed. /// A version in which the deprecated binding is planned to be removed.
until: Option<&'static str>, until: Option<&'static str>,
} }
impl Deprecation { impl DeprecationInfo {
/// Creates new deprecation info with a default message to display when /// Creates new deprecation info with a default message to display when
/// emitting the deprecation warning. /// emitting the deprecation warning.
pub fn new() -> Self { pub fn new() -> Self {
@ -373,13 +385,13 @@ impl Deprecation {
} }
/// Set the message to display when emitting the deprecation warning. /// Set the message to display when emitting the deprecation warning.
pub fn with_message(mut self, message: &'static str) -> Self { pub fn deprecated_message(&mut self, message: &'static str) -> &mut Self {
self.message = message; self.message = message;
self self
} }
/// Set the version in which the binding is planned to be removed. /// Set the version in which the binding is planned to be removed.
pub fn with_until(mut self, version: &'static str) -> Self { pub fn deprecated_until(&mut self, version: &'static str) -> &mut Self {
self.until = Some(version); self.until = Some(version);
self self
} }
@ -395,7 +407,7 @@ impl Deprecation {
} }
} }
impl Default for Deprecation { impl Default for DeprecationInfo {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new()
} }

View File

@ -1,6 +1,6 @@
//! Modifiable symbols. //! Modifiable symbols.
use crate::foundations::{Deprecation, Module, Scope, Symbol, Value}; use crate::foundations::{Module, Scope, Symbol, Value};
/// Hook up all `symbol` definitions. /// Hook up all `symbol` definitions.
pub(super) fn define(global: &mut Scope) { pub(super) fn define(global: &mut Scope) {
@ -23,7 +23,7 @@ fn extend_scope_from_codex_module(scope: &mut Scope, module: codex::Module) {
let scope_binding = scope.define(name, value); let scope_binding = scope.define(name, value);
if let Some(message) = binding.deprecation { if let Some(message) = binding.deprecation {
scope_binding.deprecated(Deprecation::new().with_message(message)); scope_binding.deprecated(message);
} }
} }
} }

View File

@ -476,18 +476,26 @@ impl Curve {
/// Computes the size of the bounding box of this curve. /// Computes the size of the bounding box of this curve.
pub fn bbox_size(&self) -> Size { pub fn bbox_size(&self) -> Size {
let mut min = Point::splat(Abs::inf()); let mut min_x = Abs::inf();
let mut max = Point::splat(-Abs::inf()); let mut min_y = Abs::inf();
let mut max_x = -Abs::inf();
let mut max_y = -Abs::inf();
let mut cursor = Point::zero(); let mut cursor = Point::zero();
for item in self.0.iter() { for item in self.0.iter() {
match item { match item {
CurveItem::Move(to) => { CurveItem::Move(to) => {
min_x = min_x.min(cursor.x);
min_y = min_y.min(cursor.y);
max_x = max_x.max(cursor.x);
max_y = max_y.max(cursor.y);
cursor = *to; cursor = *to;
} }
CurveItem::Line(to) => { CurveItem::Line(to) => {
min = min.min(cursor).min(*to); min_x = min_x.min(cursor.x);
max = max.max(cursor).max(*to); min_y = min_y.min(cursor.y);
max_x = max_x.max(cursor.x);
max_y = max_y.max(cursor.y);
cursor = *to; cursor = *to;
} }
CurveItem::Cubic(c0, c1, end) => { CurveItem::Cubic(c0, c1, end) => {
@ -499,17 +507,17 @@ impl Curve {
); );
let bbox = cubic.bounding_box(); let bbox = cubic.bounding_box();
min.x = min.x.min(Abs::pt(bbox.x0)).min(Abs::pt(bbox.x1)); min_x = min_x.min(Abs::pt(bbox.x0)).min(Abs::pt(bbox.x1));
min.y = min.y.min(Abs::pt(bbox.y0)).min(Abs::pt(bbox.y1)); min_y = min_y.min(Abs::pt(bbox.y0)).min(Abs::pt(bbox.y1));
max.x = max.x.max(Abs::pt(bbox.x0)).max(Abs::pt(bbox.x1)); max_x = max_x.max(Abs::pt(bbox.x0)).max(Abs::pt(bbox.x1));
max.y = max.y.max(Abs::pt(bbox.y0)).max(Abs::pt(bbox.y1)); max_y = max_y.max(Abs::pt(bbox.y0)).max(Abs::pt(bbox.y1));
cursor = *end; cursor = *end;
} }
CurveItem::Close => (), CurveItem::Close => (),
} }
} }
Size::new(max.x - min.x, max.y - min.y) Size::new(max_x - min_x, max_y - min_y)
} }
} }

View File

@ -24,7 +24,6 @@ pub use self::shape::*;
pub use self::stroke::*; pub use self::stroke::*;
pub use self::tiling::*; pub use self::tiling::*;
use crate::foundations::Deprecation;
use crate::foundations::{Element, Scope, Type}; use crate::foundations::{Element, Scope, Type};
/// Hook up all visualize definitions. /// Hook up all visualize definitions.
@ -42,14 +41,12 @@ pub(super) fn define(global: &mut Scope) {
global.define_elem::<CircleElem>(); global.define_elem::<CircleElem>();
global.define_elem::<PolygonElem>(); global.define_elem::<PolygonElem>();
global.define_elem::<CurveElem>(); global.define_elem::<CurveElem>();
global.define("path", Element::of::<PathElem>()).deprecated( global
Deprecation::new() .define("path", Element::of::<PathElem>())
.with_message("the `path` function is deprecated, use `curve` instead"), .deprecated("the `path` function is deprecated, use `curve` instead");
); global
global.define("pattern", Type::of::<Tiling>()).deprecated( .define("pattern", Type::of::<Tiling>())
Deprecation::new() .deprecated("the name `pattern` is deprecated, use `tiling` instead")
.with_message("the name `pattern` is deprecated, use `tiling` instead") .deprecated_until("0.15.0");
.with_until("0.15.0"),
);
global.reset_category(); global.reset_category();
} }

View File

@ -64,22 +64,17 @@ pub fn scope(_: TokenStream, item: syn::Item) -> Result<TokenStream> {
Punctuated::<MetaNameValue, Token![,]>::parse_separated_nonempty, Punctuated::<MetaNameValue, Token![,]>::parse_separated_nonempty,
)?; )?;
let mut deprecation =
quote! { crate::foundations::Deprecation::new() };
if let Some(message) = args.iter().find_map(|pair| { if let Some(message) = args.iter().find_map(|pair| {
pair.path.is_ident("message").then_some(&pair.value) pair.path.is_ident("message").then_some(&pair.value)
}) { }) {
deprecation = quote! { #deprecation.with_message(#message) } def = quote! { #def.deprecated(#message) }
} }
if let Some(version) = args.iter().find_map(|pair| { if let Some(version) = args.iter().find_map(|pair| {
pair.path.is_ident("until").then_some(&pair.value) pair.path.is_ident("until").then_some(&pair.value)
}) { }) {
deprecation = quote! { #deprecation.with_until(#version) } def = quote! { #def.deprecated_until(#version) }
} }
def = quote! { #def.deprecated(#deprecation) }
} }
_ => {} _ => {}
} }

View File

@ -17,7 +17,7 @@ use serde::Deserialize;
use serde_yaml as yaml; use serde_yaml as yaml;
use std::sync::LazyLock; use std::sync::LazyLock;
use typst::diag::{StrResult, bail}; use typst::diag::{StrResult, bail};
use typst::foundations::Deprecation; use typst::foundations::DeprecationInfo;
use typst::foundations::{ use typst::foundations::{
AutoValue, Binding, Bytes, CastInfo, Func, Module, NoneValue, ParamInfo, Repr, Scope, AutoValue, Binding, Bytes, CastInfo, Func, Module, NoneValue, ParamInfo, Repr, Scope,
Smart, Type, Value, Smart, Type, Value,
@ -382,7 +382,7 @@ fn func_page(
parent: &str, parent: &str,
func: &Func, func: &Func,
path: &[&str], path: &[&str],
deprecation: Option<&Deprecation>, deprecation: Option<&DeprecationInfo>,
) -> PageModel { ) -> PageModel {
let model = func_model(resolver, func, path, false, deprecation); let model = func_model(resolver, func, path, false, deprecation);
let name = func.name().unwrap(); let name = func.name().unwrap();
@ -403,7 +403,7 @@ fn func_model(
func: &Func, func: &Func,
path: &[&str], path: &[&str],
nested: bool, nested: bool,
deprecation: Option<&Deprecation>, deprecation: Option<&DeprecationInfo>,
) -> FuncModel { ) -> FuncModel {
let name = func.name().unwrap(); let name = func.name().unwrap();
let scope = func.scope().unwrap(); let scope = func.scope().unwrap();
@ -439,8 +439,8 @@ fn func_model(
oneliner: oneliner(details), oneliner: oneliner(details),
element: func.element().is_some(), element: func.element().is_some(),
contextual: func.contextual().unwrap_or(false), contextual: func.contextual().unwrap_or(false),
deprecation_message: deprecation.map(Deprecation::message), deprecation_message: deprecation.map(DeprecationInfo::message),
deprecation_until: deprecation.and_then(Deprecation::until), deprecation_until: deprecation.and_then(DeprecationInfo::until),
details: Html::markdown(resolver, details, nesting), details: Html::markdown(resolver, details, nesting),
example: example.map(|md| Html::markdown(resolver, md, None)), example: example.map(|md| Html::markdown(resolver, md, None)),
self_, self_,
@ -740,8 +740,8 @@ fn symbols_model(resolver: &dyn Resolver, group: &GroupData) -> SymbolsModel {
.map(|(other, _, _)| complete(other)) .map(|(other, _, _)| complete(other))
.collect(), .collect(),
deprecation_message: deprecation_message deprecation_message: deprecation_message
.or_else(|| binding.deprecation().map(Deprecation::message)), .or_else(|| binding.deprecation().map(DeprecationInfo::message)),
deprecation_until: binding.deprecation().and_then(Deprecation::until), deprecation_until: binding.deprecation().and_then(DeprecationInfo::until),
}); });
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 399 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -130,16 +130,6 @@
down, up, down, up, down, down, up, down, up, down,
) )
--- curve-stroke-gradient-sharp ---
#set page(width: auto)
#let down = curve.line((40pt, 40pt), relative: true)
#let up = curve.line((40pt, -40pt), relative: true)
#curve(
stroke: 4pt + gradient.linear(red, blue).sharp(3),
down, up, down, up, down,
)
--- curve-fill-rule --- --- curve-fill-rule ---
#stack( #stack(
dir: ltr, dir: ltr,