Skip to content

Conversation

@Seven-Streams
Copy link
Collaborator

This PR refactors the structure of the grammar compiler to improve maintainability, and it doesn't change the logic of the grammar compiler.

In this PR, the workflow of MultiThreadCompileGrammar can be represented as:

  • Grammar Optimization
  • TagDispatch Optimization
  • Generate Token Mask Caches
    • Other optimizations
    • Check all possible tokens
      • Check possible tokens in each interval with the optimization technique.

Copilot AI review requested due to automatic review settings November 6, 2025 06:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the grammar compiler code to improve maintainability by extracting large monolithic functions into smaller, more focused helper functions. The main changes involve consolidating tokenizer-related parameters into a TokenizerInfo object and breaking down complex token mask calculation logic into separate methods.

Key Changes

  • Method signatures refactored to use TokenizerInfo parameter instead of multiple individual parameters
  • Large function bodies extracted into smaller, focused helper methods (GetFirstCharacterMask, CheckAllPossibleTokens, CheckTokensInInterval, etc.)
  • MultiThreadCompileGrammar split into TagDispatchOptimization and GenerateTokenMaskCacheForScannableStates

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
@Seven-Streams Seven-Streams force-pushed the refactor/2025-11-05/compiler branch from 4efa142 to 2289d4b Compare November 6, 2025 06:54
@Seven-Streams Seven-Streams marked this pull request as draft November 7, 2025 08:00
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