Skip to content
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

Pass to check poison op #33

Merged
merged 2 commits into from
Oct 5, 2024
Merged

Pass to check poison op #33

merged 2 commits into from
Oct 5, 2024

Conversation

jackalcooper
Copy link
Contributor

@jackalcooper jackalcooper commented Oct 5, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced error handling in the MLIR compilation process to detect and report poison operations.
    • Introduced a new test module to validate error handling for absent function calls.
  • Bug Fixes

    • Improved logging and error messages for better debugging during compilation.

Copy link
Contributor

coderabbitai bot commented Oct 5, 2024

Walkthrough

The changes in this pull request introduce a new private function, check_poison!/1, to the Charms.Defm module, which detects "ub.poison" operations during the MLIR compilation process. This function raises an error if such operations are found, enhancing error handling. Additionally, a new test module, CallTest, is created to validate the error handling by simulating a function call that raises a RuntimeError, capturing and asserting log output related to the error.

Changes

File Change Summary
lib/charms/defm.ex - Added private function defp check_poison!(op) to detect "ub.poison" operations and raise errors.
- Integrated check_poison!/1 into compile_definitions/1 function.
test/call_test.exs - Introduced test module CallTest with an asynchronous test case "if with value".
- Added function defm get(env, i) :: Term.t() in module CallingAbsentFunc to test error handling.

Possibly related PRs

🐇 In the realm of code, where errors may creep,
A function was born, its promise to keep.
It checks for the poison, with care it will seek,
And logs all the errors, no need to feel bleak.
With tests now in place, our code's shining bright,
In the land of Charms, everything feels right! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jackalcooper jackalcooper merged commit ac333bb into main Oct 5, 2024
1 check passed
@jackalcooper jackalcooper deleted the check-poison-op branch October 5, 2024 06:10
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
test/call_test.exs (1)

23-25: LGTM: Assertions are well-structured, with a minor suggestion.

The assertions correctly check for the expected error messages in the log output. The use of __ENV__.file and the pre-calculated line variable is a good practice for ensuring the correct file and line number are reported.

Consider using a more specific assertion for the error message:

assert log =~ ~r/Unknown intrinsic: AbsentMod\.absent_fun\/2/

This regex-based assertion would be more robust against minor changes in the error message format.

lib/charms/defm.ex (1)

186-186: Consider the placement of the check_poison!/1 pass in the pipeline

Currently, the check_poison!/1 pass is appended before the canonicalize pass. It might be beneficial to run canonicalize first to simplify the IR, which could potentially eliminate some "ub.poison" operations before the poison check. Placing the poison check after canonicalization might improve efficiency and reduce unnecessary exceptions.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7e51617 and f408527.

📒 Files selected for processing (2)
  • lib/charms/defm.ex (2 hunks)
  • test/call_test.exs (1 hunks)
🔇 Additional comments (3)
test/call_test.exs (2)

1-7: LGTM: Test setup is well-structured.

The test module is correctly set up using ExUnit with async testing enabled. The import of ExUnit.CaptureLog is appropriate for the test's purpose of capturing log output.


8-21: Verify: Unusual test structure with inline module definition.

The test case has an unconventional structure where a module CallingAbsentFunc is defined within the test itself. While this is valid Elixir code, it's an unusual pattern that might affect test isolation and readability.

Questions to consider:

  1. Is this inline module definition necessary for the test case?
  2. Could this module be defined outside the test or in a separate file for better organization?

The use of Charms and the defm macro suggests this is testing charm-related functionality. Please ensure this structure is intentional and necessary for the specific testing requirements.

lib/charms/defm.ex (1)

134-154: Function check_poison!/1 is well-implemented

The check_poison!/1 function effectively traverses the MLIR operation to detect any "ub.poison" operations and raises an informative error message when one is found. The use of postwalk and pattern matching on %MLIR.Operation{} is appropriate, and the function adheres to Elixir conventions.

Comment on lines +15 to +18
defm get(env, i) :: Term.t() do
AbsentMod.absent_fun(env, i)
func.return(i)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unreachable code in the get/2 function.

The get/2 function contains unreachable code. The line func.return(i) will never be executed because AbsentMod.absent_fun(env, i) is expected to raise an error.

Consider removing the unreachable code:

 defm get(env, i) :: Term.t() do
   AbsentMod.absent_fun(env, i)
-  func.return(i)
 end

This change will make the function's intent clearer without affecting the test's behavior.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
defm get(env, i) :: Term.t() do
AbsentMod.absent_fun(env, i)
func.return(i)
end
defm get(env, i) :: Term.t() do
AbsentMod.absent_fun(env, i)
end

Comment on lines +138 to +144
if msg = Beaver.Walker.attributes(op)["msg"] do
msg = MLIR.CAPI.mlirStringAttrGetValue(msg) |> MLIR.StringRef.to_string()
msg <> ", " <> to_string(MLIR.Operation.location(op))
else
"Poison operation detected in the IR. #{to_string(op)}"
end
|> raise
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider defining a custom exception for poison operations

Currently, the code raises a generic exception with a custom message when a poison operation is detected. Defining a custom exception, such as PoisonOperationError, would make error handling more explicit and allow for more precise exception matching downstream.

Example:

defmodule PoisonOperationError do
  defexception message: "Poison operation detected in the IR."
end

# Then, in your `check_poison!/1` function:
...
msg = ...
raise PoisonOperationError, message: msg

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