Skip to content

Store required features in bindings - #8599

Merged
laurmaedje merged 16 commits into
mainfrom
feature-gated-bindings
Aug 7, 2026
Merged

laurmaedje merged 16 commits into
mainfrom
feature-gated-bindings

Conversation

@saecki

@saecki saecki commented Jul 1, 2026

Copy link
Copy Markdown
Member

(#8402 was closed because the base branch was deleted)

Based on #8571

This defers providing enabled library features until accessing a binding.
It also allows generating a nicer error message for feature gated bindings, instead of just saying it is undefined.

Here's an example of an error message before:

error: unknown variable: html
  ┌─ test.typ:1:1
  │
1 │ #html.div()
  │  ^^^^

and here the same one after:

error: cannot access variable `html` because the `html` feature is not enabled
  ┌─ test.typ:1:1
  │
1 │ #html.div()
  │  ^^^^

We still have to check that this doesn't hurt performance, since read_checked is a somewhat hot function.

There are currently no tests implemented, because that would require changing the TestWorld features, which is a bit of a pain and I first want to check for performance regressions.

@saecki saecki mentioned this pull request Jul 1, 2026
14 tasks done
@laurmaedje laurmaedje added diagnostics Improvements to compiler errors waiting-on-author Pull request waits on author refactor A refactoring. labels Jul 1, 2026
@saecki
saecki force-pushed the feature-gated-bindings branch 5 times, most recently from b1b88f3 to 68390b2 Compare July 3, 2026 09:27
@saecki
saecki marked this pull request as draft July 3, 2026 12:02
@saecki

saecki commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

There are currently a few places that use read not read_checked, which would allow retrieving feature gated items even when the feature is disabled. Currently they also don't emit a deprecation warning, but that's less of an issue of course. One example would be passing a module into the Dict constructor: dictionary(pdf).data-cell.
This should definitely be sorted.

@saecki
saecki force-pushed the feature-gated-bindings branch 2 times, most recently from fc304f8 to dac471f Compare July 7, 2026 14:35
@saecki
saecki force-pushed the feature-gated-bindings branch 10 times, most recently from c46437b to 440763a Compare July 15, 2026 09:01
@saecki

saecki commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

I think all of the issues mentioned above have been dealt with. The module to dictionary conversion still discards warnings, but I currently don't see a way around that without making it very noisy.
The Binding::read function has been removed. Instead there now is Binding::read_unchecked which takes a justification string analogous to Protected::access. The read_unchecked function is currently also only used in 1 place, all other occurrences have been replaced with Binding::read_checked.

Regarding performance: In scripting heavy documents these changes make the compiler slightly slower, but I think this can be justified by the improved user experience.

@saecki
saecki marked this pull request as ready for review July 15, 2026 09:08
@saecki
saecki force-pushed the feature-gated-bindings branch 2 times, most recently from f5d3ce6 to 793c5fe Compare July 15, 2026 09:45
@laurmaedje laurmaedje added waiting-on-review This PR is waiting to be reviewed. and removed waiting-on-author Pull request waits on author labels Jul 15, 2026

@isuffix isuffix left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice! I agree that user experience is worth a small performance decrease, although it is unfortunate.

I only have a few requests for more doc comments.

Comment thread tests/suite/symbols/symbol.typ Resolved
@laurmaedje laurmaedje added waiting-on-author Pull request waits on author and removed ready-for-final-review Reviewed by team member or trusted contributor and ready for final look / merge refactor A refactoring. labels Aug 5, 2026
@saecki
saecki force-pushed the feature-gated-bindings branch from 16b7fee to 4d7d324 Compare August 7, 2026 08:27
@laurmaedje laurmaedje added waiting-on-review This PR is waiting to be reviewed. and removed waiting-on-author Pull request waits on author labels Aug 7, 2026
@laurmaedje
laurmaedje force-pushed the feature-gated-bindings branch from 15b27b7 to ddc01ac Compare August 7, 2026 12:49
@laurmaedje
laurmaedje added this pull request to the merge queue Aug 7, 2026
@laurmaedje laurmaedje removed the waiting-on-review This PR is waiting to be reviewed. label Aug 7, 2026
Merged via the queue into main with commit a51e028 Aug 7, 2026
18 checks passed
@laurmaedje
laurmaedje deleted the feature-gated-bindings branch August 7, 2026 14:15
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Aug 7, 2026
93 commits novos desde v0.15.1 (tag 9dfd3a0) até upstream/main (a51e028).
397 ficheiros alterados, 5782 inserções, 2831 remoções.

Destaques do upstream:
- Store required features in bindings (typst#8599)
- Support raw serialization format for typst eval (typst#8295)
- Add diagnostics-format environment variable (typst#8438)
- More robust overhang (typst#8131)
- Fix logical indices of hyphens with respect to surrounding tags (typst#8714)
- Bump krilla and hayro (typst#8716)
- Fix line breaking for hosts starting with a digit (typst#8039)
- Fix auto hanging-indent for heading numbering (typst#7247)

Build vanilla verificado: cargo build ok (3m02s).
Dikluwe added a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
93 commits novos desde v0.15.1 (tag 9dfd3a0) até upstream/main (a51e028).
397 ficheiros alterados, 5782 inserções, 2831 remoções.

Destaques do upstream:
- Store required features in bindings (typst#8599)
- Support raw serialization format for typst eval (typst#8295)
- Add diagnostics-format environment variable (typst#8438)
- More robust overhang (typst#8131)
- Fix logical indices of hyphens with respect to surrounding tags (typst#8714)
- Bump krilla and hayro (typst#8716)
- Fix line breaking for hosts starting with a digit (typst#8039)
- Fix auto hanging-indent for heading numbering (typst#7247)

Build vanilla verificado: cargo build ok (3m02s).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Improvements to compiler errors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants