Skip to content

Commit b64d748

Browse files
author
José Valim
authored
Prepare for v1.10-rc (#9673)
1 parent 5dd271d commit b64d748

File tree

3 files changed

+116
-22
lines changed

3 files changed

+116
-22
lines changed

CHANGELOG.md

Lines changed: 103 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,98 @@
11
# Changelog for Elixir v1.10
22

3-
## v1.10.0-dev
3+
## Support for Erlang/OTP 21+
44

5-
Elixir v1.10 requires Erlang/OTP 21+.
5+
Elixir v1.10 requires Erlang/OTP 21+, allowing Elixir to integrate with Erlang/OTP's new logger. Currently, this means that the logger level, logger metadata, as well as all log messages are now shared between Erlang and Elixir APIs.
6+
7+
We will continue improving the relationship between the logging systems in future releases. In particular, we plan to expose all log levels and runtime filtering functionalities available in Erlang directly into Elixir in the next Elixir version.
8+
9+
This release also adds two new guards, `is_struct/1` and `is_map_key/2`, thanks to the strict requirement on Erlang/OTP 21+.
10+
11+
## Releases improvements
12+
13+
Elixir v1.9 introduced releases as a mechanism to package self-contained applications. Elixir v1.10 further improves releases with bug fixes and new enhancements based on feedback we got from the community. The highlights are:
14+
15+
* Allow the dual boot system of releases to be disabled on environments that are boot-time sensitive, such as embedded devices
16+
17+
* Track and raise if compile-time configuration is set or changes at runtime (more in the next section)
18+
19+
* Support for easily adding extra files to releases via overlays
20+
21+
* Allow `RELEASE_DISTRIBUTION` to be set to `none` in order to fully disable it
22+
23+
* Add a built-in `:tar` step that automatically packages releases
24+
25+
See the full CHANGELOG for more improvements.
26+
27+
## Improvements to sort-based APIs in Enum
28+
29+
`Enum.sort/1` in Elixir always sorts from lowest to highest. If you want to sort from highest to lowest, you need to call `Enum.sort/2` with a custom sorting function, such as `Enum.sort(collection, &>=/2)`, which is not immediately obvious to someone reading the code.
30+
31+
To make matters worse, comparison operators, such as `<=` and `>=`, perform structural sorting, instead of a semantic one. For example, using `>=` to sort dates descendingly won't yield the correct result. Therefore, to sort dates from more recent to oldest, one has to write `Enum.sort(dates, &(Date.compare(&1, &2) != :lt))`.
32+
33+
Elixir v1.10 streamlines the sorting functions by introducing both `:asc` and `:desc` shortcuts:
34+
35+
Enum.sort(collection, :asc) # the default
36+
Enum.sort(collection, :desc) # in reverse
37+
38+
Furthermore, if you want to perform semantic comparison, you can pass a module that provides the relevant comparison function. For example, to sort dates:
39+
40+
Enum.sort(birth_dates, Date)
41+
Enum.sort(birth_dates, {:asc, Date})
42+
Enum.sort(birth_dates, {:desc, Date})
43+
44+
This new API has also been added to `Enum.sort_by`, `Enum.min_by`, `Enum.max_by`, and friends.
45+
46+
### Tracking of compile-time configuration
47+
48+
All applications in Elixir come with an application environment. This environment is a key-value store that allows us to configure said application. While reading the application environment at runtime is the preferred approach, in some rare occasions you may want to use the application environment to configure the compilation of a certain project. This is often done by calling `Application.get_env/3` outside of a function:
49+
50+
defmodule MyApp.DBClient do
51+
@db_host Application.get_env(:my_app, :db_host, "db.local")
52+
53+
def start_link() do
54+
SomeLib.DBClient.start_link(host: @db_host)
55+
end
56+
end
57+
58+
This approach has one big limitation: if you change the value of the application environment after the code is compiled, the value used at runtime is not going to change! For example, if you are using `mix release` and your `config/releases.exs` has:
59+
60+
config :my_app, :db_host, "db.production"
61+
62+
The new value will have no effect as the code was compiled to connect to "db.local", which is mostly likely unavailable in the production environment.
63+
64+
For those reasons, reading the application environment at runtime should be the first choice. However, if you really have to read the application environment during compilation, Elixir v1.10 introduces a `Application.compile_env/3` function:
65+
66+
@db_host Application.compile_env(:my_app, :db_host, "db.local")
67+
68+
By using `compile_env/3`, Elixir will store the values used during compilation and compare the compilation values with the runtime values whenever your system starts, raising an error in case they differ. This helps developers ensure they are running their production systems with the configuration they intend to.
69+
70+
### Compiler tracing
71+
72+
This release brings enhancements to the Elixir compiler and adds new capabilities for developers to listen to compilation events.
73+
74+
In previous Elixir releases, Elixir would compile a database of cross references between modules (such as function calls, references, structs, etc) for each project. Although developers could traverse this database, they often requested more events or more information to be made available.
75+
76+
In Elixir v1.10, we have replaced this database by compiler tracing. This means that developers can now directly listen to events emitted by the compiler to store and collect all the information they need (and only the information they need).
77+
78+
Elixir itself is already using the new compiler tracing to provide new functionality. In particular, the compiler now checks for undefined function warnings more consistently. In previous versions, we would emit undefined function warnings only for files in `lib`, skipping test files and scripts.
79+
80+
Furthermore, in Elixir v1.10 developers can now disable undefined function warnings directly on the callsite. For example, imagine you have an optional dependency which may not be available in some cases. You can tell the compiler to skip warning on calls to optional modules with:
81+
82+
@compile {:no_warn_undefined, OptionalDependency}
83+
defdelegate my_function_call(arg), to: OptionalDependency
84+
85+
Finally, as consequence of these improvements, some functionality related to `xref` (our previous database), has been deprecated in favor of the new compiler tracing.
86+
87+
### Other enhancements
88+
89+
The calendar data types got many improvements, such as sigil support for third-party calendars, as well as the additions of `DateTime.now!/2`, `DateTime.shift_zone!/3`, and `NaiveDateTime.local_now/0`.
90+
91+
There are many improvements related to the Elixir AST in this release too. First of all, `Code.string_to_quoted/2` has two new options, `:token_metadata` and `:literal_encoder`, that give more control over Elixir's parser. This information has already been available to the Elixir formatter for a couple versions and has now been made public. Furthermore, all public metadata entries in the AST nodes have been extensively documented. These changes alongside the compiler improvements from previous section means tools like Credo and Boundary now have a better foundation to analyze the source code.
92+
93+
Finally, ExUnit comes with two small but important improvements: `ExUnit.CaptureIO` can now be used in tests that run asynchronously and we have added "data-structure diffing" when performing assertions with pattern matching. So now, whenever an assertion such `assert %{field: value} = expression()` fails, ExUnit will show both left-hand and right-hand sides, highlighting the parts that did not match in red.
94+
95+
## v1.10.0
696

797
### 1. Enhancements
898

@@ -14,7 +104,7 @@ Elixir v1.10 requires Erlang/OTP 21+.
14104
* [CLI] Add support for `NO_COLOR` environment variable
15105
* [Code] Add `:token_metadata` and `:literal_encoder` support to `Code.string_to_quoted/2`
16106
* [Code] Add compiler tracing to lift events done by the compiler
17-
* [Code] Return `{:error, :unavalable}` in `Code.ensure_compiled/1` if module is in a deadlock
107+
* [Code] Return `{:error, :unavailable}` in `Code.ensure_compiled/1` if module is in a deadlock
18108
* [DateTime] Add `DateTime.now!/2` and `DateTime.shift_zone!/3`
19109
* [Enum] Speed up getting one random element from enumerables
20110
* [Enum] Add `Enum.frequencies/1`, `Enum.frequencies_by/2`, and `Enum.map_intersperse/2`
@@ -41,6 +131,11 @@ Elixir v1.10 requires Erlang/OTP 21+.
41131
* [ExUnit.Assertions] Support diffs in pattern matching and in `assert_receive`
42132
* [ExUnit.CaptureIO] Supports capturing named devices in asynchronous tests
43133

134+
#### IEx
135+
136+
* [IEx] Warn on circular file imports when loading default `.iex.exs`
137+
* [IEx] Allow customization of the continuation prompt on IEx
138+
44139
#### Logger
45140

46141
* [Logger] Allow `start_options` to be configured on Logger's GenEvent
@@ -57,18 +152,20 @@ Elixir v1.10 requires Erlang/OTP 21+.
57152
* [Mix.Project] Add `Mix.Project.deps_scms/1` that returns deps with their SCMs
58153
* [Mix.Task] Add `Mix.Task.Compiler.after_compiler/2` callback, to simplify compilers that may need to run something at multiple steps
59154

60-
#### IEx
155+
### 2. Bug fixes
61156

62-
* [IEx] Warn on circular file imports when loading default `.iex.exs`
157+
#### EEx
63158

64-
### 2. Bug fixes
159+
* [EEx] Ensure multiline do/end with no spaces compile under trim mode
65160

66161
#### Elixir
67162

163+
* [Enum] Allow positive range slices on infinite streams given to `Enum.slice/2`
68164
* [Kernel] Raise error on functions/guards without implementation
69165
* [Keyword] Ensure keyword replace and update preserve order
70166
* [Module] Raise instead of silently failing when performing a write module operation during after-compile
71167
* [Stream] Close with correct accumulator in `Stream.resource/3` when called for a single-element list
168+
* [Stream] Allow `Stream.cycle/1` to be double nested inside `Stream.cycle/1`
72169
* [URI] Preserve slashes in URIs without authority
73170

74171
#### IEx

lib/elixir/lib/application.ex

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,17 @@ defmodule Application do
8484
8585
This approach has one big limitation: if you change the value of the
8686
application environment after the code is compiled, the value used at
87-
runtime is not gouing to change! For example, if you are using `mix release`
87+
runtime is not going to change! For example, if you are using `mix release`
8888
and your `config/releases.exs` has:
8989
9090
config :my_app, :db_host, "db.production"
9191
92-
This value will no effect! The same will happen if your `config/config.exs`
93-
reads the value from the system, such as:
92+
This value will have no effect as the code was compiled to connect to "db.local",
93+
which is mostly likely unavailable in the production environment.
9494
95-
config :my_app, :db_host, System.get_env("DB_HOST") || "db.local"
96-
97-
For those reasons, reading the application environment at runtime is preferred.
98-
However, if you really have to read the application environment during compilation,
99-
we recomend you to use `compile_env/3` instead:
95+
For those reasons, reading the application environment at runtime should be the
96+
first choice. However, if you really have to read the application environment
97+
during compilation, we recommend you to use `compile_env/3` instead:
10098
10199
@db_host Application.compile_env(:my_app, :db_host, "db.local")
102100

lib/logger/lib/logger.ex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ defmodule Logger do
126126
to the configured value at compilation time. This configuration is
127127
automatically set by Mix and made available as metadata when logging.
128128
129-
130-
131129
* `:compile_time_purge_matching` - purges *at compilation time* all calls
132130
that match the given conditions. This means that `Logger` calls with
133131
level lower than this option will be completely removed at compile time,
@@ -442,8 +440,8 @@ defmodule Logger do
442440
### Erlang/OTP handlers
443441
444442
While Elixir Logger provides backends, Erlang/OTP logger provides handlers.
445-
Conceptually, they represent the same concept, which is the ability to
446-
integrate into the logging system to handle each logged message/event.
443+
They represent the same concept: the ability to integrate into the logging
444+
system to handle each logged message/event.
447445
448446
However, implementation-wise, they have the following differences:
449447
@@ -459,10 +457,11 @@ defmodule Logger do
459457
is no built-in overload protection for Erlang handlers, so it is your
460458
responsibility to implement it
461459
462-
The good news is that developers can use third-party implementations for
460+
The good news is that developers can use third-party implementations of
463461
both Elixir backends and Erlang handlers.
464462
465-
Elixir backends can be configured directly in your config/config.exs:
463+
Elixir backends can be configured directly under the `:logger` application
464+
in your `config/config.exs`:
466465
467466
config :logger, backends: [ACustomBackend]
468467
@@ -476,12 +475,12 @@ defmodule Logger do
476475
:logger.add_handlers(:my_app)
477476
478477
Note we do not recommend configuring Erlang/OTP's logger directly under
479-
the `:kernel` application in your `config/config.exs` like this:
478+
the `:kernel` application in your `config/config.exs`, like this:
480479
481480
config :kernel, :logger, ...
482481
483482
This is because by the time Elixir starts, Erlang's kernel has already
484-
been started, which makes it impossible to configure it.
483+
been started, which means the configuration above would have no effect.
485484
"""
486485

487486
@type level :: :error | :warn | :info | :debug

0 commit comments

Comments
 (0)