Skip to content

Commit 6549d20

Browse files
nasercajosevalim
andauthored
Precompile runtime module paths (#12294)
Co-authored-by: José Valim <[email protected]>
1 parent 71d2791 commit 6549d20

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

lib/elixir/lib/kernel/parallel_compiler.ex

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,6 @@ defmodule Kernel.ParallelCompiler do
271271
for {{:module, module}, _} <- result,
272272
do: module
273273

274-
runtime_modules =
275-
for module <- runtime_modules,
276-
path = :code.which(module),
277-
is_list(path) and path != [],
278-
do: {module, path}
279-
280274
profile_checker(profile, compiled_modules, runtime_modules, fn ->
281275
Module.ParallelChecker.verify(checker, runtime_modules)
282276
end)

lib/elixir/lib/module/parallel_checker.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ defmodule Module.ParallelChecker do
6262
if is_map(info) do
6363
info
6464
else
65-
info |> File.read!() |> maybe_module_map(module)
65+
case File.read(info) do
66+
{:ok, binary} -> maybe_module_map(binary, module)
67+
{:error, _} -> nil
68+
end
6669
end
6770

6871
module_map && cache_from_module_map(ets, module_map)
@@ -136,7 +139,7 @@ defmodule Module.ParallelChecker do
136139
the modules and adds the ExCk chunk to the binaries. Returns the updated
137140
list of warnings from the verification.
138141
"""
139-
@spec verify(pid(), [{module(), binary()}]) :: [warning()]
142+
@spec verify(pid(), [{module(), Path.t()}]) :: [warning()]
140143
def verify(checker, runtime_files) do
141144
for {module, file} <- runtime_files do
142145
spawn({self(), checker}, module, file)

lib/mix/lib/mix/compilers/elixir.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,11 @@ defmodule Mix.Compilers.Elixir do
465465

466466
modules_set = Map.from_keys(modules, true)
467467
{_, runtime_modules} = fixpoint_runtime_modules(sources, modules_set)
468-
{:runtime, runtime_modules, warnings}
468+
469+
runtime_paths =
470+
Enum.map(runtime_modules, &{&1, Path.join(compile_path, Atom.to_string(&1) <> ".beam")})
471+
472+
{:runtime, runtime_paths, warnings}
469473
else
470474
Mix.Utils.compiling_n(length(changed), :ex)
471475

0 commit comments

Comments
 (0)