Elixir v1.17.0-rc.0 released

This release includes type inference of patterns to provide warnings for an initial set of constructs (binaries, maps, and atoms). It also includes a new Duration data type to interact with Calendar types and support for Erlang/OTP 27.

Warnings from gradual set-theoretic types

This release introduces gradual set-theoretic types to infer types from patterns and guards and use them to type check programs, enabling the Elixir compiler to find faults and bugs in codebases without requiring changes to existing software. The underlying principles, theory, and roadmap of our work have been outlined in “The Design Principles of the Elixir Type System” by Giuseppe Castagna, Guillaume Duboc, José Valim.

At the moment, Elixir developers will interact with set-theoretic types only through warnings found by the type system. The current implementation models all data types in the language:

  • binary(), integer(), float(), pid(), port(), reference() - these types are indivisible. This means both 1 and 13 get the same integer() type.

  • atom() - it represents all atoms and it is divisible. For instance, the atom :foo and :hello_world are also valid (distinct) types.

  • map() and structs - maps can be “closed” or “open”. Closed maps only allow the specified allows keys, such as %{key: atom(), value: integer()}. Open maps support any other keys in addition to the ones listed and their definition starts with ..., such as %{..., key: atom(), value: integer()}. Structs are closed maps with the __struct__ key.

  • tuple(), list(), and function() - currently they are modelled as indivisible types. The next Elixir versions will also introduce fine-grained support to them.

We focused on atoms and maps on this initial release as they are respectively the simplest and the most complex types representations, so we can stress the performance of the type system and quality of error messages. Modelling these types will also provide the most immediate benefits to Elixir developers. Assuming there is a variable named user, holding a %User{} struct with an address field, Elixir v1.17 will emit the following warnings at compile-time:

  • Pattern matching against a map or a struct that does not have the given key, such as %{adress: ...} = user (notice address vs adress)

  • Accessing a key on a map or a struct that does not have the given key, such as user.adress

  • Updating a struct or a map that does not define the given key, such as %{user | adress: ...}

  • Invoking a function on non-modules, such as user.address()

  • Capturing a function on non-modules, such as &user.address/0

  • Performing structural comparisons with structs, such as my_date < ~D[2010-04-17]

  • Performing structural comparisons between non-overlapping types, such as integer >= string

  • Building and pattern matching on binaries without the relevant specifiers, such as <<string>> (this warns because by default it expects an integer)

  • Attempting to rescue an undefined exception or an exception that is not a struct

  • Accessing a field that is not defined in a rescued exception

These new warnings help Elixir developers find bugs earlier and give more confidence when refactoring code, especially around maps and structs. While some of these warnings were emitted in the past, they were discovered using syntax analysis. The new warnings are more reliable, precise, and with better error messages. Keep in mind that not all maps have statically known keys, and the Elixir typechecker only infers types from patterns at the moment.

Future Elixir versions will infer and type check more constructs, bringing Elixir developers more warnings and quality of life improvements without changes to code. For more details, see our new reference document on gradual set-theoretic types.

The type system was made possible thanks to a partnership between CNRS and Remote. The development work is currently sponsored by Fresha, Starfish*, and Dashbit.

Erlang/OTP support

This release adds support for Erlang/OTP 27 and drops support for Erlang/OTP 24. We recommend Elixir developers to migrate to Erlang/OTP 26 or later, especially on Windows. Support for WERL (a graphical user interface for the Erlang terminal on Windows) will be removed in Elixir v1.18.

Adding Duration and shift/2 functions

Elixir introduces the Duration data type and APIs to shift dates, times, and date times by a given duration, considering different calendars and time zones.

iex> Date.shift(~D[2016-01-31], month: 2)
~D[2016-03-31]

Note the operation is called shift (instead of add) since working with durations does not obey properties such as associativity. For instance, adding one month and then one month does not give the same result as adding two months:

iex> ~D[2016-01-31] |> Date.shift(month: 1) |> Date.shift(month: 1)
~D[2016-03-29]

Still, durations are essential for building intervals, recurring events, and modelling scheduling complexities found in the world around us. For DateTimes, Elixir will correctly deal with time zone changes (such as Daylight Saving Time), but provisions are also available in case you want to surface conflicts (for example, you shifted to a wall clock that does not exist, because the clock has been moved forward by one hour). See DateTime.shift/2 for examples.

