gemini-code-assist[bot] commented on PR #18857:
URL: https://github.com/apache/tvm/pull/18857#issuecomment-3978903369

   ## Summary of Changes
   
   Hello, I'm Gemini Code Assist[^1]! 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 significantly overhauls TVM's runtime error reporting for 
compiled functions, making diagnostics much more informative and precise. By 
introducing a structured `AssertStmt` and centralizing argument binding logic 
with rich error message generation, it allows for more specific exception types 
and detailed context in error messages. This change improves the developer 
experience by providing clearer feedback on argument mismatches and type 
errors, ultimately leading to more robust and easier-to-debug TVM programs.
   
   ### Highlights
   
   * **Structured AssertStmt**: The `AssertStmt` IR node has been refactored to 
carry an explicit `kind` (e.g., 'TypeError', 'ValueError') and an array of 
`message_parts` instead of a single message string. This enables proper Python 
exception types at runtime and allows for string fragment reuse across 
assertions to reduce binary size.
   * **Consolidated ArgBinder Logic**: All argument binding and error logic for 
`PackedFunc` generation has been consolidated into a new `ArgBinder` class 
(renamed from `arg_binder` to `tvm_ffi_binder`). This class provides a single 
public API (`BindPackedArg`, `BindAllParams`) and handles all type checking, 
value loading, buffer binding, and rich error message generation.
   * **Rich Error Messages**: Error messages generated during argument binding 
