Skip to content

feat: cfg-based unreachable diagnostics - #2316

Closed
hongjr03 wants to merge 17 commits into
Myriad-Dreamin:mainfrom
hongjr03:feat/cfg
Closed

feat: cfg-based unreachable diagnostics#2316
hongjr03 wants to merge 17 commits into
Myriad-Dreamin:mainfrom
hongjr03:feat/cfg

Conversation

@hongjr03

Copy link
Copy Markdown
Contributor

This depends on and should be merged after #2302.

Add CFG construction and basic graph analysis interfaces based on the Typst AST in tinymist-analysis; rewrite the unreachable diagnostic in tinymist-lint using CFG reachability to improve span coverage and support reporting multiple consecutive unreachable segments; and add snapshot tests for unreachable in tinymist-query.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @hongjr03, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a robust Control-Flow Graph (CFG) analysis capability for Typst code, which is then immediately applied to significantly improve the accuracy and detail of unreachable code detection within the tinymist-lint component. The changes also include a substantial refactoring of the diagnostic reporting system, allowing for distinct handling of compiler and lint diagnostics, and a new modular 'hook' system for managing various post-compilation processes like preview and export. These enhancements lead to more precise and informative diagnostics for users and a more maintainable codebase for future development.

Highlights

  • Control-Flow Graph (CFG) Implementation: A new module tinymist-analysis/src/cfg has been added to construct and analyze Control-Flow Graphs directly from the Typst Abstract Syntax Tree (AST). This includes definitions for basic blocks, terminators, and graph analysis utilities like dominators and reachable blocks.
  • Enhanced Unreachable Code Diagnostics: The unreachable code diagnostic in tinymist-lint has been rewritten to leverage the new CFG analysis. This significantly improves span coverage, allowing for more precise highlighting of unreachable code, and supports reporting multiple consecutive unreachable segments.
  • Modular Diagnostic Publishing: The diagnostic publishing mechanism in tinymist has been refactored to differentiate between compiler-generated and lint-generated diagnostics. This is achieved through the introduction of DiagKind and DiagKey, allowing for more granular control and clearer categorization of issues presented to the editor.
  • Compile Hook System: A new CompileHook trait and associated implementations (DiagHook, LintHook, PreviewHook, ExportHook) have been introduced. This modularizes the handling of compilation events, making the CompileHandlerImpl more extensible and maintainable by decoupling various post-compilation tasks.
  • Comprehensive Snapshot Tests: Numerous new snapshot tests have been added in tinymist-query to validate the accuracy and behavior of the enhanced unreachable code diagnostics across various Typst code patterns, including loops, conditionals, and return statements.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant improvement to unreachable code detection by implementing a CFG-based analysis. The new cfg module in tinymist-analysis is well-structured, and the implementation of CFG construction and dominator analysis appears solid. The linter in tinymist-lint is cleanly updated to use this new analysis.

A major highlight of this PR is the refactoring in tinymist to use a CompileHook trait. This greatly improves modularity by separating concerns like diagnostics, linting, preview updates, and exports into their own hooks. This is an excellent architectural improvement.

The addition of comprehensive tests for various unreachable code scenarios is also very valuable.

I have a few minor suggestions for improving code clarity and consistency, but overall this is a high-quality contribution.

Comment thread crates/tinymist-lint/src/lib.rs Outdated
Comment thread crates/tinymist-lint/src/lib.rs Outdated
Comment thread crates/tinymist/src/project.rs
@hongjr03

Copy link
Copy Markdown
Contributor Author

Closed in favor of #2321.

@hongjr03 hongjr03 closed this Dec 21, 2025
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