Skip to content

[Quality] Fixes typings in ast frontend#2520

Open
ppppqp wants to merge 5 commits into
tile-ai:mainfrom
ppppqp:panqp--fix-ast-pyright
Open

[Quality] Fixes typings in ast frontend#2520
ppppqp wants to merge 5 commits into
tile-ai:mainfrom
ppppqp:panqp--fix-ast-pyright

Conversation

@ppppqp

@ppppqp ppppqp commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Learning tilelang frontend and fixes various typing issues by the way. This is a purly quality PR. No behavior changes.

  • Added type alias Span and QuoteReplacement for better readability
  • Added assertions for typing alignment
  • Fixed a minor bug: ast_set_span(tmp_store, node.targets[0]) should be ast_set_span(tmp_store, ast_get_span(node.targets[0]))
  • Some small improvements: reduce redundant branches, early exit on loop

Summary

  • Tightened typing in tilelang/language/eager/ast.py by adding Span and QuoteReplacement aliases and updating AST helper/visitor/quote function signatures to be more precise about accepted span inputs and returned node types.
  • Added typing-alignment assertions and casts (e.g., frame/local capture depth in BaseBuilder, non-None guard in BaseBuilder.boolop, and explicit quote1(...)ast.Assign in DSLMutator.flush_binds).
  • Fixed span propagation for multi-target assignment lowering by changing ast_set_span(tmp_store, node.targets[0]) to ast_set_span(tmp_store, ast_get_span(node.targets[0])) (copying span metadata from the normalized target).
  • Refined a few internal rewrites/annotations across visit_For, visit_Assign, visit_FunctionDef, visit_IfExp, and visit_With (including early break once the kernel context is found).

C++ style / lint notes

  • This PR only changes tilelang/language/eager/ast.py, so it does not touch C++, CI/lint tooling, or docs/developer_guide/cpp_style.md.
  • The “C++ API Style Audit (warning only)” CI step is not relevant here.
  • No new warning-only style issues are expected since the change is limited to Python typing and span metadata handling.

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run pre-commit run --all-files in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR tightens typing and span handling in tilelang/language/eager/ast.py, updates quote and span utilities, adds assertions in BaseBuilder, and refines DSLMutator lowering and return annotations for assignments, loops, function defs, with handling, and conditional expressions.

Changes

Eager AST typing and span handling

Layer / File(s) Summary
Span and quote utilities
tilelang/language/eager/ast.py
Adds Span and QuoteReplacement aliases, updates span accessors, and refactors quote helpers and visitor methods to normalize spans and return more specific AST node types.
Operator helpers and frame checks
tilelang/language/eager/ast.py
Casts operator/boolop class names to literal types, asserts frame depth in get_parent_locals, and asserts the right operand in BaseBuilder.boolop's "And" branch.
DSLMutator lowering updates
tilelang/language/eager/ast.py
Adjusts visit_For, _emit_assign_target, flush_binds, visit_Assign, visit_FunctionDef, visit_IfExp, and visit_With with tighter typing, span propagation, and return annotations.

Estimated code review effort: 2 (Simple) | ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: typing fixes in the AST frontend.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

def ast_set_span(ast: ast.AST, span: tuple[int, int, int, int]):
if not ast_has_span(ast):
def ast_set_span(ast: ast.AST, span: Span | None):
if span is None or not ast_has_span(ast):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A bit redundant. This is for type alignment for patterns like ast_set_span(ast_set_span()) but ast_has_span already guards it.

ast_set_span(tmp_store, node.targets[0])
ast_set_span(tmp_load, node.targets[0])
stmt = self._emit_assign_target(tmp_store, rval)
ast_set_span(tmp_store, ast_get_span(node.targets[0]))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A minor bug here

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
tilelang/language/eager/ast.py (1)

34-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider strict=True on zip.

_span_attrs and span are always length-4 by construction (Span: TypeAlias = tuple[int, int, int, int]), so this is low risk, but adding strict=True costs nothing and guards against future drift if either side's arity changes.

🔧 Suggested tweak
-    for attr, value in zip(_span_attrs, span):
+    for attr, value in zip(_span_attrs, span, strict=True):
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tilelang/language/eager/ast.py` at line 34, The span unpacking in the AST
helper uses zip without enforcing equal lengths; update the loop in the code
that iterates over _span_attrs and span to use strict=True. This change should
be applied where the span dictionary/object is built, so the existing behavior
stays the same while guarding the Span tuple and _span_attrs from drifting out
of sync.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tilelang/language/eager/ast.py`:
- Line 34: The span unpacking in the AST helper uses zip without enforcing equal
lengths; update the loop in the code that iterates over _span_attrs and span to
use strict=True. This change should be applied where the span dictionary/object
is built, so the existing behavior stays the same while guarding the Span tuple
and _span_attrs from drifting out of sync.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b0c9f20a-9f74-48ff-a527-eda5ffc2a1e6

📥 Commits

Reviewing files that changed from the base of the PR and between 14fc963 and 8342379.

📒 Files selected for processing (1)
  • tilelang/language/eager/ast.py

arg_stmt = quote1(f'{name} = __tb.arg("{name}", {name})', span=arg)
else:
arg_stmt = quote1(f'{name} = __tb.arg("{name}", {name})', span=arg)
arg_stmt = quote1(f'{name} = __tb.arg("{name}", {name})', span=arg)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

two branches are identical. The annotation parsing is inside _parse_arg_annot

is_kernel_ctx = True
break

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Early exit as soon as we are sure this is a kernel context

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