rabbitmq / ra

A Raft implementation for Erlang and Elixir that strives to be efficient and make it easier to use multiple Raft clusters in a single system.
Other
798 stars 93 forks source link

Quote `maybe` atoms #401

Closed sile closed 8 months ago

sile commented 8 months ago

Proposed Changes

Basically, ra codebase quotes maybe atoms (to support the maybe feature in the future I guess). However there are some maybe atoms that are not quoted, and ra can't be compiled if the maybe feature is enabled. This PR fixes this problem. Of course, this is not a critical problem. So, feel free to close this PR if it seems not needed.

Types of Changes

What types of changes does your code introduce to this project? Put an x in the boxes that apply

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask on the mailing list. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

Further Comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc.

michaelklishin commented 8 months ago

maybe in this case is a type name. It's a bit unexpected that the same quoting rules would apply to type specs since there cannot be any conflict with the maybe keyword.

Also, Ra is compiled and passes all tests on CI on Erlang 26 (where maybe is supposedly always enabled). But Make-based tests fail with this PR.

What am I missing?

michaelklishin commented 8 months ago

Maybe (pun intended) we should sidestep the issue entirely :) https://github.com/rabbitmq/ra/pull/402

sile commented 8 months ago

Thank you for your comments.

Seeing the OTP 26 highlight, the runtime's maybe feature is enabled by default, but the compiler's is not. If we enable the compiler's maybe feature, ra cannot be compiled as follows:

// Erlang/OTP version
$ erl -boot start_clean -noshell -eval 'io:format(erlang:system_info(system_version)).' -s init stop
Erlang/OTP 26 [erts-14.1] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]

// Clone ra
$ git clone https://github.com/rabbitmq/ra.git 
$ cd ra/

// Compile ra_log.erl without and with the maybe_expr compile feature 

// without (default) => OK
$ erlc src/ra_log.erl

// with => NG
$ erlc -enable-feature maybe_expr src/ra_log.erl
src/ra_log.erl:549:6: syntax error before: 'maybe'
%  549|     {maybe(log_entry()), state()}.
%     |      ^
sile commented 8 months ago

Maybe (pun intended) we should sidestep the issue entirely :) https://github.com/rabbitmq/ra/pull/402

The approach of #402 is perfect for me :) Thank you!