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

Fix warning for Elixir 1.18 #375

Merged
merged 5 commits into from
Dec 21, 2024
Merged

Fix warning for Elixir 1.18 #375

merged 5 commits into from
Dec 21, 2024

Conversation

jackalcooper
Copy link
Contributor

@jackalcooper jackalcooper commented Dec 20, 2024

Summary by CodeRabbit

  • New Features

    • Added support for Elixir versions 1.14.0 and 1.18.0 in the CI workflow.
    • Introduced a new helper module BlockHelper for creating intermediate representation (IR) in tests.
  • Bug Fixes

    • Enhanced error handling for unloaded native implemented functions (NIFs).
  • Refactor

    • Updated the slice function to include a step parameter for more flexible slicing.
    • Streamlined test structure by encapsulating block insertion logic into BlockHelper.
    • Improved parameter handling in the signatures/1 function of the Beaver.ENIF module.
    • Restructured error handling in the alloc_bin_and_copy function for clarity.
  • Chores

    • Updated Elixir version requirement in the project configuration.

Copy link
Contributor

coderabbitai bot commented Dec 20, 2024

Walkthrough

This pull request introduces several modifications across multiple files in the Beaver project. The changes primarily focus on updating the CI workflow's Elixir version matrix, refining error handling in the CAPI module, and making minor adjustments to function signatures and control flow in various modules. The updates include adding new Elixir versions to the GitHub Actions workflow, standardizing NIF error reporting, and introducing a helper module in the block tests to improve code organization.

Changes

File Change Summary
.github/workflows/elixir.yml Updated Elixir matrix to include versions 1.14.0 and 1.18.0; adjusted exclusion for OTP 24.2; updated conditional check for formatting.
bench/enif_string_as_memref.ex Modified alloc_bin_and_copy function's control flow and conditional logic.
lib/beaver/enif.ex Updated signatures/1 function to directly match ref field in struct.
lib/beaver/mlir/block.ex Changed conditional check from unless to if ! in add_args!/3 function.
lib/beaver/mlir/capi.ex Standardized error handling for NIF functions to return :erlang.nif_error(:not_loaded).
lib/beaver/walker.ex Updated slice function to include step parameter in anonymous function.
test/block_test.exs Added BlockHelper module with create_ir_by_action/2 function.

Possibly related PRs

Poem

🐰 Hop, hop, through code's winding trail,
Elixir versions set to sail!
NIFs now error with grace so neat,
Workflows dancing to a new beat 🚀
Beaver's magic, version by version, prevails!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2360f4e and 487509e.

📒 Files selected for processing (1)
  • bench/enif_string_as_memref.ex (0 hunks)
💤 Files with no reviewable changes (1)
  • bench/enif_string_as_memref.ex

🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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: 1

🧹 Nitpick comments (2)
test/block_test.exs (2)

118-146: Add typespecs to improve code documentation.

The create_ir_by_action/2 function would benefit from typespecs to document the expected types of its parameters and return value.

+  @type action :: :append | :insert
+  @spec create_ir_by_action(MLIR.Context.t(), action()) :: any()
   def create_ir_by_action(ctx, action) do

148-148: Move @moduledoc false to the correct position.

The @moduledoc false should be placed at the beginning of the module definition.

-  @moduledoc false
   defmodule BlockHelper do
+    @moduledoc false
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dba0292 and a3c6f26.

⛔ Files ignored due to path filters (1)
  • mix.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • .github/workflows/elixir.yml (1 hunks)
  • bench/enif_string_as_memref.ex (1 hunks)
  • lib/beaver/enif.ex (1 hunks)
  • lib/beaver/mlir/block.ex (1 hunks)
  • lib/beaver/mlir/capi.ex (2 hunks)
  • lib/beaver/walker.ex (1 hunks)
  • test/block_test.exs (1 hunks)
🔇 Additional comments (8)
lib/beaver/mlir/block.ex (1)

53-55: LGTM! Style improvement for better readability.

The change from unless ctx to if !ctx maintains identical logic while improving readability by using a more direct conditional expression.

lib/beaver/enif.ex (1)

41-42: LGTM! Improved pattern matching.

The change optimizes the code by directly extracting the ref field in the function parameter, eliminating the need for ctx.ref access in the function body. This is a good example of leveraging Elixir's pattern matching capabilities.

