Elixir

Elixir

Elixir Core Team

Elixir v1.16.0-rc.0 released

Code snippets in diagnostics

Elixir v1.15 introduced a new compiler diagnostic format and the ability to print multiple error diagnostics per compilation (in addition to multiple warnings).

With Elixir v1.16, we also include code snippets in exceptions and diagnostics raised by the compiler. For example, a syntax error now includes a pointer to where the error happened:

** (SyntaxError) invalid syntax found on lib/my_app.ex:1:17:
    error: syntax error before: '*'
    │
  1 │ [1, 2, 3, 4, 5, *]
    │                 ^
    │
    └─ lib/my_app.ex:1:17

For mismatched delimiters, it now shows both delimiters:

** (MismatchedDelimiterError) mismatched delimiter found on lib/my_app.ex:1:18:
    error: unexpected token: )
    │
  1 │ [1, 2, 3, 4, 5, 6)
    │ │                └ mismatched closing delimiter (expected "]")
    │ └ unclosed delimiter
    │
    └─ lib/my_app.ex:1:18

Errors and warnings diagnostics also include code snippets. When possible, we will show precise spans, such as on undefined variables:

  error: undefined variable "unknown_var"
  │
5 │     a - unknown_var
  │         ^^^^^^^^^^^
  │
  └─ lib/sample.ex:5:9: Sample.foo/1

Otherwise the whole line is underlined:

error: function names should start with lowercase characters or underscore, invalid name CamelCase
  │
3 │   def CamelCase do
  │   ^^^^^^^^^^^^^^^^
  │
  └─ lib/sample.ex:3

A huge thank you to Vinícius Muller for working on the new diagnostics.

Revamped documentation

Elixir’s Getting Started guided has been made part of the Elixir repository and incorporated into ExDoc. This was an opportunity to revisit and unify all official guides and references.

We have also incorporated and extended the work on Understanding Code Smells in Elixir Functional Language, by Lucas Vegi and Marco Tulio Valente, from ASERG/DCC/UFMG, into the official document in the form of anti-patterns. The anti-patterns are divided into four categories: code-related, design-related, process-related, and meta-programming. Our goal is to give all developers examples of potential anti-patterns, with context and examples on how to improve their codebases.

Another ExDoc feature we have incorporated in this release is the addition of cheatsheets, starting with a cheatsheet for the Enum module. If you would like to contribute future cheatsheets to Elixir itself, feel free to start a discussion with an issue.

Finally, we have started enriching our documentation with Mermaid.js diagrams. You can find examples in the GenServer and Supervisor docs.

v1.16.0-rc.0 (2023-10-31)

1. Enhancements

EEx

  • [EEx] Include relative file information in diagnostics

Elixir

  • [Code] Automatically include columns in parsing options
  • [Code] Introduce MismatchedDelimiterError for handling mismatched delimiter exceptions
  • [Code.Fragment] Handle anonymous calls in fragments
  • [Code.Formatter] Trim trailing whitespace on heredocs with \r\n
  • [Kernel] Suggest module names based on suffix and casing errors when the module does not exist in UndefinedFunctionError
  • [Kernel.ParallelCompiler] Introduce Kernel.ParallelCompiler.pmap/2 to compile multiple additional entries in parallel
  • [Kernel.SpecialForms] Warn if True/False/Nil are used as aliases and there is no such alias
  • [Macro] Add Macro.compile_apply/4
  • [Module] Add support for @nifs annotation from Erlang/OTP 25
  • [Module] Add support for missing @dialyzer configuration
  • [String] Update to Unicode 15.1.0
  • [Task] Add :limit option to Task.yield_many/2

Mix

  • [mix] Add MIX_PROFILE to profile a list of comma separated tasks
  • [mix compile.elixir] Optimize scenario where there are thousands of files in lib/ and one of them is changed
  • [mix test] Allow testing multiple file:line at once, such as mix test test/foo_test.exs:13 test/bar_test.exs:27

2. Bug fixes

Elixir

  • [Code.Fragment] Fix crash in Code.Fragment.surround_context/2 when matching on ->
  • [IO] Raise when using IO.binwrite/2 on terminated device (mirroring IO.write/2)
  • [Kernel] Do not expand aliases recursively (the alias stored in Macro.Env is already expanded)
  • [Kernel] Ensure dbg module is a compile-time dependency
  • [Kernel] Warn when a private function or macro uses unquote/1 and the function/macro itself is unused
  • [Kernel] Do not define an alias for nested modules starting with Elixir. in their definition
  • [Kernel.ParallelCompiler] Consider a module has been defined in @after_compile callbacks to avoid deadlocks
  • [Path] Ensure Path.relative_to/2 returns a relative path when the given argument does not share a common prefix with cwd

ExUnit

  • [ExUnit] Raise on incorrectly dedented doctests

Mix

  • [Mix] Ensure files with duplicate modules are recompiled whenever any of the files change

3. Soft deprecations (no warnings emitted)

Elixir

  • [File] Deprecate File.stream!(file, options, line_or_bytes) in favor of keeping the options as last argument, as in File.stream!(file, line_or_bytes, options)
  • [Kernel.ParallelCompiler] Deprecate Kernel.ParallelCompiler.async/1 in favor of Kernel.ParallelCompiler.pmap/2
  • [Path] Deprecate Path.safe_relative_to/2 in favor of Path.safe_relative/2

4. Hard deprecations

Elixir

  • [Date] Deprecate inferring a range with negative step, call Date.range/3 with a negative step instead
  • [Enum] Deprecate passing a range with negative step on Enum.slice/2, give first..last//1 instead
  • [Kernel] ~R/.../ is deprecated in favor of ~r/.../. This is because ~R/.../ still allowed escape codes, which did not fit the definition of uppercase sigils
  • [String] Deprecate passing a range with negative step on String.slice/2, give first..last//1 instead

ExUnit

  • [ExUnit.Formatter] Deprecate format_time/2, use format_times/1 instead

Mix

  • [mix compile.leex] Require :leex to be added as a compiler to run the leex compiler
  • [mix compile.yecc] Require :yecc to be added as a compiler to run the yecc compiler

Most Liked

dimitarvp

dimitarvp

For people reading left-to-right (I’d argue most of the literate humanity) this reads like “replies come before requests, WTF?”.

My Mermaid.JS is rusty so I can’t offer a PR at the moment (plus I don’t have much free time, if any) but I’d suggest the diagram to be redone so it gives the clearer impression of (1) several clients sending requests in parallel, (2) they get replies and (3) replies come one by one and never in parallel.

16
Post #3
adw632

adw632

I think this is a cool visually styled cheat sheet for Enum by @angelikatyborska :

adw632

adw632

Also worth capturing that whilst sending requests may appear to be sent in parallel they actually get serialized to “near the end” of the process message box through a clever lock free algorithm in the BEAM. Furthermore the BEAM punishes the callers when a process/GenServer message box grows large by reducing their scheduling reduction count so that in effect it creates a kind of back presssure so that existing queued work can be processed ahead of new work.

The subsequent processing of those messages within the genserver is also a serial process and once a message is received by the genserver process, all further message processing is blocked whilst the genserver is busy doing work, waiting on an IO or otherwise detained from servicing the message box in the receive call within the genserver “runloop”.

Hence why with any non trivial genserver processing it is typical to use a “hot potato” approach and spawn/dispatch the actual request processing to yet another process so as to allow the genserver process to get back to servicing the message queue as fast as possible.

If you don’t reduce the time spent between handle_* callbacks and receive then the latency experienced by clients of the genserver increases in direct proportion to every instruction/reduction spent outside of receive.

This is why we use :noreply in handle_call to allow returning to receive and replying from another process such as a Task that actually does the work.

Where Next?

Popular in News Top

josevalim
This is a small release with important bug fixes for those using Cover and Dialyzer on Erlang 19. See the release notes for more info: R...
New
Elixir
1. Enhancements Elixir [Regex] Raise error message when regexes are used as default values in struct fields for compatibility with Erlan...
New
Elixir
Official announcement: Elixir v1.15 released - The Elixir programming language This release requires Erlang/OTP 24 and later. Elixir v1...
New
Elixir
1. Enhancements Elixir [Code] Emit :defmodule tracing event on module definition Mix [Mix] Add Mix.install_project_dir/0 [Mix] Add env...
New
josevalim
Hello everyone, Two vulnerabilities have been disclosed to Plug. Applications that provide file uploading functionality to a local files...
New
josevalim
Hi! :wave: I hope everyone is well! The Elixir team releases new versions every 6 months, typically every January and July. However, si...
New
New
Elixir
1. Bug fixes Logger [Logger.Translator] Fix logger crash when :gen_statem’s format_status/2 returns non-tuple Mix [mix deps.get] Fix r...
New
josevalim
Note: this is a language proposal so please keep the discussion on topic. If you want to talk about related behaviour but not strictly pa...
New
Elixir
1. Bug fixes Elixir [Code] Fix Code.quoted_to_algebra/2 for operator with :do key as operand [Kernel.ParallelCompiler] Do not crash para...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43657 311
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36432 110
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement