Repository navigation
Warning suppression - #4459
Closed
PgBiel wants to merge 62 commits into
Closed
Warning suppression#4459PgBiel wants to merge 62 commits into
PgBiel wants to merge 62 commits into
Conversation
warnings now get tracepoints
adds tracepoints to returned errors and warnings automatically
avoids an unnecessary sink extension if the sink is empty
no idea why this is needed but it is
done directly in the lexer.
- Improve tree search - Improve annotation argument loop
istudyatuni
reviewed
Jul 29, 2024
Member
|
Based on the update posted by @PgBiel above, I'll close this for the time being:
|
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
UPDATE (2024-08-06): After lots of discussion (internally, over Discord etc.) regarding not only the ideal syntax for annotations, but also the potential use cases for warn suppression, we've decided to prioritize other, more important improvements for diagnostics, so this PR won't move forward for the time being.
This PR implements warning suppression within Typst source code, and all the underlying features that it requires:
DecoratorAnnotation syntax (used to annotate where warn suppression occurs, indicating which warnings are suppressed)Regarding internals, also implements some important lexing changes (might conflict a bit with #4364 , but hopefully not very much).
The idea is to make it possible to add more warnings without hurting UX too much, by allowing users to suppress them.
Draft: There are some rough edges in some places, so the PR shouldn't be merged just yet. (Also, many more tests are needed.)
Overview
This is what it looks like:
(Note: Used to be
/! allow("unnecessary-stars")in the initial version of the PR)We can see all three main elements of this PR here:
DecoratorAnnotation syntax:// @name("argument", "argument2")annotates something relevant to the compiler at the source code.decoratorsannotations should be nearly as flexible as comments so that they can be inserted in various locations within the source code. Hence why the syntax resembles that of comments as well.**having no effect now has an identifier,"unnecessary-stars". This is bikesheddable and I chose some (in principle, reasonable) initial names for all existing warnings.allowdecorator, which takes warning identifiers, causes the given warning to be suppressed if it is raised under the decorator. That is, it won't be raised by the compiler at that point.Of note, warning suppression applies to warnings raised not only directly under the decorator (or nested within what's under it), but also warnings raised in other files (or elsewhere in the same file) which have tracepoints that lead back to the decorator. For now, only calling functions (during eval) adds tracepoints to warnings, meaning that warnings raised during layout won't have tracepoints, or the tracepoints will be incomplete (e.g. warnings in a
context { }).This means that the
unnecessary-starswarning will be suppressed in all of the following cases:But not in the cases below (must be up to one line above):
Implementation highlights
diag.rs.next()returns aSyntaxNode. It's almost always a leaf node, except when there is an error (then an error is returned - this meanstake_errorand such are now internal) or when lexing a decorator (which returns a node with a subtree).SyntaxKind, and as such I didn't change raw elements to use this new lexer API. I think this is better suited to a separate PR to better gauge if there could be any possible regressions when implementing that.Engine::tracepointwhich is used to run some code and then immediately attach a tracepoint to the returned errors (through a returnedSourceDiagnostic) and warnings (through a temporarySink, which is created in the function and then merged into the outer engine'sSink).impl Eval for FuncCallto add a tracepoint to all warnings raised during a function's evaluation. This allows tracking which function calls led to a warning being raised.Sink, we now store duplicate warnings (relaxed warning deduplication), but only as long as they have differing tracepoints. This is because we need to keep track of all sets of tracepoints for a warning, since anallowdecorator above a particular tracepoint might suppress that warning at that point, but the warning might still be raised because it wasn't suppressed at other tracepoint chains.LinkedNode::prev_attached_decoratorwhich searches for the nearest sibling decorator before the given syntax node, but only up to one line before it. That is, decorators two lines above a given node don't apply to it. (To properly implement this, syntax nodes now keep track of if they have 0, 1 or 2 newlines within them.)Sink::suppress_and_deduplicate_warningswhich performs suppression by searching the syntax tree near where each warning was raised - as well as near each tracepoint - by checking if there is any decorator sibling before the node at the warning's span that suppresses it (see the previous item). If not, checks the node's parent, and keeps checking parents and their attached decorators until either a decorator suppressing this warning is found, or we reached the root node of the source file.compileto take and return the warnings, so warning suppression always occurs after a compilation.TODO
A few TODOs before undrafting:
\r\ncorrectly. Thanks @LaurenzV!)context { }and tracepointsImprove theKeeping as is for nowTracetrait stuff indiag.rs(I feel like there might be a less convoluted way to do this)Decorator::argumentsconsideringDecoratorName