Repository navigation
Detailed non-convergence diagnostics for introspections - #7364
Conversation
|
I did a quick test with https://typst.app/project/r9GASqmDOYasvWLDv5x4cI and the warning looks good 👍 What would be even nicer, would be to have some kind of stacktrace. In the example above Nevertheless this PR is a great step forward and would be enough to close my initial issue! |
I have some plans for better traces for introspections (and context expressions, too) for the future. They won't work exactly like the normal stack traces as there are some rather fundamental implementation limitations, but it should also help with tracking down the causes. Essentially, it'll be a trace of the content tree rather than a trace of the call stack. |
|
This diagnostics helped me tweak my autobreak feature 🎉 The actual bug is not resolved, but at least I can understand a little bit better how Typst works! |
981caa8 to
387c394
Compare
|
I'm not a fan of the hacky |
Because that would have been a more complex change to the test parsing and I did not consider it worth the time and (potentially, depends on how complex it would) maintenance effort. I also don't think it's that hacky tbh. |
|
Fair enough. |
spanned hints are introduced in typst/typst#7364
protect protect
spanned hints are introduced in typst/typst#7364
Description
This PR adds rich diagnostics for non-convergence of the document. Previously, only a single global warning would be emitted. Now, there are individual warnings for each specific introspection that did not converge.
This is implemented by tracing all introspections that occur during compilation (in a manner similar to how warnings are accumulated), re-running them against the documents for all iterations, and checking whether they converged.
Each introspection is now represented by a type that knows how to resolve itself against a document and how to diagnose its own non-convergence. This makes it easy to introduce new introspections with high-quality diagnostics.
Closes #4528.
Design
Previously, when considering the problem of introspection diagnostics, I struggled to find a way to retain spans (pointing to source code locations) for diagnostics without them interfering with memoization and query deduplication (important for efficiency). The crucial insight of this PR is that we can decouple the high-level introspections (which are recorded with spans) from the low-level methods on the introspector (spanless and deduplicated).
Aside from the ability to record spans, this decoupling also lets us produce more high-level diagnostics. For example, while the
QueryIntrospectionmaps directly tointrospector.query, theStateAtIntrospectioninternally usesintrospector.queryto resolve the state's value, but its convergence behavior and its diagnostics are at the level of abstractions of state.Examples
Many of these examples use a
switchfunction, which invokes a callback with the current layout iteration number. It's definition is as follows:The
switchfunctionPosition
Query 1
Query 2
Heading & Reference
State
State (errored)
Counter
Bibliography 1
Bibliography 2
Page
Supplement & Numbering
Measurement
Help links (Feedback wanted!)
Some diagnostics contains links.
As state warnings are most common (because of the
context s.update(s.get() + 1))anti-pattern), I figured extra help might be in order for those.The links are currently still 404. My idea with these was to provide stable, readable permalinks whose concrete destination we can adjust as the documentation and teaching materials evolve. I'd imagine adding more of those help links over time.
For example, such a help link could start out as pointing to a Forum post and later migrate to the documentation as its expanded. Having a layer of decoupling seems more robust to me that trying to link directly into the docs (that link is bound to get broken at some point and we can't update old compilers to point elsewhere).
For now, there aren't great materials for these two links. If someone knows good Forum posts for these two, that might be helpful. Otherwise, I'd probably link to https://typst.app/docs/reference/context/#compiler-iterations and https://typst.app/docs/reference/introspection/state/#caution for now.
Overall, I'm also interested in feedback on the help link idea! An alternative to the link idea would be stable error codes, but this is a much more complex endeavour and not really likely to happen particularly soon. So I figured, these links might be a pragmatic solution to help users now.