Skip to content

syntax: Allow specifying a preferred compiler version - #7800

Open
tingerrr wants to merge 2 commits into
typst:mainfrom
tingerrr:tinger/lzwvlklvksnn
Open

tingerrr wants to merge 2 commits into
typst:mainfrom
tingerrr:tinger/lzwvlklvksnn

Conversation

@tingerrr

@tingerrr tingerrr commented Feb 4, 2026 •

Copy link
Copy Markdown
Contributor

While this has currently no effect, it allows packages to already set a preferred compiler version before any breaking changes are introduced. This is integral for initial adoption of the compatibility feature, as introducing it with the breaking change would constitute a chicken and egg problem.

Consider a package targeting Typst 0.14, if Typst introduced a breaking change and the new manifest format in 0.15, then the package could not set the preferred compiler version to 0.14 without breaking itself for 0.14 also.

This would make it effectively a 0.15.0 targeting package without being able to use the new feature.

@tingerrr
tingerrr force-pushed the tinger/lzwvlklvksnn branch from 2410fe3 to 91b4749 Compare February 4, 2026 10:18
@laurmaedje

Copy link
Copy Markdown
Member

As discussed on Discord, let's land this change and the actual compatibility behavior together and leave this as a draft for now.

@laurmaedje
laurmaedje marked this pull request as draft February 5, 2026 12:01
@laurmaedje laurmaedje added the waiting-on-author Pull request waits on author label Feb 5, 2026
@isuffix isuffix added packages Anything related to Typst package management. internals About internal changes to the codebase. labels May 17, 2026
@tingerrr
tingerrr force-pushed the tinger/lzwvlklvksnn branch from 91b4749 to cfce964 Compare May 25, 2026 09:00
@tingerrr

Copy link
Copy Markdown
Contributor Author

I've based #7620 on this and some work on my fork to see how one would use this for such a breaking change. It seems especially tough to do this for syntax related changes, because most of the lower level API in typst-syntax has no pre-existing context objects to attach this information to. It would also have to be tied to Source in someway to be used in reparsing, I think.

For anything between parsing and export a comemo-cached function using a World can be used to map FileId to CompatOptions. I'm unsure if we still have access to World on export, but this is probably easily added there too.

However, for syntax changes like string interpolation this is a little tougher, the main breaking point seems to be World::file and World::source. If you pass a flag like string_interpolation: bool down the syntax API, it inevitably bubbles up to these methods. And since you're inside World you likely can't construct a tracked instance without running into problems. Maybe tracking the inner file store/loader can solve this, but I don't know how recursive tracking interacts with comemo.

@saecki

saecki commented May 28, 2026

Copy link
Copy Markdown
Member

I think the current plan is to introduce the compatibility behavior in 0.16, but I think it would make sense to either land this, or a more general lenient manifest parsing mechanism with 0.15.

@tingerrr

Copy link
Copy Markdown
Contributor Author

I'm fine with landing this on its own, I'll mark it as ready and you guys can decide what you prefer. If you make the parsing more lenient in some other way let me know and/or close this one so I can rebase the rest of the work on that.

@tingerrr
tingerrr marked this pull request as ready for review May 28, 2026 16:58
@tingerrr
tingerrr force-pushed the tinger/lzwvlklvksnn branch from cfce964 to d401841 Compare May 30, 2026 12:18
@tingerrr

Copy link
Copy Markdown
Contributor Author

I think I arrived at a design that works quite well, but I'll need some more time to test it properly since I didn't write the string interpolation MVP with the ability to toggle it on and off in mind.

As of now, I went with a new method on World, FileStore, and FileLoader called preferred_version which maps &VirtualRoot -> PreferredVersion. Though, one might wonder if this should just return a manifest right away, since we throw away a lot of info otherwise.

Putting it on FileStore has the upside of making it available for parsing and for World to get in other stages, But this means we don't use comemo for caching the root -> version mapping, instead using slots similar to typst_kit::files::FileSlot.

@tingerrr
tingerrr force-pushed the tinger/lzwvlklvksnn branch 2 times, most recently from c309602 to 65f3679 Compare May 31, 2026 09:58
@laurmaedje

Copy link
Copy Markdown
Member

Discussed this with @saecki. While there are some benefits to having 0.15 series compilers already recognize this syntax, I don't think it's too important as there are good alternatives (e.g. linting people to prefer compiler = "0.15" over compiler = { minimum = "0.15" } specifically for 0.15) and I would rather not rush the syntax change.

@tingerrr

tingerrr commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Great, means I'm in no hurry!

@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 6, 2026
@tingerrr
tingerrr force-pushed the tinger/lzwvlklvksnn branch 3 times, most recently from 89f1d07 to 73b29f8 Compare August 9, 2026 18:06
@tingerrr tingerrr mentioned this pull request Aug 9, 2026
@tingerrr
tingerrr force-pushed the tinger/lzwvlklvksnn branch 4 times, most recently from 45aa1c4 to fb2db90 Compare October 18, 2026 10:42
@tingerrr
tingerrr force-pushed the tinger/lzwvlklvksnn branch 2 times, most recently from 51abf22 to 20bb614 Compare October 29, 2026 22:02
@tingerrr
tingerrr force-pushed the tinger/lzwvlklvksnn branch from 20bb614 to 83ac6f2 Compare November 13, 2026 09:58
@tingerrr
tingerrr force-pushed the tinger/lzwvlklvksnn branch from 83ac6f2 to 59da928 Compare November 25, 2026 10:59
The preferred compiler version set within a `typst.toml` manifest
file applies to every file in the root this manifest is contained in.
This preferred version can then be used to opt into limited backwards
compatiblity guarantees.

For example, a future version of typst may introduce custom types,
which require dedicated syntax like a `type` keyword. To avoid making
every old version of a package break instantly and forcing the whole
ecosystem to migrate effectively at once, the compatibilty feature could
retain the old parsing behavior in packages. This allows projects and
packages to target new typst version without requiring updates to their
dependencies immedately.
@tingerrr
tingerrr force-pushed the tinger/lzwvlklvksnn branch from 59da928 to 7b1b742 Compare November 28, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internals About internal changes to the codebase. packages Anything related to Typst package management. waiting-on-review This PR is waiting to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants