beaver-lodge / beaver

MLIR Toolkit in Elixir and Zig.
MIT License
161 stars 8 forks source link

Refactor diagnostic and string printer #368

Closed jackalcooper closed 1 week ago

jackalcooper commented 1 week ago

Summary by CodeRabbit

coderabbitai[bot] commented 1 week ago

[!WARNING]

Rate limit exceeded

@jackalcooper has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 8 seconds before requesting another review.

⌛ How to resolve this issue? After the wait time has elapsed, a review can be triggered using the `@coderabbitai review` command as a PR comment. Alternatively, push new commits to this PR. We recommend that you space out your commits to avoid hitting the rate limit.
🚦 How do rate limits work? CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our [FAQ](https://coderabbit.ai/docs/faq) for further information.
📥 Commits Files that changed from the base of the PR and between c8523917a11474566693bed03f2059e83cd9ac69 and 46945dd44e7e5ac56a19bbf6f2cf748a909fd4d4.

Walkthrough

The changes in this pull request primarily enhance the documentation and functionality of the Beaver project, which serves as a front end for MLIR using Elixir. Key updates include an expanded README with new examples, a clearer project motivation, and enhanced installation instructions. Additionally, several modules have been modified, including the introduction of new functions and the renaming of parameters for consistency. Notably, the Beaver.Diagnostic module has been removed, replaced by a new Beaver.DiagnosticHandlerRunner, which manages diagnostics more effectively.

Changes

File Path Change Summary
README.md Added content and examples related to Beaver, expanded motivation section, new code examples for defining functions and passes, clarified project goals, detailed installation guide, and development instructions.
lib/beaver.ex Updated mlir macro to enhance context retrieval, added with_diagnostics function for running functions with a diagnostic handler, and updated documentation accordingly.
lib/beaver/deferred.ex Added module documentation, updated from_opts/2 to use fetch_context/1, introduced fetch_context/1 and fetch_block/1 functions for better context and block retrieval.
lib/beaver/diagnostic.ex Module removed, eliminating all associated diagnostic handling functionality.
lib/beaver/diagnostic/server.ex Module removed, which handled diagnostic messages using a GenServer.
lib/beaver/dsl/pattern.ex Updated Env struct field from block to blk, modified references in function signatures and macro implementations.
lib/beaver/dsl/ssa.ex Renamed block field to blk in type definition and struct declaration, updated put_block function.
lib/beaver/enif.ex Renamed block parameter to blk in declare_external_functions/2 and call/2, added default value for opts in invoke/4.
lib/beaver/mlir.ex Added new functions for context and location retrieval, modified existing functions to streamline entity handling, and added new types for Identifier and Diagnostic.
lib/beaver/mlir/attribute.ex Removed equal? function, updated float function to change context retrieval method.
lib/beaver/mlir/block.ex Updated add_args!/3 function to use MLIR.context/1 for context retrieval.
lib/beaver/mlir/capi.ex Added documentation for potential Elixir code execution from MLIR C APIs, renamed and added several functions for clarity and consistency.
lib/beaver/mlir/capi_codegen.ex Updated kinds/0 function to include a new KindDecl for Beaver.StringPrinter.
lib/beaver/mlir/capi_kinds.ex Removed Diagnostic entry from mlir_mods list.
lib/beaver/mlir/diagnostic.ex Introduced new Beaver.MLIR.Diagnostic module with functions for severity and detaching diagnostic handlers.
lib/beaver/mlir/dialect/cf.ex Renamed block parameter to blk in cond_br function.
lib/beaver/mlir/external_pass.ex Updated do_create function to use Beaver.PassRunner instead of MLIR.Pass.Server.
lib/beaver/mlir/identifier.ex Added new get/2 function for retrieving MLIR identifiers.
lib/beaver/mlir/operation.ex Renamed block parameter to blk, removed equal? function, updated context retrieval method in get_and_update.
lib/beaver/mlir/pass/composer.ex Enhanced error handling in add_pipeline and updated context retrieval method in to_pm.
lib/beaver/mlir/pass/server.ex Module removed, which handled MLIR passes using a GenServer.
lib/beaver/mlir/pattern.ex Updated context retrieval in apply_ function.
lib/beaver/mlir/sigils.ex Updated documentation examples to use MLIR.equal?/2 for equality checks.
lib/beaver/mlir/type.ex Removed multiple clauses from equal?/2 function.
lib/beaver/pass_runner.ex Introduced new Beaver.PassRunner GenServer module for executing MLIR passes.
lib/beaver/slang.ex Renamed block option to blk in various function calls and macro definitions.
lib/beaver/string_printer.ex Introduced new Beaver.StringPrinter module for interacting with MLIR CAPI using a string callback.
native/gen_wrapper.exs Expanded @io_only module attribute to include additional entries for Zig code generation.
native/include/mlir-c/Beaver/Op.h Added new function declaration for mlirIdentifierPrint.
native/lib/CAPI/Beaver.cpp Added new function mlirIdentifierPrint for printing MLIR identifiers.
native/src/diagnostic.zig Introduced new error handling and diagnostic sending functionality, modified existing methods for clarity.
native/src/logical_mutex.zig Introduced Token struct for thread synchronization and signaling functions.
native/src/main.zig Updated NIF loading to include new logical mutex resource.
native/src/mlir_capi.zig Updated allKinds to include string_ref.Printer.ResourceKind.
native/src/pass.zig Modified Token structure handling and updated BeaverPass functions for error handling and resource management.
native/src/string_ref.zig Renamed Printer function to PrinterNIF, added new Printer struct for managing multiple string references.
test/arith_test.exs Updated test context access to use pattern matching.
test/block_test.exs Updated test context access and assertions for diagnostic information.
test/bytecode_test.exs Updated context access and retrieval method for MLIR module creation.
test/capi_test.exs Standardized context retrieval for locations and updated test signatures.
test/cf_test.exs Updated test context access for clarity and correctness.
test/cuda_runtime_test.exs Updated test context access using pattern matching.
test/debug_output_test.exs Updated test context access for clarity and conciseness.
test/diagnostic_test.exs Introduced new DiagnosticTest module for testing Beaver.DiagnosticHandler.
test/e2e_test.exs Updated test context access for JIT-compiled function invocation.
test/elixir_ast_dialect_test.exs Updated test context access for clarity.
test/enif_test.exs Updated test context access for multiple tests.
test/entity_test.exs Enhanced testing for MLIR entities, standardized equality checks, and improved context handling.
test/env_test.exs Updated test context access for clarity.
test/exterior_test.exs Updated test context access for clarity.
test/gen_ir_test.exs Updated test context access for clarity.
test/gpu_test.exs Updated test context access for clarity.
test/irdl_test.exs Updated test context access for clarity.
test/load_ir_test.exs Updated test context access for clarity.
test/memref_test.exs Updated test context access for clarity.
test/op_test.exs Updated test context access for clarity.
test/pass_test.exs Enhanced diagnostic capabilities in tests, simplified context usage, and added new test case for error handling.
test/pdl_test.exs Updated test context access for clarity.
test/redundant_transpose_test.exs Updated test context access and modified attribute comparison logic.
test/region_test.exs Updated test context access for clarity.
test/string_ref_test.exs Changed testing framework to Beaver.Case and added new tests for Beaver.StringPrinter.
test/support/beaver_case.ex Updated setup for diagnostic server to use Beaver.DiagnosticHandlerRunner.
test/support/dummy.ex Updated parameter name from block to blk in put_func.
test/support/elixir_ast_dialect.ex Updated parameter names in gen_mlir function.
test/support/toy_pass.ex Added error handling in run/1 function.
test/support/translate.ex Updated mlir macro calls to use blk instead of block.
test/tosa_test.exs Updated test context access for clarity.
test/type_infer_test.exs Updated test context access and modified type assertion mechanism.
test/walker_test.exs Updated test context access for clarity.
lib/beaver/diagnostic_handler_runner.ex Introduced new Beaver.DiagnosticHandlerRunner module for managing diagnostic handlers.
lib/beaver/mlir/affine_map.ex Updated formatting of use Kinda.ResourceKind directive.
lib/beaver/mlir/dialect.ex Updated formatting of use Kinda.ResourceKind directive.
lib/beaver/mlir/location.ex Updated formatting of use Kinda.ResourceKind directive.
lib/beaver/mlir/logical_result.ex Updated formatting of use Kinda.ResourceKind directive.
lib/beaver/mlir/op_operand.ex Updated formatting of use Kinda.ResourceKind directive.
lib/beaver/mlir/pass_manager.ex Updated formatting of use Kinda.ResourceKind directive.
lib/beaver/mlir/region.ex Updated formatting of use Kinda.ResourceKind directive.
lib/beaver/mlir/string_ref.ex Updated formatting of use Kinda.ResourceKind directive.
lib/beaver/mlir/value.ex Updated formatting of use Kinda.ResourceKind directive.
lib/beaver/native/opaque_ptr.ex Updated formatting of use Kinda.ResourceKind directive.
mix.exs Updated docs() function to modify Utils group and adjusted make_precompiler_nif_versions function for target string handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Beaver
    participant MLIR
    User->>Beaver: Define function
    Beaver->>MLIR: Create MLIR operation
    MLIR-->>Beaver: Operation created
    Beaver->>User: Return operation result

Possibly related PRs

Poem

🐰 In the land of code where beavers play,
New functions and docs brighten the day.
With blk and ctx, we hop with glee,
Crafting MLIR, as happy as can be!
So let’s celebrate with a joyful cheer,
For Beaver’s journey, we hold so dear! 🎉


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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
🪧 Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.