Skip to content

Conversation

@lyfne123
Copy link
Contributor

@lyfne123 lyfne123 commented Feb 2, 2026

Introduce a new IRVerifier system that provides a unified framework for IR validation:

  • Add IRVerifier class as central verification orchestrator

    • Support dynamic enabling/disabling of individual verification rules
    • Collect all diagnostics without throwing exceptions during checks
    • Provide verify() for inspection and verify_or_throw() for enforcement
  • Define VerifyRule interface for pluggable verification checks

    • Refactor SSA verification into SSAVerifyRule
    • Refactor type checking into TypeCheckRule
  • Add Diagnostic infrastructure for structured error reporting

    • DiagnosticSeverity enum for Error/Warning levels
    • Diagnostic struct with severity, rule name, error code, message, and span
    • VerificationError exception for error-level diagnostics
  • Extract Span class to separate header (span.h)

    • Reduce coupling by avoiding full core.h includes
    • Make Span independently usable in error reporting
  • Integrate with Pass system

    • Add run_verifier() factory function to create verification pass
    • Enable verification to be inserted between transformation passes
    • Generate unified verification reports via IRVerifier::GenerateReport()
  • Add comprehensive Python bindings and type stubs

    • Expose IRVerifier, Diagnostic, and DiagnosticSeverity to Python
    • Provide passes.run_verifier() in Python API
  • Add full test coverage with 12 unit tests

This replaces the previous scattered error reporting with a unified diagnostic system, enabling better error collection and more flexible verification workflows.

Introduce a new IRVerifier system that provides a unified framework for IR validation:

- Add IRVerifier class as central verification orchestrator
  - Support dynamic enabling/disabling of individual verification rules
  - Collect all diagnostics without throwing exceptions during checks
  - Provide verify() for inspection and verify_or_throw() for enforcement

- Define VerifyRule interface for pluggable verification checks
  - Refactor SSA verification into SSAVerifyRule
  - Refactor type checking into TypeCheckRule

- Add Diagnostic infrastructure for structured error reporting
  - DiagnosticSeverity enum for Error/Warning levels
  - Diagnostic struct with severity, rule name, error code, message, and span
  - VerificationError exception for error-level diagnostics

- Extract Span class to separate header (span.h)
  - Reduce coupling by avoiding full core.h includes
  - Make Span independently usable in error reporting

- Integrate with Pass system
  - Add run_verifier() factory function to create verification pass
  - Enable verification to be inserted between transformation passes
  - Generate unified verification reports via IRVerifier::GenerateReport()

- Add comprehensive Python bindings and type stubs
  - Expose IRVerifier, Diagnostic, and DiagnosticSeverity to Python
  - Provide passes.run_verifier() in Python API

- Add full test coverage with 12 unit tests

This replaces the previous scattered error reporting with a unified diagnostic
system, enabling better error collection and more flexible verification workflows.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @lyfne123, 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 significantly enhances the Intermediate Representation (IR) validation capabilities by introducing a robust and extensible IRVerifier system. This new framework centralizes the process of checking IR correctness, moving away from disparate error handling mechanisms. It provides a standardized way to define and execute verification rules, collect detailed diagnostics, and integrate seamlessly into the existing IR pass infrastructure, ultimately leading to more reliable IR transformations and clearer error reporting for developers.

Highlights

  • Unified IR Verification System: Introduces the IRVerifier class as a central orchestrator for managing and executing Intermediate Representation (IR) validation rules, replacing previous scattered error reporting.
  • Pluggable Verification Rules: Defines a VerifyRule interface, enabling new verification checks to be easily added. Existing SSA and TypeCheck verifications have been refactored into SSAVerifyRule and TypeCheckRule respectively, adhering to this new interface.
  • Structured Diagnostic Reporting: Implements a comprehensive Diagnostic infrastructure, including DiagnosticSeverity (Error/Warning levels), rule names, specific error codes, human-readable messages, and source Span information for detailed issue reporting.
  • Configurable Verification Workflow: The IRVerifier supports dynamic enabling/disabling of individual rules and provides two modes: verify() to collect all diagnostics without throwing exceptions, and verify_or_throw() to enforce validation by raising a VerificationError if errors are found.
  • Source Span Refactoring: The Span class, which tracks source code locations for IR nodes, has been extracted into its own header (span.h) to reduce coupling and enhance its independent usability across the codebase.
  • Pass System Integration and Python Bindings: The new verifier system is integrated into the existing pass manager via a run_verifier() factory function, allowing verification to be inserted between transformation passes. Additionally, IRVerifier, Diagnostic, and DiagnosticSeverity are exposed through comprehensive Python bindings with type stubs.

🧠 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 to enable Memory in your admin console.

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.

Copy link
Contributor

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

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 well-designed and extensible IRVerifier system, which is a significant improvement for the project's IR validation capabilities. The refactoring of existing verification logic into pluggable rules is clean and thorough. The changes are comprehensive, covering the C++ core, Python bindings, type stubs, and are supported by a solid set of unit tests. I have a few minor suggestions to further improve the implementation.

Comment on lines +342 to +347
Diagnostic(DiagnosticSeverity sev, std::string rule, int code, std::string msg, ir::Span s)
: severity(sev),
rule_name(std::move(rule)),
error_code(code),
message(std::move(msg)),
span(std::move(s)) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve performance and avoid an unnecessary copy, consider passing ir::Span by const reference instead of by value. Since Span contains a std::string, passing it by value can lead to an extra copy-then-move operation when called with an l-value, whereas passing by const& results in a single copy.

Suggested change
Diagnostic(DiagnosticSeverity sev, std::string rule, int code, std::string msg, ir::Span s)
: severity(sev),
rule_name(std::move(rule)),
error_code(code),
message(std::move(msg)),
span(std::move(s)) {}
Diagnostic(DiagnosticSeverity sev, std::string rule, int code, std::string msg, const ir::Span& s)
: severity(sev),
rule_name(std::move(rule)),
error_code(code),
message(std::move(msg)),
span(s) {}

[&rule](const VerifyRulePtr& r) { return r->GetName() == rule->GetName(); });

if (it == rules_.end()) {
rules_.push_back(rule);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For a minor performance improvement, you can use std::move here. Since the rule parameter is passed by value, moving it into the vector avoids an unnecessary atomic increment and decrement of the shared_ptr's reference count.

Suggested change
rules_.push_back(rule);
rules_.push_back(std::move(rule));

Comment on lines +134 to +135
oss << " Location: " << d.span.filename_ << ":" << d.span.begin_line_ << ":" << d.span.begin_column_
<< "\n";
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better encapsulation and maintainability, consider using the d.span.to_string() method to format the source location. This avoids directly accessing the members of the Span object and relies on its own string representation logic.

    oss << "  Location: " << d.span.to_string() << "\n";

@lyfne123 lyfne123 merged commit fd253fd into hw-native-sys:main Feb 2, 2026
2 checks passed
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