-
Notifications
You must be signed in to change notification settings - Fork 8
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
Conversation
WalkthroughThis 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
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
edcdc31
to
c1aa835
Compare
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.
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
⛔ 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:
- Adding the
step
parameter to the slicing function - Using the step parameter in the range construction with the
//
operator
bench/enif_string_as_memref.ex
Outdated
if !(loc =~ __ENV__.file) do | ||
raise "wrong location" | ||
end |
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.
🛠️ 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.
if !(loc =~ __ENV__.file) do | |
raise "wrong location" | |
end | |
if !(loc =~ __ENV__.file) do | |
raise "Location mismatch - Expected: #{__ENV__.file}, Got: #{loc}" | |
end |
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.
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:
- Moving this to a separate config or environment variable
- Using a version-based tag instead of a date-based one
- 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
📒 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:
- Darwin (macOS) platforms use only NIF 2.17, while other platforms support both 2.16 and 2.17
- The build configuration in
native/build.zig
shows platform-specific handling for rpath settings:- Linux: Uses
$ORIGIN
- macOS: Uses
@loader_path
- Linux: Uses
- 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
Summary by CodeRabbit
New Features
BlockHelper
for creating intermediate representation (IR) in tests.Bug Fixes
Refactor
slice
function to include a step parameter for more flexible slicing.BlockHelper
.signatures/1
function of theBeaver.ENIF
module.alloc_bin_and_copy
function for clarity.Chores