fix(codegen): remove unsafe name-based extra_tile_buf_types_ fallback in GetExprTypeAnnotation#629
Conversation
… in GetExprTypeAnnotation The var_name_to_mlir_ -> extra_tile_buf_types_ fallback in GetExprTypeAnnotation was unsafe when multiple variables share the same name_hint_. After the auto-naming refactor (hw-native-sys#619), variables like the reshape result and row_expand_mul result can both have name_hint_ "t__tile". The name fallback mapped "t__tile" to %reshape_buf (shape [1,64]), which was then incorrectly used as the type annotation for the [64,64] row_expand_mul result in tcolexpandmul, causing a type mismatch error in ptoas. The pointer-based var_to_mlir_ lookup and the var_to_memref_ / var_name_to_memref_ fallbacks are sufficient and correct.
Summary of ChangesHello, 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 addresses a critical bug in the code generation process by removing an unsafe name-based fallback mechanism that led to incorrect type annotations. The problematic fallback caused issues when different variables shared the same Highlights
Using Gemini Code AssistThe 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
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 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. Footnotes
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughA cleanup to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
Code Review
This pull request addresses a bug in the code generator's type annotation logic. It removes an unsafe name-based fallback in GetExprTypeAnnotation that could lead to incorrect type lookups when multiple variables shared the same name_hint_. The change is a direct removal of the problematic code block. The analysis in the pull request description accurately details the cause of the bug, and the fix appears correct and sufficient. No issues were found with this change.
Summary
Remove the
var_name_to_mlir_→extra_tile_buf_types_name-based fallback inGetExprTypeAnnotation, which produced incorrect type annotations when multiple variables shared the samename_hint_.Bug Analysis
After the auto-naming refactor (#619), the
ConvertToSSApass generates variables with abase__qualifier_vNnaming scheme. When a program has both atile.reshaperesult and atile.row_expand_mulresult derived from the same source variable, they can both receivename_hint_ = "t__tile"despite having completely different shapes ([1, 64]vs[64, 64]).The lookup chain in
GetExprTypeAnnotationwas:var_to_mlir_[ptr]→extra_tile_buf_types_[mlir_name](pointer-based, correct)var_name_to_mlir_[name_hint_]→extra_tile_buf_types_[mlir_name](name-based, BUGGY)var_to_memref_[ptr]→GetTileBufTypeString(memref)(pointer-based, correct)var_name_to_memref_[name_hint_]→GetTileBufTypeString(memref)(name-based, safe — MemRef carries its own shape)When the
row_expand_mulresultt__tile(shape[64, 64]) was looked up:var_to_mlir_)var_name_to_mlir_["t__tile"]returned%reshape_buf, andextra_tile_buf_types_["%reshape_buf"]returned the reshape output type[1, 64]This caused
tcolexpandmulto be emitted with a[1, 64]type annotation for its[64, 64]input, which ptoas rejected as a type mismatch.The fix removes step 2. The remaining fallback paths (steps 3 and 4) are sufficient and correct — they resolve through MemRef which carries its own shape information.
Testing
examples/rms_norm.py --simpasses (previously failed with type mismatch)examples/softmax.py --simpasses