Skip to content

Refactor folding - #3294

Merged
laurmaedje merged 3 commits into
mainfrom
refactor-folding
Jan 30, 2024
Merged

laurmaedje merged 3 commits into
mainfrom
refactor-folding

Conversation

@laurmaedje

Copy link
Copy Markdown
Member

This significantly simplifies the way Fold works:

  • Folding doesn't have the concept of an Output type anymore. Instead, things are always folded against themselves (Self).
  • Folding and resolving are now decoupled and, by extension, resolving can be fully decoupled from the style chain accessors. This means that Respect set rules in where selectors #3290 can fold without resolving at the same time, so that changes to #[resolve] continue to not be breaking changes and overall things behave more predictably.
  • Fixes complex code involving folding Option and Smart: The reason for all the complexity is that there are two semantically different usages of these types: Typically, a fold of Option<T> should prefer an inner None against and outer X because the user literally wrote none. However, Option<T> is also sometimes used to express that the user wrote nothing (e.g. an omitted side in a Sides dictionary). Then, the outer X should be preferred. The few places where this is the case have now explicit comments to explain the difference.
  • Also removes a few unnecessary #[ty] and cast! usages for #[internal] types. This necessitated a bugfix for the #[elem] macro, which would erroneously include internal fields in the Construct implementation.

@laurmaedje
laurmaedje enabled auto-merge January 30, 2024 09:41
@laurmaedje
laurmaedje added this pull request to the merge queue Jan 30, 2024
Merged via the queue into main with commit f14288c Jan 30, 2024
@laurmaedje
laurmaedje deleted the refactor-folding branch January 30, 2024 09:55
Dherse pushed a commit to Dherse/typst that referenced this pull request Feb 4, 2024
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant