Skip to content

Commit 66ac6a3

Browse files
fertapricJosé Valim
authored andcommitted
Ensure reproducible builds (boostrapping issue) (#9385)
During bootstrap, the generated AST for the `defexception` macro does not include import metadata when calling to Kernel functions without using the qualified name. That's not the case when the Kernel is later recompiled. When compiling the standard library, exceptions like `FunctionClauseError` were generating different ASTs (different metadata) depending on if they were compiled with the bootstrapped Kernel or the later compiled one.
1 parent 50caa25 commit 66ac6a3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4433,14 +4433,18 @@ defmodule Kernel do
44334433
defoverridable message: 1
44344434

44354435
@impl true
4436-
def exception(msg) when is_binary(msg) do
4436+
def exception(msg) when Kernel.is_binary(msg) do
44374437
exception(message: msg)
44384438
end
44394439
end
44404440

44414441
# TODO: Change the implementation on v2.0 to simply call Kernel.struct!/2
4442+
# Calls to Kernel functions must be fully-qualified to ensure
4443+
# reproducible builds; otherwise, this macro will generate ASTs
4444+
# with different metadata (:import, :context) depending on if
4445+
# it is the bootstrapped version or not.
44424446
@impl true
4443-
def exception(args) when is_list(args) do
4447+
def exception(args) when Kernel.is_list(args) do
44444448
struct = __struct__()
44454449
{valid, invalid} = Enum.split_with(args, fn {k, _} -> Map.has_key?(struct, k) end)
44464450

@@ -4451,9 +4455,9 @@ defmodule Kernel do
44514455
_ ->
44524456
IO.warn(
44534457
"the following fields are unknown when raising " <>
4454-
"#{inspect(__MODULE__)}: #{inspect(invalid)}. " <>
4458+
"#{Kernel.inspect(__MODULE__)}: #{Kernel.inspect(invalid)}. " <>
44554459
"Please make sure to only give known fields when raising " <>
4456-
"or redefine #{inspect(__MODULE__)}.exception/1 to " <>
4460+
"or redefine #{Kernel.inspect(__MODULE__)}.exception/1 to " <>
44574461
"discard unknown fields. Future Elixir versions will raise on " <>
44584462
"unknown fields given to raise/2"
44594463
)

0 commit comments

Comments
 (0)