You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+170-5Lines changed: 170 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,117 @@
1
1
# Changelog for Elixir v1.18
2
2
3
-
TODO.
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
4
5
5
## Type system improvements
6
6
7
+
The most exciting change in Elixir v1.18 is typing 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
+
defmoduleUserdo
11
+
defstruct [:age, :car_choice]
12
+
13
+
defdrive(%User{age: age, car_choice: car}, cars_choices) when age >=18do
14
+
if car in car_choices do
15
+
{:ok, car}
16
+
else
17
+
{:error, :no_choice}
18
+
end
19
+
end
20
+
21
+
defdrive(%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()}` or `{: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:
> 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
+
caseUser.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
+
7
102
* Type inference of patterns (typing inference of guards will be part of an upcoming release)
8
103
9
104
* Type checking of all language constructs, including local and remote calls, except `for`, `with`, and closures
10
105
11
-
* Type checking of all `Kernel` and conversion functions inlined by the compiler
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
12
109
13
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
14
111
15
112
* Detection of clauses and patterns that will never match from `case`, `cond`, and `=`
16
113
17
-
* Detection of unused clauses from private functions
114
+
* Detection of unused clauses in private functions
18
115
19
116
## ExUnit improvements
20
117
@@ -43,11 +140,68 @@ With features like async tests, suite partitioning, and now grouping, Elixir dev
43
140
44
141
## `mix format --migrate`
45
142
46
-
TODO.
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
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() => _}`|
47
201
48
202
## Potential incompatibilities
49
203
50
-
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+.
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).
51
205
52
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:
53
207
@@ -72,6 +226,7 @@ You may also prefer to write using guards:
72
226
#### Elixir
73
227
74
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`
75
230
*[Code] Support several migration options in `Code.format_string!/2`
76
231
*[Code] Add parenthesis around `--` and `---` in `Code.format_string!/2` to make precedence clearer
77
232
*[Code] Include more metadata in `Code.string_to_quoted/2` when `token_metadata: true` to help compute ranges from the AST
@@ -86,18 +241,23 @@ You may also prefer to write using guards:
86
241
*[Kernel] Perform validation of root AST nodes in `unquote` and `unquote_splicing` to catch bugs earlier
87
242
*[Kernel] Add source, behaviour, and record information to Docs chunk metadata
88
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
89
245
*[List] Add `List.ends_with?/2`
90
246
*[Macro] Improve `dbg` handling of `if/2`, `with/1` and of code blocks
91
247
*[Macro] Add `Macro.struct_info!/2` to return struct information mirroring `mod.__info__(:struct)`
92
248
*[Registry] Add `Registry.lock/3` for local locking
93
249
*[PartitionSupervisor] Add `PartitionSupervisor.resize!/2` to resize the number of partitions in a supervisor (up to the limit it was started with)
94
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__` as optional macro callback to `Protocol`, no longer requiring empty implementations
95
253
*[String] Inspect special whitespace and zero-width characters using their Unicode representation
254
+
*[String] Update Unicode to 16.0
96
255
97
256
#### ExUnit
98
257
99
258
*[ExUnit] Support parameterized tests on `ExUnit.Case`
100
259
*[ExUnit] Support test groups: tests in the same group never run concurrently
260
+
*[ExUnit.Case] Add `test_pid` as a tag
101
261
102
262
#### IEx
103
263
@@ -109,6 +269,7 @@ You may also prefer to write using guards:
109
269
*[mix compile] Ensure only a single operating system process can compile at a given time
110
270
*[mix deps.get] Ensure only a single operating system process can fetch deps at a given time
111
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
112
273
*[mix test] Taint failure manifest if requiring or compiling tests fail
113
274
*[Mix.Project] Add a `:listeners` configuration to listen to compilation events from the current and other operating system processes
114
275
*[Mix.Task.Compiler] Add API for fetching all persisted compiler diagnostics
@@ -122,13 +283,15 @@ You may also prefer to write using guards:
122
283
*[Code.Formatter] Fix formatter adding extra escapes to quoted remote calls
123
284
*[Code.Fragment] Properly handle keyword keys as their own entry
0 commit comments