now include `AccessPath` tracking for cross-reference (e.g., 'expected to match 
a.shape[0]') and the full function signature for better context. Cached 
`StringImm` values are used for signature string reuse.
   * **Simplified MakePackedAPI**: The `make_packed_api.cc` file has been 
significantly simplified by delegating argument processing and error generation 
to the new `ArgBinder`.
   * **LLVM and C Codegen Updates**: The LLVM and C host codegens have been 
updated to utilize the new `TVMFFIErrorSetRaisedFromCStrParts` mechanism, which 
handles the array of message parts. LLVM codegen also includes a noinline 
helper function for efficient error raising.
   
   🧠 **New Feature in Public Preview:** You can now enable **Memory** to help 
**Gemini Code Assist** learn from your team's feedback. This makes future code 
reviews more consistent and personalized to your project's style. **Click 
[here](https://codeassist.google/code-review/login) to enable Memory in your 
admin console.**
   
   <details>
   <summary><b>Changelog</b></summary>
   
   * **include/tvm/script/ir_builder/tir/frame.h**
       * Updated `AssertFrameNode` to include `kind` (StringImm) and 
`message_parts` (Array<StringImm>) fields, replacing the single `message` field.
   * **include/tvm/tir/stmt.h**
       * Modified `AssertStmtNode` to store `kind` and `message_parts` instead 
of a single `message` expression, and removed the `body` field.
       * Updated the `AssertStmt` constructor to accept `kind`, `condition`, 
and `message_parts`.
   * **python/tvm/script/parser/tir/parser.py**
       * Updated `visit_assert` to parse assert messages that can now be a 
tuple of `(kind, [parts...])` in addition to a plain string.
   * **python/tvm/tir/stmt.py**
       * Updated the Python `AssertStmt` class to reflect the new `kind` and 
`message_parts` attributes and adjusted its constructor.
   * **src/arith/ir_mutator_with_analyzer.cc**
       * Removed the handling of `op->message` from 
`IRMutatorWithAnalyzer::VisitStmt_` for `AssertStmtNode`.
   * **src/arith/ir_visitor_with_analyzer.cc**
       * Removed the visit of `op->message` from 
`IRVisitorWithAnalyzer::VisitStmt_` for `AssertStmtNode`.
   * **src/relax/op/tensor/inspect.cc**
       * Updated `tir::AssertStmt` calls to use the new `kind` and 
`message_parts` format, specifying 'RuntimeError' as the kind.
   * **src/s_tir/analysis/estimate_flops.cc**
       * Removed the handling of `op->message` from `FlopEstimator::VisitStmt_` 
for `AssertStmtNode`.
   * **src/s_tir/transform/bound_checker.cc**
       * Updated `AssertStmt` creation to use the new `kind` and 
`message_parts` format, setting 'RuntimeError' as the kind.
   * **src/script/ir_builder/tir/frame.cc**
       * Updated `AssertFrameNode::ExitWithScope` to construct 
`tvm::tir::AssertStmt` with the new `kind` and `message_parts`.
   * **src/script/ir_builder/tir/ir.cc**
       * Modified the `Assert` function to initialize `AssertFrameNode` with a 
default 'RuntimeError' kind and wrap the message in `message_parts`.
   * **src/script/printer/tir/stmt.cc**
       * Updated the `IRDocsifier` for `tir::AssertStmt` to print messages in 
the new `(kind, [part0, part1, ...])` tuple format, falling back to the old 
format for single 'RuntimeError' messages.
   * **src/target/llvm/codegen_cpu.cc**
       * Added support for `TVMFFIErrorSetRaisedFromCStrParts` function type 
and an internal `GetOrCreateSetRaisedHelper` noinline function to manage 
multi-part error messages.
       * Updated `VisitStmt_` for `AssertStmtNode` to use the new 
`GetOrCreateSetRaisedHelper` for generating error calls with `kind` and 
`message_parts`.
   * **src/target/llvm/codegen_cpu.h**
       * Added declarations for 
`ftype_tvm_ffi_error_set_raised_from_c_str_parts_` and 
`GetOrCreateSetRaisedHelper`.
       * Introduced `set_raised_helpers_` map to cache noinline helper 
functions for error raising.
   * **src/target/source/codegen_c.cc**
       * Modified `VisitStmt_` for `AssertStmtNode` to generate C code that 
constructs an array of `const char*` for `message_parts` and calls 
`TVMFFIErrorSetRaisedFromCStrParts`.
   * **src/target/source/codegen_c_host.cc**
       * Updated `VisitStmt_` for `AssertStmtNode` to use 
`TVMFFIErrorSetRaisedFromCStrParts` for error reporting.
       * Changed the default `emit_asserts` flag to `true` in `BuildCHost`.
   * **src/tir/ir/stmt.cc**
       * Updated the `AssertStmt` constructor to accept `StringImm kind` and 
`ffi::Array<StringImm> message_parts`, and adjusted reflection registration.
   * **src/tir/ir/stmt_functor.cc**
       * Modified `StmtVisitor` and `StmtMutator` to correctly visit and mutate 
the new `kind` and `message_parts` fields of `AssertStmtNode`.
   * **src/tir/ir/tir_visitor_with_path.cc**
       * Updated `TIRVisitorWithPath::VisitStmt_` for `AssertStmtNode` to visit 
the new `kind` and `message_parts` fields.
   * **src/tir/transform/arg_binder.cc**
       * Removed the old `arg_binder.cc` implementation.
   * **src/tir/transform/arg_binder.h**
       * Removed the old `arg_binder.h` header.
   * **src/tir/transform/make_packed_api.cc**
       * Replaced inclusion of `arg_binder.h` with `tvm_ffi_binder.h`.
       * Updated `MakeAssertEQ` and `MakeAssertNotNull` helper functions to 
construct `AssertStmt` with `kind` and `message_parts`, including the function 
signature for context.
       * Refactored argument binding logic to use the new `ArgBinder` (from 
`tvm_ffi_binder.h`), simplifying the `MakePackedAPI` function.
   * **src/tir/transform/split_host_device.cc**
       * Updated `AssertStmt` calls to use the new `kind` and `message_parts` 
format, setting 'RuntimeError' as the kind.
   * **src/tir/transform/tvm_ffi_binder.cc**
       * Added new source file implementing the `ArgBinder` class, which 
handles argument binding, type checking, and rich error message generation with 
`AccessPath` tracking.
   * **src/tir/transform/tvm_ffi_binder.h**
       * Added new header file for the `ArgBinder` class, defining its 
interface for consolidated argument binding and error reporting.
   * **tests/python/codegen/test_codegen_assert.py**
       * Added new test file to verify basic `AssertStmt` codegen 
functionality, including different error kinds and multi-part messages.
   * **tests/python/codegen/test_codegen_error_handling.py**
       * Added new test file with integration tests for rich error messages 
generated by `MakePackedAPI` and `ArgBinder`, covering type, shape, and 
alignment mismatches.
   * **tests/python/tir-base/test_tir_constructor.py**
       * Updated the `AssertStmt` constructor test to reflect the new `kind` 
and `message_parts` parameters.
   * **tests/python/tir-transform/test_tir_transform_make_packed_api.py**
       * Updated existing tests to assert against the new structure of 
`AssertStmt` within `MakePackedAPI` output, specifically checking for `kind` 
and multi-part messages including function signatures.
   * **tests/python/tvmscript/test_tvmscript_ir_builder_tir.py**
       * Updated `AssertStmt` creation in tests to use the new `kind` and 
`message_parts` format.
   </details>
   
   <details>
   <summary><b>Activity</b></summary>
   
   * The pull request introduces new test files (`test_codegen_assert.py`, 
`test_codegen_error_handling.py`) to cover the new `AssertStmt` and `ArgBinder` 
functionalities.
   * Existing tests (`test_tir_constructor.py`, 
`test_tir_transform_make_packed_api.py`, `test_tvmscript_ir_builder_tir.py`) 
have been updated to align with the new `AssertStmt` structure and error 
message format.
   * The test plan in the PR description indicates comprehensive testing across 
different backends (LLVM, C) and various aspects of the new error reporting, 
including basic `AssertStmt` codegen, rich error messages, and existing 
transform tests.
   </details>
   
   <details>
   <summary><b>Using Gemini Code Assist</b></summary>
   <br>
   
   The full guide for Gemini Code Assist can be found on our [documentation 
page](https://developers.google.com/gemini-code-assist/docs/review-github-code),
 here are some quick tips.
   
   <b>Invoking Gemini</b>
   
   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.
   
   <b>Customization</b>
   
   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](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
   
   <b>Limitations & Feedback</b>
   
   Gemini Code Assist may make mistakes. Please leave feedback on any instances 
where its feedback is incorrect or counter productive. You can react with 
:thumbsup: and :thumbsdown: 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](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
   
   <b>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](https://cloud.google.com/products/gemini/code-assist).</b>
   </details>
   
   
   [^1]: Review the [Privacy Notices](https://policies.google.com/privacy), 
[Generative AI Prohibited Use 
Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of 
Service](https://policies.google.com/terms), and learn how to configure Gemini 
Code Assist in GitHub 
[here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
 Gemini can make mistakes, so double check it and [use code with 
caution](https://support.google.com/legal/answer/13505487).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to