Finally, a new Kernel.to_timeout/1 function has been added, which helps developers normalize durations and integers to a timeout used by Process APIs. For example, to send a message after one hour, one can now write:

Process.send_after(pid, :wake_up, to_timeout(hour: 1))

1. Enhancements

Elixir

  • [Access] Add Access.find/1 that mirrors Enum.find/2
  • [Code] Support cursor inside fn/rescue/catch/else/after inside Code.Fragment.container_cursor_to_quoted/2
  • [Date] Add Date.shift/2 to shift dates with duration and calendar-specific semantics
  • [Date] Allow Date to accept years outside of -9999..9999 range
  • [DateTime] Add DateTime.shift/2 to shift datetimes with duration and calendar-specific semantics
  • [Duration] Add a new Duration data type
  • [GenServer] Add c:GenServer.format_status/1 callback
  • [Kernel] Add Kernel.get_in/1 with safe nil-handling for access and structs
  • [Kernel] Add Kernel.is_non_struct_map/1 guard
  • [Kernel] Add Kernel.to_timeout/1
  • [Kernel] Emit warnings for undefined functions from modules defined within the same context as the caller code
  • [Kernel] Support integers in uppercase sigils
  • [Macro] Add Macro.Env.define_alias/4, Macro.Env.define_import/4, Macro.Env.define_require/4, Macro.Env.expand_alias/4, Macro.Env.expand_import/5, and Macro.Env.expand_require/6 to aid the implementation of language servers and embedded languages
  • [NaiveDateTime] Add NaiveDateTime.shift/2 to shift naive datetimes with duration and calendar-specific semantics
  • [Process] Add Process.set_label/1
  • [String] Add String.byte_slice/3 to slice a string to a maximum number of bytes while keeping it UTF-8 encoded
  • [System] Support use_stdio: false in System.cmd/3 and System.shell/2
  • [Time] Add Time.shift/2 to shift times with duration and calendar-specific semantics

ExUnit

  • [ExUnit] Propagate the test process itself as a caller in start_supervised
  • [ExUnit] Include max cases in ExUnit reports

IEx

  • [IEx.Helpers] Warns if recompile was called and the current working directory changed
  • [IEx.Helpers] Add c/0 as an alias to continue/0
  • [IEx.Pry] Add IEx.Pry.annotate_quoted/3 to annotate a quoted expression with pry breakpoints

Logger

  • [Logger] Format :gen_statem reports using Elixir data structures
  • [Logger] Include process label in logger events

Mix

  • [mix deps] Add :depth option to Mix.SCM.Git, thus supporting shallow clones of Git dependencies
  • [mix deps] Warn if :optional is used in combination with :in_umbrella
  • [mix deps.get] Do not add optional dependency requirements if its parent dep was skipped
  • [mix deps.tree] Add --umbrella-only to mix deps.tree
  • [mix test] Add mix test --breakpoints that sets up a breakpoint before each test that will run
  • [mix test] Add mix test --repeat-until-failure to rerun tests until a failure occurs
  • [mix test] Add mix test --slowest-modules to print slowest modules based on all of the tests they hold

2. Bug fixes

Elixir

  • [bin/elixir.bat] Improve handling of quotes and exclamation marks in flags
  • [Code] Address a bug where AST nodes for (a -> b) were not wrapped as part of the literal encoder
  • [Kernel] Resolve inconsistencies of how .. and ... are handled at the AST level
  • [Kernel] Fix parsing precedence of ambiguous operators followed by containers
  • [Kernel] Do not expand code in quote bind_quoted: ... twice
  • [Kernel] Respect :line property when :file is given as option to quote
  • [Kernel] Do not crash on Macro.escape/2 when passing a quote triplet without valid meta
  • [Module] Return default value in Module.get_attribute/3 for persisted attributes which have not yet been written to

IEx

  • [IEx.Helpers] Update the history size whenever history is pruned

Mix

  • [mix deps] Fix error message for diverged SCM definition in sibling

3. Soft deprecations (no warnings emitted)

Elixir

  • [GenServer] Deprecate c:GenServer.format_status/2 callback to align with Erlang/OTP 25+

4. Hard deprecations

