summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/content.rs18
-rw-r--r--src/model/layout.rs16
-rw-r--r--src/model/property.rs4
-rw-r--r--src/model/recipe.rs6
-rw-r--r--src/model/show.rs19
-rw-r--r--src/model/styles.rs4
6 files changed, 43 insertions, 24 deletions
diff --git a/src/model/content.rs b/src/model/content.rs
index dbea141c..92d592a6 100644
--- a/src/model/content.rs
+++ b/src/model/content.rs
@@ -4,6 +4,7 @@ use std::iter::Sum;
use std::mem;
use std::ops::{Add, AddAssign};
+use comemo::Tracked;
use typed_arena::Arena;
use super::{
@@ -23,7 +24,8 @@ use crate::World;
/// Layout content into a collection of pages.
///
/// Relayouts until all pinned locations are converged.
-pub fn layout(world: &dyn World, content: &Content) -> SourceResult<Vec<Frame>> {
+#[comemo::memoize]
+pub fn layout(world: Tracked<dyn World>, content: &Content) -> SourceResult<Vec<Frame>> {
let styles = StyleChain::with_root(&world.config().styles);
let scratch = Scratch::default();
@@ -232,7 +234,7 @@ impl Content {
impl Layout for Content {
fn layout(
&self,
- world: &dyn World,
+ world: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
) -> SourceResult<Vec<Frame>> {
@@ -330,9 +332,9 @@ impl Sum for Content {
}
/// Builds a document or a flow node from content.
-struct Builder<'a, 'w> {
+struct Builder<'a> {
/// The core context.
- world: &'w dyn World,
+ world: Tracked<'a, dyn World>,
/// Scratch arenas for building.
scratch: &'a Scratch<'a>,
/// The current document building state.
@@ -354,8 +356,8 @@ struct Scratch<'a> {
templates: Arena<Content>,
}
-impl<'a, 'w> Builder<'a, 'w> {
- fn new(world: &'w dyn World, scratch: &'a Scratch<'a>, top: bool) -> Self {
+impl<'a> Builder<'a> {
+ fn new(world: Tracked<'a, dyn World>, scratch: &'a Scratch<'a>, top: bool) -> Self {
Self {
world,
scratch,
@@ -662,7 +664,7 @@ impl<'a> ParBuilder<'a> {
true
}
- fn finish(self, parent: &mut Builder<'a, '_>) {
+ fn finish(self, parent: &mut Builder<'a>) {
let (mut children, shared) = self.0.finish();
if children.is_empty() {
return;
@@ -746,7 +748,7 @@ impl<'a> ListBuilder<'a> {
true
}
- fn finish(self, parent: &mut Builder<'a, '_>) -> SourceResult<()> {
+ fn finish(self, parent: &mut Builder<'a>) -> SourceResult<()> {
let (items, shared) = self.items.finish();
let kind = match items.items().next() {
Some(item) => item.kind,
diff --git a/src/model/layout.rs b/src/model/layout.rs
index 68847471..8064afff 100644
--- a/src/model/layout.rs
+++ b/src/model/layout.rs
@@ -5,6 +5,8 @@ use std::fmt::{self, Debug, Formatter, Write};
use std::hash::Hash;
use std::sync::Arc;
+use comemo::{Prehashed, Tracked};
+
use super::{Barrier, NodeId, Resolve, StyleChain, StyleEntry};
use crate::diag::SourceResult;
use crate::eval::{RawAlign, RawLength};
@@ -14,7 +16,6 @@ use crate::geom::{
};
use crate::library::graphics::MoveNode;
use crate::library::layout::{AlignNode, PadNode};
-use crate::util::Prehashed;
use crate::World;
/// A node that can be layouted into a sequence of regions.
@@ -24,7 +25,7 @@ pub trait Layout: 'static {
/// Layout this node into the given regions, producing frames.
fn layout(
&self,
- world: &dyn World,
+ world: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
) -> SourceResult<Vec<Frame>>;
@@ -214,9 +215,10 @@ impl LayoutNode {
}
impl Layout for LayoutNode {
+ #[comemo::memoize]
fn layout(
&self,
- world: &dyn World,
+ world: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
) -> SourceResult<Vec<Frame>> {
@@ -285,7 +287,7 @@ struct EmptyNode;
impl Layout for EmptyNode {
fn layout(
&self,
- _: &dyn World,
+ _: Tracked<dyn World>,
regions: &Regions,
_: StyleChain,
) -> SourceResult<Vec<Frame>> {
@@ -307,7 +309,7 @@ struct SizedNode {
impl Layout for SizedNode {
fn layout(
&self,
- world: &dyn World,
+ world: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
) -> SourceResult<Vec<Frame>> {
@@ -354,7 +356,7 @@ struct FillNode {
impl Layout for FillNode {
fn layout(
&self,
- world: &dyn World,
+ world: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
) -> SourceResult<Vec<Frame>> {
@@ -379,7 +381,7 @@ struct StrokeNode {
impl Layout for StrokeNode {
fn layout(
&self,
- world: &dyn World,
+ world: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
) -> SourceResult<Vec<Frame>> {
diff --git a/src/model/property.rs b/src/model/property.rs
index 8681da7d..18f41eee 100644
--- a/src/model/property.rs
+++ b/src/model/property.rs
@@ -3,13 +3,15 @@ use std::fmt::{self, Debug, Formatter};
use std::hash::Hash;
use std::sync::Arc;
+use comemo::Prehashed;
+
use super::{Interruption, NodeId, StyleChain};
use crate::eval::{RawLength, Smart};
use crate::geom::{Corners, Length, Numeric, Relative, Sides, Spec};
use crate::library::layout::PageNode;
use crate::library::structure::{EnumNode, ListNode};
use crate::library::text::ParNode;
-use crate::util::{Prehashed, ReadableTypeId};
+use crate::util::ReadableTypeId;
/// A style property originating from a set rule or constructor.
#[derive(Clone, Hash)]
diff --git a/src/model/recipe.rs b/src/model/recipe.rs
index 980d939b..6b21ccf2 100644
--- a/src/model/recipe.rs
+++ b/src/model/recipe.rs
@@ -1,5 +1,7 @@
use std::fmt::{self, Debug, Formatter};
+use comemo::Tracked;
+
use super::{Content, Interruption, NodeId, Show, ShowNode, StyleChain, StyleEntry};
use crate::diag::SourceResult;
use crate::eval::{Args, Func, Regex, Value};
@@ -29,7 +31,7 @@ impl Recipe {
/// Try to apply the recipe to the target.
pub fn apply(
&self,
- world: &dyn World,
+ world: Tracked<dyn World>,
styles: StyleChain,
sel: Selector,
target: Target,
@@ -75,7 +77,7 @@ impl Recipe {
}
/// Call the recipe function, with the argument if desired.
- fn call<F>(&self, world: &dyn World, arg: F) -> SourceResult<Content>
+ fn call<F>(&self, world: Tracked<dyn World>, arg: F) -> SourceResult<Content>
where
F: FnOnce() -> Value,
{
diff --git a/src/model/show.rs b/src/model/show.rs
index 56fb29ba..b30b2264 100644
--- a/src/model/show.rs
+++ b/src/model/show.rs
@@ -2,10 +2,11 @@ use std::fmt::{self, Debug, Formatter, Write};
use std::hash::Hash;
use std::sync::Arc;
+use comemo::{Prehashed, Tracked};
+
use super::{Content, NodeId, Selector, StyleChain};
use crate::diag::SourceResult;
use crate::eval::Dict;
-use crate::util::Prehashed;
use crate::World;
/// A node that can be realized given some styles.
@@ -18,7 +19,11 @@ pub trait Show: 'static {
/// The base recipe for this node that is executed if there is no
/// user-defined show rule.
- fn realize(&self, world: &dyn World, styles: StyleChain) -> SourceResult<Content>;
+ fn realize(
+ &self,
+ world: Tracked<dyn World>,
+ styles: StyleChain,
+ ) -> SourceResult<Content>;
/// Finalize this node given the realization of a base or user recipe. Use
/// this for effects that should work even in the face of a user-defined
@@ -30,7 +35,7 @@ pub trait Show: 'static {
#[allow(unused_variables)]
fn finalize(
&self,
- world: &dyn World,
+ world: Tracked<dyn World>,
styles: StyleChain,
realized: Content,
) -> SourceResult<Content> {
@@ -74,13 +79,17 @@ impl Show for ShowNode {
self.0.encode(styles)
}
- fn realize(&self, world: &dyn World, styles: StyleChain) -> SourceResult<Content> {
+ fn realize(
+ &self,
+ world: Tracked<dyn World>,
+ styles: StyleChain,
+ ) -> SourceResult<Content> {
self.0.realize(world, styles)
}
fn finalize(
&self,
- world: &dyn World,
+ world: Tracked<dyn World>,
styles: StyleChain,
realized: Content,
) -> SourceResult<Content> {
diff --git a/src/model/styles.rs b/src/model/styles.rs
index b61bd535..93b615fc 100644
--- a/src/model/styles.rs
+++ b/src/model/styles.rs
@@ -3,6 +3,8 @@ use std::hash::Hash;
use std::iter;
use std::marker::PhantomData;
+use comemo::Tracked;
+
use super::{Barrier, Content, Key, Property, Recipe, Selector, Show, Target};
use crate::diag::SourceResult;
use crate::frame::Role;
@@ -279,7 +281,7 @@ impl<'a> StyleChain<'a> {
/// Apply show recipes in this style chain to a target.
pub fn apply(
self,
- world: &dyn World,
+ world: Tracked<dyn World>,
target: Target,
) -> SourceResult<Option<Content>> {
// Find out how many recipes there any and whether any of their patterns