|
1 |
| -# Changelog for Elixir v1.18 |
| 1 | +# Changelog for Elixir v1.19 |
2 | 2 |
|
3 |
| -Elixir v1.18 is an impressive release with improvements across the two main efforts happening within the Elixir ecosystem right now: set-theoretic types and language servers. It also comes with built-in JSON support and adds new capabilities to its unit testing library. Here is a quick break down. |
4 |
| - |
5 |
| -## Type system improvements |
6 |
| - |
7 |
| -The most exciting change in Elixir v1.18 is type checking of function calls, alongside gradual inference of patterns and return types. To understand how this will impact your programs, consider the following code: |
8 |
| - |
9 |
| -```elixir |
10 |
| -defmodule User do |
11 |
| - defstruct [:age, :car_choice] |
12 |
| - |
13 |
| - def drive(%User{age: age, car_choice: car}, cars_choices) when age >= 18 do |
14 |
| - if car in car_choices do |
15 |
| - {:ok, car} |
16 |
| - else |
17 |
| - {:error, :no_choice} |
18 |
| - end |
19 |
| - end |
20 |
| - |
21 |
| - def drive(%User{}, _car_choices) do |
22 |
| - {:error, :not_allowed} |
23 |
| - end |
24 |
| -end |
25 |
| -``` |
26 |
| - |
27 |
| -Elixir's type system will infer the `drive` function expects a `%User{}` struct as input and returns either `{:ok, dynamic()}`, `{:error, :no_choice}`, or `{:error, :not_allowed}`. |
28 |
| - |
29 |
| -Therefore, the following code should emit a violation, due to an invalid argument: |
30 |
| - |
31 |
| -```elixir |
32 |
| -User.drive({:ok, %User{}}, car_choices) |
33 |
| -``` |
34 |
| - |
35 |
| -Here is the warning: |
36 |
| - |
37 |
| -``` |
38 |
| - warning: incompatible types given to User.drive/2: |
39 |
| -
|
40 |
| - User.drive({:ok, %User{age: nil, car_choice: nil}}, car_choices) |
41 |
| -
|
42 |
| - given types: |
43 |
| -
|
44 |
| - {:ok, %User{age: nil, car_choice: nil}}, empty_list() |
45 |
| -
|
46 |
| - but expected one of: |
47 |
| -
|
48 |
| - dynamic(%User{age: term(), car_choice: term()}), dynamic() |
49 |
| -
|
50 |
| - where "car_choices" was given the type: |
51 |
| -
|
52 |
| - # type: empty_list() |
53 |
| - # from: lib/foo.ex:21:17 |
54 |
| - car_choices = [] |
55 |
| -
|
56 |
| - typing violation found at: |
57 |
| - │ |
58 |
| - 22 │ User.drive({:ok, %User{}}, car_choices) |
59 |
| - │ ~ |
60 |
| - │ |
61 |
| - └─ lib/foo.ex:22:10: Example.run/0 |
62 |
| -``` |
63 |
| - |
64 |
| -> The mismatched arguments are shown in red, if your terminal supports ANSI coloring. |
65 |
| -
|
66 |
| -And the next snippet will warn because the `:error` clause will never match, as that's not a valid return type of the `User.drive/2` call: |
67 |
| - |
68 |
| -```elixir |
69 |
| -case User.drive(user, car_choices) do |
70 |
| - {:ok, car} -> car |
71 |
| - :error -> Logger.error("User cannot drive") |
72 |
| -end |
73 |
| -``` |
74 |
| - |
75 |
| -And here is the warning: |
76 |
| - |
77 |
| -``` |
78 |
| - warning: the following clause will never match: |
79 |
| -
|
80 |
| - :error |
81 |
| -
|
82 |
| - because it attempts to match on the result of: |
83 |
| -
|
84 |
| - User.drive(user, car_choices) |
85 |
| -
|
86 |
| - which has type: |
87 |
| -
|
88 |
| - dynamic({:ok, term()} or {:error, :no_choice} or {:error, :not_allowed}) |
89 |
| -
|
90 |
| - typing violation found at: |
91 |
| - │ |
92 |
| - 26 │ :error -> Logger.error("User cannot drive") |
93 |
| - │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
94 |
| - │ |
95 |
| - └─ lib/foo.ex:26: Example.run/0 |
96 |
| -``` |
97 |
| - |
98 |
| -For more details on typing inference and the trade-offs made by the Elixir team, [see our official documentation](https://hexdocs.pm/elixir/1.18/gradual-set-theoretic-types.html#type-inference). |
99 |
| - |
100 |
| -There are many other improvements to the type system, which we will go in detail within the official release. Meanwhile, here is a list summary of the overall improvements done to the type system: |
101 |
| - |
102 |
| -* Type inference of patterns (typing inference of guards will be part of an upcoming release) |
103 |
| - |
104 |
| -* Type checking of all language constructs, including local and remote calls, except `for`, `with`, and closures |
105 |
| - |
106 |
| -* Type checking of all functions inlined by the compiler found in `Kernel` |
107 |
| - |
108 |
| -* Type checking of all conversion functions inlined by the compiler |
109 |
| - |
110 |
| -* [Support for tuples and lists as composite types](https://elixir-lang.org/blog/2024/08/28/typing-lists-and-tuples/) as well as type checking of their basic operations |
111 |
| - |
112 |
| -* Detection of clauses and patterns that will never match from `case`, `cond`, and `=` |
113 |
| - |
114 |
| -* Detection of unused clauses in private functions |
115 |
| - |
116 |
| -## ExUnit improvements |
117 |
| - |
118 |
| -ExUnit now supports parameterized tests to run the same test module multiple times under different parameters. |
119 |
| - |
120 |
| -For example, Elixir ships a local, decentralized and scalable key-value process storage called `Registry`. The registry can be partitioned and its implementation differs depending if partitioning is enabled or not. Therefore, during tests, we want to ensure both modes are exercised. With Elixir v1.18, we can achieve this by writing: |
121 |
| - |
122 |
| -```elixir |
123 |
| -defmodule Registry.Test do |
124 |
| - use ExUnit.Case, |
125 |
| - async: true, |
126 |
| - parameterize: [ |
127 |
| - %{partitions: 1}, |
128 |
| - %{partitions: 8} |
129 |
| - ] |
130 |
| - |
131 |
| - # ... the actual tests ... |
132 |
| -end |
133 |
| -``` |
134 |
| - |
135 |
| -ExUnit parameterizes whole test modules. If your modules are configured to run concurrently, as above, so will the parameterized ones. |
136 |
| - |
137 |
| -ExUnit also comes with the ability of specifying test groups. While ExUnit supports running tests concurrently, those tests must not have shared state between them. However, in large applications, it may be common for some tests to depend on some shared state, and other tests to depend on a completely separate state. For example, part of your tests may depend on Cassandra, while others depend on Redis. Prior to Elixir v1.18, these tests could not run concurrently, but in v1.18 they might as long as they are assigned to different groups. Tests modules within the same group do not run concurrently, but across groups, they might. |
138 |
| - |
139 |
| -With features like async tests, suite partitioning, and now grouping, Elixir developers have plenty of flexibility to make the most use of their machine resources, both in development and in CI. |
140 |
| - |
141 |
| -## `mix format --migrate` |
142 |
| - |
143 |
| -The `mix format` command now supports an explicit `--migrate` flag, which will convert constructs that have been deprecated in Elixir to their latest version. Because this flag rewrites the AST, it is not guaranteed the migrated format will always be valid when used in combination with macros that also perform AST rewriting. |
144 |
| - |
145 |
| -As of this release, the following migrations are executed: |
146 |
| - |
147 |
| - * Normalize parens in bitstring modifiers - it removes unnecessary parentheses in known bitstring modifiers, for example `<<foo::binary()>>` becomes `<<foo::binary>>`, or adds parentheses for custom modifiers, where `<<foo::custom_type>>` becomes `<<foo::custom_type()>>`. |
148 |
| - |
149 |
| - * Charlists as sigils - formats charlists as `~c` sigils, for example `'foo'` becomes `~c"foo"`. |
150 |
| - |
151 |
| - * `unless` as negated `if`s - rewrites `unless` expressions using `if` with a negated condition, for example `unless foo do` becomes `if !foo do`. |
152 |
| - |
153 |
| -More migrations may be added in future releases. |
154 |
| - |
155 |
| -## JSON support |
156 |
| - |
157 |
| -This release includes official support for JSON encoding and decoding. |
158 |
| - |
159 |
| -Both encoder and decoder fully conform to [RFC 8259](https://tools.ietf.org/html/rfc8259) and |
160 |
| -[ECMA 404](https://ecma-international.org/publications-and-standards/standards/ecma-404/) |
161 |
| -standards. |
162 |
| - |
163 |
| -### Encoding |
164 |
| - |
165 |
| -Encoding can be done via `JSON.encode!/1` and `JSON.encode_to_iodata!/1` functions. |
166 |
| -The default encoding rules are applied as follows: |
167 |
| - |
168 |
| -| **Elixir** | **JSON** | |
169 |
| -|------------------------|----------| |
170 |
| -| `integer() \| float()` | Number | |
171 |
| -| `true \| false ` | Boolean | |
172 |
| -| `nil` | Null | |
173 |
| -| `binary()` | String | |
174 |
| -| `atom()` | String | |
175 |
| -| `list()` | Array | |
176 |
| -| `%{binary() => _}` | Object | |
177 |
| -| `%{atom() => _}` | Object | |
178 |
| -| `%{integer() => _}` | Object | |
179 |
| - |
180 |
| -You may also implement the `JSON.Encoder` protocol for custom data structures. |
181 |
| -If you have a struct, you can derive the implementation of the `JSON.Encoder` |
182 |
| -by specifying which fields should be encoded to JSON: |
183 |
| - |
184 |
| -```elixir |
185 |
| - @derive {JSON.Encoder, only: [....]} |
186 |
| - defstruct ... |
187 |
| -``` |
188 |
| - |
189 |
| -### Decoding |
190 |
| - |
191 |
| -Decoding can be done via `JSON.decode/2` and `JSON.decode!/2` functions. |
192 |
| -The default decoding rules are applied as follows: |
193 |
| - |
194 |
| -| **JSON** | **Elixir** | |
195 |
| -|----------|------------------------| |
196 |
| -| Number | `integer() \| float()` | |
197 |
| -| Boolean | `true \| false` | |
198 |
| -| Null | `nil` | |
199 |
| -| String | `binary()` | |
200 |
| -| Object | `%{binary() => _}` | |
201 |
| - |
202 |
| -## Potential incompatibilities |
203 |
| - |
204 |
| -This release no longer supports WERL (a graphical user interface on Windows used by Erlang 25 and earlier). For a better user experience on Windows terminals, use Erlang/OTP 26+ (this is also the last Elixir release to support Erlang/OTP 25). |
205 |
| - |
206 |
| -Furthermore, in order to support inference of patterns, Elixir will raise if it finds recursive variable definitions. This means patterns that never match, such as this one, will no longer compile: |
207 |
| - |
208 |
| - def foo(x = {:ok, y}, x = y) |
209 |
| - |
210 |
| -However, recursion of root variables (where variables directly point to each other), will also fail to compile: |
211 |
| - |
212 |
| - def foo(x = y, y = z, z = x) |
213 |
| - |
214 |
| -While the definition above could succeed (as long as all three arguments are equal), the cycle is not necessary and could be removed, as below: |
215 |
| - |
216 |
| - def foo(x = y, y = z, z) |
217 |
| - |
218 |
| -You may also prefer to write using guards: |
219 |
| - |
220 |
| - def foo(x, y, z) when x == y and y == z |
221 |
| - |
222 |
| -## v1.18.0-dev |
| 3 | +## v1.19.0-dev |
223 | 4 |
|
224 | 5 | ### 1. Enhancements
|
225 | 6 |
|
226 |
| -#### Elixir |
227 |
| - |
228 |
| - * [CLI] Add experimental PowerShell scripts for `elixir`, `elixirc`, and `mix` on Windows. Those provide a safer entry point for running Elixir from other platforms |
229 |
| - * [Calendar] Add `Duration.to_string/1` |
230 |
| - * [Code] Support several migration options in `Code.format_string!/2` |
231 |
| - * [Code] Add parenthesis around `--` and `---` in `Code.format_string!/2` to make precedence clearer |
232 |
| - * [Code] Include more metadata in `Code.string_to_quoted/2` when `token_metadata: true` to help compute ranges from the AST |
233 |
| - * [Code.Fragment] Have `:capture_arg` as its own entry in `Code.Fragment.surround_context/2` |
234 |
| - * [Config] Add `Config.read_config/1` |
235 |
| - * [Enumerable] Add `Enum.product_by/2` and `Enum.sum_by/2` |
236 |
| - * [Exception] Add `MissingApplicationsError` exception to denote missing applications |
237 |
| - * [Kernel] Update source code parsing to match [UTS #55](https://www.unicode.org/reports/tr55/) latest recommendations. In particular, mixed script is allowed in identifiers as long as they are separate by underscores (`_`), such as `http_сервер`. Previously allowed highly restrictive identifiers, which mixed Latin and other scripts, such as the japanese word for t-shirt, `Tシャツ`, now require the underscore as well |
238 |
| - * [Kernel] Warn on bidirectional confusability in identifiers |
239 |
| - * [Kernel] Verify the type of the binary generators |
240 |
| - * [Kernel] Track the type of tuples in patterns and inside `elem/2` |
241 |
| - * [Kernel] Perform validation of root AST nodes in `unquote` and `unquote_splicing` to catch bugs earlier |
242 |
| - * [Kernel] Add source, behaviour, and record information to Docs chunk metadata |
243 |
| - * [Kernel] Support deterministic builds in tandem with Erlang by setting `ERL_COMPILER_OPTIONS=deterministic`. Keep in mind deterministic builds strip source and other compile time information, which may be relevant for programs |
244 |
| - * [Kernel] Allow aliases and imports to be enabled conditionally in module body |
245 |
| - * [List] Add `List.ends_with?/2` |
246 |
| - * [Macro] Improve `dbg` handling of `if/2`, `with/1` and of code blocks |
247 |
| - * [Macro] Add `Macro.struct_info!/2` to return struct information mirroring `mod.__info__(:struct)` |
248 |
| - * [Registry] Add `Registry.lock/3` for local locking |
249 |
| - * [PartitionSupervisor] Add `PartitionSupervisor.resize!/2` to resize the number of partitions in a supervisor (up to the limit it was started with) |
250 |
| - * [Process] Handle arbitrarily high integer values in `Process.sleep/1` |
251 |
| - * [Protocol] Add `@undefined_impl_description` to customize error message when an implementation is undefined |
252 |
| - * [Protocol] Add `__deriving__/1` as optional macro callback to `Protocol`, no longer requiring empty implementations |
253 |
| - * [String] Inspect special whitespace and zero-width characters using their Unicode representation |
254 |
| - * [String] Update Unicode to 16.0 |
255 |
| - |
256 |
| -#### ExUnit |
257 |
| - |
258 |
| - * [ExUnit] Support parameterized tests on `ExUnit.Case` |
259 |
| - * [ExUnit] Support test groups: tests in the same group never run concurrently |
260 |
| - * [ExUnit.Case] Add `test_pid` as a tag |
261 |
| - |
262 |
| -#### IEx |
263 |
| - |
264 |
| - * [IEx] Add `:dot_iex` support to `IEx.configure/1` |
265 |
| - * [IEx] Add report for normal/shutdown exits in IEx |
266 |
| - |
267 |
| -#### Mix |
268 |
| - |
269 |
| - * [mix compile] Ensure only a single operating system process can compile at a given time |
270 |
| - * [mix deps.get] Ensure only a single operating system process can fetch deps at a given time |
271 |
| - * [mix format] Add `mix format --migrate` to migrate from deprecated functionality |
272 |
| - * [mix format] Add new options and metadata to improve formatting applying by editors and other environments |
273 |
| - * [mix test] Taint failure manifest if requiring or compiling tests fail |
274 |
| - * [Mix.Project] Add a `:listeners` configuration to listen to compilation events from the current and other operating system processes |
275 |
| - * [Mix.Task.Compiler] Add API for fetching all persisted compiler diagnostics |
276 |
| - * [Mix.Task.Compiler] Add API for fetching all compiler tasks |
277 |
| - |
278 | 7 | ### 2. Bug fixes
|
279 | 8 |
|
280 |
| -#### Elixir |
281 |
| - |
282 |
| - * [Code] Fix delimiter metadata for single quoted atoms and remote calls in `Code.string_to_quoted/2` |
283 |
| - * [Code.Formatter] Fix formatter adding extra escapes to quoted remote calls |
284 |
| - * [Code.Fragment] Properly handle keyword keys as their own entry |
285 |
| - * [Inspect.Algebra] Ensure `next_break_fits` respects `line_length` |
286 |
| - * [Kernel] Validate AST on `unquote` and `unquote_splicing` to provide better error reports instead of failing too late inside the compiler |
287 |
| - * [Module] Include module attribute line and name when tracing its aliases |
288 |
| - * [Stream] Do not halt streams twice in `Stream.transform/5` |
289 |
| - * [URI] Fix a bug when a schemaless URI is given to `URI.merge/2` |
290 |
| - |
291 |
| -#### ExUnit |
292 |
| - |
293 |
| - * [ExUnit.Assertions] Raise if guards are used in `assert/1` with `=` |
294 |
| - * [ExUnit.Assertions] Format inserted/deleted maps in list assertions |
295 |
| - |
296 |
| -#### IEx |
297 |
| - |
298 |
| - * [IEx.Helpers] `IEx.Helpers.recompile/0` will reload modules changed by other operating system processes |
299 |
| - |
300 |
| -#### Mix |
301 |
| - |
302 |
| - * [mix compile] Ensure warnings from external resources are emitted with `--all-warnings` when files do not change |
303 |
| - * [mix deps.compile] Fix escaping issues when invoking `rebar3` in some cases |
304 |
| - * [mix escript] Fix escript layout and support storing `priv` directories |
305 |
| - * [mix release] Make `.app` files deterministic in releases |
306 |
| - * [Mix.Shell] Fix `Mix.Shell` on Windows when outputting non UTF-8 characters |
307 |
| - |
308 | 9 | ### 3. Soft deprecations (no warnings emitted)
|
309 | 10 |
|
310 |
| -#### Elixir |
311 |
| - |
312 |
| - * [Inspect.Algebra] `color/3` is deprecated in favor of `color_doc/3` |
313 |
| - * [Inspect.Algebra] `fold_doc/2` is deprecated in favor of `fold/2` |
314 |
| - * [Kernel] Deprecate `unless` in favor of `if`. Use `mix format --migrate` to automate the migration |
315 |
| - * [Macro] `Macro.struct!/2` is deprecated in favor of `Macro.struct_info!/2` |
316 |
| - * [Protocol] Defining `__deriving__/3` inside the `Any` implementation is deprecated, derive it inside the protocol definition itself |
317 |
| - |
318 | 11 | ### 4. Hard deprecations
|
319 | 12 |
|
320 |
| -#### EEx |
321 |
| - |
322 |
| - * [EEx] `<%#` is deprecated in favor of `<%!--` or `<% #` |
323 |
| - * [EEx] `c:EEx.handle_text/2` is deprecated in favor of `c:EEx.handle_text/3` |
324 |
| - |
325 |
| -#### Elixir |
326 |
| - |
327 |
| - * [Code] Setting `:warnings_as_errors` is deprecated via `Code.put_compiler_option/2`. This must not affect developers, as the `:warnings_as_errors` option is managed by Mix tasks, and not directly used via the `Code` module |
328 |
| - * [Enumerable] Deprecate returning a two-arity function in `Enumerable.slice/1` |
329 |
| - * [List] `List.zip/1` is deprecated in favor of `Enum.zip/1` |
330 |
| - * [Module] Deprecate `Module.eval_quoted/3` in favor of `Code.eval_quoted/3` |
331 |
| - * [Range] Deprecate inferring negative ranges on `Range.new/2` |
332 |
| - * [Tuple] `Tuple.append/2` is deprecated, use `Tuple.insert_at/3` instead |
333 |
| - |
334 |
| -#### Mix |
335 |
| - |
336 |
| - * [mix cmd] Deprecate `mix cmd --app APP` in favor of `mix do --app APP` |
337 |
| - * [Mix.Tasks.Compile] Deprecate `compilers/0` in favor of `Mix.Task.Compiler.compilers/0` |
338 |
| - |
339 |
| -## v1.17 |
| 13 | +## v1.18 |
340 | 14 |
|
341 |
| -The CHANGELOG for v1.17 releases can be found [in the v1.17 branch](https://github.com/elixir-lang/elixir/blob/v1.17/CHANGELOG.md). |
| 15 | +The CHANGELOG for v1.18 releases can be found [in the v1.18 branch](https://github.com/elixir-lang/elixir/blob/v1.18/CHANGELOG.md). |
0 commit comments