Elixir

  • [IO] Passing :all to IO.read/2 and IO.binread/2 is deprecated, pass :eof instead
  • [Kernel] Single-quote charlists are deprecated, use ~c instead
  • [Kernel] Deprecate escaping closing delimiter in uppercase sigils
  • [Range] left..right without explicit steps inside patterns and guards is deprecated, write left..right//step instead
  • [Range] Decreasing ranges, such as 10..1 without an explicit step is deprecated, write 10..1//-1 instead

ExUnit

  • [ExUnit.Case] register_test/4 is deprecated in favor of register_test/6 for performance reasons
61 Likes

Holy cr*p, I haven’t been following 1.17 development beyond the beginnings of the type system—there’s so much good stuff in here.

6 Likes

:pray: :pray: :pray: :clap: :clap: :clap: :christmas_tree:

1 Like

We’re stranded on OTP 25.

Not sure if that was typo and they want to say 25 as this would also be supported, see:
Between Elixir and Erlang/OTP section of Compatibility and deprecations documentation.

Recommend != required, so maybe there are some significant performance changes in OTP 26 or other important changes, but anyway you should be fine until Erlang/OTP 18 stable release + next Elixir version after it.

Latest Elixir fully supports previous 3 Erlang stable releases and sometimes one next in patch release which was not possible in Elixir version 1.16.3, see:

Seeing recent release dates we can estimate that Erlang/OTP 28 would be released around the middle of May 2025, so the earlier version of Elixir which would drop support for 25 would be 1.19 which stable release would most probably be around June 2025, so you should still have at least a year of support.

Likely not a typo. OTP 26 has the new shell implementation and it’s highlighted because OTP 25 would be supported by 1.18, but werl wouldn’t be. And 1.18 will be the next elixir release in about 6 month.

1 Like

Is migrating to WSL not a possibility? BTW it would be interesting to know why you are using windows for development, just a preference or you are interacting with some windows API in your applications?

Pretty nice, I didn’t expect the gradual set-theoretic typing to start making their way into Elixir as soon!

Also I’ll always chuckle when “atom” is described as “divisible”. :smiley:

9 Likes

Could someone possibly point me to what changed in how the ... operator is handled? It seems to have broken the macros in this library: GitHub - bonfire-networks/arrows: A handful of (mostly) arrow macros with superpowers. (with the new compilation error undefined function .../0 (expected the module to define such a function or for it to be imported, but none are available)

Very curious to hear initial feedback/reports from those working on very large codebases! José has mentioned elsewhere that the type system found at least one bug in both Phoenix and Livebook (I may be remembering the projects incorrectly). Would be exciting to hear whether the same is true for other large projects, as well as initial reports on compile times and whether this first implementation affects it.

3 Likes

The ... is mentioned only for Typespec here. If so it shouldn’t change anything in code. Not know this project before, but I would recommend to not use it as you can simply use |> tap(&func/1) or |> then(&func/1) which are available since 1.12.0 release.

@mayel ... is now consistently treated as a nullary operator, similar to .., while before it depended on the context. For compatibility, you can match on it as {:..., _, ctx} when is_atom(ctx) and ctx == []. I will add a note to the CHANGELOG.

3 Likes

Thanks! Did you mean when is_atom(ctx) or ctx == [] though?

Yes, sorry!

1 Like

I still Develop on windows, because all my corporate clients are running window servers.

That’s the only way to ensure i can get a fair 1-1 taste of what my clients will possibly experience

2 Likes

Ditto. Plus my app talks to windows only applications via their C API.

I use a Linux VM instead of WSL because it slows down vmware workstation pro, which I use every day.

2 Likes

Erlang 26 isn’t broken anymore on windows; just use the newest one

If OTP version 27 is affected then all 26.x versions too.

1 Like

Try it? It crashed out with the earlier version but I upgraded, presently running as follows:

C:\Users\Owner>elixir --version
Erlang/OTP 26 [erts-14.2.1] [source] [64-bit] [smp:20:20] [ds:20:20:10] [async-threads:1] [jit:ns]

Elixir 1.16.0 (compiled with Erlang/OTP 26)

and no more problems. This is running on Windows 11. I have WSL for my Docker but Erlang and Elixir are just running in Windows…

Looks like you did not even read the linked issue … There was more than one problem, the issue is still open, it does not fail every time and what’s most important recent comment also describes problem with rebar3, not iex, elixir --version or whatever else works for you.