elixir icon indicating copy to clipboard operation
elixir copied to clipboard

Support Erlang/OTP 25 new features

Open josevalim opened this issue 2 years ago • 13 comments

To be implemented when Erlang 25 is released:

  • [x] Format terms in binary construction error message (https://github.com/erlang/otp/pull/5281)
  • [x] Improved error messages in evaluation (https://github.com/erlang/otp/pull/5631)
  • [x] Add pretty printing from EEP 54 (https://github.com/erlang/otp/pull/5752)
  • [x] Add compile attribute -nifs

To be implemented when we require Erlang 25 exclusively:

  • [x] Use "undefined" as node name for remote/rpc and document -start_epmd false -erl_epmd_port 6789 on both vm.args/remote.vm.args if you need epmdless
  • [x] Use :erlang.float_to_binary([:short]) in Float.to_string/1 instead of private API
  • [x] Use new format_status/1 callback for GenServer
  • [x] Remove the calling_self clause in GenServer.call as that is now in Erlang/OTP
  • [x] Use new system certificates

Please do not send PRs for those, as it will take a while until we can effectively accept them.

josevalim avatar Aug 31 '21 14:08 josevalim

Erlang 25 will also support reconfiguration of logger, which will allow us to use config :kernel, :logger, […] in development and releases without need for restarting whole init (https://github.com/erlang/otp/pull/5186).

hauleth avatar Sep 30 '21 17:09 hauleth

Do you want a separate issue for compiling with OTP 25? This is from GitHub CI, and I tried clearing the CI cache, but it may be related to a NIF?

Running mix local.rebar,--force
  /home/runner/work/_temp/.setup-beam/elixir/bin/mix local.rebar --force
  
  Error: 7.616 [error] beam/beam_load.c(86): Error loading module 'Elixir.Code.Formatter':
  Warning:   lambda already defined for label 749. To fix this, please recompile this module with an OTP 25 compiler.
  
  Error: 7.616 [error] Loading of /home/runner/work/_temp/.setup-beam/elixir/bin/../lib/elixir/ebin/Elixir.Code.Formatter.beam failed: :badfile
  
  ** (UndefinedFunctionError) function Code.Formatter.locals_without_parens/0 is undefined (module Code.Formatter is not available)
      (elixir 1.13.4) Code.Formatter.locals_without_parens()
      (elixir 1.13.4) lib/code/normalizer.ex:22: Code.Normalizer.normalize/2
  Warning:     (elixir 1.13.4) lib/code.ex:1107: Code.quoted_to_algebra/2
  Error: The process '/home/runner/work/_temp/.setup-beam/elixir/bin/mix' failed with exit code 1

nathany-copia avatar May 18 '22 15:05 nathany-copia

You are using a precompiled Elixir version. It is just a matter of time until we have precompiled versions for OTP 25. It is usually tackled automatically by build tools. You can also compile it yourself.

josevalim avatar May 18 '22 15:05 josevalim

Thanks. I've opened an issue with erlef/setup-beam.

https://github.com/erlef/setup-beam/issues/117

nathany-copia avatar May 18 '22 16:05 nathany-copia

I noticed there were also changes to the gen_server application (among others): https://github.com/erlang/otp/pull/5792 Is this something that we need to pull into Elixir as well?

dvic avatar Jul 18 '22 12:07 dvic

Our goal is to use the task API for that. We will see how it will go once we support it in OTP 24.

josevalim avatar Jul 18 '22 12:07 josevalim

Note for compile attribute -nifs:

reference: erlang/otp pull request 'compiler: Start all potential nif functions with a nif_start #6193', merged on erlang/otp:master

the pull request change the way attribute -nifs is considered (optional ?):

... Due to backwards compatibility, the nifs attribute is not required, so when a module containing a call to erlang:load_nif/2 is encountered, the compiler is forced to conservatively assume that in such a module, all functions are potential nifs ... ... This patch extends the v3_core-pass to make all functions start with a nif_start instruction when the nifs attribute isn't present in the module but a call to erlang:load_nif/2 is. ...

henrythebuilder avatar Aug 03 '22 16:08 henrythebuilder

Would it make sense to add support for the -nifs attribute already?

I believe it would be fine to always emit it as a persisted attribute - it would be just ignored on older OTP releases.

I had to do some ugly hacks to get the support in the current version https://github.com/spawnfest/json_native/blob/main/lib/jason_native.ex#L10-L13

michalmuskala avatar Oct 17 '22 15:10 michalmuskala

Yes, we can definitely support it. A PR is welcome!

josevalim avatar Oct 17 '22 15:10 josevalim

I looked into this a bit. It's not particularly complicated, but we do need to port validation rules from erl_lint (since Elixir skips running the checks there). In particular, it collects information if there's a call to erlang:load_nif anywhere inside the module

michalmuskala avatar Oct 24 '22 08:10 michalmuskala

I'm wondering why the following task requires "OTP 25 exclusively"? Afaik the functionality had been in OTP since 23.

Use "undefined" as node name for remote/rpc and document -start_epmd false -erl_epmd_port 6789 on both vm.args/remote.vm.args if you need epmdless

LostKobrakai avatar Dec 09 '22 12:12 LostKobrakai

I don't remember the details but I tried to add it on main and ran into issues for the RPC case. The rest of the support is already in and you can use undefined in main.

josevalim avatar Dec 09 '22 13:12 josevalim

Next Elixir version will depend on OTP 25+26+27, so we can start tackling this one.

josevalim avatar Oct 30 '23 22:10 josevalim