Eqwalizer: fixes and improvements#633
Merged
Merged
Conversation
249a7fa to
54b692b
Compare
And also avoid exception handling when a logger module is not set.
- Revert `ra_log:fold/6` argument order to match callers - Add missing `ra_lib:unwrap/1` - Replace missing `ra_lib:max/2` with `max/2` - Export `compaction_result()` type in `ra_log_segments` Co-authored-by: Cursor <cursoragent@cursor.com>
`filename:rootname/1` is quite expensive for binaries because it converts the binary to a list, reverses it, flattens it, and then converts it back to a binary. This adds `ra_lib:rootname/1` which is a highly optimized version specifically for binary filenames. It uses a fast backwards scan over the binary (`binary:at/2`) and avoids all the expensive list conversions and allocations. It correctly handles all the edge cases of `filename:rootname/1` (e.g. `<<".hidden">>`, `<<"/path/.hidden">>`, `<<"/path/a.b">>`, `<<"/path/..hidden">>`). Included a unit test to ensure it perfectly matches the behavior of `filename:rootname/1`. Co-authored-by: Cursor <cursoragent@cursor.com>
`filename:rootname/1` is quite expensive for binaries because it converts the binary to a list, reverses it, flattens it, and then converts it back to a binary. This adds `ra_lib:rootname/1` which is a highly optimized version specifically for binary filenames. It uses a fast backwards scan over the binary (`binary:at/2`) and avoids all the expensive list conversions and allocations. It correctly handles all the edge cases of `filename:rootname/1` (e.g. `<<".hidden">>`, `<<"/path/.hidden">>`, `<<"/path/a.b">>`, `<<"/path/..hidden">>`), and also correctly handles both Unix and Windows directory separators by delegating to `rootname_win32/3` on Windows. Included unit tests to ensure it perfectly matches the behavior of `filename:rootname/1` on both platforms. Also updated `ra_log_segments:with_ext/2` to use the new `ra_lib:rootname/1`. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
This PR improves Eqwalizer/Dialyzer compatibility across Ra by tightening and adjusting types/specs, updating a few function signatures/usages, and adding support tooling to the build so Eqwalizer can be run against the project.
Changes:
- Introduces Eqwalizer support via
eqwalizer_supportplugin and a neweqwalizer_specsmodule providing external/stub specs. - Updates multiple core and test modules to align types/specs (e.g.,
ra_log:fold/…signature updates, richer message/effect types). - Refactors a handful of utilities and test helpers (quoting of peer args, minor rewrites, additional small helper functions/types).
Reviewed changes
Copilot reviewed 33 out of 34 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| test/ra_system_SUITE.erl | Adjust peer data_dir argument quoting. |
| test/ra_SUITE.erl | Adjust peer data_dir argument quoting. |
| test/ra_server_SUITE.erl | Adds dialyzer suppression; simplifies meck expectations. |
| test/ra_log_SUITE.erl | Updates ra_log:fold call order to match new signature. |
| test/ra_log_meta_SUITE.erl | Minor test value adjustments and lint ignore. |
| test/ra_log_memory.erl | Type/spec adjustments for Eqwalizer/Dialyzer. |
| test/ra_log_2_SUITE.erl | Updates ra_log:fold call order to match new signature. |
| test/coordination_SUITE.erl | Adjust peer data_dir argument quoting. |
| src/ra.hrl | Type improvements (from/consistent_query_ref/milliseconds) and logger dispatch change. |
| src/ra.erl | Spec return-type widening for node failure cases. |
| src/ra_system.erl | Switches remote fetch to erpc:call/4. |
| src/ra_snapshot.erl | Spec refinement for file error types. |
| src/ra_server.erl | Type refinements for server state/messages/effects; updates ra_log:fold usage. |
| src/ra_server_proc.erl | Tightens worker pid matching in init path. |
| src/ra_seq.erl | Spec cleanup and helper extraction for first/last. |
| src/ra_range.erl | Spec cleanup for fold. |
| src/ra_mt.erl | Minor safety/type refinements around term lookup and deletion range. |
| src/ra_monitors.erl | Exports component/0 type. |
| src/ra_machine.erl | Spec refinements; removes duplicate milliseconds type; minor reflection cleanup. |
| src/ra_lol.erl | Spec generalization for ordering/search/foldr. |
| src/ra_log.erl | Major type/spec adjustments; changes fold signature; adds read plan type check helper. |
| src/ra_log_wal.erl | Type/spec fixes; uses prim_file:list_dir/1; simplifies tmp-file creation. |
| src/ra_log_snapshot.erl | Adds lint ignore for bound var. |
| src/ra_log_segments.erl | Adds exported compaction result type; binary filename handling; minor spec fixes. |
| src/ra_log_segment.erl | Spec tightening for read_sparse and filename types. |
| src/ra_log_segment_writer.erl | Spec update for directory arg type. |
| src/ra_log_meta.erl | Record/spec refinements for fetch overloads and dets ref type. |
| src/ra_lib.erl | Adds unwrap/1, whereis/1, rootname/1; improves generics in specs; adds tests. |
| src/ra_leaderboard.erl | Spec update to allow undefined leader. |
| src/ra_flru.erl | Spec/type generalization toward dynamic(). |
| src/ra_env.erl | Adds logger_mod/0; tightens data_dir/0 and configure_logger/1 guards. |
| src/ra_directory.erl | Minor refactor of overview list construction; spec update. |
| src/eqwalizer_specs.erl | New: stub specs for external modules/functions for Eqwalizer. |
| rebar.config | Adds eqwalizer_support project plugin. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A PR combining multiple equalizer found issues mostly around type specs.
Ra doesn't completely pass eqwalizer but this is a good start.