-
Notifications
You must be signed in to change notification settings - Fork 14
feat(ir): add IRVerifier system with configurable verification rules #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
Summary of ChangesHello @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 Highlights
🧠 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 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. 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
|
There was a problem hiding this 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.
| 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)) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| rules_.push_back(rule); | |
| rules_.push_back(std::move(rule)); |
| oss << " Location: " << d.span.filename_ << ":" << d.span.begin_line_ << ":" << d.span.begin_column_ | ||
| << "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduce a new IRVerifier system that provides a unified framework for IR validation:
Add IRVerifier class as central verification orchestrator
Define VerifyRule interface for pluggable verification checks
Add Diagnostic infrastructure for structured error reporting
Extract Span class to separate header (span.h)
Integrate with Pass system
Add comprehensive Python bindings and type stubs
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.