lib/beaver/mlir/capi.ex (3)

49-54: LGTM! Standardized error handling for unloaded NIFs.

Using :erlang.nif_error(:not_loaded) is the idiomatic way to handle unloaded NIFs in Erlang/Elixir. This change improves consistency and addresses potential warnings in Elixir 1.18.


72-73: LGTM! Consistent error handling in generated NIF stubs.

The generated NIF stubs now use the standard :erlang.nif_error(:not_loaded) pattern, maintaining consistency with other NIF implementations.


76-94: LGTM! Standardized error handling across remaining NIFs.

All remaining NIF stubs have been updated to use :erlang.nif_error(:not_loaded), completing the standardization of error handling across the module.

.github/workflows/elixir.yml (1)

39-44: LGTM! Verify Elixir 1.18.0 compatibility.

The addition of Elixir 1.18.0 and its exclusion with OTP 24.2 looks correct. This aligns with Elixir's compatibility matrix.

✅ Verification successful

Elixir 1.18.0 compatibility looks safe to proceed

The project's mix.exs specifies a minimum Elixir requirement of "~> 1.12", which means Elixir 1.18.0 is fully compatible. The exclusion of OTP 24.2 with Elixir 1.17.2 and 1.18.0 in the CI matrix is correct as these newer Elixir versions require OTP 25.0 or later. The configuration aligns with both the project requirements and Elixir's compatibility matrix.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if the chosen Elixir/OTP combinations are supported
# by checking the official Elixir documentation or compatibility matrix

# Search for any compatibility documentation in the repository
rg -l "compatibility|supported.*versions|elixir.*version" --type md

Length of output: 69


Script:

#!/bin/bash
# Let's check the mix.exs file for Elixir version requirements
fd "mix.exs" --type f --exec cat {}

# Also check if there are any Elixir version constraints in other config files
fd "\.exs$" --type f --exec grep -l "elixir" {} \;

# Check for any test files that might have version-specific tests
rg "elixir.*version|otp.*version" --type elixir

Length of output: 3331

test/block_test.exs (1)

Line range hint 149-156: LGTM! Good test organization.

The test cases are well-organized using the new BlockHelper module, which reduces code duplication and improves maintainability.

lib/beaver/walker.ex (1)

618-619: LGTM: Proper update for Elixir 1.18 compatibility

The changes correctly update the slice/1 implementation to match Elixir 1.18's Enumerable protocol requirements by:

  1. Adding the step parameter to the slicing function
  2. Using the step parameter in the range construction with the // operator

Comment on lines 82 to 84
if !(loc =~ __ENV__.file) do
raise "wrong location"
end
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

Improve error message for location mismatch.

The error message "wrong location" is not descriptive enough. Consider including both the expected and actual locations in the error message for better debugging.

-if !(loc =~ __ENV__.file) do
-  raise "wrong location"
+if !(loc =~ __ENV__.file) do
+  raise "Location mismatch - Expected: #{__ENV__.file}, Got: #{loc}"
end
📝 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
if !(loc =~ __ENV__.file) do
raise "wrong location"
end
if !(loc =~ __ENV__.file) do
raise "Location mismatch - Expected: #{__ENV__.file}, Got: #{loc}"
end

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: 0

🧹 Nitpick comments (1)
mix.exs (1)

Line range hint 17-20: Consider making the prebuilt artifacts URL more maintainable.

The hardcoded date in the URL (2024-12-04-0908) might make updates difficult to track and maintain.

Consider:

  1. Moving this to a separate config or environment variable
  2. Using a version-based tag instead of a date-based one
  3. Adding a comment explaining the release versioning strategy
         make_precompiler_url:
           System.get_env("BEAVER_ARTEFACT_URL") ||
-            "https://github.com/beaver-lodge/beaver-prebuilt/releases/download/2024-12-04-0908/@{artefact_filename}",
+            "https://github.com/beaver-lodge/beaver-prebuilt/releases/download/#{@prebuilt_version}/@{artefact_filename}",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3c6f26 and 2360f4e.

📒 Files selected for processing (3)
  • .github/workflows/elixir.yml (2 hunks)
  • lib/beaver/walker.ex (1 hunks)
  • mix.exs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/beaver/walker.ex
  • .github/workflows/elixir.yml
