Skip to content

Commit 0303993

Browse files
author
José Valim
committed
Clean up compiler checks
1 parent ba6c6da commit 0303993

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

lib/elixir/lib/kernel/parallel_compiler.ex

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,19 @@ defmodule Kernel.ParallelCompiler do
8888
end
8989

9090
# Release waiting processes
91-
defp spawn_compilers(%{entries: [{h, kind} | t], waiting: waiting} = state) do
91+
defp spawn_compilers(%{entries: [{ref, found} | t], waiting: waiting} = state) do
9292
waiting =
93-
case List.keytake(waiting, h, 1) do
94-
{{_kind, ^h, ref, _module, _defining}, waiting} ->
95-
send h, {ref, kind}
93+
case List.keytake(waiting, ref, 2) do
94+
{{_kind, pid, ^ref, _on, _defining}, waiting} ->
95+
send pid, {ref, found}
9696
waiting
9797
nil ->
9898
waiting
9999
end
100100
spawn_compilers(%{state | entries: t, waiting: waiting})
101101
end
102102

103-
defp spawn_compilers(%{entries: [h | t], queued: queued, output: output, options: options} = state) do
103+
defp spawn_compilers(%{entries: [file | files], queued: queued, output: output, options: options} = state) do
104104
parent = self()
105105

106106
{pid, ref} =
@@ -111,11 +111,11 @@ defmodule Kernel.ParallelCompiler do
111111

112112
exit(try do
113113
_ = if output do
114-
:elixir_compiler.file_to_path(h, output)
114+
:elixir_compiler.file_to_path(file, output)
115115
else
116-
:elixir_compiler.file(h, Keyword.get(options, :dest))
116+
:elixir_compiler.file(file, Keyword.get(options, :dest))
117117
end
118-
{:shutdown, h}
118+
{:shutdown, file}
119119
catch
120120
kind, reason ->
121121
{:failure, kind, reason, System.stacktrace}
@@ -125,8 +125,8 @@ defmodule Kernel.ParallelCompiler do
125125
timeout = Keyword.get(options, :long_compilation_threshold, 5) * 1_000
126126
timer_ref = Process.send_after(self(), {:timed_out, pid}, timeout)
127127

128-
new_queued = [{pid, ref, h, timer_ref} | queued]
129-
spawn_compilers(%{state | entries: t, queued: new_queued})
128+
new_queued = [{pid, ref, file, timer_ref} | queued]
129+
spawn_compilers(%{state | entries: files, queued: new_queued})
130130
end
131131

132132
# No more files, nothing waiting, queue is empty, we are done
@@ -137,8 +137,9 @@ defmodule Kernel.ParallelCompiler do
137137
# Queued x, waiting for x: POSSIBLE ERROR! Release processes so we get the failures
138138
defp spawn_compilers(%{entries: [], waiting: waiting, queued: queued} = state) when length(waiting) == length(queued) do
139139
entries = for {pid, _, _, _} <- queued,
140-
on = waiting_on_without_definition(waiting, pid),
141-
do: {on, {pid, :not_found}}
140+
entry = waiting_on_without_definition(waiting, pid),
141+
{_, _, ref, on, _} = entry,
142+
do: {on, {ref, :not_found}}
142143

143144
# Instead of releasing all files at once, we release them in groups
144145
# based on the module they are waiting on. We pick the module being
@@ -168,11 +169,11 @@ defmodule Kernel.ParallelCompiler do
168169
end
169170

170171
defp waiting_on_without_definition(waiting, pid) do
171-
{_kind, ^pid, _, on, _defining} = List.keyfind(waiting, pid, 1)
172+
{_, ^pid, _, on, _} = entry = List.keyfind(waiting, pid, 1)
172173
if Enum.any?(waiting, fn {_, _, _, _, defining} -> on in defining end) do
173174
nil
174175
else
175-
on
176+
entry
176177
end
177178
end
178179

@@ -182,9 +183,9 @@ defmodule Kernel.ParallelCompiler do
182183

183184
receive do
184185
{:struct_available, module} ->
185-
available = for {:struct, pid, _, waiting_module, _defining} <- waiting,
186+
available = for {:struct, _, ref, waiting_module, _defining} <- waiting,
186187
module == waiting_module,
187-
do: {pid, :found}
188+
do: {ref, :found}
188189

189190
spawn_compilers(%{state | entries: available ++ entries, result: [{:struct, module} | result]})
190191

@@ -196,9 +197,9 @@ defmodule Kernel.ParallelCompiler do
196197
# Release the module loader which is waiting for an ack
197198
send child, {ref, :ack}
198199

199-
available = for {:module, pid, _, waiting_module, _defining} <- waiting,
200+
available = for {:module, _, ref, waiting_module, _defining} <- waiting,
200201
module == waiting_module,
201-
do: {pid, :found}
202+
do: {ref, :found}
202203

203204
cancel_waiting_timer(queued, child)
204205

lib/mix/lib/mix/dep/elixir_scm.ex

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,19 @@ defmodule Mix.Dep.ElixirSCM do
2020
end
2121

2222
def read(manifest_path \\ Mix.Project.manifest_path) do
23-
case manifest(manifest_path) |> File.read() do
23+
case File.read(manifest(manifest_path)) do
2424
{:ok, contents} ->
2525
try do
26-
:erlang.binary_to_term(contents)
26+
:erlang.binary_to_term(contents)
2727
else
2828
{@manifest_vsn, vsn, scm} ->
2929
{:ok, vsn, scm}
30-
3130
_ ->
3231
{:ok, "1.0.0", nil} # Force old version if file exists but old format
3332
rescue
3433
_ ->
3534
{:ok, "1.0.0", nil} # Force old version if file exists but old format
3635
end
37-
3836
_ ->
3937
:error
4038
end

lib/mix/lib/mix/tasks/compile.protocols.ex

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,14 @@ defmodule Mix.Tasks.Compile.Protocols do
133133

134134
defp read_manifest(manifest, output) do
135135
try do
136-
manifest |> File.read!() |> :erlang.binary_to_term()
137-
else
138-
[@manifest_vsn | t] ->
139-
t
140-
136+
[@manifest_vsn | t] =
137+
manifest |> File.read! |> :erlang.binary_to_term()
138+
t
139+
rescue
141140
_ ->
142-
# If manifest is out of date, remove old files
141+
# If there is no manifest or it is out of date, remove old files
143142
File.rm_rf(output)
144143
[]
145-
rescue
146-
_ -> []
147144
end
148145
end
149146

0 commit comments

Comments
 (0)