Skip to content

Eqwalizer: fixes and improvements#633

Merged
kjnilsson merged 16 commits into
mainfrom
eqwalizer2
May 28, 2026
Merged

Eqwalizer: fixes and improvements#633
kjnilsson merged 16 commits into
mainfrom
eqwalizer2

Conversation

@kjnilsson

@kjnilsson kjnilsson commented May 15, 2026

Copy link
Copy Markdown
Contributor

A PR combining multiple equalizer found issues mostly around type specs.

Ra doesn't completely pass eqwalizer but this is a good start.

@kjnilsson kjnilsson force-pushed the eqwalizer2 branch 3 times, most recently from 249a7fa to 54b692b Compare May 15, 2026 14:27
And also avoid exception handling when a logger module is not set.
kjnilsson and others added 5 commits May 18, 2026 12:00
- 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>
@kjnilsson kjnilsson changed the title Eqwalizer: refactor log macros to avoid type uncertainty. Eqwalizer: fixes and improvements May 28, 2026
@kjnilsson kjnilsson requested a review from Copilot May 28, 2026 10:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_support plugin and a new eqwalizer_specs module 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.

Comment thread src/ra_system.erl Outdated
Comment thread src/eqwalizer_specs.erl
Comment thread src/eqwalizer_specs.erl
Comment thread src/eqwalizer_specs.erl
Comment thread src/eqwalizer_specs.erl
Comment thread src/eqwalizer_specs.erl
Comment thread test/ra_log_memory.erl
kjnilsson and others added 3 commits May 28, 2026 12:30
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>
kjnilsson and others added 3 commits May 28, 2026 12:36
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>
@kjnilsson kjnilsson marked this pull request as ready for review May 28, 2026 12:45
@kjnilsson kjnilsson merged commit f9c25c2 into main May 28, 2026
8 checks passed
@kjnilsson kjnilsson deleted the eqwalizer2 branch May 28, 2026 12:46
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.

3 participants