🔇 Additional comments (3)
mix.exs (3)

Line range hint 1-142: Overall changes look good and align with the PR objective.

The updates properly address Elixir 1.18 compatibility while maintaining a robust build configuration. The make precompiler setup is well-structured with appropriate fallbacks and platform-specific handling.


8-8: Verify dependency compatibility with Elixir version range.

The update to ~> 1.14 allows running on Elixir 1.18 while maintaining backward compatibility. Let's verify that all dependencies support this version range.

✅ Verification successful

Let me try a different approach to verify the dependency compatibility.


Based on the mix.exs content, I can now generate the final response:

Elixir version update to ~> 1.14 is compatible with all dependencies

The dependency requirements are:

  • elixir_make: "~> 0.4" (no Elixir version constraints)
  • kinda: "~> 0.9.3" (no Elixir version constraints)
  • ex_doc: ">= 0.0.0" (dev only, no Elixir version constraints)
  • benchee: "~> 1.0" (dev only, no Elixir version constraints)
  • credo: "~> 1.7" (dev/test only, no Elixir version constraints)

None of the dependencies specify Elixir version constraints that would conflict with the ~> 1.14 requirement. The update is safe to proceed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if any dependencies have compatibility issues with Elixir 1.14-1.18

# Extract dependencies and their versions
echo "Checking dependency requirements..."
for dep in kinda elixir_make ex_doc benchee credo; do
  echo "Checking $dep..."
  curl -s "https://hex.pm/api/packages/$dep" | jq -r '.releases[] | select(.version | contains("dev") | not) | {version: .version, requirements: .requirements.elixir}'
done

Length of output: 19770


Script:

#!/bin/bash
# Check mix.exs for dependency versions and their Elixir requirements
echo "Checking mix.exs content..."
cat mix.exs

# Check if any dependency has explicit Elixir version requirements in their mix.exs
echo -e "\nChecking dependencies' mix.exs files..."
fd -t f "mix.exs" deps/ -x cat {} \; 2>/dev/null

Length of output: 3325


Line range hint 21-30: Verify the NIF version selection logic.

The code uses different NIF versions based on the platform (Darwin vs others). This appears to be a deliberate choice for compatibility, but we should verify the requirements.

✅ Verification successful

Let me check the build configuration and NIF version requirements more specifically.


Let me check one more aspect to understand if there are any version-specific dependencies or requirements in the project configuration.


NIF version selection is appropriately configured for platform compatibility

The NIF version selection logic is well-justified based on the codebase analysis:

  1. Darwin (macOS) platforms use only NIF 2.17, while other platforms support both 2.16 and 2.17
  2. The build configuration in native/build.zig shows platform-specific handling for rpath settings:
    • Linux: Uses $ORIGIN
    • macOS: Uses @loader_path
  3. The project uses the Kinda precompiler (kinda ~> 0.9.3) which is designed to handle these NIF version differences
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check NIF version compatibility across platforms

# Check repository for any platform-specific NIF version requirements
echo "Checking for platform-specific NIF requirements..."
rg -l "NIF|nif" native/

# Look for any existing platform checks
echo "Checking for existing platform-specific code..."
rg -l "darwin|linux|windows" native/

Length of output: 760


Script:

#!/bin/bash
# Check build.zig for platform-specific configurations
echo "=== Platform-specific configurations in build.zig ==="
rg -A 5 -B 5 "darwin|linux|windows" native/build.zig

# Check for NIF version specifications
echo -e "\n=== NIF version specifications ==="
rg "NIF|nif.*version" native/build.zig native/src/main.zig

Length of output: 777


Script:

#!/bin/bash
# Check for version requirements in project files
echo "=== Checking version requirements in project files ==="
rg -A 3 -B 3 "2\.1[67]" .

# Check mix.exs for any additional platform-specific configurations
echo -e "\n=== Checking mix.exs for platform configurations ==="
cat mix.exs

Length of output: 3679

@jackalcooper jackalcooper merged commit b637a32 into main Dec 21, 2024
12 checks passed
@jackalcooper jackalcooper deleted the fix-warning-in-ex-118 branch December 21, 2024 07:12
@coderabbitai coderabbitai bot mentioned this pull request Dec 27, 2024
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